servo: Merge #12794 - webgl: Validate that depthRange near <= far (from anholt:webgl-depthrange-validate); r=emilio
authorEric Anholt <eric@anholt.net>
Wed, 10 Aug 2016 05:40:19 -0500
changeset 339465 674050d1dcf963fb7f13ba4963505a452a1dd9ce
parent 339464 63a0345638db416f018aa0c7bac82a41e4e6e970
child 339466 e94b60610d268a9a26b9ae4161930db476efdba4
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
servo: Merge #12794 - webgl: Validate that depthRange near <= far (from anholt:webgl-depthrange-validate); r=emilio <!-- Please describe your changes on the following line: --> Add a check for one of the subcases of webgl-specific.html. I added a longer comment citing the spec than is common in the file -- we've found these kinds of citations really useful in Mesa, but if we want to keep it to the spec link, I could change it. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Fixes a subtest of webgl-specific.html. Source-Repo: https://github.com/servo/servo Source-Revision: f2b861fb24e2322d21c1a990ef25e49d2965b0ce
servo/components/script/dom/webglrenderingcontext.rs
--- a/servo/components/script/dom/webglrenderingcontext.rs
+++ b/servo/components/script/dom/webglrenderingcontext.rs
@@ -982,16 +982,25 @@ impl WebGLRenderingContextMethods for We
     fn DepthMask(&self, flag: bool) {
         self.ipc_renderer
             .send(CanvasMsg::WebGL(WebGLCommand::DepthMask(flag)))
             .unwrap()
     }
 
     // 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."
+        if near > far {
+            return self.webgl_error(InvalidOperation);
+        }
+
         self.ipc_renderer
             .send(CanvasMsg::WebGL(WebGLCommand::DepthRange(near as f64, far as f64)))
             .unwrap()
     }
 
     // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
     fn Enable(&self, cap: u32) {
         match cap {