Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / rendering / point-specific-shader-variables.html
blob71f0bcad502fa78a3060d95ac2059323a22c85d7
1 <!--
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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
15 </head>
16 <body>
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;
24 varying vec2 vPos;
26 void main()
28 gl_Position = vec4(aPosition, 0, 1);
29 vPos = aPosition;
31 gl_PointSize = 1.0;
33 </script>
35 <script id="vs-conditional" type="x-shader/x-vertex">
36 uniform float renderingPoints; // not assigned, equal to 0.0
37 attribute vec2 aPosition;
39 varying vec2 vPos;
41 void main()
43 gl_Position = vec4(aPosition, 0, 1);
44 vPos = aPosition;
46 if (renderingPoints > 0.0) {
47 gl_PointSize = 1.0;
50 </script>
52 <script id="fs-overwrite" type="x-shader/x-fragment">
53 varying mediump vec2 vPos;
55 void main()
57 gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);
58 gl_FragColor = vec4(vPos * -2.0, 0, 1);
60 </script>
62 <script id="fs-unused-branch" type="x-shader/x-fragment">
63 varying mediump vec2 vPos;
64 uniform mediump float uDefaultsToZero;
66 void main()
68 gl_FragColor = vec4(vPos * -2.0, 0, 1);
69 if (uDefaultsToZero == 1.0) {
70 gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);
73 </script>
75 <script>
76 "use strict";
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([
90 -1, -1,
91 +1, -1,
92 -1, +1,
93 ]);
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);
102 //////////
104 debug("");
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
117 //////////
119 debug("");
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
131 //////////
133 debug("");
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
146 //////////
148 debug("");
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;
161 </script>
163 <script src="../../js/js-test-post.js"></script>
165 </body>
166 </html>