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>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
18 gl_Position = vPosition;
21 <script id=
"fshaderArraysOfStructs" type=
"x-shader/x-fragment">#version
300 es
22 precision highp float;
23 out vec4 my_FragColor;
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;
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;
41 <script id=
"fshaderArraysOfStructsContainingArrays" type=
"x-shader/x-fragment">#version
300 es
42 precision highp float;
43 out vec4 my_FragColor;
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];
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;
63 <div id=
"description"></div>
64 <div id=
"console"></div>
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
) {
77 debug('Testing fragment shader with an uniform block containing ' + shaderBlockDescription
);
78 var program
= wtu
.setupProgram(gl
, ['vshader', fragShader
], ['vPosition'], undefined, true);
80 testFailed("Loading program failed");
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);
102 testFailed("WebGL context creation failed");
104 wtu
.setupUnitQuad(gl
);
105 runTest("fshaderArraysOfStructs", 2 * 4, 'arrays of structs');
106 runTest("fshaderArraysOfStructsContainingArrays", 2 * 3 * 4, 'arrays of structs containing arrays');
110 var successfullyParsed
= true;
112 <script src=
"../../js/js-test-post.js"></script>