From f8a63c405591f8f8f92595684e0d5c957aec2a53 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 8 Jan 2022 12:19:11 -0500 Subject: [PATCH] hal/gles: small fixes for external context --- wgpu-hal/src/gles/adapter.rs | 3 ++- wgpu-hal/src/gles/egl.rs | 4 ++++ wgpu-hal/src/gles/queue.rs | 12 +++++++----- wgpu-hal/src/gles/web.rs | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 9c882c8c4..b8beef5ee 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -442,7 +442,8 @@ impl super::Adapter { let r = renderer.to_lowercase(); // Check for Mesa sRGB clear bug. See // [`super::PrivateCapabilities::MESA_I915_SRGB_SHADER_CLEAR`]. - if r.contains("mesa") + if context.is_owned() + && r.contains("mesa") && r.contains("intel") && r.split(&[' ', '(', ')'][..]) .any(|substr| substr.len() == 3 && substr.chars().nth(2) == Some('l')) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 6b18339da..ea49dfb3e 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -293,6 +293,10 @@ unsafe impl Sync for AdapterContext {} unsafe impl Send for AdapterContext {} impl AdapterContext { + pub fn is_owned(&self) -> bool { + self.egl.is_some() + } + #[cfg(feature = "renderdoc")] pub fn raw_context(&self) -> *mut raw::c_void { match self.egl { diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 18e143994..6e735779a 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -46,11 +46,13 @@ impl super::Queue { gl.draw_buffers(&[glow::COLOR_ATTACHMENT0 + draw_buffer]); gl.draw_arrays(glow::TRIANGLES, 0, 3); - // Reset the draw buffers to what they were before the clear - let indices = (0..self.draw_buffer_count as u32) - .map(|i| glow::COLOR_ATTACHMENT0 + i) - .collect::>(); - gl.draw_buffers(&indices); + if self.draw_buffer_count != 0 { + // Reset the draw buffers to what they were before the clear + let indices = (0..self.draw_buffer_count as u32) + .map(|i| glow::COLOR_ATTACHMENT0 + i) + .collect::>(); + gl.draw_buffers(&indices); + } #[cfg(not(target_arch = "wasm32"))] for draw_buffer in 0..self.draw_buffer_count as u32 { gl.disable_draw_buffer(glow::BLEND, draw_buffer); diff --git a/wgpu-hal/src/gles/web.rs b/wgpu-hal/src/gles/web.rs index 00fdcb528..1c0ee6a9d 100644 --- a/wgpu-hal/src/gles/web.rs +++ b/wgpu-hal/src/gles/web.rs @@ -11,6 +11,10 @@ pub struct AdapterContext { } impl AdapterContext { + pub fn is_owned(&self) -> bool { + false + } + /// Obtain a lock to the EGL context and get handle to the [`glow::Context`] that can be used to /// do rendering. #[track_caller]