From 94f45bcb6481059a904f48d78b58338aa7ec8304 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Tue, 1 Oct 2024 09:13:26 +0200 Subject: [PATCH] Add `get_parameter_bool_array` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- src/lib.rs | 3 +++ src/native.rs | 7 +++++++ src/web_sys.rs | 22 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4e51991..9331aef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -888,6 +888,9 @@ pub trait HasContext: __private::Sealed { #[doc(alias = "glGetBooleanv")] unsafe fn get_parameter_bool(&self, parameter: u32) -> bool; + #[doc(alias = "glGetBooleanv")] + unsafe fn get_parameter_bool_array(&self, parameter: u32) -> [bool; N]; + #[doc(alias = "glGetIntegerv")] unsafe fn get_parameter_i32(&self, parameter: u32) -> i32; diff --git a/src/native.rs b/src/native.rs index b552cd3..986a916 100644 --- a/src/native.rs +++ b/src/native.rs @@ -2003,6 +2003,13 @@ impl HasContext for Context { value != FALSE } + unsafe fn get_parameter_bool_array(&self, parameter: u32) -> [bool; N] { + let gl = &self.raw; + let mut value = [0; N]; + gl.GetBooleanv(parameter, &mut value[0]); + value.map(|v| v != FALSE) + } + unsafe fn get_parameter_i32(&self, parameter: u32) -> i32 { let gl = &self.raw; let mut value = 0; diff --git a/src/web_sys.rs b/src/web_sys.rs index 7f73725..190ea1d 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -3370,6 +3370,24 @@ impl HasContext for Context { .unwrap_or(false) } + unsafe fn get_parameter_bool_array(&self, parameter: u32) -> [bool; N] { + let value = match self.raw { + RawRenderingContext::WebGl1(ref gl) => gl.get_parameter(parameter), + RawRenderingContext::WebGl2(ref gl) => gl.get_parameter(parameter), + } + .unwrap(); + use wasm_bindgen::JsCast; + let mut v = [false; N]; + if let Some(value) = value.as_bool() { + v[0] = value; + } else if let Some(values) = value.dyn_ref::() { + for (i, val) in values.values().into_iter().enumerate() { + v[i] = val.unwrap().as_bool().unwrap_or_default(); + } + } + v + } + unsafe fn get_parameter_i32(&self, parameter: u32) -> i32 { match self.raw { RawRenderingContext::WebGl1(ref gl) => gl.get_parameter(parameter), @@ -5499,7 +5517,9 @@ impl HasContext for Context { let raw_query = queries.get_unchecked(query); match self.extensions.ext_disjoint_timer_query_webgl2 { Some(ref ext) => ext.query_counter_ext(raw_query, target), - None => panic!("Query counters are not supported without EXT_disjoint_timer_query_webgl2"), + None => { + panic!("Query counters are not supported without EXT_disjoint_timer_query_webgl2") + } } }