Make GL/GLES decisions based on the API in use.

This commit is contained in:
Josh Matthews 2019-07-10 17:34:16 -04:00
parent 812bf8d816
commit dbaed5ed92
13 changed files with 83 additions and 52 deletions

36
Cargo.lock generated
View file

@ -397,7 +397,7 @@ dependencies = [
"cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"half 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "half 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -418,7 +418,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1", "malloc_size_of 0.0.1",
@ -485,7 +485,7 @@ name = "cgl"
version = "0.2.3" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -598,7 +598,7 @@ dependencies = [
"embedder_traits 0.0.1", "embedder_traits 0.0.1",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1", "gfx_traits 0.0.1",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1509,7 +1509,7 @@ dependencies = [
[[package]] [[package]]
name = "gleam" name = "gleam"
version = "0.6.17" version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2198,7 +2198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"leaky-cow 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "leaky-cow 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -2530,7 +2530,7 @@ dependencies = [
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gaol 0.2.0 (git+https://github.com/servo/gaol)", "gaol 0.2.0 (git+https://github.com/servo/gaol)",
"gfx 0.0.1", "gfx 0.0.1",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_thread_2013 0.0.1", "layout_thread_2013 0.0.1",
@ -3191,7 +3191,7 @@ dependencies = [
"core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3754,7 +3754,7 @@ dependencies = [
"bindgen 0.49.0 (registry+https://github.com/rust-lang/crates.io-index)", "bindgen 0.49.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gvr-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "gvr-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3770,7 +3770,7 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3855,7 +3855,7 @@ dependencies = [
"enum-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "enum-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"headers 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "headers 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4095,7 +4095,7 @@ dependencies = [
"clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4299,7 +4299,7 @@ dependencies = [
"cmake 0.1.40 (git+https://github.com/alexcrichton/cmake-rs)", "cmake 0.1.40 (git+https://github.com/alexcrichton/cmake-rs)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glx 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "glx 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"io-surface 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "io-surface 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5410,7 +5410,7 @@ dependencies = [
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5479,7 +5479,7 @@ dependencies = [
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
@ -5506,7 +5506,7 @@ version = "0.0.1"
source = "git+https://github.com/servo/webxr#3951634a06e2f9417f04e8ada969589f5b8a01d2" source = "git+https://github.com/servo/webxr#3951634a06e2f9417f04e8ada969589f5b8a01d2"
dependencies = [ dependencies = [
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"webxr-api 0.0.1 (git+https://github.com/servo/webxr)", "webxr-api 0.0.1 (git+https://github.com/servo/webxr)",
] ]
@ -5517,7 +5517,7 @@ version = "0.0.1"
source = "git+https://github.com/servo/webxr#3951634a06e2f9417f04e8ada969589f5b8a01d2" source = "git+https://github.com/servo/webxr#3951634a06e2f9417f04e8ada969589f5b8a01d2"
dependencies = [ dependencies = [
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
"typetag 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "typetag 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5846,7 +5846,7 @@ dependencies = [
"checksum gif 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff3414b424657317e708489d2857d9575f4403698428b040b609b9d1c1a84a2c" "checksum gif 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff3414b424657317e708489d2857d9575f4403698428b040b609b9d1c1a84a2c"
"checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604" "checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604"
"checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd"
"checksum gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7f46fd8874e043ffac0d638ed1567a2584f7814f6d72b4db37ab1689004a26c4" "checksum gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "c8a455b5a3ccd35daeb89fdb8a89ebb0a1fe23c05c7a7f9017840bc3ae176f71"
"checksum glib 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d70d737019da0473a7cd6d9240571cf58c6897dcb10edf32b90774f4ba237c1b" "checksum glib 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d70d737019da0473a7cd6d9240571cf58c6897dcb10edf32b90774f4ba237c1b"
"checksum glib-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b86a9169fbc9cf9a0ef315039c2304b09d5c575c5fde7defba3576a0311b863" "checksum glib-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b86a9169fbc9cf9a0ef315039c2304b09d5c575c5fde7defba3576a0311b863"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"

View file

@ -27,6 +27,7 @@ pub enum GLContextFactory {
Native( Native(
NativeGLContextHandle, NativeGLContextHandle,
Option<Box<dyn CloneableDispatcher + Send>>, Option<Box<dyn CloneableDispatcher + Send>>,
gl::GlType,
), ),
OSMesa(OSMesaContextHandle), OSMesa(OSMesaContextHandle),
} }
@ -35,6 +36,7 @@ impl GLContextFactory {
/// Creates a new GLContextFactory that uses the currently bound GL context to create shared contexts. /// Creates a new GLContextFactory that uses the currently bound GL context to create shared contexts.
pub fn current_native_handle( pub fn current_native_handle(
dispatcher: Box<dyn CloneableDispatcher + Send>, dispatcher: Box<dyn CloneableDispatcher + Send>,
api_type: gl::GlType,
) -> Option<GLContextFactory> { ) -> Option<GLContextFactory> {
let dispatcher = if cfg!(target_os = "windows") { let dispatcher = if cfg!(target_os = "windows") {
// Used to dispatch functions from the GLContext thread to the main thread's // Used to dispatch functions from the GLContext thread to the main thread's
@ -46,7 +48,8 @@ impl GLContextFactory {
// FIXME(emilio): This assumes a single GL backend per platform which is // FIXME(emilio): This assumes a single GL backend per platform which is
// not true on Linux, we probably need a third `Egl` variant or abstract // not true on Linux, we probably need a third `Egl` variant or abstract
// it a bit more... // it a bit more...
NativeGLContext::current_handle().map(|handle| GLContextFactory::Native(handle, dispatcher)) NativeGLContext::current_handle()
.map(|handle| GLContextFactory::Native(handle, dispatcher, api_type))
} }
/// Creates a new GLContextFactory that uses the currently bound OSMesa context to create shared contexts. /// Creates a new GLContextFactory that uses the currently bound OSMesa context to create shared contexts.
@ -63,13 +66,13 @@ impl GLContextFactory {
) -> Result<GLContextWrapper, &'static str> { ) -> Result<GLContextWrapper, &'static str> {
let attributes = map_attrs(attributes); let attributes = map_attrs(attributes);
Ok(match *self { Ok(match *self {
GLContextFactory::Native(ref handle, ref dispatcher) => { GLContextFactory::Native(ref handle, ref dispatcher, ref api_type) => {
GLContextWrapper::Native(GLContext::new_shared_with_dispatcher( GLContextWrapper::Native(GLContext::new_shared_with_dispatcher(
// FIXME(nox): Why are those i32 values? // FIXME(nox): Why are those i32 values?
size.to_i32(), size.to_i32(),
attributes, attributes,
ColorAttachmentType::Texture, ColorAttachmentType::Texture,
gl::GlType::default(), *api_type,
Self::gl_version(webgl_version), Self::gl_version(webgl_version),
Some(handle), Some(handle),
dispatcher.as_ref().map(|d| (**d).clone()), dispatcher.as_ref().map(|d| (**d).clone()),
@ -99,13 +102,13 @@ impl GLContextFactory {
) -> Result<GLContextWrapper, &'static str> { ) -> Result<GLContextWrapper, &'static str> {
let attributes = map_attrs(attributes); let attributes = map_attrs(attributes);
Ok(match *self { Ok(match *self {
GLContextFactory::Native(..) => { GLContextFactory::Native(_, _, ref api_type) => {
GLContextWrapper::Native(GLContext::new_shared_with_dispatcher( GLContextWrapper::Native(GLContext::new_shared_with_dispatcher(
// FIXME(nox): Why are those i32 values? // FIXME(nox): Why are those i32 values?
size.to_i32(), size.to_i32(),
attributes, attributes,
ColorAttachmentType::Texture, ColorAttachmentType::Texture,
gl::GlType::default(), *api_type,
Self::gl_version(webgl_version), Self::gl_version(webgl_version),
None, None,
None, None,

View file

@ -138,9 +138,13 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
) )
.expect("WebGLContext not found"); .expect("WebGLContext not found");
let glsl_version = Self::get_glsl_version(&data.ctx); let glsl_version = Self::get_glsl_version(&data.ctx);
let api_type = match data.ctx.gl().get_type() {
gl::GlType::Gl => GlType::Gl,
gl::GlType::Gles => GlType::Gles,
};
// FIXME(nox): Should probably be done by offscreen_gl_context. // FIXME(nox): Should probably be done by offscreen_gl_context.
if !is_gles() { if api_type != GlType::Gles {
// Points sprites are enabled by default in OpenGL 3.2 core // Points sprites are enabled by default in OpenGL 3.2 core
// and in GLES. Rather than doing version detection, it does // and in GLES. Rather than doing version detection, it does
// not hurt to enable them anyways. // not hurt to enable them anyways.
@ -163,6 +167,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
limits, limits,
share_mode, share_mode,
glsl_version, glsl_version,
api_type,
} }
})) }))
.unwrap(); .unwrap();

View file

@ -76,6 +76,12 @@ pub enum WebGLMsg {
Exit, Exit,
} }
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub enum GlType {
Gl,
Gles,
}
/// Contains the WebGLCommand sender and information about a WebGLContext /// Contains the WebGLCommand sender and information about a WebGLContext
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WebGLCreateContextResult { pub struct WebGLCreateContextResult {
@ -87,6 +93,8 @@ pub struct WebGLCreateContextResult {
pub share_mode: WebGLContextShareMode, pub share_mode: WebGLContextShareMode,
/// The GLSL version supported by the context. /// The GLSL version supported by the context.
pub glsl_version: WebGLSLVersion, pub glsl_version: WebGLSLVersion,
/// The GL API used by the context.
pub api_type: GlType,
} }
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize)]
@ -761,12 +769,6 @@ parameters! {
} }
} }
pub fn is_gles() -> bool {
// TODO: align this with the actual kind of graphics context in use, rather than
// making assumptions based on platform
cfg!(any(target_os = "android", target_os = "ios"))
}
#[macro_export] #[macro_export]
macro_rules! gl_enums { macro_rules! gl_enums {
($(pub enum $name:ident { $($variant:ident = $mod:ident::$constant:ident,)+ })*) => { ($(pub enum $name:ident { $($variant:ident = $mod:ident::$constant:ident,)+ })*) => {

View file

@ -46,7 +46,7 @@ use canvas_traits::canvas::{
}; };
use canvas_traits::canvas::{CompositionOrBlending, LineCapStyle, LineJoinStyle, RepetitionStyle}; use canvas_traits::canvas::{CompositionOrBlending, LineCapStyle, LineJoinStyle, RepetitionStyle};
use canvas_traits::webgl::GLLimits; use canvas_traits::webgl::GLLimits;
use canvas_traits::webgl::{ActiveAttribInfo, ActiveUniformInfo, TexDataType, TexFormat}; use canvas_traits::webgl::{ActiveAttribInfo, ActiveUniformInfo, GlType, TexDataType, TexFormat};
use canvas_traits::webgl::{WebGLBufferId, WebGLChan, WebGLContextShareMode, WebGLError}; use canvas_traits::webgl::{WebGLBufferId, WebGLChan, WebGLContextShareMode, WebGLError};
use canvas_traits::webgl::{WebGLFramebufferId, WebGLMsgSender, WebGLPipeline, WebGLProgramId}; use canvas_traits::webgl::{WebGLFramebufferId, WebGLMsgSender, WebGLPipeline, WebGLProgramId};
use canvas_traits::webgl::{WebGLReceiver, WebGLRenderbufferId, WebGLSLVersion, WebGLSender}; use canvas_traits::webgl::{WebGLReceiver, WebGLRenderbufferId, WebGLSLVersion, WebGLSender};
@ -439,7 +439,7 @@ unsafe_no_jsmanaged_fields!(StorageType);
unsafe_no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle); unsafe_no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
unsafe_no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending); unsafe_no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
unsafe_no_jsmanaged_fields!(RepetitionStyle); unsafe_no_jsmanaged_fields!(RepetitionStyle);
unsafe_no_jsmanaged_fields!(WebGLError, GLLimits); unsafe_no_jsmanaged_fields!(WebGLError, GLLimits, GlType);
unsafe_no_jsmanaged_fields!(TimeProfilerChan); unsafe_no_jsmanaged_fields!(TimeProfilerChan);
unsafe_no_jsmanaged_fields!(MemProfilerChan); unsafe_no_jsmanaged_fields!(MemProfilerChan);
unsafe_no_jsmanaged_fields!(PseudoElement); unsafe_no_jsmanaged_fields!(PseudoElement);

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::EXTShaderTextureLodBinding;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion}; use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct; use dom_struct::dom_struct;
#[dom_struct] #[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for EXTShaderTextureLod {
fn is_supported(ext: &WebGLExtensions) -> bool { fn is_supported(ext: &WebGLExtensions) -> bool {
// This extension is always available on desktop GL. // This extension is always available on desktop GL.
!is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod") !ext.is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod")
} }
fn enable(_ext: &WebGLExtensions) {} fn enable(_ext: &WebGLExtensions) {}

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::OESElementIndexUintBinding;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion}; use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct; use dom_struct::dom_struct;
#[dom_struct] #[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for OESElementIndexUint {
fn is_supported(ext: &WebGLExtensions) -> bool { fn is_supported(ext: &WebGLExtensions) -> bool {
// This extension is always available in desktop OpenGL. // This extension is always available in desktop OpenGL.
!is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint") !ext.is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint")
} }
fn enable(ext: &WebGLExtensions) { fn enable(ext: &WebGLExtensions) {

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESS
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{is_gles, WebGLVersion}; use canvas_traits::webgl::WebGLVersion;
use dom_struct::dom_struct; use dom_struct::dom_struct;
#[dom_struct] #[dom_struct]
@ -40,7 +40,7 @@ impl WebGLExtension for OESStandardDerivatives {
fn is_supported(ext: &WebGLExtensions) -> bool { fn is_supported(ext: &WebGLExtensions) -> bool {
// The standard derivatives are always available in desktop OpenGL. // The standard derivatives are always available in desktop OpenGL.
!is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"]) !ext.is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"])
} }
fn enable(ext: &WebGLExtensions) { fn enable(ext: &WebGLExtensions) {

View file

@ -18,7 +18,7 @@ use crate::dom::oestexturehalffloat::OESTextureHalfFloat;
use crate::dom::webglcolorbufferfloat::WEBGLColorBufferFloat; use crate::dom::webglcolorbufferfloat::WEBGLColorBufferFloat;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::webgltexture::TexCompression; use crate::dom::webgltexture::TexCompression;
use canvas_traits::webgl::WebGLVersion; use canvas_traits::webgl::{GlType, WebGLVersion};
use fnv::{FnvHashMap, FnvHashSet}; use fnv::{FnvHashMap, FnvHashSet};
use gleam::gl::{self, GLenum}; use gleam::gl::{self, GLenum};
use js::jsapi::JSObject; use js::jsapi::JSObject;
@ -146,14 +146,16 @@ pub struct WebGLExtensions {
extensions: DomRefCell<HashMap<String, Box<dyn WebGLExtensionWrapper>>>, extensions: DomRefCell<HashMap<String, Box<dyn WebGLExtensionWrapper>>>,
features: DomRefCell<WebGLExtensionFeatures>, features: DomRefCell<WebGLExtensionFeatures>,
webgl_version: WebGLVersion, webgl_version: WebGLVersion,
api_type: GlType,
} }
impl WebGLExtensions { impl WebGLExtensions {
pub fn new(webgl_version: WebGLVersion) -> WebGLExtensions { pub fn new(webgl_version: WebGLVersion, api_type: GlType) -> WebGLExtensions {
Self { Self {
extensions: DomRefCell::new(HashMap::new()), extensions: DomRefCell::new(HashMap::new()),
features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)), features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)),
webgl_version, webgl_version,
api_type,
} }
} }
@ -425,6 +427,10 @@ impl WebGLExtensions {
} }
type_ type_
} }
pub fn is_gles(&self) -> bool {
self.api_type == GlType::Gles
}
} }
// Helper structs // Helper structs

View file

@ -14,7 +14,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::webglobject::WebGLObject; use crate::dom::webglobject::WebGLObject;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{ use canvas_traits::webgl::{
is_gles, webgl_channel, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult, webgl_channel, GlType, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult,
}; };
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell; use std::cell::Cell;
@ -120,7 +120,15 @@ impl WebGLRenderbuffer {
self.ever_bound.get() self.ever_bound.get()
} }
pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> { pub fn storage(
&self,
api_type: GlType,
internal_format: u32,
width: i32,
height: i32,
) -> WebGLResult<()> {
let is_gles = api_type == GlType::Gles;
// Validate the internal_format, and save it for completeness // Validate the internal_format, and save it for completeness
// validation. // validation.
let actual_format = match internal_format { let actual_format = match internal_format {
@ -131,7 +139,7 @@ impl WebGLRenderbuffer {
constants::DEPTH_STENCIL => WebGL2RenderingContextConstants::DEPTH24_STENCIL8, constants::DEPTH_STENCIL => WebGL2RenderingContextConstants::DEPTH24_STENCIL8,
constants::RGB5_A1 => { constants::RGB5_A1 => {
// 16-bit RGBA formats are not supported on desktop GL. // 16-bit RGBA formats are not supported on desktop GL.
if is_gles() { if is_gles {
constants::RGB5_A1 constants::RGB5_A1
} else { } else {
WebGL2RenderingContextConstants::RGBA8 WebGL2RenderingContextConstants::RGBA8
@ -139,7 +147,7 @@ impl WebGLRenderbuffer {
}, },
constants::RGB565 => { constants::RGB565 => {
// RGB565 is not supported on desktop GL. // RGB565 is not supported on desktop GL.
if is_gles() { if is_gles {
constants::RGB565 constants::RGB565
} else { } else {
WebGL2RenderingContextConstants::RGB8 WebGL2RenderingContextConstants::RGB8

View file

@ -52,8 +52,8 @@ use crate::dom::window::Window;
use backtrace::Backtrace; use backtrace::Backtrace;
use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::WebGLError::*;
use canvas_traits::webgl::{ use canvas_traits::webgl::{
webgl_channel, AlphaTreatment, DOMToTextureCommand, GLContextAttributes, GLLimits, Parameter, webgl_channel, AlphaTreatment, DOMToTextureCommand, GLContextAttributes, GLLimits, GlType,
TexDataType, TexFormat, TexParameter, WebGLCommand, WebGLCommandBacktrace, Parameter, TexDataType, TexFormat, TexParameter, WebGLCommand, WebGLCommandBacktrace,
WebGLContextShareMode, WebGLError, WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLContextShareMode, WebGLError, WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender,
WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand, WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand,
YAxisTreatment, YAxisTreatment,
@ -166,6 +166,7 @@ pub struct WebGLRenderingContext {
default_vao: DomOnceCell<WebGLVertexArrayObjectOES>, default_vao: DomOnceCell<WebGLVertexArrayObjectOES>,
current_vao: MutNullableDom<WebGLVertexArrayObjectOES>, current_vao: MutNullableDom<WebGLVertexArrayObjectOES>,
textures: Textures, textures: Textures,
api_type: GlType,
} }
impl WebGLRenderingContext { impl WebGLRenderingContext {
@ -216,11 +217,12 @@ impl WebGLRenderingContext {
// what was requested // what was requested
size: Cell::new(size), size: Cell::new(size),
current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0)), current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0)),
extension_manager: WebGLExtensions::new(webgl_version), extension_manager: WebGLExtensions::new(webgl_version, ctx_data.api_type),
capabilities: Default::default(), capabilities: Default::default(),
default_vao: Default::default(), default_vao: Default::default(),
current_vao: Default::default(), current_vao: Default::default(),
textures: Textures::new(max_combined_texture_image_units), textures: Textures::new(max_combined_texture_image_units),
api_type: ctx_data.api_type,
} }
}) })
} }
@ -2106,6 +2108,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
handle_potential_webgl_error!( handle_potential_webgl_error!(
self, self,
shader.compile( shader.compile(
self.api_type,
self.webgl_version, self.webgl_version,
self.glsl_version, self.glsl_version,
&self.limits, &self.limits,
@ -4031,7 +4034,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
self.bound_renderbuffer.get().ok_or(InvalidOperation), self.bound_renderbuffer.get().ok_or(InvalidOperation),
return return
); );
handle_potential_webgl_error!(self, rb.storage(internal_format, width, height)); handle_potential_webgl_error!(
self,
rb.storage(self.api_type, internal_format, width, height)
);
if let Some(fb) = self.bound_framebuffer.get() { if let Some(fb) = self.bound_framebuffer.get() {
fb.invalidate_renderbuffer(&*rb); fb.invalidate_renderbuffer(&*rb);
} }

View file

@ -14,7 +14,7 @@ use crate::dom::webgl_extensions::ext::oesstandardderivatives::OESStandardDeriva
use crate::dom::webgl_extensions::WebGLExtensions; use crate::dom::webgl_extensions::WebGLExtensions;
use crate::dom::webglobject::WebGLObject; use crate::dom::webglobject::WebGLObject;
use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use canvas_traits::webgl::{webgl_channel, WebGLVersion}; use canvas_traits::webgl::{webgl_channel, GlType, WebGLVersion};
use canvas_traits::webgl::{GLLimits, WebGLCommand, WebGLError}; use canvas_traits::webgl::{GLLimits, WebGLCommand, WebGLError};
use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLShaderId}; use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLShaderId};
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -93,6 +93,7 @@ impl WebGLShader {
/// glCompileShader /// glCompileShader
pub fn compile( pub fn compile(
&self, &self,
api_type: GlType,
webgl_version: WebGLVersion, webgl_version: WebGLVersion,
glsl_version: WebGLSLVersion, glsl_version: WebGLSLVersion,
limits: &GLLimits, limits: &GLLimits,
@ -122,7 +123,7 @@ impl WebGLShader {
}; };
let validator = match webgl_version { let validator = match webgl_version {
WebGLVersion::WebGL1 => { WebGLVersion::WebGL1 => {
let output_format = if cfg!(any(target_os = "android", target_os = "ios")) { let output_format = if api_type == GlType::Gles {
Output::Essl Output::Essl
} else { } else {
Output::Glsl Output::Glsl
@ -130,7 +131,7 @@ impl WebGLShader {
ShaderValidator::for_webgl(self.gl_type, output_format, &params).unwrap() ShaderValidator::for_webgl(self.gl_type, output_format, &params).unwrap()
}, },
WebGLVersion::WebGL2 => { WebGLVersion::WebGL2 => {
let output_format = if cfg!(any(target_os = "android", target_os = "ios")) { let output_format = if api_type == GlType::Gles {
Output::Essl Output::Essl
} else { } else {
match (glsl_version.major, glsl_version.minor) { match (glsl_version.major, glsl_version.minor) {

View file

@ -747,7 +747,7 @@ fn create_constellation(
GLContextFactory::current_osmesa_handle() GLContextFactory::current_osmesa_handle()
} else { } else {
let dispatcher = Box::new(MainThreadDispatcher::new(compositor_proxy.clone())) as Box<_>; let dispatcher = Box::new(MainThreadDispatcher::new(compositor_proxy.clone())) as Box<_>;
GLContextFactory::current_native_handle(dispatcher) GLContextFactory::current_native_handle(dispatcher, window_gl.get_type())
}; };
let (external_image_handlers, external_images) = WebrenderExternalImageHandlers::new(); let (external_image_handlers, external_images) = WebrenderExternalImageHandlers::new();