From e8d771154fbe9c9d13e8c5098f7aba48a04961a1 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:45:29 +0200 Subject: [PATCH] Add `get_parameter_*i64*` functions Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- src/lib.rs | 9 +++++++++ src/native.rs | 19 +++++++++++++++++++ src/web_sys.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 76ddea8..3d440e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/native.rs b/src/native.rs index 5e69bf1..ab18b48 100644 --- a/src/native.rs +++ b/src/native.rs @@ -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; diff --git a/src/web_sys.rs b/src/web_sys.rs index d9e3bda..3d84c43 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -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::() { + 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),