Implement TextureFormat::Stencil8 + add stencil example #3343
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
Fixes #3196
Description
It's common for 2d applications to use the stencil buffer without depth buffers, but wgpu so far required you to allocate (at minimum) a
Depth24PlusStencil8
, which can be wasteful.Stencil8
will, on supported platforms, only contain the stencil buffer and nothing else.It currently maps to:
S8_UINT
,D24_UNORM_S8_UINT
orD32_SFLOAT_S8_UINT
GL_STENCIL_INDEX8
MTLPixelFormat.stencil8
DXGI_FORMAT_D24_UNORM_S8_UINT
Depth24PlusStencil8
DXGI_FORMAT_D24_UNORM_S8_UINT
Depth24PlusStencil8
Testing
In addition to adding the new format to the existing
clear_texture_tests
, I've added an example calledstencil-triangles
which shows how to use stencil testing in wgpu.All tests* pass for me on Windows and Mac.
*except for shadow on Mac, and water on Windows. Those seem to be known bugs and unrelated to my code though.
I've also confirmed that a large project I contribute to, Ruffle, runs and passes all its visual tests using Stencil8 on DX12, Vulkan, and GLES. I'm not able to run it on Metal currently.