Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / uniforms / uniform-blocks-with-arrays.html
blob2d40a62c005a12030e442e6bcb406fd3bf2f5a78
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>WebGL uniform blocks containing arrays 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 <script id="vshader" type="x-shader/x-vertex">#version 300 es
16 in vec4 vPosition;
17 void main() {
18 gl_Position = vPosition;
20 </script>
21 <script id="fshaderArraysOfStructs" type="x-shader/x-fragment">#version 300 es
22 precision highp float;
23 out vec4 my_FragColor;
24 struct light_t {
25 vec4 intensity;
27 const int maxLights = 2;
28 layout(std140) uniform lightData { light_t lights[maxLights]; };
29 vec4 processLight(vec4 lighting, light_t light)
31 return lighting + light.intensity;
33 void main()
35 vec4 lighting = vec4(0, 1, 0, 1);
36 for (int n = 0; n < maxLights; n++)
37 lighting = processLight(lighting, lights[n]);
38 my_FragColor = lighting;
40 </script>
41 <script id="fshaderArraysOfStructsContainingArrays" type="x-shader/x-fragment">#version 300 es
42 precision highp float;
43 out vec4 my_FragColor;
44 struct light_t {
45 vec4 intensity[3];
47 const int maxLights = 2;
48 layout(std140) uniform lightData { light_t lights[maxLights]; };
49 vec4 processLight(vec4 lighting, light_t light)
51 return lighting + light.intensity[1];
53 void main()
55 vec4 lighting = vec4(0, 1, 0, 1);
56 for (int n = 0; n < maxLights; n++)
57 lighting = processLight(lighting, lights[n]);
58 my_FragColor = lighting;
60 </script>
61 </head>
62 <body>
63 <div id="description"></div>
64 <div id="console"></div>
65 <script>
66 "use strict";
67 description();
69 // GLSL ES 3.00.6 section 4.3.7:
70 // "Otherwise, built-in types, previously declared structures, and arrays of these are allowed as the type of a declarator in the same manner they are allowed outside a block."
72 var wtu = WebGLTestUtils;
73 var gl = wtu.create3DContext(undefined, undefined, 2);
75 function runTest(fragShader, bufferFloatCount, shaderBlockDescription) {
76 debug('');
77 debug('Testing fragment shader with an uniform block containing ' + shaderBlockDescription);
78 var program = wtu.setupProgram(gl, ['vshader', fragShader], ['vPosition'], undefined, true);
79 if (!program) {
80 testFailed("Loading program failed");
81 return;
83 var blockIndex = gl.getUniformBlockIndex(program, "lightData");
85 var uniformBuffer = gl.createBuffer();
86 gl.bindBuffer(gl.UNIFORM_BUFFER, uniformBuffer);
87 gl.bufferData(gl.UNIFORM_BUFFER, new Float32Array(bufferFloatCount), gl.DYNAMIC_READ);
89 gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, uniformBuffer);
90 gl.uniformBlockBinding(program, blockIndex, 0);
92 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors from uniform buffer setup");
94 wtu.clearAndDrawUnitQuad(gl);
96 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors from draw");
98 wtu.checkCanvas(gl, [0, 255, 0, 255], 'should be green', 1);
101 if (!gl) {
102 testFailed("WebGL context creation failed");
103 } else {
104 wtu.setupUnitQuad(gl);
105 runTest("fshaderArraysOfStructs", 2 * 4, 'arrays of structs');
106 runTest("fshaderArraysOfStructsContainingArrays", 2 * 3 * 4, 'arrays of structs containing arrays');
109 debug("");
110 var successfullyParsed = true;
111 </script>
112 <script src="../../js/js-test-post.js"></script>
114 </body>
115 </html>