mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
enable debug extension on emscripten (#3519)
* enable debug extension on emscripten * update changelog * extract emscripten stuff into a separate module * use unmasked queries on w-u-u, and only enable extension on emscripten * fix docs
This commit is contained in:
parent
30064ead9f
commit
af5f4d20f4
@ -102,6 +102,7 @@ By @teoxoy in [#3436](https://github.com/gfx-rs/wgpu/pull/3436)
|
||||
#### GLES
|
||||
|
||||
- [gles] fix: Set FORCE_POINT_SIZE if it is vertex shader with mesh consist of point list. By @REASY in [3440](https://github.com/gfx-rs/wgpu/pull/3440)
|
||||
- [gles] fix: enable `WEBGL_debug_renderer_info` before querying unmasked vendor/renderer to avoid crashing on emscripten in [#3519](https://github.com/gfx-rs/wgpu/pull/3519)
|
||||
|
||||
#### General
|
||||
|
||||
|
@ -186,10 +186,21 @@ impl super::Adapter {
|
||||
let extensions = gl.supported_extensions();
|
||||
|
||||
let (vendor_const, renderer_const) = if extensions.contains("WEBGL_debug_renderer_info") {
|
||||
// emscripten doesn't enable "WEBGL_debug_renderer_info" extension by default. so, we do it manually.
|
||||
// See https://github.com/gfx-rs/wgpu/issues/3245 for context
|
||||
#[cfg(target_os = "emscripten")]
|
||||
if unsafe { super::emscripten::enable_extension("WEBGL_debug_renderer_info\0") } {
|
||||
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
|
||||
} else {
|
||||
(glow::VENDOR, glow::RENDERER)
|
||||
}
|
||||
// glow already enables WEBGL_debug_renderer_info on wasm32-unknown-unknown target by default.
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
|
||||
} else {
|
||||
(glow::VENDOR, glow::RENDERER)
|
||||
};
|
||||
|
||||
let (vendor, renderer) = {
|
||||
let vendor = unsafe { gl.get_parameter_string(vendor_const) };
|
||||
let renderer = unsafe { gl.get_parameter_string(renderer_const) };
|
||||
|
26
wgpu-hal/src/gles/emscripten.rs
Normal file
26
wgpu-hal/src/gles/emscripten.rs
Normal file
@ -0,0 +1,26 @@
|
||||
extern "C" {
|
||||
/// returns 1 if success. 0 if failure. extension name must be null terminated
|
||||
fn emscripten_webgl_enable_extension(
|
||||
context: std::ffi::c_int,
|
||||
extension: *const std::ffi::c_char,
|
||||
) -> std::ffi::c_int;
|
||||
fn emscripten_webgl_get_current_context() -> std::ffi::c_int;
|
||||
}
|
||||
/// Webgl requires extensions to be enabled before using them.
|
||||
/// This function can be used to enable webgl extension on emscripten target.
|
||||
///
|
||||
/// returns true on success
|
||||
///
|
||||
/// # Safety:
|
||||
///
|
||||
/// - opengl context MUST BE current
|
||||
/// - extension_name_null_terminated argument must be a valid string with null terminator.
|
||||
/// - extension must be present. check `glow_context.supported_extensions()`
|
||||
pub unsafe fn enable_extension(extension_name_null_terminated: &str) -> bool {
|
||||
unsafe {
|
||||
emscripten_webgl_enable_extension(
|
||||
emscripten_webgl_get_current_context(),
|
||||
extension_name_null_terminated.as_ptr() as _,
|
||||
) == 1
|
||||
}
|
||||
}
|
@ -59,6 +59,8 @@ To address this, we invalidate the vertex buffers based on:
|
||||
///cbindgen:ignore
|
||||
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
|
||||
mod egl;
|
||||
#[cfg(target_os = "emscripten")]
|
||||
mod emscripten;
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||
mod web;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user