Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/uniforms/uniform-default-values.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL uniform default values</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
35 <script src="../../resources/js-test-pre.js"></script>
36 <script src="../resources/webgl-test.js"></script>
37 <script src="../resources/webgl-test-utils.js"></script>
38 </head>
39 <body>
40 <div id="description"></div>
41 <div id="console"></div>
42 <canvas id="example" width="2" height="2"> </canvas>
43 <script id="vshader0" type="x-shader/x-vertex">
44 attribute vec4 vPosition;
45 void main()
46 {
47 gl_Position = vPosition;
48 }
49 </script>
50 <script id="fshader0" type="x-shader/x-fragment">
51 precision mediump float;
52 uniform $(type) u_uniform;
53
54 bool isZero($(type) value) {
55 $(check);
56 }
57
58 void main()
59 {
60 gl_FragColor = isZero(u_uniform) ? vec4(0,1,0,1) : vec4(1,0,0,1);
61 }
62 </script>
63 <script id="vshader1" type="x-shader/x-vertex">
64 attribute vec4 vPosition;
65 varying vec4 v_color;
66 uniform $(type) u_uniform;
67
68 bool isZero($(type) value) {
69 $(check);
70 }
71
72 void main()
73 {
74 gl_Position = vPosition;
75 v_color = isZero(u_uniform) ? vec4(0,1,0,1) : vec4(1,0,0,1);
76 }
77 </script>
78 <script id="fshader1" type="x-shader/x-fragment">
79 precision mediump float;
80 varying vec4 v_color;
81 void main()
82 {
83 gl_FragColor = v_color;
84 }
85 </script>
86 <script id="vshader2" type="x-shader/x-vertex">
87 attribute vec4 vPosition;
88 void main()
89 {
90 gl_Position = vPosition;
91 }
92 </script>
93 <script id="fshader2" type="x-shader/x-fragment">
94 precision mediump float;
95 uniform $(type) u_uniform[2];
96
97 bool isZero($(type) value) {
98 $(check);
99 }
100
101 void main()
102 {
103 gl_FragColor = isZero(u_uniform[1]) ? vec4(0,1,0,1) : vec4(1,0,0,1);
104 }
105 </script>
106 <script id="vshader3" type="x-shader/x-vertex">
107 attribute vec4 vPosition;
108 varying vec4 v_color;
109 uniform $(type) u_uniform[2];
110
111 bool isZero($(type) value) {
112 $(check);
113 }
114
115 void main()
116 {
117 gl_Position = vPosition;
118 v_color = isZero(u_uniform[1]) ? vec4(0,1,0,1) : vec4(1,0,0,1);
119 }
120 </script>
121 <script id="fshader3" type="x-shader/x-fragment">
122 precision mediump float;
123 varying vec4 v_color;
124 void main()
125 {
126 gl_FragColor = v_color;
127 }
128 </script>
129 <script>
130 description();
131
132 var tests = [
133 { type: 'float',
134 check: "return value == 0.0",
135 setFn: function(gl, loc) { gl.uniform1f(loc, 3.0); }
136 },
137 { type: 'int',
138 check: "return value == 0",
139 setFn: function(gl, loc) { gl.uniform1i(loc, 3.0); }
140 },
141 { type: 'bool',
142 check: "return value == false",
143 setFn: function(gl, loc) { gl.uniform1i(loc, 1); }
144 },
145 { type: 'vec2',
146 check: "return value[0] == 0.0 && value[1] == 0.0",
147 setFn: function(gl, loc) { gl.uniform2f(loc, 3.0, 3.0); }
148 },
149 { type: 'vec3',
150 check: "return value[0] == 0.0 && value[1] == 0.0 && value[2] == 0.0",
151 setFn: function(gl, loc) { gl.uniform3f(loc, 3.0, 3.0, 3.0); }
152 },
153 { type: 'vec4',
154 check: "return value[0] == 0.0 && value[1] == 0.0 && value[2] == 0.0 && value[ 3] == 0.0",
155 setFn: function(gl, loc) { gl.uniform4f(loc, 3.0, 3.0, 3.0, 3.0); }
156 },
157 { type: 'ivec2',
158 check: "return value[0] == 0 && value[1] == 0",
159 setFn: function(gl, loc) { gl.uniform2i(loc, 3, 3); }
160 },
161 { type: 'ivec3',
162 check: "return value[0] == 0 && value[1] == 0 && value[2] == 0",
163 setFn: function(gl, loc) { gl.uniform3i(loc, 3, 3, 3); }
164 },
165 { type: 'ivec4',
166 check: "return value[0] == 0 && value[1] == 0 && value[2] == 0 && value[3] == 0",
167 setFn: function(gl, loc) { gl.uniform4i(loc, 3, 3, 3, 3); }
168 },
169 { type: 'bvec2',
170 check: "return value[0] == false && value[1] == false",
171 setFn: function(gl, loc) { gl.uniform2i(loc, 1, 1); }
172 },
173 { type: 'bvec3',
174 check: "return value[0] == false && value[1] == false && value[2] == false",
175 setFn: function(gl, loc) { gl.uniform3i(loc, 1, 1, 1); }
176 },
177 { type: 'bvec4',
178 check: "return value[0] == false && value[1] == false && value[2] == false && value[3] == false",
179 setFn: function(gl, loc) { gl.uniform4i(loc, 1, 1, 1, 1); }
180 },
181 { type: 'mat2',
182 check:
183 "return " +
184 "value[0][0] == 0.0 && value[0][1] == 0.0 && " +
185 "value[1][0] == 0.0 && value[1][0] == 0.0",
186 valueCheck:
187 "return " +
188 "value[0] == 0.0 && value[1] == 0.0 && " +
189 "value[2] == 0.0 && value[3] == 0.0",
190 setFn: function(gl, loc) { gl.uniformMatrix2fv(loc, false, [1, 1, 1, 1]); }
191 },
192 { type: 'mat3',
193 check:
194 "return " +
195 "value[0][0] == 0.0 && value[1][0] == 0.0 && value[2][0] == 0.0 && " +
196 "value[0][1] == 0.0 && value[1][1] == 0.0 && value[2][1] == 0.0 && " +
197 "value[0][2] == 0.0 && value[1][2] == 0.0 && value[2][2] == 0.0",
198 valueCheck:
199 "return " +
200 "value[0] == 0.0 && value[1] == 0.0 && value[2] == 0.0 && " +
201 "value[3] == 0.0 && value[4] == 0.0 && value[5] == 0.0 && " +
202 "value[6] == 0.0 && value[7] == 0.0 && value[8] == 0.0",
203 setFn: function(gl, loc) { gl.uniformMatrix3fv(loc, false, [1, 1, 1, 1, 1, 1, 1, 1, 1]); }
204 },
205 { type: 'mat4',
206 check:
207 "return " +
208 "value[0][0] == 0.0 && value[1][0] == 0.0 && value[2][0] == 0.0 && value[3][ 0] == 0.0 && " +
209 "value[0][1] == 0.0 && value[1][1] == 0.0 && value[2][1] == 0.0 && value[3][ 1] == 0.0 && " +
210 "value[0][2] == 0.0 && value[1][2] == 0.0 && value[2][2] == 0.0 && value[3][ 2] == 0.0 && " +
211 "value[0][3] == 0.0 && value[1][3] == 0.0 && value[2][3] == 0.0 && value[3][ 3] == 0.0",
212 valueCheck:
213 "return " +
214 "value[ 0] == 0.0 && value[ 1] == 0.0 && value[ 2] == 0.0 && value[ 3] == 0. 0 && " +
215 "value[ 4] == 0.0 && value[ 5] == 0.0 && value[ 6] == 0.0 && value[ 7] == 0. 0 && " +
216 "value[ 8] == 0.0 && value[ 9] == 0.0 && value[10] == 0.0 && value[11] == 0. 0 && " +
217 "value[12] == 0.0 && value[13] == 0.0 && value[14] == 0.0 && value[15] == 0. 0",
218 setFn: function(gl, loc) { gl.uniformMatrix4fv(loc, false, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); }
219 },
220 { type: 'sampler2D',
221 check:
222 "vec4 v = texture2D(value, vec2(0, 0));" +
223 "return v.x == 1.0 && v.y == 1.0 && v.z == 1.0 && v.w == 1.0",
224 valueCheck:
225 "return value == 0",
226 setFn: function(gl, loc) { gl.uniform1i(loc, 1); }
227 },
228 { type: 'samplerCube',
229 check:
230 "vec4 v = textureCube(value, vec3(0, 0, 0));" +
231 "return v.x == 1.0 && v.y == 1.0 && v.z == 1.0 && v.w == 1.0",
232 valueCheck:
233 "return value == 0",
234 setFn: function(gl, loc) { gl.uniform1i(loc, 1); }
235 },
236 ];
237
238 var wtu = WebGLTestUtils;
239 var gl = wtu.create3DContext();
240 var c = document.getElementById("console");
241
242 wtu.setupUnitQuad(gl, [0, 1]);
243
244 // Set unit 0 to a non-0 texture.
245 var haveVertexTextureImageUnits =
246 gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) >= 2;
247 var tex2D = gl.createTexture();
248 var texCube = gl.createTexture();
249 gl.bindTexture(gl.TEXTURE_2D, tex2D);
250 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
251
252 var pixel = new Uint8Array([255, 255, 255, 255]);
253 var targets = [
254 gl.TEXTURE_2D,
255 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
256 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
257 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
258 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
259 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
260 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
261 ];
262 for (var ii = 0; ii < targets.length; ++ii) {
263 gl.texImage2D(
264 targets[ii], 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
265 }
266
267 var shaderTemplates = [
268 { vs: "vshader0", fs: "fshader0", type: 'f' },
269 { vs: "vshader1", fs: "fshader1", type: 'v' },
270 { vs: "vshader2", fs: "fshader2", type: 'f' },
271 { vs: "vshader3", fs: "fshader3", type: 'v' },
272 ];
273
274 // Get shader templates
275 for (var ii = 0; ii < shaderTemplates.length; ++ii) {
276 template = shaderTemplates[ii];
277 template.vs = wtu.getScript(template.vs);
278 template.fs = wtu.getScript(template.fs);
279 }
280
281 function testType(test) {
282 debug("");
283 debug("testing: " + test.type);
284
285 for (var ii = 0; ii < shaderTemplates.length; ++ii) {
286 var template = shaderTemplates[ii];
287
288 if (test.type.substring(0, 7) == "sampler" &&
289 template.type == 'v' &&
290 !haveVertexTextureImageUnits) {
291 continue;
292 }
293
294 var vs = wtu.replaceParams(template.vs, test);
295 var fs = wtu.replaceParams(template.fs, test);
296
297 wtu.addShaderSource(c, "vertex shader", vs);
298 wtu.addShaderSource(c, "fragment shader", fs);
299
300 var vs = wtu.loadShader(gl, vs, gl.VERTEX_SHADER);
301 var fs = wtu.loadShader(gl, fs, gl.FRAGMENT_SHADER);
302 var program = wtu.createProgram(gl, vs, fs);
303
304 gl.useProgram(program);
305
306 var loc = gl.getUniformLocation(program, "u_uniform[1]");
307 if (!loc) {
308 var loc = gl.getUniformLocation(program, "u_uniform");
309 }
310
311 var value = gl.getUniform(program, loc);
312 eval("checkFn = function(value) {" + (test.valueCheck ? test.valueCheck : te st.check) + ";}");
313 if (checkFn(value)) {
314 testPassed("uniform is zero");
315 } else {
316 testFailed("uniform is not zero");
317 }
318
319 debug("default value should be zero");
320 wtu.drawQuad(gl);
321 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green", 0);
322
323 debug("test test by setting value");
324 test.setFn(gl, loc);
325
326 wtu.drawQuad(gl);
327 wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red", 0);
328
329 debug("re-linking should reset to defaults");
330 gl.linkProgram(program);
331
332 wtu.drawQuad(gl);
333 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green", 0);
334
335 gl.deleteProgram(program);
336 gl.deleteShader(vs);
337 gl.deleteShader(fs);
338
339 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no GL errors");
340 }
341 }
342
343 var testNdx = 0;
344 function runNextTest() {
345 testType(tests[testNdx++]);
346 if (testNdx >= tests.length) {
347 finishTest();
348 } else {
349 setTimeout(runNextTest, 1);
350 }
351 }
352
353 runNextTest();
354
355 successfullyParsed = true;
356
357 </script>
358 </body>
359 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698