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 Buffers should work on second compile
</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'
>
18 layout(location=
0) in vec4 position;
19 layout(std140, column_major) uniform Uniforms1 {
25 gl_Position = transform * position;
28 <script id='fshader' type='x-shader/x-fragment'
>
30 precision highp float;
32 layout(std140) uniform Uniforms2 {
43 <div id=
"description"></div>
44 <canvas id=
"canvas" style=
"width: 50px; height: 50px;"> </canvas>
45 <div id=
"console"></div>
48 description("This test verifies that getUniformBlockIndex isn't broken on second compile.");
50 debug("This is a regression test for <a href='http://crbug.com/716018'>http://crbug.com/716018</a>");
53 var wtu
= WebGLTestUtils
;
54 var canvas
= document
.getElementById("canvas");
55 var gl
= wtu
.create3DContext(canvas
, null, 2);
58 gl
.clearColor(0, 0, 0, 1);
59 var vsSource
= document
.getElementById("vshader").text
.trim();
60 var fsSource
= document
.getElementById("fshader").text
.trim();
63 // Run twice to make sure that the second build does not cause errors
64 // (i.e. due to caching).
65 for (var i
= 0; i
< 2; ++i
) {
66 debug("Compile/test iteration " + i
);
68 var vertexShader
= gl
.createShader(gl
.VERTEX_SHADER
);
69 gl
.shaderSource(vertexShader
, vsSource
);
70 gl
.compileShader(vertexShader
);
71 // Note: if COMPILE_STATUS is retrieved here, it hides the bug.
73 var fragmentShader
= gl
.createShader(gl
.FRAGMENT_SHADER
);
74 gl
.shaderSource(fragmentShader
, fsSource
);
75 gl
.compileShader(fragmentShader
);
76 // Note: if COMPILE_STATUS is retrieved here, it hides the bug.
78 var program
= gl
.createProgram();
79 gl
.attachShader(program
, vertexShader
);
80 gl
.attachShader(program
, fragmentShader
);
81 gl
.linkProgram(program
);
83 gl
.useProgram(program
);
85 var uniforms1Location
= gl
.getUniformBlockIndex(program
, "Uniforms1");
86 gl
.uniformBlockBinding(program
, uniforms1Location
, 0);
87 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "uniforms1Location was " + uniforms1Location
);
89 var uniforms2Location
= gl
.getUniformBlockIndex(program
, "Uniforms2");
90 gl
.uniformBlockBinding(program
, uniforms2Location
, 1);
91 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "uniforms2Location was " + uniforms2Location
);
99 var successfullyParsed
= true;
102 <script src=
"../../js/js-test-post.js"></script>