Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Properly clamp arguments to WebGLRenderingContext.depthRange
  • Loading branch information
nox committed Apr 5, 2018
1 parent 7b4d66b commit fb290e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 3 additions & 2 deletions components/canvas/webgl_thread.rs
Expand Up @@ -695,8 +695,9 @@ impl WebGLImpl {
ctx.gl().depth_func(func),
WebGLCommand::DepthMask(flag) =>
ctx.gl().depth_mask(flag),
WebGLCommand::DepthRange(near, far) =>
ctx.gl().depth_range(near, far),
WebGLCommand::DepthRange(near, far) => {
ctx.gl().depth_range(near.max(0.).min(1.) as f64, far.max(0.).min(1.) as f64)
}
WebGLCommand::Disable(cap) =>
ctx.gl().disable(cap),
WebGLCommand::Enable(cap) =>
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/webgl.rs
Expand Up @@ -177,7 +177,7 @@ pub enum WebGLCommand {
FrontFace(u32),
DepthFunc(u32),
DepthMask(bool),
DepthRange(f64, f64),
DepthRange(f32, f32),
Enable(u32),
Disable(u32),
CompileShader(WebGLShaderId, String),
Expand Down
9 changes: 2 additions & 7 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -1925,16 +1925,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn DepthRange(&self, near: f32, far: f32) {
// From the WebGL 1.0 spec, 6.12: Viewport Depth Range:
//
// "A call to depthRange will generate an
// INVALID_OPERATION error if zNear is greater than
// zFar."
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#VIEWPORT_DEPTH_RANGE
if near > far {
return self.webgl_error(InvalidOperation);
}

self.send_command(WebGLCommand::DepthRange(near as f64, far as f64))
self.send_command(WebGLCommand::DepthRange(near, far))
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
Expand Down

0 comments on commit fb290e9

Please sign in to comment.