Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query_counter and get_query_parameter_u64_with_offset #260

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading