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 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
11 <script src=
"../../js/js-test-pre.js"></script>
12 <script src=
"../../js/webgl-test-utils.js"></script>
15 <div id=
"description"></div>
16 <div id=
"console"></div>
20 description("Tests the WebGLUniformLocation API");
22 var wtu
= WebGLTestUtils
;
23 var contextA
= wtu
.create3DContext();
24 var contextB
= wtu
.create3DContext();
25 var programA1
= wtu
.loadStandardProgram(contextA
);
26 var programA2
= wtu
.loadStandardProgram(contextA
);
27 var programB
= wtu
.loadStandardProgram(contextB
);
28 var programS
= wtu
.loadProgramFromFile(contextA
, "../../resources/structUniformShader.vert", "../../resources/fragmentShader.frag");
29 var programV
= wtu
.loadProgramFromFile(contextA
, "../../resources/floatUniformShader.vert", "../../resources/noopUniformShader.frag");
30 var locationA
= contextA
.getUniformLocation(programA1
, 'u_modelViewProjMatrix');
31 var locationB
= contextB
.getUniformLocation(programB
, 'u_modelViewProjMatrix');
32 var locationSx
= contextA
.getUniformLocation(programS
, "u_struct.x");
34 var locationArray0
= contextA
.getUniformLocation(programS
, "u_array[0]");
35 var locationArray1
= contextA
.getUniformLocation(programS
, "u_array[1]");
36 var locationVec4
= contextA
.getUniformLocation(programV
, "fval4");
38 var vec
= [1, 2, 3, 4];
39 var mat
= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
41 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programA2)");
42 wtu
.shouldGenerateGLError(contextA
, contextA
.INVALID_OPERATION
, "contextA.uniformMatrix4fv(locationA, false, mat)");
43 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programA1)");
44 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniformMatrix4fv(locationA, false, mat)");
45 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniformMatrix4fv(null, false, mat)");
47 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programS)");
48 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform1i(locationSx, 333)");
49 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform1f(locationArray0, 4.0)");
50 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform1f(locationArray1, 5.0)");
52 shouldBe("contextA.getUniform(programS, locationSx)", "333");
53 shouldBe("contextA.getUniform(programS, locationArray0)", "4.0");
54 shouldBe("contextA.getUniform(programS, locationArray1)", "5.0");
56 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programV)");
57 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform4fv(locationVec4, vec)");
58 shouldBe("contextA.getUniform(programV, locationVec4)", "vec");
60 shouldBeNull("contextA.getUniformLocation(programV, \"IDontExist\")");
61 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.linkProgram(programA1)");
62 // After linking all boxes are bad.
63 wtu
.shouldGenerateGLError(contextA
, contextA
.INVALID_OPERATION
, "contextA.uniformMatrix4fv(locationA, false, mat)");
65 // after re-linking the same program, all uniform locations become invalid.
66 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programS)");
67 contextA
.stencilMask(1);
68 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.linkProgram(programS)");
69 wtu
.shouldGenerateGLError(contextA
, contextA
.INVALID_OPERATION
, "contextA.uniform1i(locationSx, 3)");
70 wtu
.shouldGenerateGLError(contextA
, contextA
.INVALID_OPERATION
, "contextA.getUniform(programS, locationSx)");
71 // Make sure that with no current program, uniform location validation doesn't get confused.
72 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(null)");
73 wtu
.shouldGenerateGLError(contextA
, contextA
.INVALID_OPERATION
, "contextA.uniform1i(locationSx, 3)");
74 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.useProgram(programS)");
76 // Retrieve the locations again, and they should be good.
77 locationSx
= contextA
.getUniformLocation(programS
, "u_struct.x");
78 locationArray0
= contextA
.getUniformLocation(programS
, "u_array[0]");
80 contextA
.stencilMask(0);
81 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform1i(locationSx, 3)");
82 wtu
.shouldGenerateGLError(contextA
, contextA
.NO_ERROR
, "contextA.uniform1f(locationArray0, 123)");
83 shouldBe("contextA.getUniform(programS, locationSx)", "3");
84 shouldBe("contextA.getUniform(programS, locationArray0)", "123");
86 // getUniformLocation should return a different object everytime, should not cache and return the same object
87 debug("Testing that getUniformLocation returns a different object everytime");
88 locationSx
= contextA
.getUniformLocation(programS
, "u_struct.x");
89 locationSx2
= contextA
.getUniformLocation(programS
, "u_struct.x");
90 shouldBeFalse("locationSx === locationSx2");
93 shouldBeFalse("locationSx.foo === locationSx2.foo");
95 var successfullyParsed
= true;
98 <script src=
"../../js/js-test-post.js"></script>