Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / ext-polygon-offset-clamp.html
blobce14e96fc749edb623c92a31c20d535e544d837d
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_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>
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_polygon_offset_clamp extension, if it is available.");
24 debug("");
26 var wtu = WebGLTestUtils;
27 var gl = wtu.create3DContext();
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(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() {
41 debug("");
42 debug("Check enums");
43 shouldBe("ext.POLYGON_OFFSET_CLAMP_EXT", "0x8E1B");
46 function checkQueries() {
47 debug("");
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");
53 debug("");
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");
60 debug("");
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() {
70 debug("");
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 // ^ | __________________
79 // | | __/ __/
80 // | V __/ __/ <--- Draw 1 (red): factor width, offset 0, clamp 0.25
81 // | __/ __/
82 // | __/ __/
83 // |/ __/
84 // | __/
85 // | __/
86 // |/
87 // |
88 // |
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);
101 gl.bufferData(
102 gl.ARRAY_BUFFER,
103 new Float32Array([-1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1]),
104 gl.STATIC_DRAW);
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);
112 gl.clearDepth(0);
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);
127 wtu.checkCanvasRect(
129 0, 0, 3 * w / 4 - 1, h,
130 [0, 255, 0, 255], "should be green");
132 wtu.checkCanvasRect(
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() {
141 checkEnums();
142 checkQueries();
143 checkClamping();
146 function runTest() {
147 if (!gl) {
148 testFailed("WebGL context does not exist");
149 return;
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);
159 if (ext !== null) {
160 runTestExtension();
161 } else {
162 testPassed("No EXT_polygon_offset_clamp support -- this is legal");
166 runTest();
168 var successfullyParsed = true;
169 </script>
170 <script src="../../js/js-test-post.js"></script>
171 </body>
172 </html>