Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / ext-depth-clamp.html
blob6082c9880c1e1609661e0503a4e7dc55f2a3d21b
1 <!--
2 Copyright (c) 2023 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL EXT_depth_clamp Conformance Tests</title>
12 <LINK rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <canvas width="32" height="32" id="c"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script>
21 "use strict";
22 description("This test verifies the functionality of the EXT_depth_clamp extension, if it is available.");
24 debug("");
26 var wtu = WebGLTestUtils;
27 var gl = wtu.create3DContext("c");
28 var ext;
29 const w = gl.drawingBufferWidth;
30 const h = gl.drawingBufferHeight;
32 function runTestNoExtension() {
33 debug("");
34 debug("Check the parameter without the extension");
35 shouldBeNull("gl.getParameter(0x864F /* DEPTH_CLAMP_EXT */)");
36 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "parameter unknown without enabling the extension");
37 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
39 debug("Check the cap without the extension");
40 gl.disable(0x864F /* DEPTH_CLAMP_EXT */);
41 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "cap unknown without enabling the extension");
42 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
44 gl.enable(0x864F /* DEPTH_CLAMP_EXT */);
45 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "cap unknown without enabling the extension");
46 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
48 shouldBeFalse("gl.isEnabled(0x864F /* DEPTH_CLAMP_EXT */)");
49 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "cap unknown without enabling the extension");
50 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
53 function checkEnums() {
54 debug("");
55 debug("Check enums");
56 shouldBe("ext.DEPTH_CLAMP_EXT", "0x864F");
59 function checkQueries() {
60 debug("");
61 debug("Check default state");
62 shouldBeFalse('gl.isEnabled(ext.DEPTH_CLAMP_EXT)');
63 shouldBeFalse('gl.getParameter(ext.DEPTH_CLAMP_EXT)');
64 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
66 debug("");
67 debug("Check state update using the new capability");
68 gl.enable(ext.DEPTH_CLAMP_EXT);
69 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
70 shouldBeTrue('gl.isEnabled(ext.DEPTH_CLAMP_EXT)');
71 shouldBeTrue('gl.getParameter(ext.DEPTH_CLAMP_EXT)');
72 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
74 gl.disable(ext.DEPTH_CLAMP_EXT);
75 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
76 shouldBeFalse('gl.isEnabled(ext.DEPTH_CLAMP_EXT)');
77 shouldBeFalse('gl.getParameter(ext.DEPTH_CLAMP_EXT)');
78 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
81 function checkClamping() {
82 debug("");
83 debug("Check depth clamp operation");
85 // Draw a red quad located beyond the clipping volume.
86 // When depth clamping is enabled, it must be drawn.
87 const vertexShader = `
88 attribute vec2 vPosition;
89 uniform float u_depth;
90 void main() {
91 gl_Position = vec4(vPosition, u_depth, 1.0);
92 }`;
93 const program = wtu.setupProgram(gl, [vertexShader,
94 wtu.simpleColorFragmentShader]);
95 gl.useProgram(program);
96 const colorLoc = gl.getUniformLocation(program, "u_color");
97 const depthLoc = gl.getUniformLocation(program, "u_depth");
99 wtu.setupUnitQuad(gl);
100 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
102 // Red beyond the far plane
103 gl.uniform4f(colorLoc, 1, 0, 0, 1);
104 gl.uniform1f(depthLoc, +2);
106 // Clipped
107 wtu.clearAndDrawUnitQuad(gl);
108 wtu.checkCanvasRect(gl, 0, 0, w, h, [255, 255, 255, 255]);
110 // Enable depth clamping, disable depth clipping
111 gl.enable(ext.DEPTH_CLAMP_EXT);
113 // Not clipped
114 wtu.clearAndDrawUnitQuad(gl);
115 wtu.checkCanvasRect(gl, 0, 0, w, h, [255, 0, 0, 255]);
117 // Green beyond the near plane
118 gl.uniform4f(colorLoc, 0, 1, 0, 1);
119 gl.uniform1f(depthLoc, -2);
121 // Not clipped
122 wtu.clearAndDrawUnitQuad(gl);
123 wtu.checkCanvasRect(gl, 0, 0, w, h, [0, 255, 0, 255]);
125 // Blue beyond the near plane with clamping disabled
126 gl.disable(ext.DEPTH_CLAMP_EXT);
127 gl.uniform4f(colorLoc, 0, 0, 1, 1);
129 // Clipped
130 wtu.clearAndDrawUnitQuad(gl);
131 wtu.checkCanvasRect(gl, 0, 0, w, h, [255, 255, 255, 255]);
133 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
136 function runTestExtension() {
137 checkEnums();
138 checkQueries();
139 checkClamping();
142 function runTest() {
143 if (!gl) {
144 testFailed("WebGL context does not exist");
145 return;
147 testPassed("WebGL context exists");
149 runTestNoExtension();
151 ext = gl.getExtension("EXT_depth_clamp");
153 wtu.runExtensionSupportedTest(gl, "EXT_depth_clamp", ext !== null);
155 if (ext !== null) {
156 runTestExtension();
157 } else {
158 testPassed("No EXT_depth_clamp support -- this is legal");
162 runTest();
164 var successfullyParsed = true;
165 </script>
166 <script src="../../js/js-test-post.js"></script>
167 </body>
168 </html>