From 7b4d66b621f28cedb47fd8400a6d8fcb75c22b86 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 4 Apr 2018 16:22:28 +0200 Subject: [PATCH] Manually clamp the argument of WebGLRenderingContext.clearDepth Better be safe than to feed stuff to some GPU driver that wouldn't clamp it. --- components/canvas/webgl_thread.rs | 5 +++-- components/canvas_traits/webgl.rs | 2 +- components/script/dom/webglrenderingcontext.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 933c8893cf2..01ab0a15250 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -678,8 +678,9 @@ impl WebGLImpl { ctx.gl().clear(mask), WebGLCommand::ClearColor(r, g, b, a) => ctx.gl().clear_color(r, g, b, a), - WebGLCommand::ClearDepth(depth) => - ctx.gl().clear_depth(depth), + WebGLCommand::ClearDepth(depth) => { + ctx.gl().clear_depth(depth.max(0.).min(1.) as f64) + } WebGLCommand::ClearStencil(stencil) => ctx.gl().clear_stencil(stencil), WebGLCommand::ColorMask(r, g, b, a) => diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs index 55d2843c276..01e3c49fc3d 100644 --- a/components/canvas_traits/webgl.rs +++ b/components/canvas_traits/webgl.rs @@ -170,7 +170,7 @@ pub enum WebGLCommand { BufferSubData(u32, isize, ByteBuf), Clear(u32), ClearColor(f32, f32, f32, f32), - ClearDepth(f64), + ClearDepth(f32), ClearStencil(i32), ColorMask(bool, bool, bool, bool), CullFace(u32), diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 5819b33357e..81f28ceb1cd 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1876,7 +1876,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn ClearDepth(&self, depth: f32) { - self.send_command(WebGLCommand::ClearDepth(depth as f64)) + self.send_command(WebGLCommand::ClearDepth(depth)) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3