Skip to content

Commit

Permalink
Add query_counter and get_query_parameter_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Oct 16, 2023
1 parent d62451c commit 5989546
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,9 +1147,9 @@ pub trait HasContext {
) where
S: AsRef<str>;

unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static;
unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static;

unsafe fn get_debug_message_log(&self, count: u32) -> Vec<DebugMessageLogEntry>;

Expand Down Expand Up @@ -1200,8 +1200,12 @@ 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_ptr(&self, query: Self::Query, parameter: u32, value: *mut ());

unsafe fn delete_transform_feedback(&self, transform_feedback: Self::TransformFeedback);

unsafe fn create_transform_feedback(&self) -> Result<Self::TransformFeedback, String>;
Expand Down
13 changes: 11 additions & 2 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2856,13 +2856,23 @@ 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;
gl.GetQueryObjectuiv(query.0.get(), parameter, &mut value);
value
}

unsafe fn get_query_parameter_ptr(&self, query: Self::Query, parameter: u32, value: *mut ()) {
let gl = &self.raw;
gl.GetQueryObjectuiv(query.0.get(), parameter, value.cast());
}

unsafe fn create_transform_feedback(&self) -> Result<Self::TransformFeedback, String> {
let gl = &self.raw;
let mut name = 0;
Expand Down Expand Up @@ -3096,8 +3106,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);
Expand Down
8 changes: 8 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4558,6 +4558,10 @@ impl HasContext for Context {
}
}

unsafe fn query_counter(&self, 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);
Expand All @@ -4571,6 +4575,10 @@ impl HasContext for Context {
}
}

unsafe fn get_query_parameter_ptr(&self, query: Self::Query, parameter: u32) -> u32 {
panic!("Query buffers are not supported");
}

unsafe fn create_transform_feedback(&self) -> Result<Self::TransformFeedback, String> {
let raw_transform_feedback = match self.raw {
RawRenderingContext::WebGl1(ref _gl) => {
Expand Down

0 comments on commit 5989546

Please sign in to comment.