5 <title>WebGL
2 gl_VertexID Large Count Tests
</title>
6 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
7 <script src=
"../../js/desktop-gl-constants.js"></script>
8 <script src=
"../../js/js-test-pre.js"></script>
9 <script src=
"../../js/webgl-test-utils.js"></script>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
14 <!-- Shaders for testing instanced draws -->
15 <script id=
"vs" type=
"text/plain">
18 uniform ivec2 resolution;
21 gl_VertexID % resolution.x,
22 gl_VertexID / resolution.x);
23 vec2 xy = (vec2(pixel) +
0.5) / vec2(resolution) *
2.0 -
1.0;
25 gl_Position = vec4(xy,
0,
1);
29 <script id=
"fs" type=
"text/plain">
31 precision mediump float;
41 description("Test gl_VertexID");
45 const wtu
= WebGLTestUtils
;
46 const canvas
= document
.createElement("canvas");
50 const gl
= wtu
.create3DContext(canvas
, null, 2);
52 // document.body.appendChild(gl.canvas);
53 // gl.canvas.style.background = 'yellow';
54 // gl.canvas.style.margin = '20px';
55 // const ext = gl.getExtension('WEBGL_debug_renderer_info');
57 // debug(gl.getParameter(ext.UNMASKED_RENDERER_WEBGL));
62 testFailed("WebGL context does not exist");
65 testPassed("WebGL context exists");
67 const vs
= document
.getElementById("vs").innerHTML
.trim();
68 const fs
= document
.getElementById("fs").innerHTML
.trim();
69 const prog
= wtu
.loadProgram(gl
, vs
, fs
);
71 const resolutionLoc
= gl
.getUniformLocation(prog
, 'resolution');
72 const colorLoc
= gl
.getUniformLocation(prog
, 'color');
77 debug("----------------");
80 const u8Color
= c
=> c
.map(v
=> v
* 255 | 0);
81 const transparentBlack
= [0, 0, 0, 0];
82 const red
= [1, 0, 0, 1];
83 const green
= [0, 1, 0, 1];
84 const blue
= [0, 0, 1, 1];
86 const test = function(first
, count
, color
) {
88 debug(`drawArrays(first: ${first}, count: ${count})`);
89 gl
.clear(gl
.COLOR_BUFFER_BIT
);
90 gl
.uniform4fv(colorLoc
, color
);
91 gl
.uniform2i(resolutionLoc
, size
, size
);
92 gl
.drawArrays(gl
.POINTS
, first
, count
);
93 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
94 const y
= first
/ size
;
95 const height
= count
/ size
;
97 // The shader draws 1 pixel points by looking at gl_VertexID
98 // as a 1D index into a 2D array. In other words
99 // row = gl_VertexID / width;
100 // col = gl_VertexID % width;
101 // Setting first to a value of rows * width (ie, y * size)
102 // lets us skip y rows when drawing so we then check that
103 // from y to height rows are the expected color and everything
104 // else is the cleared color.
105 wtu
.checkCanvasRect(gl
, 0, y
, size
, height
, u8Color(color
));
106 wtu
.checkCanvasRect(gl
, 0, 0, size
, size
- height
, transparentBlack
);
109 test(0, size
* size
, red
);
110 test(size
* size
/ 2, size
* size
/ 2, green
);
111 test(size
* size
/ 4, size
* size
/ 4 * 3, blue
);
112 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "There should be no remaining errors");
116 var successfullyParsed
= true;
118 <script src=
"../../js/js-test-post.js"></script>
124 Copyright (c) 2019 The Khronos Group Inc.
125 Use of this source code is governed by an MIT-style license that can be
126 found in the LICENSE.txt file.