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 sampler uniforms conformance 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>
17 <canvas id=
"example" width=
"2" height=
"2" style=
"width: 40px; height: 40px;"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
26 "Tests that only Uniform1i and Uniform1iv can be used to set" +
29 var canvas2d
= document
.getElementById("canvas2d");
31 var wtu
= WebGLTestUtils
;
32 var gl
= wtu
.create3DContext("example");
33 var program
= wtu
.setupTexturedQuad(gl
);
35 var textureLoc
= gl
.getUniformLocation(program
, "tex");
37 gl
.uniform1i(textureLoc
, 1);
38 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
39 "uniform1i can set a sampler uniform");
40 gl
.uniform1iv(textureLoc
, [1]);
41 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
42 "uniform1iv can set a sampler uniform");
43 gl
.uniform1f(textureLoc
, 1);
44 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
45 "uniform1f returns INVALID_OPERATION if attempting to set a sampler uniform");
46 gl
.uniform1fv(textureLoc
, [1]);
47 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
48 "uniform1fv returns INVALID_OPERATION if attempting to set a sampler uniform");
50 var maxTextureUnits
= gl
.getParameter(gl
.MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
52 var testUniformi = function() {
54 for (var ii
= 0; ii
< maxTextureUnits
; ++ii
) {
55 gl
.uniform1i(textureLoc
, ii
);
56 success
= success
&& (gl
.getError() == gl
.NO_ERROR
);
58 expectTrue(success
, "uniform1i works for any valid texture unit");
61 var testUniformiv = function() {
63 for (var ii
= 0; ii
< maxTextureUnits
; ++ii
) {
64 gl
.uniform1iv(textureLoc
, [ii
]);
65 success
= success
&& (gl
.getError() == gl
.NO_ERROR
);
67 expectTrue(success
, "uniform1iv works for any valid texture unit");
75 var generateInvalidUniformiTests = function(start
, end
) {
78 for (var ii
= start
; ii
< end
; ++ii
) {
79 gl
.uniform1i(textureLoc
, ii
);
80 success
= success
&& (gl
.getError() == gl
.INVALID_VALUE
);
82 expectTrue(success
, "uniform1i generates INVALID_VALUE for invalid texture units 0x" + start
.toString(16) + " to 0x" + end
.toString(16));
86 var generateInvalidUniformivTests = function(start
, end
) {
89 for (var ii
= start
; ii
< end
; ++ii
) {
90 gl
.uniform1iv(textureLoc
, [ii
]);
91 success
= success
&& (gl
.getError() == gl
.INVALID_VALUE
);
93 expectTrue(success
, "uniform1iv generates INVALID_VALUE for invalid texture units 0x" + start
.toString(16) + " to 0x" + end
.toString(16));
98 for (var ii
= maxTextureUnits
; ii
< 0x10000; ii
+= step
) {
99 steps
.push(generateInvalidUniformiTests(ii
, ii
+ step
));
100 steps
.push(generateInvalidUniformivTests(ii
, ii
+ step
));
103 steps
.push(finishTest
);
108 var successfullyParsed
= true;