2 Copyright (c) 2022 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 WEBGL_provoking_vertex 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=
"16" height=
"16" id=
"c"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
22 description("This test verifies the functionality of the WEBGL_provoking_vertex extension, if it is available.");
26 var wtu
= WebGLTestUtils
;
27 var gl
= wtu
.create3DContext("c", null, 2);
30 function runTestNoExtension() {
32 debug("Check getParameter without the extension");
33 shouldBeNull("gl.getParameter(0x8E4F /* PROVOKING_VERTEX_WEBGL */)");
34 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
, "parameter unknown without enabling the extension");
38 function runTestExtension() {
41 shouldBe("ext.FIRST_VERTEX_CONVENTION_WEBGL", "0x8E4D");
42 shouldBe("ext.LAST_VERTEX_CONVENTION_WEBGL", "0x8E4E");
43 shouldBe("ext.PROVOKING_VERTEX_WEBGL", "0x8E4F");
46 debug("Check default state");
47 shouldBe("gl.getParameter(ext.PROVOKING_VERTEX_WEBGL)", "ext.LAST_VERTEX_CONVENTION_WEBGL");
48 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "parameter known with the extension enabled");
51 debug("Check state updates");
52 ext
.provokingVertexWEBGL(ext
.FIRST_VERTEX_CONVENTION_WEBGL
);
53 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "provokingVertexWEBGL(ext.FIRST_VERTEX_CONVENTION_WEBGL) generates no errors");
54 shouldBe("gl.getParameter(ext.PROVOKING_VERTEX_WEBGL)", "ext.FIRST_VERTEX_CONVENTION_WEBGL");
55 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
56 ext
.provokingVertexWEBGL(ext
.LAST_VERTEX_CONVENTION_WEBGL
);
57 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "provokingVertexWEBGL(ext.LAST_VERTEX_CONVENTION_WEBGL) generates no errors");
58 shouldBe("gl.getParameter(ext.PROVOKING_VERTEX_WEBGL)", "ext.LAST_VERTEX_CONVENTION_WEBGL");
59 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
62 debug("Check invalid provoking vertex mode");
63 ext
.provokingVertexWEBGL(ext
.FIRST_VERTEX_CONVENTION_WEBGL
);
64 ext
.provokingVertexWEBGL(ext
.PROVOKING_VERTEX_WEBGL
);
65 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
, "invalid provoking mode generates an error");
66 shouldBe("gl.getParameter(ext.PROVOKING_VERTEX_WEBGL)", "ext.FIRST_VERTEX_CONVENTION_WEBGL");
67 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
70 debug("Check provoking vertex operation");
72 const vs
= `#version 300 es
77 gl_Position = vec4(position, 0, 1);
81 const fs
= `#version 300 es
88 const program
= wtu
.setupProgram(gl
, [vs
, fs
]);
89 gl
.useProgram(program
);
91 const tex
= gl
.createTexture();
92 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
93 gl
.texStorage2D(gl
.TEXTURE_2D
, 1, gl
.R32I
, 16, 16);
95 const fb
= gl
.createFramebuffer();
96 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
97 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex
, 0);
99 const vb
= gl
.createBuffer();
100 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vb
);
101 const buf
= new ArrayBuffer(36);
102 new Float32Array(buf
, 0, 6).set([-1.0, -1.0, 3.0, -1.0, -1.0, 3.0]);
103 new Int32Array(buf
, 24, 3).set([1, 2, 3]);
104 gl
.bufferData(gl
.ARRAY_BUFFER
, buf
, gl
.STATIC_DRAW
);
106 const positionLocation
= gl
.getAttribLocation(program
, "position");
107 gl
.enableVertexAttribArray(positionLocation
);
108 gl
.vertexAttribPointer(positionLocation
, 2, gl
.FLOAT
, false, 0, 0);
110 const intAttribLocation
= gl
.getAttribLocation(program
, "intAttrib");
111 gl
.enableVertexAttribArray(intAttribLocation
);
112 gl
.vertexAttribIPointer(intAttribLocation
, 1, gl
.INT
, 0, 24);
114 const pixel
= new Int32Array(4);
116 ext
.provokingVertexWEBGL(ext
.LAST_VERTEX_CONVENTION_WEBGL
);
117 gl
.clearBufferiv(gl
.COLOR
, 0, new Int32Array(4));
118 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
119 gl
.readPixels(0, 0, 1, 1, gl
.RGBA_INTEGER
, gl
.INT
, pixel
);
122 testPassed("Correct last provoking vertex");
124 testFailed("Incorrect last provoking vertex");
127 ext
.provokingVertexWEBGL(ext
.FIRST_VERTEX_CONVENTION_WEBGL
);
128 gl
.clearBufferiv(gl
.COLOR
, 0, new Int32Array(4));
129 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
130 gl
.readPixels(0, 0, 1, 1, gl
.RGBA_INTEGER
, gl
.INT
, pixel
);
133 testPassed("Correct first provoking vertex");
135 testFailed("Incorrect first provoking vertex");
141 testFailed("context does not exist");
143 testPassed("context exists");
145 runTestNoExtension();
147 ext
= gl
.getExtension("WEBGL_provoking_vertex");
149 wtu
.runExtensionSupportedTest(gl
, "WEBGL_provoking_vertex", ext
!== null);
154 testPassed("No WEBGL_provoking_vertex support -- this is legal");
161 var successfullyParsed
= true;
163 <script src=
"../../js/js-test-post.js"></script>