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_polygon_offset_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_polygon_offset_clamp extension, if it is available.");
26 var wtu
= WebGLTestUtils
;
27 var gl
= wtu
.create3DContext();
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(0x8E1B /* POLYGON_OFFSET_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");
40 function checkEnums() {
43 shouldBe("ext.POLYGON_OFFSET_CLAMP_EXT", "0x8E1B");
46 function checkQueries() {
48 debug("Check default state");
49 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_FACTOR)', '0.0');
50 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_UNITS)', '0.0');
51 shouldBe('gl.getParameter(ext.POLYGON_OFFSET_CLAMP_EXT)', '0.0');
52 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
54 debug("Check state update using the new function");
55 ext
.polygonOffsetClampEXT(1.0, 2.0, 3.0);
56 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_FACTOR)', '1.0');
57 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_UNITS)', '2.0');
58 shouldBe('gl.getParameter(ext.POLYGON_OFFSET_CLAMP_EXT)', '3.0');
59 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
61 debug("Check that the unextended function resets the clamp value to zero");
62 gl
.polygonOffset(4.0, 5.0);
63 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_FACTOR)', '4.0');
64 shouldBe('gl.getParameter(gl.POLYGON_OFFSET_UNITS)', '5.0');
65 shouldBe('gl.getParameter(ext.POLYGON_OFFSET_CLAMP_EXT)', '0.0');
66 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
69 function checkClamping() {
71 debug("Check polygon offset clamp operation");
73 // The shader creates a depth slope from left (0) to right (1).
75 // This test issues two draw calls:
77 // Draw 2 (green): factor width, offset 0, clamp 0.5, depth test: Greater
78 // ^ | __________________
80 // | V __/ __/ <--- Draw 1 (red): factor width, offset 0, clamp 0.25
89 // +------------------------------->
91 // Result: <---------green--------><--red-->
94 const program
= wtu
.setupProgram(gl
, [wtu
.simpleVertexShader
,
95 wtu
.simpleColorFragmentShader
]);
96 gl
.useProgram(program
);
97 const colorLoc
= gl
.getUniformLocation(program
, "u_color");
99 const buf
= gl
.createBuffer();
100 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buf
);
103 new Float32Array([-1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1]),
105 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
106 gl
.enableVertexAttribArray(0);
108 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
110 gl
.enable(gl
.POLYGON_OFFSET_FILL
);
111 gl
.clearColor(0, 0, 0, 1);
113 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
115 gl
.enable(gl
.DEPTH_TEST
);
117 gl
.depthFunc(gl
.ALWAYS
);
118 gl
.uniform4f(colorLoc
, 1, 0, 0, 1);
119 ext
.polygonOffsetClampEXT(w
, 0, 0.25);
120 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 4);
122 gl
.depthFunc(gl
.GREATER
);
123 gl
.uniform4f(colorLoc
, 0, 1, 0, 1);
124 ext
.polygonOffsetClampEXT(w
, 0, 0.5);
125 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 4);
129 0, 0, 3 * w
/ 4 - 1, h
,
130 [0, 255, 0, 255], "should be green");
134 3 * w
/ 4 + 1, 0, w
/ 4 - 1, h
,
135 [255, 0, 0, 255], "should be red");
137 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
140 function runTestExtension() {
148 testFailed("WebGL context does not exist");
151 testPassed("WebGL context exists");
153 runTestNoExtension();
155 ext
= gl
.getExtension("EXT_polygon_offset_clamp");
157 wtu
.runExtensionSupportedTest(gl
, "EXT_polygon_offset_clamp", ext
!== null);
162 testPassed("No EXT_polygon_offset_clamp support -- this is legal");
168 var successfullyParsed
= true;
170 <script src=
"../../js/js-test-post.js"></script>