mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
Switch to using glow as the default renderer both on native and the web (#1020)
* Switch to using glow as the default renderer both on native and the web * Simplify code to find WebGL context for glow * egui_web: make webgl an opt-in feature * Stop using deprecated WEBGL_debug_renderer_info
This commit is contained in:
@@ -62,7 +62,7 @@ fn requires_brightening(canvas: &web_sys::HtmlCanvasElement) -> bool {
|
||||
.dyn_into::<WebGlRenderingContext>()
|
||||
.unwrap();
|
||||
let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap();
|
||||
crate::webgl1::is_safari_and_webkit_gtk(&gl) && !user_agent.contains("Mac OS X")
|
||||
crate::is_safari_and_webkit_gtk(&gl) && !user_agent.contains("Mac OS X")
|
||||
}
|
||||
|
||||
impl crate::Painter for WrappedGlowPainter {
|
||||
@@ -116,32 +116,28 @@ impl crate::Painter for WrappedGlowPainter {
|
||||
}
|
||||
|
||||
pub fn init_glow_context_from_canvas(canvas: &HtmlCanvasElement) -> glow::Context {
|
||||
let ctx = canvas.get_context("webgl2");
|
||||
if let Ok(ctx) = ctx {
|
||||
crate::console_log("webgl found");
|
||||
if let Some(ctx) = ctx {
|
||||
crate::console_log("webgl 2 selected");
|
||||
let gl_ctx = ctx.dyn_into::<web_sys::WebGl2RenderingContext>().unwrap();
|
||||
glow::Context::from_webgl2_context(gl_ctx)
|
||||
} else {
|
||||
let ctx = canvas.get_context("webgl");
|
||||
if let Ok(ctx) = ctx {
|
||||
crate::console_log("falling back to webgl1");
|
||||
if let Some(ctx) = ctx {
|
||||
crate::console_log("webgl1 selected");
|
||||
let gl2_ctx = canvas
|
||||
.get_context("webgl2")
|
||||
.expect("Failed to query about WebGL2 context");
|
||||
|
||||
let gl_ctx = ctx.dyn_into::<web_sys::WebGlRenderingContext>().unwrap();
|
||||
crate::console_log("success");
|
||||
glow::Context::from_webgl1_context(gl_ctx)
|
||||
} else {
|
||||
panic!("tried webgl1 but can't get context");
|
||||
}
|
||||
} else {
|
||||
panic!("tried webgl1 but can't get context");
|
||||
}
|
||||
}
|
||||
if let Some(gl2_ctx) = gl2_ctx {
|
||||
crate::console_log("WebGL2 found");
|
||||
let gl2_ctx = gl2_ctx
|
||||
.dyn_into::<web_sys::WebGl2RenderingContext>()
|
||||
.unwrap();
|
||||
glow::Context::from_webgl2_context(gl2_ctx)
|
||||
} else {
|
||||
panic!("tried webgl2 but something went wrong");
|
||||
let gl1 = canvas
|
||||
.get_context("webgl")
|
||||
.expect("Failed to query about WebGL1 context");
|
||||
|
||||
if let Some(gl1) = gl1 {
|
||||
crate::console_log("WebGL2 not available - falling back to WebGL2");
|
||||
let gl1_ctx = gl1.dyn_into::<web_sys::WebGlRenderingContext>().unwrap();
|
||||
glow::Context::from_webgl1_context(gl1_ctx)
|
||||
} else {
|
||||
panic!("Failed to get WebGL context.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user