From af5e7b5ba357227621e328e9a64b1ffc9fba6bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 16 Oct 2023 05:14:17 +0200 Subject: [PATCH] Add `query_counter` and `get_query_parameter_with_offset` --- src/lib.rs | 15 ++++++++++++--- src/native.rs | 28 ++++++++++++++++++---------- src/web_sys.rs | 13 +++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 19e639e..649234f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1147,9 +1147,9 @@ pub trait HasContext { ) where S: AsRef; - unsafe fn debug_message_callback(&mut self, callback: F) - where - F: FnMut(u32, u32, u32, u32, &str) + 'static; + unsafe fn debug_message_callback(&mut self, callback: F) + where + F: FnMut(u32, u32, u32, u32, &str) + 'static; unsafe fn get_debug_message_log(&self, count: u32) -> Vec; @@ -1200,8 +1200,17 @@ pub trait HasContext { unsafe fn end_query(&self, target: u32); + unsafe fn query_counter(&self, query: Self::Query, target: u32); + unsafe fn get_query_parameter_u32(&self, query: Self::Query, parameter: u32) -> u32; + unsafe fn get_query_parameter_with_offset( + &self, + query: Self::Query, + parameter: u32, + offset: usize, + ); + unsafe fn delete_transform_feedback(&self, transform_feedback: Self::TransformFeedback); unsafe fn create_transform_feedback(&self) -> Result; diff --git a/src/native.rs b/src/native.rs index 91fa565..906265e 100644 --- a/src/native.rs +++ b/src/native.rs @@ -2619,16 +2619,10 @@ impl HasContext for Context { let gl = &self.raw; if gl.DebugMessageCallback_is_loaded() { - gl.DebugMessageCallback( - Some(raw_debug_message_callback), - raw_ptr, - ); + gl.DebugMessageCallback(Some(raw_debug_message_callback), raw_ptr); } else { // Fallback to extension - gl.DebugMessageCallbackKHR( - Some(raw_debug_message_callback), - raw_ptr, - ); + gl.DebugMessageCallbackKHR(Some(raw_debug_message_callback), raw_ptr); } self.debug_callback = Some(DebugCallbackRawPtr { callback: raw_ptr }); @@ -2856,6 +2850,11 @@ impl HasContext for Context { gl.EndQuery(target); } + unsafe fn query_counter(&self, query: Self::Query, target: u32) { + let gl = &self.raw; + gl.QueryCounter(query.0.get(), target); + } + unsafe fn get_query_parameter_u32(&self, query: Self::Query, parameter: u32) -> u32 { let gl = &self.raw; let mut value = 0; @@ -2863,6 +2862,16 @@ impl HasContext for Context { value } + unsafe fn get_query_parameter_with_offset( + &self, + query: Self::Query, + parameter: u32, + offset: usize, + ) { + let gl = &self.raw; + gl.GetQueryObjectuiv(query.0.get(), parameter, offset as *mut _); + } + unsafe fn create_transform_feedback(&self) -> Result { let gl = &self.raw; let mut name = 0; @@ -3096,8 +3105,7 @@ extern "system" fn raw_debug_message_callback( length: i32, message: *const native_gl::GLchar, user_param: *mut std::ffi::c_void, -) -{ +) { let _result = std::panic::catch_unwind(move || unsafe { let callback: &mut DebugCallback = &mut *(user_param as *mut DebugCallback); let slice = std::slice::from_raw_parts(message as *const u8, length as usize); diff --git a/src/web_sys.rs b/src/web_sys.rs index 5410287..a6fa3fe 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -4558,6 +4558,10 @@ impl HasContext for Context { } } + unsafe fn query_counter(&self, query: Self::Query, target: u32) { + panic!("Query counters are not supported"); + } + unsafe fn get_query_parameter_u32(&self, query: Self::Query, parameter: u32) -> u32 { let queries = self.queries.borrow(); let raw_query = queries.get_unchecked(query); @@ -4571,6 +4575,15 @@ impl HasContext for Context { } } + unsafe fn get_query_parameter_with_offset( + &self, + query: Self::Query, + parameter: u32, + offset: usize, + ) -> u32 { + panic!("Query buffers are not supported"); + } + unsafe fn create_transform_feedback(&self) -> Result { let raw_transform_feedback = match self.raw { RawRenderingContext::WebGl1(ref _gl) => {