Skip to content

Commit

Permalink
Add get_parameter_bool_array
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Oct 1, 2024
1 parent c63b514 commit 94f45bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const N: usize>(&self, parameter: u32) -> [bool; N];

#[doc(alias = "glGetIntegerv")]
unsafe fn get_parameter_i32(&self, parameter: u32) -> i32;

Expand Down
7 changes: 7 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,13 @@ impl HasContext for Context {
value != FALSE
}

unsafe fn get_parameter_bool_array<const N: usize>(&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;
Expand Down
22 changes: 21 additions & 1 deletion src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3370,6 +3370,24 @@ impl HasContext for Context {
.unwrap_or(false)
}

unsafe fn get_parameter_bool_array<const N: usize>(&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::<js_sys::Array>() {
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),
Expand Down Expand Up @@ -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")
}
}
}

Expand Down

0 comments on commit 94f45bc

Please sign in to comment.