Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / uniforms / uniform-samplers-test.html
blobfc680c0eaae90c2ae57d1ce959d78b848ce7a9ca
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 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>
15 </head>
16 <body>
17 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
21 <script>
22 "use strict";
23 function init()
25 description(
26 "Tests that only Uniform1i and Uniform1iv can be used to set" +
27 "sampler uniforms.");
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() {
53 var success = true;
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() {
62 var success = true;
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");
70 var steps = [
71 testUniformi,
72 testUniformiv,
75 var generateInvalidUniformiTests = function(start, end) {
76 return function() {
77 var success = true;
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) {
87 return function() {
88 var success = true;
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));
97 var step = 0x1000;
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);
104 wtu.runSteps(steps);
107 init();
108 var successfullyParsed = true;
109 </script>
110 </body>
111 </html>