added `view_formats` details to the docs

pull/448/head
Benjamin Hansen 1 year ago
parent 7227f8d169
commit 9f2ecaec4a

@ -80,7 +80,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -79,7 +79,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -78,7 +78,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -80,7 +80,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -141,7 +141,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -137,7 +137,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -142,7 +142,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -142,7 +142,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -292,7 +292,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -292,7 +292,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -346,7 +346,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -353,7 +353,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -535,7 +535,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -363,7 +363,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -306,7 +306,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -398,7 +398,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -398,7 +398,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -278,7 +278,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -280,7 +280,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -217,7 +217,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -80,7 +80,7 @@ impl Display {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -283,7 +283,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -87,7 +87,7 @@ impl Render {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -277,7 +277,7 @@ impl State {
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);

@ -169,7 +169,7 @@ The `limits` field describes the limit of certain types of resources that we can
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![surface_format],
view_formats: vec![],
};
surface.configure(&device, &config);
```
@ -190,16 +190,20 @@ Make sure that the width and height of the `SurfaceTexture` are not 0, as that c
<div class="note">
If you want to let your users pick what `PresentMode` they use, you can use [Surface::get_supported_modes()](https://docs.rs/wgpu/latest/wgpu/struct.Surface.html#method.get_supported_modes) to get a list of all the `PresentMode`s the surface supports:
If you want to let your users pick what `PresentMode` they use, you can use [SurfaceCapabilities::present_modes](https://docs.rs/wgpu/latest/wgpu/struct.SurfaceCapabilities.html#structfield.present_modes) to get a list of all the `PresentMode`s the surface supports:
```rust
let modes = surface.get_supported_modes(&adapter);
let modes = &surface_caps.present_modes;
```
Regardless, `PresentMode::Fifo` will always be supported, and `PresentMode::AutoVsync` and `PresentMode::AutoNoVsync` have fallback support and therefore will work on all platforms.
</div>
`alpha_mode` is honestly not something I'm familiar with. I believe it has something to do with transparent windows, but feel free to open a pull request. For now we'll just use the first `AlphaMode` in the list given by `surface_caps`.
`view_formats` is a list of `TextureFormat`s that you can use when creating `TextureView`s (we'll cover those briefly later in the this tutorial as well as more in depth [in the texture tutorial](../beginner/tutorial5-textures)). As of writing this means that if your surface is srgb color space, you can create a texture view that uses a linear color space.
Now that we've configured our surface properly we can add these new fields at the end of the method.
```rust

@ -65,6 +65,14 @@ let diffuse_texture = device.create_texture(
// COPY_DST means that we want to copy data to this texture
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("diffuse_texture"),
// This is the same as with the SurfaceConfig. It
// specifies what texture formats can be used to
// create TextureViews for this texture. The base
// texture format (Rgba8UnormSrgb in this case) is
// always supported. Note that using a different
// texture format is not supported on the WebGL2
// backend.
view_formats: &[],
}
);
```
@ -493,6 +501,7 @@ impl Texture {
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
view_formats: &[],
}
);

@ -442,6 +442,12 @@ pub fn from_image(
is_normal_map: bool, // NEW!
) -> Result<Self> {
// ...
// NEW!
let format = if is_normal_map {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Rgba8UnormSrgb
};
let texture = device.create_texture(&wgpu::TextureDescriptor {
label,
size,
@ -449,12 +455,9 @@ pub fn from_image(
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
// UPDATED!
format: if is_normal_map {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Rgba8UnormSrgb
},
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});
// ...

Loading…
Cancel
Save