Skip to content

Commit

Permalink
Add get_parameter_*i64* functions
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Oct 19, 2024
1 parent 53bc025 commit e8d7711
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ pub trait HasContext: __private::Sealed {
#[doc(alias = "glGetIntegerv")]
unsafe fn get_parameter_i32_slice(&self, parameter: u32, out: &mut [i32]);

#[doc(alias = "glGetInteger64v")]
unsafe fn get_parameter_i64(&self, parameter: u32) -> i64;

#[doc(alias = "glGetInteger64v")]
unsafe fn get_parameter_i64_slice(&self, parameter: u32, out: &mut [i64]);

#[doc(alias = "glGetInteger64i_v")]
unsafe fn get_parameter_indexed_i64(&self, parameter: u32, index: u32) -> i64;

#[doc(alias = "glGetFloatv")]
unsafe fn get_parameter_f32(&self, parameter: u32) -> f32;

Expand Down
19 changes: 19 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,25 @@ impl HasContext for Context {
gl.GetIntegerv(parameter, &mut out[0]);
}

unsafe fn get_parameter_i64(&self, parameter: u32) -> i64 {
let gl = &self.raw;
let mut value = 0;
gl.GetInteger64v(parameter, &mut value);
value
}

unsafe fn get_parameter_i64_slice(&self, parameter: u32, out: &mut [i64]) {
let gl = &self.raw;
gl.GetInteger64v(parameter, &mut out[0]);
}

unsafe fn get_parameter_indexed_i64(&self, parameter: u32, index: u32) -> i64 {
let gl = &self.raw;
let mut value = 0;
gl.GetInteger64i_v(parameter, index, &mut value);
value
}

unsafe fn get_parameter_f32(&self, parameter: u32) -> f32 {
let gl = &self.raw;
let mut value: f32 = 0.0;
Expand Down
44 changes: 44 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,50 @@ impl HasContext for Context {
}
}

unsafe fn get_parameter_i64(&self, parameter: u32) -> i64 {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl.get_parameter(parameter),
RawRenderingContext::WebGl2(ref gl) => gl.get_parameter(parameter),
}
.unwrap()
.as_f64()
.map(|v| v as i64)
// Errors will be caught by the browser or through `get_error`
// so return a default instead
.unwrap_or(0)
}

unsafe fn get_parameter_i64_slice(&self, parameter: u32, v: &mut [i64]) {
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;
if let Some(value) = value.as_f64() {
v[0] = value as i64;
} else if let Some(values) = value.dyn_ref::<js_sys::Array>() {
v.iter_mut().zip(values.values()).for_each(|(v, val)| {
*v = val.unwrap().as_f64().map(|x| x as i64).unwrap_or_default()
})
}
}

unsafe fn get_parameter_indexed_i64(&self, parameter: u32, index: u32) -> i64 {
match self.raw {
RawRenderingContext::WebGl1(ref _gl) => {
panic!("Get parameter indexed is not supported")
}
RawRenderingContext::WebGl2(ref gl) => gl.get_indexed_parameter(parameter, index),
}
.unwrap()
.as_f64()
.map(|v| v as i64)
// Errors will be caught by the browser or through `get_error`
// so return a default instead
.unwrap_or(0)
}

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

0 comments on commit e8d7711

Please sign in to comment.