Skip to content

Commit

Permalink
egui_glow: Only disable sRGB framebuffer on supported platforms (#3994)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nopey authored Feb 8, 2024
1 parent 377f86e commit 21f08af
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/egui_glow/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -253,6 +261,7 @@ impl Painter {
is_webgl_1,
vao,
srgb_textures,
supports_srgb_framebuffer,
vbo,
element_array_buffer,
textures: Default::default(),
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 21f08af

Please sign in to comment.