Skip to content

Commit

Permalink
Add query_counter and get_query_parameter_u64_with_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc authored and grovesNL committed Oct 16, 2023
1 parent d62451c commit f4fa72e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
15 changes: 12 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,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_u64_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<Self::TransformFeedback, String>;
Expand Down
28 changes: 18 additions & 10 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -2856,13 +2850,28 @@ 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_u64_with_offset(
&self,
query: Self::Query,
parameter: u32,
offset: usize,
) {
let gl = &self.raw;
gl.GetQueryObjectui64v(query.0.get(), parameter, offset as *mut _);
}

unsafe fn create_transform_feedback(&self) -> Result<Self::TransformFeedback, String> {
let gl = &self.raw;
let mut name = 0;
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 13 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, 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);
Expand All @@ -4571,6 +4575,15 @@ impl HasContext for Context {
}
}

unsafe fn get_query_parameter_u64_with_offset(
&self,
query: Self::Query,
parameter: u32,
offset: usize,
) {
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 f4fa72e

Please sign in to comment.