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_clip_control 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_clip_control 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 parameters without the extension");
35 shouldBeNull("gl.getParameter(0x935C /* CLIP_ORIGIN_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");
38 shouldBeNull("gl.getParameter(0x935D /* CLIP_DEPTH_MODE_EXT */)");
39 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
, "parameter unknown without enabling the extension");
40 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
43 function checkEnums() {
46 shouldBe("ext.LOWER_LEFT_EXT", "0x8CA1");
47 shouldBe("ext.UPPER_LEFT_EXT", "0x8CA2");
49 shouldBe("ext.NEGATIVE_ONE_TO_ONE_EXT", "0x935E");
50 shouldBe("ext.ZERO_TO_ONE_EXT", "0x935F");
52 shouldBe("ext.CLIP_ORIGIN_EXT", "0x935C");
53 shouldBe("ext.CLIP_DEPTH_MODE_EXT", "0x935D");
56 function checkQueries() {
58 debug("Check default state");
59 shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
60 shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
62 debug("Check state updates using the new function");
63 ext
.clipControlEXT(ext
.UPPER_LEFT_EXT
, ext
.ZERO_TO_ONE_EXT
);
64 shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.UPPER_LEFT_EXT');
65 shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.ZERO_TO_ONE_EXT');
66 ext
.clipControlEXT(ext
.LOWER_LEFT_EXT
, ext
.ZERO_TO_ONE_EXT
);
67 shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
68 shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.ZERO_TO_ONE_EXT');
69 ext
.clipControlEXT(ext
.UPPER_LEFT_EXT
, ext
.NEGATIVE_ONE_TO_ONE_EXT
);
70 shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.UPPER_LEFT_EXT');
71 shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
72 ext
.clipControlEXT(ext
.LOWER_LEFT_EXT
, ext
.NEGATIVE_ONE_TO_ONE_EXT
);
73 shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
74 shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
75 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
78 function checkDepthMode() {
80 debug("Check depth mode toggling");
82 gl
.enable(gl
.DEPTH_TEST
);
83 gl
.clear(gl
.DEPTH_BUFFER_BIT
);
85 const program
= wtu
.setupProgram(gl
, [wtu
.simpleVertexShader
,
86 wtu
.simpleColorFragmentShader
]);
87 gl
.useProgram(program
);
88 const colorLoc
= gl
.getUniformLocation(program
, "u_color");
89 wtu
.setupUnitQuad(gl
);
91 // Draw red at 0 with the default depth mode
92 gl
.uniform4f(colorLoc
, 1, 0, 0, 1);
93 ext
.clipControlEXT(ext
.LOWER_LEFT_EXT
, ext
.NEGATIVE_ONE_TO_ONE_EXT
);
95 wtu
.checkCanvasRect(gl
, 0, 0, w
, h
, [255, 0, 0, 255]);
97 // Draw green at 0, depth test must fail
98 gl
.uniform4f(colorLoc
, 0, 1, 0, 1);
100 wtu
.checkCanvasRect(gl
, 0, 0, w
, h
, [255, 0, 0, 255]);
102 // Draw green at 0 after switching the depth mode
103 ext
.clipControlEXT(ext
.LOWER_LEFT_EXT
, ext
.ZERO_TO_ONE_EXT
);
104 wtu
.drawUnitQuad(gl
);
105 wtu
.checkCanvasRect(gl
, 0, 0, w
, h
, [0, 255, 0, 255]);
107 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
110 function checkClipOrigin() {
112 debug("Check clip origin toggling");
114 gl
.disable(gl
.DEPTH_TEST
);
116 const vertexShader
= `
117 attribute vec4 vPosition;
120 gl_Position = vPosition;
123 const fragmentShader
= `
124 precision mediump float;
128 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
130 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
134 const program
= wtu
.setupProgram(gl
, [vertexShader
, fragmentShader
]);
135 gl
.useProgram(program
);
137 wtu
.setupUnitQuad(gl
);
139 ext
.clipControlEXT(ext
.LOWER_LEFT_EXT
, ext
.NEGATIVE_ONE_TO_ONE_EXT
);
140 wtu
.drawUnitQuad(gl
);
141 wtu
.checkCanvasRect(gl
, 0, 0, w
, h
/ 2 - 2, [0, 255, 0, 255]);
142 wtu
.checkCanvasRect(gl
, 0, h
/ 2 + 2, w
, h
/ 2 - 2, [255, 0, 0, 255]);
144 ext
.clipControlEXT(ext
.UPPER_LEFT_EXT
, ext
.NEGATIVE_ONE_TO_ONE_EXT
);
145 wtu
.drawUnitQuad(gl
);
146 wtu
.checkCanvasRect(gl
, 0, 0, w
, h
/ 2 - 2, [255, 0, 0, 255]);
147 wtu
.checkCanvasRect(gl
, 0, h
/ 2 + 2, w
, h
/ 2 - 2, [0, 255, 0, 255]);
149 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
152 function runTestExtension() {
161 testFailed("WebGL context does not exist");
164 testPassed("WebGL context exists");
166 runTestNoExtension();
168 ext
= gl
.getExtension("EXT_clip_control");
170 wtu
.runExtensionSupportedTest(gl
, "EXT_clip_control", ext
!== null);
175 testPassed("No EXT_clip_control support -- this is legal");
181 var successfullyParsed
= true;
183 <script src=
"../../js/js-test-post.js"></script>