diff --git a/src/lib.rs b/src/lib.rs index 9331aef..76ddea8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); @@ -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); diff --git a/src/native.rs b/src/native.rs index 986a916..5e69bf1 100644 --- a/src/native.rs +++ b/src/native.rs @@ -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) { @@ -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); @@ -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); diff --git a/src/web_sys.rs b/src/web_sys.rs index be72cb1..d9e3bda 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -2546,7 +2546,7 @@ impl HasContext for Context { } } - unsafe fn supports_f64_precision() -> bool { + unsafe fn supports_f64_precision(&self) -> bool { false } @@ -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), @@ -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"); }