Skip to content

Commit

Permalink
Manually clamp the argument of WebGLRenderingContext.clearDepth
Browse files Browse the repository at this point in the history
Better be safe than to feed stuff to some GPU driver that wouldn't clamp it.
  • Loading branch information
nox committed Apr 5, 2018
1 parent fc6335c commit 7b4d66b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions components/canvas/webgl_thread.rs
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/webgl.rs
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webglrenderingcontext.rs
Expand Up @@ -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
Expand Down

0 comments on commit 7b4d66b

Please sign in to comment.