Skip to content

Commit

Permalink
Add get_parameter_bool
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Sep 25, 2024
1 parent cba8089 commit 32a9ac1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ pub trait HasContext: __private::Sealed {

unsafe fn get_buffer_parameter_i32(&self, target: u32, parameter: u32) -> i32;

#[doc(alias = "glGetBooleanv")]
unsafe fn get_parameter_bool(&self, parameter: u32) -> bool;

#[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 @@ -1987,6 +1987,13 @@ impl HasContext for Context {
value
}

unsafe fn get_parameter_bool(&self, parameter: u32) -> bool {
let gl = &self.raw;
let mut value = 0;
gl.GetBooleanv(parameter, &mut value);
value != FALSE
}

unsafe fn get_parameter_i32(&self, parameter: u32) -> i32 {
let gl = &self.raw;
let mut value = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,18 @@ impl HasContext for Context {
.unwrap_or(0)
}

unsafe fn get_parameter_bool(&self, parameter: u32) -> bool {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl.get_parameter(parameter),
RawRenderingContext::WebGl2(ref gl) => gl.get_parameter(parameter),
}
.unwrap()
.as_bool()
// Errors will be caught by the browser or through `get_error`
// so return a default instead
.unwrap_or(false)
}

unsafe fn get_parameter_i32(&self, parameter: u32) -> i32 {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl.get_parameter(parameter),
Expand Down

0 comments on commit 32a9ac1

Please sign in to comment.