From f05e070d6059fd24f7155014d748db34cf6d0ce7 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Tue, 8 Feb 2022 02:58:27 +0700 Subject: [PATCH] feature = emscripten, compability fixes for wgpu-native (#2450) --- wgpu-hal/examples/raw-gles.rs | 5 +++-- wgpu-hal/src/gles/egl.rs | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/wgpu-hal/examples/raw-gles.rs b/wgpu-hal/examples/raw-gles.rs index 815f4c182..34ad02147 100644 --- a/wgpu-hal/examples/raw-gles.rs +++ b/wgpu-hal/examples/raw-gles.rs @@ -4,8 +4,9 @@ //! Emscripten build: //! 1. install emsdk //! 2. build this example with cargo: -//! EMMAKEN_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten --features emscripten,webgl -//! 3. copy raw-gles.em.html into target/wasm32-unknown-emscripten/debug/examples/ and open it in browser +//! EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten --features emscripten,webgl +//! 3. copy raw-gles.em.html into target directory and open it in browser: +//! cp wgpu-hal/examples/raw-gles.em.html target/wasm32-unknown-emscripten/debug/examples extern crate wgpu_hal as hal; diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index e20c76b5e..2e55bbf47 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -501,19 +501,21 @@ impl Inner { // Testing if context can be binded without surface // and creating dummy pbuffer surface if not. - let pbuffer = - if version >= (1, 5) || display_extensions.contains("EGL_KHR_surfaceless_context") { - log::info!("\tEGL context: +surfaceless"); - None - } else { - let attributes = [egl::WIDTH, 1, egl::HEIGHT, 1, egl::NONE]; - egl.create_pbuffer_surface(display, config, &attributes) - .map(Some) - .map_err(|e| { - log::warn!("Error in create_pbuffer_surface: {:?}", e); - crate::InstanceError - })? - }; + let pbuffer = if version >= (1, 5) + || display_extensions.contains("EGL_KHR_surfaceless_context") + || cfg!(feature = "emscripten") + { + log::info!("\tEGL context: +surfaceless"); + None + } else { + let attributes = [egl::WIDTH, 1, egl::HEIGHT, 1, egl::NONE]; + egl.create_pbuffer_surface(display, config, &attributes) + .map(Some) + .map_err(|e| { + log::warn!("Error in create_pbuffer_surface: {:?}", e); + crate::InstanceError + })? + }; Ok(Self { egl: EglContext {