Skip to content

Commit c5c5ae8

Browse files
nickguletskiiEriKWDev
authored andcommitted
Issue SetDrawColorBuffers before clearing buffers in GLES, use clear_buffer_f32_slice instead of clear (gfx-rs#5666)
* Issue SetDrawColorBuffers commands before issuing ClearColor This is necessary for glClearBuffer calls to work correctly on some machines (e.g. AMD Renoir graphics running on Linux). Without this, glClearBuffer calls are ignored. * Use clear_buffer_f32_slice instead of gl.clear to suppress WebGL warnings This fixes the following WebGL warning: "WebGL warning: drawBuffers: `buffers[i]` must be NONE or COLOR_ATTACHMENTi." When using native OpenGL, it is acceptable to call glDrawBuffers with an array of buffers where i != COLOR_ATTACHMENTi. In WebGL, this is not allowed. * Run cargo fmt * Add changes for PR gfx-rsGH-5666 to the CHANGELOG
1 parent e65dc4e commit c5c5ae8

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ By @stefnotch in [#5410](https://github.com/gfx-rs/wgpu/pull/5410)
8181
#### GLES / OpenGL
8282

8383
- Fix regression on OpenGL (EGL) where non-sRGB still used sRGB [#5642](https://github.com/gfx-rs/wgpu/pull/5642)
84+
- Fix `ClearColorF`, `ClearColorU` and `ClearColorI` commands being issued before `SetDrawColorBuffers` [#5666](https://github.com/gfx-rs/wgpu/pull/5666)
85+
- Replace `glClear` with `glClearBufferF` because `glDrawBuffers` requires that the ith buffer must be `COLOR_ATTACHMENTi` or `NONE` [#5666](https://github.com/gfx-rs/wgpu/pull/5666)
8486

8587
## v0.20.0 (2024-04-28)
8688

wgpu-hal/src/gles/command.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ impl crate::CommandEncoder for super::CommandEncoder {
608608
depth: 0.0..1.0,
609609
});
610610

611+
if !rendering_to_external_framebuffer {
612+
// set the draw buffers and states
613+
self.cmd_buffer
614+
.commands
615+
.push(C::SetDrawColorBuffers(desc.color_attachments.len() as u8));
616+
}
617+
611618
// issue the clears
612619
for (i, cat) in desc
613620
.color_attachments
@@ -638,13 +645,6 @@ impl crate::CommandEncoder for super::CommandEncoder {
638645
}
639646
}
640647

641-
if !rendering_to_external_framebuffer {
642-
// set the draw buffers and states
643-
self.cmd_buffer
644-
.commands
645-
.push(C::SetDrawColorBuffers(desc.color_attachments.len() as u8));
646-
}
647-
648648
if let Some(ref dsat) = desc.depth_stencil_attachment {
649649
let clear_depth = !dsat.depth_ops.contains(crate::AttachmentOps::LOAD);
650650
let clear_stencil = !dsat.stencil_ops.contains(crate::AttachmentOps::LOAD);

wgpu-hal/src/gles/queue.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,13 +1075,7 @@ impl super::Queue {
10751075
{
10761076
unsafe { self.perform_shader_clear(gl, draw_buffer, *color) };
10771077
} else {
1078-
// Prefer `clear` as `clear_buffer` functions have issues on Sandy Bridge
1079-
// on Windows.
1080-
unsafe {
1081-
gl.draw_buffers(&[glow::COLOR_ATTACHMENT0 + draw_buffer]);
1082-
gl.clear_color(color[0], color[1], color[2], color[3]);
1083-
gl.clear(glow::COLOR_BUFFER_BIT);
1084-
}
1078+
unsafe { gl.clear_buffer_f32_slice(glow::COLOR, draw_buffer, color) };
10851079
}
10861080
}
10871081
C::ClearColorU(draw_buffer, ref color) => {

0 commit comments

Comments
 (0)