Skip to content
New issue

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

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

Already on GitHub? # to your account

clear_depth, depth_range with auto select the best function #310

Merged
merged 2 commits into from
Oct 16, 2024
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
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,14 @@ pub trait HasContext: __private::Sealed {

unsafe fn clear_color(&self, red: f32, green: f32, blue: f32, alpha: f32);

unsafe fn supports_f64_precision() -> bool;
unsafe fn supports_f64_precision(&self) -> bool;

unsafe fn clear_depth_f64(&self, depth: f64);

unsafe fn clear_depth_f32(&self, depth: f32);

unsafe fn clear_depth(&self, depth: f64);

unsafe fn clear_stencil(&self, stencil: i32);

unsafe fn clear(&self, mask: u32);
Expand Down Expand Up @@ -1471,6 +1473,8 @@ pub trait HasContext: __private::Sealed {

unsafe fn depth_range_f64(&self, near: f64, far: f64);

unsafe fn depth_range(&self, near: f64, far: f64);

unsafe fn depth_range_f64_slice(&self, first: u32, count: i32, values: &[[f64; 2]]);

unsafe fn scissor(&self, x: i32, y: i32, width: i32, height: i32);
Expand Down
21 changes: 18 additions & 3 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,8 @@ impl HasContext for Context {
gl.ClearColor(red, green, blue, alpha);
}

unsafe fn supports_f64_precision() -> bool {
// TODO: Handle OpenGL ES
true
unsafe fn supports_f64_precision(&self) -> bool {
!self.version.is_embedded
}

unsafe fn clear_depth_f64(&self, depth: f64) {
Expand All @@ -1251,6 +1250,14 @@ impl HasContext for Context {
gl.ClearDepthf(depth);
}

unsafe fn clear_depth(&self, depth: f64) {
if self.supports_f64_precision() {
self.clear_depth_f64(depth);
} else {
self.clear_depth_f32(depth as f32);
}
}

unsafe fn clear_stencil(&self, stencil: i32) {
let gl = &self.raw;
gl.ClearStencil(stencil);
Expand Down Expand Up @@ -3266,6 +3273,14 @@ impl HasContext for Context {
gl.DepthRange(near, far);
}

unsafe fn depth_range(&self, near: f64, far: f64) {
if self.supports_f64_precision() {
self.depth_range_f64(near, far);
} else {
self.depth_range_f32(near as f32, far as f32);
}
}

unsafe fn depth_range_f64_slice(&self, first: u32, count: i32, values: &[[f64; 2]]) {
let gl = &self.raw;
gl.DepthRangeArrayv(first, count, values.as_ptr() as *const f64);
Expand Down
10 changes: 9 additions & 1 deletion src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ impl HasContext for Context {
}
}

unsafe fn supports_f64_precision() -> bool {
unsafe fn supports_f64_precision(&self) -> bool {
false
}

Expand All @@ -2561,6 +2561,10 @@ impl HasContext for Context {
}
}

unsafe fn clear_depth(&self, depth: f64) {
self.clear_depth_f32(depth as f32);
}

unsafe fn clear_stencil(&self, stencil: i32) {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl.clear_stencil(stencil),
Expand Down Expand Up @@ -4891,6 +4895,10 @@ impl HasContext for Context {
panic!("Depth range with 64-bit float values is not supported");
}

unsafe fn depth_range(&self, near: f64, far: f64) {
self.depth_range_f32(near as f32, far as f32)
}

unsafe fn depth_range_f64_slice(&self, _first: u32, _count: i32, _values: &[[f64; 2]]) {
panic!("Depth range with 64-bit float slices is not supported");
}
Expand Down
Loading