Skip to content

Commit 3cb6361

Browse files
committed
Require WebGL 2 for WASM builds
WebGL 2 is supported by all major browsers nowadays (even Safari). ImageFlags::REPEAT_X seems to not work with WebGL1 and causes mis-rendering (see by changing examples/demo.rs to use that instead of ImageFlags::empty()).
1 parent 1119c46 commit 3cb6361

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88
- **breaking**: Removed pub key field in ImageId. This accidentally
99
exposed the implementation detail of the image store (generational-arena),
1010
which has been replaced with slotmap.
11+
- For WASM builds, require WebGL 2. This is supported by all major browsers
12+
and needed to make `ImageFlags::REPEAT_X/Y` work.
1113
- Bumped MSRV to 1.66.
1214

1315
## [0.8.2] - 2024-01-20

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ glutin = { version = "0.30.3", optional = true, default-features = false }
3939
web_sys = { version = "0.3", package = "web-sys", features = [
4040
"WebGlContextAttributes",
4141
"HtmlImageElement",
42+
"WebGl2RenderingContext",
4243
] }
4344
wasm-bindgen = "0.2"
4445

src/renderer/opengl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ impl OpenGl {
8989
attrs.antialias(false);
9090

9191
use wasm_bindgen::JsCast;
92-
let webgl1_context = match canvas.get_context_with_context_options("webgl", &attrs) {
93-
Ok(Some(context)) => context.dyn_into::<web_sys::WebGlRenderingContext>().unwrap(),
92+
let webgl2_context = match canvas.get_context_with_context_options("webgl2", &attrs) {
93+
Ok(Some(context)) => context.dyn_into::<web_sys::WebGl2RenderingContext>().unwrap(),
9494
_ => {
9595
return Err(ErrorKind::GeneralError(
96-
"Canvas::getContext failed to retrieve WebGL 1 context".to_owned(),
96+
"Canvas::getContext failed to retrieve WebGL 2 context".to_owned(),
9797
))
9898
}
9999
};
100100

101-
let context = glow::Context::from_webgl1_context(webgl1_context);
101+
let context = glow::Context::from_webgl2_context(webgl2_context);
102102
Self::new_from_context(context, true)
103103
}
104104

0 commit comments

Comments
 (0)