Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alpha blending in WebGL backends #650

Merged
merged 10 commits into from
Aug 25, 2021
Prev Previous commit
Next Next commit
Add comments
  • Loading branch information
AsmPrgmC3 committed Aug 25, 2021
commit 64e41be8ab3c26380dd1b541faed297a3c846d7b
16 changes: 8 additions & 8 deletions egui_web/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ impl WebBackend {
pub fn new(canvas_id: &str) -> Result<Self, JsValue> {
let ctx = egui::CtxRef::default();

let painter: Box<dyn Painter> =
if let Ok(webgl2_painter) = webgl2::WebGl2Painter::new(canvas_id) {
console_log("Using WebGL2 backend");
Box::new(webgl2_painter)
} else {
console_log("Falling back to WebGL1 backend");
Box::new(webgl1::WebGlPainter::new(canvas_id)?)
};
let painter: Box<dyn Painter> = Box::new(webgl1::WebGlPainter::new(canvas_id)?);
// if let Ok(webgl2_painter) = webgl2::WebGl2Painter::new(canvas_id) {
// console_log("Using WebGL2 backend");
// Box::new(webgl2_painter)
// } else {
// console_log("Falling back to WebGL1 backend");
// Box::new(webgl1::WebGlPainter::new(canvas_id)?)
// };

Ok(Self {
egui_ctx: ctx,
Expand Down
6 changes: 6 additions & 0 deletions egui_web/src/webgl1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ impl crate::Painter for WebGlPainter {
}
}

/// Uses a framebuffer to render everything in linear color space and convert it back to sRGB
/// in a separate "post processing" step
struct PostProcess {
gl: Gl,
pos_buffer: WebGlBuffer,
Expand All @@ -521,6 +523,8 @@ impl PostProcess {
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::NEAREST as i32);
gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::NEAREST as i32);
gl.pixel_storei(Gl::UNPACK_ALIGNMENT, 1);
// TODO: https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
// Dark colors are slightly wrong when not using SRGB8_ALPHA8 format
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
Gl::TEXTURE_2D,
0,
Expand Down Expand Up @@ -597,6 +601,8 @@ impl PostProcess {
if (width, height) != self.texture_size {
gl.bind_texture(Gl::TEXTURE_2D, Some(&self.texture));
gl.pixel_storei(Gl::UNPACK_ALIGNMENT, 1);
// TODO: https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
// Dark colors are slightly wrong when not using SRGB8_ALPHA8 format
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
Gl::TEXTURE_2D,
0,
Expand Down
2 changes: 2 additions & 0 deletions egui_web/src/webgl2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ impl crate::Painter for WebGl2Painter {
}
}

/// Uses a framebuffer to render everything in linear color space and convert it back to sRGB
/// in a separate "post processing" step
struct PostProcess {
gl: Gl,
pos_buffer: WebGlBuffer,
Expand Down