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).

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

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 <servo/servo#30782>
This commit is contained in:
Magnus Larsen 2024-02-07 23:54:14 -08:00 committed by GitHub
parent 377f86efb5
commit 21f08afcbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 1 deletions

View File

@ -86,6 +86,7 @@ pub struct Painter {
is_webgl_1: bool, is_webgl_1: bool,
vao: crate::vao::VertexArrayObject, vao: crate::vao::VertexArrayObject,
srgb_textures: bool, srgb_textures: bool,
supports_srgb_framebuffer: bool,
vbo: glow::Buffer, vbo: glow::Buffer,
element_array_buffer: glow::Buffer, element_array_buffer: glow::Buffer,
@ -173,6 +174,13 @@ impl Painter {
}); });
log::debug!("SRGB texture Support: {:?}", srgb_textures); 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 { unsafe {
let vert = compile_shader( let vert = compile_shader(
&gl, &gl,
@ -253,6 +261,7 @@ impl Painter {
is_webgl_1, is_webgl_1,
vao, vao,
srgb_textures, srgb_textures,
supports_srgb_framebuffer,
vbo, vbo,
element_array_buffer, element_array_buffer,
textures: Default::default(), textures: Default::default(),
@ -314,7 +323,7 @@ impl Painter {
glow::ONE, glow::ONE,
); );
if !cfg!(target_arch = "wasm32") { if self.supports_srgb_framebuffer {
self.gl.disable(glow::FRAMEBUFFER_SRGB); self.gl.disable(glow::FRAMEBUFFER_SRGB);
check_for_gl_error!(&self.gl, "FRAMEBUFFER_SRGB"); check_for_gl_error!(&self.gl, "FRAMEBUFFER_SRGB");
} }