diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c4424464e..362633008e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ Bottom level categories: #### GLES - Surfaces support now `TextureFormat::Rgba8Unorm` and (non-web only) `TextureFormat::Bgra8Unorm`. By @Wumpf in [#3070](https://github.com/gfx-rs/wgpu/pull/3070) +- Support alpha to coverage. By @Wumpf in [#3156](https://github.com/gfx-rs/wgpu/pull/3156) ### Bug Fixes diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index beaf600e6e..4a9ee22d07 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -20,6 +20,7 @@ pub(super) struct State { color_targets: ArrayVec, stencil: super::StencilState, depth_bias: wgt::DepthBiasState, + alpha_to_coverage_enabled: bool, samplers: [Option; super::MAX_SAMPLERS], texture_slots: [TextureSlotDesc; super::MAX_TEXTURE_SLOTS], render_size: wgt::Extent3d, @@ -795,6 +796,14 @@ impl crate::CommandEncoder for super::CommandEncoder { .commands .push(C::ConfigureDepthStencil(aspects)); + // set multisampling state + if pipeline.alpha_to_coverage_enabled != self.state.alpha_to_coverage_enabled { + self.state.alpha_to_coverage_enabled = pipeline.alpha_to_coverage_enabled; + self.cmd_buffer + .commands + .push(C::SetAlphaToCoverage(pipeline.alpha_to_coverage_enabled)); + } + // set blend states if self.state.color_targets[..] != pipeline.color_targets[..] { if pipeline diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 96be1f569b..196894c0a2 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -1090,6 +1090,7 @@ impl crate::Device for super::Device { .depth_stencil .as_ref() .map(|ds| conv::map_stencil(&ds.stencil)), + alpha_to_coverage_enabled: desc.multisample.alpha_to_coverage_enabled, }) } unsafe fn destroy_render_pipeline(&self, pipeline: super::RenderPipeline) { diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 929f369833..bad5c08b91 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -502,6 +502,7 @@ pub struct RenderPipeline { depth: Option, depth_bias: wgt::DepthBiasState, stencil: Option, + alpha_to_coverage_enabled: bool, } // SAFE: WASM doesn't have threads @@ -742,6 +743,7 @@ enum Command { SetDepth(DepthState), SetDepthBias(wgt::DepthBiasState), ConfigureDepthStencil(crate::FormatAspects), + SetAlphaToCoverage(bool), SetVertexAttribute { buffer: Option, buffer_desc: VertexBufferDesc, diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 69edfd5c86..35e55befca 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -992,6 +992,13 @@ impl super::Queue { gl.disable(glow::STENCIL_TEST); } } + C::SetAlphaToCoverage(enabled) => { + if enabled { + gl.enable(glow::SAMPLE_ALPHA_TO_COVERAGE); + } else { + gl.disable(glow::SAMPLE_ALPHA_TO_COVERAGE); + } + } C::SetProgram(program) => { gl.use_program(Some(program)); }