2 Copyright (c) 2019 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>Point-specific shader variables test
</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 id=
"c" width=
"64" height=
"64"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
21 <script id=
"vs-assign" type=
"x-shader/x-vertex">
22 attribute vec2 aPosition;
28 gl_Position = vec4(aPosition,
0,
1);
35 <script id=
"vs-conditional" type=
"x-shader/x-vertex">
36 uniform float renderingPoints; // not assigned, equal to
0.0
37 attribute vec2 aPosition;
43 gl_Position = vec4(aPosition,
0,
1);
46 if (renderingPoints
> 0.0) {
52 <script id=
"fs-overwrite" type=
"x-shader/x-fragment">
53 varying mediump vec2 vPos;
57 gl_FragColor = vec4(gl_PointCoord.xy,
0,
1);
58 gl_FragColor = vec4(vPos * -
2.0,
0,
1);
62 <script id=
"fs-unused-branch" type=
"x-shader/x-fragment">
63 varying mediump vec2 vPos;
64 uniform mediump float uDefaultsToZero;
68 gl_FragColor = vec4(vPos * -
2.0,
0,
1);
69 if (uDefaultsToZero ==
1.0) {
70 gl_FragColor = vec4(gl_PointCoord.xy,
0,
1);
77 description(document
.title
);
79 debug('This test verifies rendering with programs referencing shader variables specific to rendering of POINTS primitives.');
81 var wtu
= WebGLTestUtils
;
82 var gl
= wtu
.create3DContext("c", {depth
: false});
84 var prog_overwrite
= wtu
.setupProgram(gl
, ["vs-assign", "fs-overwrite"], ["aPosition"]);
85 var prog_branch
= wtu
.setupProgram(gl
, ["vs-assign", "fs-unused-branch"], ["aPosition"]);
86 var prog_cond_overwrite
= wtu
.setupProgram(gl
, ["vs-conditional", "fs-overwrite"], ["aPosition"]);
87 var prog_cond_branch
= wtu
.setupProgram(gl
, ["vs-conditional", "fs-unused-branch"], ["aPosition"]);
89 var vertData
= new Float32Array([
95 var vertexObject
= gl
.createBuffer();
96 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
97 gl
.bufferData(gl
.ARRAY_BUFFER
, vertData
, gl
.STATIC_DRAW
);
99 gl
.enableVertexAttribArray(0);
100 gl
.vertexAttribPointer(0, 2, gl
.FLOAT
, false, 0, 0);
105 debug("prog-overwrite");
107 gl
.clear(gl
.COLOR_BUFFER_BIT
);
108 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left
110 gl
.useProgram(prog_overwrite
);
111 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
113 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
114 wtu
.checkCanvasRect(gl
, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right
120 debug("prog-branch");
122 gl
.clear(gl
.COLOR_BUFFER_BIT
);
123 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left
125 gl
.useProgram(prog_branch
);
126 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
128 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
129 wtu
.checkCanvasRect(gl
, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right
134 debug("prog-cond-overwrite");
136 gl
.clear(gl
.COLOR_BUFFER_BIT
);
137 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left
139 gl
.useProgram(prog_cond_overwrite
);
140 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
142 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
143 wtu
.checkCanvasRect(gl
, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right
149 debug("prog-cond-branch");
151 gl
.clear(gl
.COLOR_BUFFER_BIT
);
152 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left
154 gl
.useProgram(prog_cond_branch
);
155 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
157 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
158 wtu
.checkCanvasRect(gl
, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right
160 var successfullyParsed
= true;
163 <script src=
"../../js/js-test-post.js"></script>