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.
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>
17 <canvas width=
"32" height=
"32" id=
"c"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
22 description("This test verifies the functionality of the EXT_depth_clamp extension, if it is available.");
26 var wtu
= WebGLTestUtils
;
27 var gl
= wtu
.create3DContext("c");
29 const w
= gl
.drawingBufferWidth
;
30 const h
= gl
.drawingBufferHeight
;
32 function runTestNoExtension() {
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() {
56 shouldBe("ext.DEPTH_CLAMP_EXT", "0x864F");
59 function checkQueries() {
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");
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() {
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;
91 gl_Position = vec4(vPosition, u_depth, 1.0);
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);
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
);
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);
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);
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() {
144 testFailed("WebGL context does not exist");
147 testPassed("WebGL context exists");
149 runTestNoExtension();
151 ext
= gl
.getExtension("EXT_depth_clamp");
153 wtu
.runExtensionSupportedTest(gl
, "EXT_depth_clamp", ext
!== null);
158 testPassed("No EXT_depth_clamp support -- this is legal");
164 var successfullyParsed
= true;
166 <script src=
"../../js/js-test-post.js"></script>