From 21f08afcbbef419472c4b815226e714dac6b3da4 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Wed, 7 Feb 2024 23:54:14 -0800 Subject: [PATCH] egui_glow: Only disable sRGB framebuffer on supported platforms (#3994) This solves a GL_INVALID_ENUM error common on Windows (occurs on my Windows 10 machine with a GTX 1070 Ti). ARB_framebuffer_SRGB is entirely unsupported on WebGL, hence why latest egui (master branch) doesn't try to disable SRGB framebuffers on wasm32 and this PR's code doesn't even check for ARB_framebuffer_sRGB on wasm32. * For --- crates/egui_glow/src/painter.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/egui_glow/src/painter.rs b/crates/egui_glow/src/painter.rs index b1278ac39d5..5116c95d585 100644 --- a/crates/egui_glow/src/painter.rs +++ b/crates/egui_glow/src/painter.rs @@ -86,6 +86,7 @@ pub struct Painter { is_webgl_1: bool, vao: crate::vao::VertexArrayObject, srgb_textures: bool, + supports_srgb_framebuffer: bool, vbo: glow::Buffer, element_array_buffer: glow::Buffer, @@ -173,6 +174,13 @@ impl Painter { }); log::debug!("SRGB texture Support: {:?}", srgb_textures); + let supports_srgb_framebuffer = !cfg!(target_arch = "wasm32") + && supported_extensions.iter().any(|extension| { + // {GL,GLX,WGL}_ARB_framebuffer_sRGB, … + extension.ends_with("ARB_framebuffer_sRGB") + }); + log::debug!("SRGB framebuffer Support: {:?}", supports_srgb_framebuffer); + unsafe { let vert = compile_shader( &gl, @@ -253,6 +261,7 @@ impl Painter { is_webgl_1, vao, srgb_textures, + supports_srgb_framebuffer, vbo, element_array_buffer, textures: Default::default(), @@ -314,7 +323,7 @@ impl Painter { glow::ONE, ); - if !cfg!(target_arch = "wasm32") { + if self.supports_srgb_framebuffer { self.gl.disable(glow::FRAMEBUFFER_SRGB); check_for_gl_error!(&self.gl, "FRAMEBUFFER_SRGB"); }