Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / samplers / samplers.html
blobe6fbc69011272fc0e57821f662ae2165b1f666f1
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 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 </head>
16 <body>
17 <div id="description"></div>
18 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
19 <div id="console"></div>
20 <script>
21 "use strict";
22 description("This test verifies the functionality of the Sampler objects.");
24 debug("");
26 var wtu = WebGLTestUtils;
27 var canvas = document.getElementById("canvas");
28 var gl = wtu.create3DContext(canvas, null, 2);
29 var s = null;
30 var s1 = null;
31 var s2 = null;
32 var testCases = null;
34 if (!gl) {
35 testFailed("WebGL context does not exist");
36 } else {
37 testPassed("WebGL context exists");
39 runBindingTest();
40 runObjectTest();
41 runParameterTest();
42 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
45 function enumToString(value) {
46 return wtu.glEnumToString(gl, value);
49 function runBindingTest() {
50 debug("Testing binding enum");
52 shouldBe("gl.SAMPLER_BINDING", "0x8919");
54 // Default value is null
55 shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)");
56 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "SAMPLER_BINDING query should succeed");
58 debug("Testing binding a Sampler object");
59 s1 = gl.createSampler();
60 s2 = gl.createSampler();
61 gl.bindSampler(0, s1);
62 shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1");
63 gl.bindSampler(0, s2);
64 shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s2");
66 // Bindings should not affect other units.
67 gl.bindSampler(1, s1);
68 shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s2");
69 gl.activeTexture(gl.TEXTURE1);
70 shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1");
71 gl.activeTexture(gl.TEXTURE0);
73 // Should be able to bind a single sampler to multiple texture units.
74 gl.bindSampler(0, s1);
75 shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1");
77 // Deleting samplers should unbind them.
78 gl.deleteSampler(s1);
79 gl.deleteSampler(s2);
80 shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)");
81 gl.activeTexture(gl.TEXTURE1);
82 shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)");
83 gl.activeTexture(gl.TEXTURE0);
85 // Shouldn't be able to bind a deleted sampler.
86 gl.bindSampler(0, s2);
87 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted Sampler object");
88 gl.bindSampler(0, null);
89 shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)");
90 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
93 function runObjectTest() {
94 debug("Testing object creation");
96 s1 = gl.createSampler();
97 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createSampler should not set an error");
98 shouldBeNonNull("s1");
100 // Expect true, even if never bound
101 shouldBeTrue("gl.isSampler(s1)");
102 gl.bindSampler(0, s1);
103 shouldBeTrue("gl.isSampler(s1)");
104 gl.bindSampler(0, null);
105 shouldBeTrue("gl.isSampler(s1)");
106 gl.deleteSampler(s1);
107 shouldBeFalse("gl.isSampler(s1)");
109 shouldBeFalse("gl.isSampler(null)");
111 s1 = null;
114 function runParameterTest() {
115 debug("Testing getSamplerParameter and samplerParameter[if]");
117 s = gl.createSampler();
118 gl.bindSampler(0, s);
120 debug("Checking default param for getSamplerParameter");
122 testCases = [
123 { pname: gl.TEXTURE_WRAP_S, defaultParam: gl.REPEAT },
124 { pname: gl.TEXTURE_WRAP_T, defaultParam: gl.REPEAT },
125 { pname: gl.TEXTURE_WRAP_R, defaultParam: gl.REPEAT },
126 { pname: gl.TEXTURE_MIN_FILTER, defaultParam: gl.NEAREST_MIPMAP_LINEAR },
127 { pname: gl.TEXTURE_MAG_FILTER, defaultParam: gl.LINEAR },
128 { pname: gl.TEXTURE_COMPARE_MODE, defaultParam: gl.NONE },
129 { pname: gl.TEXTURE_COMPARE_FUNC, defaultParam: gl.LEQUAL },
130 { pname: gl.TEXTURE_MIN_LOD, defaultParam: -1000 },
131 { pname: gl.TEXTURE_MAX_LOD, defaultParam: 1000 },
134 for (var ii = 0; ii < testCases.length; ++ii) {
135 var pname = testCases[ii].pname;
136 var defaultParam = testCases[ii].defaultParam;
137 shouldBe("gl.getSamplerParameter(s, " + pname + ")", defaultParam.toString());
138 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
141 debug("Checking valid pname and param for samplerParameteri");
143 testCases = [
144 { pname: gl.TEXTURE_WRAP_S, param: gl.REPEAT },
145 { pname: gl.TEXTURE_WRAP_S, param: gl.MIRRORED_REPEAT },
146 { pname: gl.TEXTURE_WRAP_S, param: gl.CLAMP_TO_EDGE },
147 { pname: gl.TEXTURE_WRAP_T, param: gl.REPEAT },
148 { pname: gl.TEXTURE_WRAP_T, param: gl.MIRRORED_REPEAT },
149 { pname: gl.TEXTURE_WRAP_T, param: gl.CLAMP_TO_EDGE },
150 { pname: gl.TEXTURE_WRAP_R, param: gl.REPEAT },
151 { pname: gl.TEXTURE_WRAP_R, param: gl.MIRRORED_REPEAT },
152 { pname: gl.TEXTURE_WRAP_R, param: gl.CLAMP_TO_EDGE },
153 { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST },
154 { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR },
155 { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST_MIPMAP_NEAREST },
156 { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST_MIPMAP_LINEAR },
157 { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR_MIPMAP_NEAREST },
158 { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR_MIPMAP_LINEAR },
159 { pname: gl.TEXTURE_MAG_FILTER, param: gl.NEAREST },
160 { pname: gl.TEXTURE_MAG_FILTER, param: gl.LINEAR },
161 { pname: gl.TEXTURE_COMPARE_MODE, param: gl.NONE },
162 { pname: gl.TEXTURE_COMPARE_MODE, param: gl.COMPARE_REF_TO_TEXTURE },
163 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.LEQUAL },
164 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.GEQUAL },
165 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.LESS },
166 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.GREATER },
167 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.EQUAL },
168 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.NOTEQUAL },
169 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.ALWAYS },
170 { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.NEVER },
173 for (var ii = 0; ii < testCases.length; ++ii) {
174 var pname = testCases[ii].pname;
175 var param = testCases[ii].param;
176 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.samplerParameteri(s, " + pname + ", " + param + ")");
177 shouldBe("gl.getSamplerParameter(s, " + pname + ")", param);
178 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
181 debug("Checking valid pname and param for samplerParameterf");
182 testCases = [
183 { pname: gl.TEXTURE_MIN_LOD, param: -500 },
184 { pname: gl.TEXTURE_MIN_LOD, param: 0 },
185 { pname: gl.TEXTURE_MIN_LOD, param: 10.0 },
186 { pname: gl.TEXTURE_MAX_LOD, param: 500 },
187 { pname: gl.TEXTURE_MAX_LOD, param: 0 },
188 { pname: gl.TEXTURE_MAX_LOD, param: 10.0 },
191 for (var ii = 0; ii < testCases.length; ++ii) {
192 var pname = testCases[ii].pname;
193 var param = testCases[ii].param;
194 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.samplerParameterf(s, " + pname + ", " + param + ")");
195 shouldBe("gl.getSamplerParameter(s, " + pname + ")", param.toString());
196 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
199 debug("Checking invalid pname and param");
201 testCases = [
202 { pname: gl.TEXTURE_IMMUTABLE_FORMAT, param: null, expectedError: gl.INVALID_ENUM },
203 { pname: gl.TEXTURE_BASE_LEVEL, param: null, expectedError: gl.INVALID_ENUM },
204 { pname: gl.TEXTURE_MAX_LEVEL, param: null, expectedError: gl.INVALID_ENUM },
205 { pname: gl.TEXTURE_WRAP_S, param: 0x812D,/* GL_CLAMP_TO_BORDER */ expectedError: gl.INVALID_ENUM },
206 { pname: gl.TEXTURE_WRAP_T, param: 0x812D,/* GL_CLAMP_TO_BORDER */ expectedError: gl.INVALID_ENUM },
207 { pname: gl.TEXTURE_MAG_FILTER, param: gl.LINEAR_MIPMAP_NEAREST, expectedError: gl.INVALID_ENUM },
210 for (var ii = 0; ii < testCases.length; ++ii) {
211 var pname = testCases[ii].pname;
212 var param = testCases[ii].param;
213 var expectedError = testCases[ii].expectedError;
214 if (param == null) {
215 wtu.shouldGenerateGLError(gl, expectedError, "gl.getSamplerParameter(s, " + pname + ")");
216 } else {
217 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.getSamplerParameter(s, " + pname + ")");
219 wtu.shouldGenerateGLError(gl, expectedError, "gl.samplerParameteri(s, " + pname + ", " + param + ")");
220 wtu.shouldGenerateGLError(gl, expectedError, "gl.samplerParameterf(s, " + pname + ", " + param + ")");
224 debug("");
225 var successfullyParsed = true;
226 </script>
227 <script src="../../js/js-test-post.js"></script>
229 </body>
230 </html>