|
|
@ -86,27 +86,36 @@ impl crate::Painter for WrappedGlowPainter { |
|
|
|
} |
|
|
|
|
|
|
|
/// Returns glow context and shader prefix.
|
|
|
|
fn init_glow_context_from_canvas(canvas: &HtmlCanvasElement) -> (glow::Context, &str) { |
|
|
|
let gl2_ctx = canvas |
|
|
|
.get_context("webgl2") |
|
|
|
.expect("Failed to query about WebGL2 context"); |
|
|
|
fn init_glow_context_from_canvas(canvas: &HtmlCanvasElement) -> (glow::Context, &'static str) { |
|
|
|
const BEST_FIRST: bool = true; |
|
|
|
|
|
|
|
if let Some(gl2_ctx) = gl2_ctx { |
|
|
|
crate::console_log("WebGL2 found."); |
|
|
|
let gl2_ctx = gl2_ctx |
|
|
|
.dyn_into::<web_sys::WebGl2RenderingContext>() |
|
|
|
.unwrap(); |
|
|
|
let glow_ctx = glow::Context::from_webgl2_context(gl2_ctx); |
|
|
|
let shader_prefix = ""; |
|
|
|
(glow_ctx, shader_prefix) |
|
|
|
let result = if BEST_FIRST { |
|
|
|
// Trying WebGl2 first
|
|
|
|
init_webgl2(canvas).or_else(|| init_webgl1(canvas)) |
|
|
|
} else { |
|
|
|
let gl1 = canvas |
|
|
|
// Trying WebGl1 first (useful for testing).
|
|
|
|
crate::console_warn("Looking for WebGL1 first"); |
|
|
|
init_webgl1(canvas).or_else(|| init_webgl2(canvas)) |
|
|
|
}; |
|
|
|
|
|
|
|
if let Some(result) = result { |
|
|
|
result |
|
|
|
} else { |
|
|
|
panic!("WebGL isn't supported"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn init_webgl1(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static str)> { |
|
|
|
let gl1_ctx = canvas |
|
|
|
.get_context("webgl") |
|
|
|
.expect("Failed to query about WebGL1 context"); |
|
|
|
.expect("Failed to query about WebGL2 context"); |
|
|
|
|
|
|
|
if let Some(gl1) = gl1 { |
|
|
|
crate::console_log("WebGL2 not available - falling back to WebGL1."); |
|
|
|
let gl1_ctx = gl1.dyn_into::<web_sys::WebGlRenderingContext>().unwrap(); |
|
|
|
let gl1_ctx = gl1_ctx?; |
|
|
|
crate::console_log("WebGL1 selected."); |
|
|
|
|
|
|
|
let gl1_ctx = gl1_ctx |
|
|
|
.dyn_into::<web_sys::WebGlRenderingContext>() |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
let shader_prefix = if crate::webgl1_requires_brightening(&gl1_ctx) { |
|
|
|
crate::console_log("Enabling webkitGTK brightening workaround."); |
|
|
@ -117,11 +126,24 @@ fn init_glow_context_from_canvas(canvas: &HtmlCanvasElement) -> (glow::Context, |
|
|
|
|
|
|
|
let glow_ctx = glow::Context::from_webgl1_context(gl1_ctx); |
|
|
|
|
|
|
|
(glow_ctx, shader_prefix) |
|
|
|
} else { |
|
|
|
panic!("Failed to get WebGL context."); |
|
|
|
} |
|
|
|
} |
|
|
|
Some((glow_ctx, shader_prefix)) |
|
|
|
} |
|
|
|
|
|
|
|
fn init_webgl2(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static str)> { |
|
|
|
let gl2_ctx = canvas |
|
|
|
.get_context("webgl2") |
|
|
|
.expect("Failed to query about WebGL2 context"); |
|
|
|
|
|
|
|
let gl2_ctx = gl2_ctx?; |
|
|
|
crate::console_log("WebGL2 selected."); |
|
|
|
|
|
|
|
let gl2_ctx = gl2_ctx |
|
|
|
.dyn_into::<web_sys::WebGl2RenderingContext>() |
|
|
|
.unwrap(); |
|
|
|
let glow_ctx = glow::Context::from_webgl2_context(gl2_ctx); |
|
|
|
let shader_prefix = ""; |
|
|
|
|
|
|
|
Some((glow_ctx, shader_prefix)) |
|
|
|
} |
|
|
|
|
|
|
|
trait DummyWebGLConstructor { |
|
|
@ -133,10 +155,10 @@ trait DummyWebGLConstructor { |
|
|
|
#[cfg(not(target_arch = "wasm32"))] |
|
|
|
impl DummyWebGLConstructor for glow::Context { |
|
|
|
fn from_webgl1_context(_context: WebGlRenderingContext) -> Self { |
|
|
|
panic!("you cant use egui_web(glow) on native") |
|
|
|
panic!("you can't use egui_web(glow) on native") |
|
|
|
} |
|
|
|
|
|
|
|
fn from_webgl2_context(_context: WebGl2RenderingContext) -> Self { |
|
|
|
panic!("you cant use egui_web(glow) on native") |
|
|
|
panic!("you can't use egui_web(glow) on native") |
|
|
|
} |
|
|
|
} |
|
|
|