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

Side by Side Diff: conformance/ogles/ogles-utils.js

Issue 41993002: Add ToT WebGL conformance tests : part 9 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « conformance/ogles/mustpass.run.txt ('k') | conformance/ogles/process-ogles2-tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
OLDNEW
(Empty)
1 /*
2 ** Copyright (c) 2012 The Khronos Group Inc.
3 **
4 ** Permission is hereby granted, free of charge, to any person obtaining a
5 ** copy of this software and/or associated documentation files (the
6 ** "Materials"), to deal in the Materials without restriction, including
7 ** without limitation the rights to use, copy, modify, merge, publish,
8 ** distribute, sublicense, and/or sell copies of the Materials, and to
9 ** permit persons to whom the Materials are furnished to do so, subject to
10 ** the following conditions:
11 **
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Materials.
14 **
15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22 */
23 OpenGLESTestRunner = (function(){
24 var wtu = WebGLTestUtils;
25 var gl;
26
27 var HALF_GRID_MAX_SIZE = 32;
28 var KNOWN_ATTRIBS = [
29 "gtf_Vertex",
30 "gtf_Color"
31 ];
32
33 var GTFPIXELTOLERANCE = 24;
34 var GTFACCEPTABLEFAILURECONT = 10;
35 var GTFAMDPIXELTOLERANCE = 12;
36 var GTFSCORETOLERANCE = 0.65;
37 var GTFNCCTOLARANCEZERO = 0.25;
38 var GTFKERNALSIZE = 5;
39
40 function log(msg) {
41 // debug(msg);
42 }
43
44 function compareImages(refData, tstData, width, height, diff) {
45 function isPixelSame(offset) {
46 // First do simple check
47 if (Math.abs(refData[offset + 0] - tstData[offset + 0]) <= GTFPIXELTOLERANCE &&
48 Math.abs(refData[offset + 1] - tstData[offset + 1]) <= GTFPIXELTOLERANCE &&
49 Math.abs(refData[offset + 2] - tstData[offset + 2]) <= GTFPIXELTOLERANCE ) {
50 return true;
51 }
52
53 // TODO: Implement crazy check that's used in OpenGL ES 2.0 conformance test s.
54 // NOTE: on Desktop things seem to be working. Maybe the more complex check
55 // is needed for embedded systems?
56 return false;
57 }
58
59 var same = true;
60 for (var yy = 0; yy < height; ++yy) {
61 for (var xx = 0; xx < width; ++xx) {
62 var offset = (yy * width + xx) * 4;
63 var diffOffset = ((height - yy - 1) * width + xx) * 4;
64 diff[diffOffset + 0] = 0;
65 diff[diffOffset + 1] = 0;
66 diff[diffOffset + 2] = 0;
67 diff[diffOffset + 3] = 255;
68 if (!isPixelSame(offset)) {
69 diff[diffOffset] = 255;
70 if (same) {
71 same = false;
72 testFailed("pixel @ (" + xx + ", " + yy + " was [" +
73 tstData[offset + 0] + "," +
74 tstData[offset + 1] + "," +
75 tstData[offset + 2] + "," +
76 tstData[offset + 3] + "] expected [" +
77 refData[offset + 0] + "," +
78 refData[offset + 1] + "," +
79 refData[offset + 2] + "," +
80 refData[offset + 3] + "]")
81 }
82 }
83 }
84 }
85 return same;
86 }
87
88 function persp(fovy, aspect, n, f) {
89 var dz = f - n;
90 var rad = fovy / 2.0 * 3.14159265 / 180;
91
92 var s = Math.sin(rad);
93 if (dz == 0 || s == 0 || aspect == 0)
94 return;
95
96 var cot = Math.cos(rad) / s;
97
98 return [
99 cot / aspect,
100 0.0,
101 0.0,
102 0.0,
103
104 0.0,
105 cot,
106 0.0,
107 0.0,
108
109 0.0,
110 0.0,
111 -(f + n) / dz,
112 -1.0,
113
114 0.0,
115 0.0,
116 -2.0 * f * n / dz,
117 0.0
118 ];
119 }
120
121 function setAttribs(attribs, buffers) {
122 for (var name in attribs) {
123 var buffer = buffers[name];
124 if (!buffer) {
125 testFailed("no buffer for attrib:" + name);
126 continue;
127 }
128 var loc = attribs[name];
129 log("setup attrib: " + loc + " as " + name);
130 var buf = gl.createBuffer();
131 gl.bindBuffer(gl.ARRAY_BUFFER, buf);
132 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(buffer.data), gl.STATIC_DRAW );
133 gl.enableVertexAttribArray(loc);
134 gl.vertexAttribPointer(loc, buffer.numComponents, gl.FLOAT, false, 0, 0);
135 }
136 }
137
138 function drawSquare(attribs) {
139 var buffers = {
140 "gtf_Vertex": {
141 data: [
142 1.0, -1.0, -2.0,
143 1.0, 1.0, -2.0,
144 -1.0, -1.0, -2.0,
145 -1.0, 1.0, -2.0
146 ],
147 numComponents: 3
148 },
149 "gtf_Color": {
150 data: [
151 0.5, 1.0, 0.0,
152 0.0, 1.0, 1.0,
153 1.0, 0.0, 0.0,
154 0.5, 0.0, 1.0
155 ],
156 numComponents: 3,
157 },
158 "gtf_SecondaryColor": {
159 data: [
160 0.5, 0.0, 1.0,
161 1.0, 0.0, 0.0,
162 0.0, 1.0, 1.0,
163 0.5, 1.0, 0.0
164 ],
165 numComponents: 3,
166 },
167 "gtf_Normal": {
168 data: [
169 0.5, 0.0, 1.0,
170 1.0, 0.0, 0.0,
171 0.0, 1.0, 1.0,
172 0.5, 1.0, 0.0
173 ],
174 numComponents: 3,
175 },
176 "gtf_MultiTexCoord0": {
177 data: [
178 1.0, 0.0,
179 1.0, 1.0,
180 0.0, 0.0,
181 0.0, 1.0
182 ],
183 numComponents: 2,
184 },
185 "gtf_FogCoord": {
186 data: [
187 0.0,
188 1.0,
189 0.0,
190 1.0
191 ],
192 numComponents: 1,
193 }
194 };
195 setAttribs(attribs, buffers);
196 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
197 }
198
199 function drawFrontBackSquare(attribs) {
200 var front = {
201 "gtf_Vertex": {
202 data: [
203 1.0, -1.0, -2.0,
204 1.0, 0.0, -2.0,
205 -1.0, -1.0, -2.0,
206 -1.0, 0.0, -2.0
207 ],
208 numComponents: 3
209 },
210 "gtf_Color": {
211 data: [
212 0.0, 1.0, 0.0,
213 0.0, 1.0, 0.0,
214 0.0, 1.0, 0.0,
215 0.0, 1.0, 0.0
216 ],
217 numComponents: 3,
218 },
219 "gtf_MultiTexCoord0": {
220 data: [
221 1.0, 0.0,
222 1.0, 0.5,
223 0.0, 0.0,
224 0.0, 0.5
225 ],
226 numComponents: 2,
227 }
228 };
229 setAttribs(attribs, front);
230 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
231
232 var back = {
233 "gtf_Vertex": {
234 data: [
235 1.0, 1.0, -2.0,
236 1.0, 0.0, -2.0,
237 -1.0, 1.0, -2.0,
238 -1.0, 0.0, -2.0
239 ],
240 numComponents: 3
241 },
242 "gtf_Color": {
243 data: [
244 1.0, 0.0, 0.0,
245 1.0, 0.0, 0.0,
246 1.0, 0.0, 0.0,
247 1.0, 0.0, 0.0
248 ],
249 numComponents: 3,
250 },
251 "gtf_MultiTexCoord0": {
252 data: [
253 1.0, 0.1,
254 1.0, 0.5,
255 0.0, 0.1,
256 0.0, 0.5
257 ],
258 numComponents: 2,
259 }
260 };
261 setAttribs(attribs, back);
262 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
263 }
264
265 function drawGrid(attribs, width, height) {
266 var n = Math.min(Math.floor(Math.max(width, height) / 4), HALF_GRID_MAX_SIZE);
267
268 var numVertices = (n + n) * (n + n) * 6;
269
270 var gridVertices = [];
271 var gridColors = [];
272 var gridSecColors = [];
273 var gridNormals = [];
274 var gridFogCoords = [];
275 var gridTexCoords0 = [];
276
277 var currentVertex = 0;
278 var currentColor = 0;
279 var currentSecColor = 0;
280 var currentTexCoord0 = 0;
281 var currentNormal = 0;
282 var currentFogCoord = 0;
283
284 var z = -2.0;
285 for(var i = -n; i < n; ++i)
286 {
287 var x1 = i / n;
288 var x2 = (i + 1) / n;
289 for(var j = -n; j < n; ++j)
290 {
291 var y1 = j / n;
292 var y2 = (j + 1) / n;
293
294 // VERTEX 0
295 gridVertices[currentVertex++] = x1;
296 gridVertices[currentVertex++] = y1;
297 gridVertices[currentVertex++] = z;
298 gridColors[currentColor++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
299 gridColors[currentColor++] = (x1 + 1.0) / 2.0;
300 gridColors[currentColor++] = (y1 + 1.0) / 2.0;
301 gridSecColors[currentSecColor++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
302 gridSecColors[currentSecColor++] = (x2 + 1.0) / 2.0;
303 gridSecColors[currentSecColor++] = (y2 + 1.0) / 2.0;
304 gridTexCoords0[currentTexCoord0++] = (x1 + 1.0) / 2.0;
305 gridTexCoords0[currentTexCoord0++] = (y1 + 1.0) / 2.0;
306 gridNormals[currentNormal++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
307 gridNormals[currentNormal++] = (x2 + 1.0) / 2.0;
308 gridNormals[currentNormal++] = (y2 + 1.0) / 2.0;
309 gridFogCoords[currentFogCoord++] = (y1 + 1.0) / 2.0;
310
311 // VERTEX 1
312 gridVertices[currentVertex++] = x2;
313 gridVertices[currentVertex++] = y1;
314 gridVertices[currentVertex++] = z;
315 gridColors[currentColor++] = 1.0 - (x2 + y1 + 2.0) / 4.0;
316 gridColors[currentColor++] = (x2 + 1.0) / 2.0;
317 gridColors[currentColor++] = (y1 + 1.0) / 2.0;
318 gridSecColors[currentSecColor++] = 1.0 - (x1 + y2 + 2.0) / 4.0;
319 gridSecColors[currentSecColor++] = (x1 + 1.0) / 2.0;
320 gridSecColors[currentSecColor++] = (y2 + 1.0) / 2.0;
321 gridTexCoords0[currentTexCoord0++] = (x2 + 1.0) / 2.0;
322 gridTexCoords0[currentTexCoord0++] = (y1 + 1.0) / 2.0;
323 gridNormals[currentNormal++] = 1.0 - (x1 + y2 + 2.0) / 4.0;
324 gridNormals[currentNormal++] = (x1 + 1.0) / 2.0;
325 gridNormals[currentNormal++] = (y2 + 1.0) / 2.0;
326 gridFogCoords[currentFogCoord++] = (y1 + 1.0) / 2.0;
327
328 // VERTEX 2
329 gridVertices[currentVertex++] = x2;
330 gridVertices[currentVertex++] = y2;
331 gridVertices[currentVertex++] = z;
332 gridColors[currentColor++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
333 gridColors[currentColor++] = (x2 + 1.0) / 2.0;
334 gridColors[currentColor++] = (y2 + 1.0) / 2.0;
335 gridSecColors[currentSecColor++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
336 gridSecColors[currentSecColor++] = (x1 + 1.0) / 2.0;
337 gridSecColors[currentSecColor++] = (y1 + 1.0) / 2.0;
338 gridTexCoords0[currentTexCoord0++] = (x2 + 1.0) / 2.0;
339 gridTexCoords0[currentTexCoord0++] = (y2 + 1.0) / 2.0;
340 gridNormals[currentNormal++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
341 gridNormals[currentNormal++] = (x1 + 1.0) / 2.0;
342 gridNormals[currentNormal++] = (y1 + 1.0) / 2.0;
343 gridFogCoords[currentFogCoord++] = (y2 + 1.0) / 2.0;
344
345 // VERTEX 2
346 gridVertices[currentVertex++] = x2;
347 gridVertices[currentVertex++] = y2;
348 gridVertices[currentVertex++] = z;
349 gridColors[currentColor++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
350 gridColors[currentColor++] = (x2 + 1.0) / 2.0;
351 gridColors[currentColor++] = (y2 + 1.0) / 2.0;
352 gridSecColors[currentSecColor++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
353 gridSecColors[currentSecColor++] = (x1 + 1.0) / 2.0;
354 gridSecColors[currentSecColor++] = (y1 + 1.0) / 2.0;
355 gridTexCoords0[currentTexCoord0++] = (x2 + 1.0) / 2.0;
356 gridTexCoords0[currentTexCoord0++] = (y2 + 1.0) / 2.0;
357 gridNormals[currentNormal++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
358 gridNormals[currentNormal++] = (x1 + 1.0) / 2.0;
359 gridNormals[currentNormal++] = (y1 + 1.0) / 2.0;
360 gridFogCoords[currentFogCoord++] = (y2 + 1.0) / 2.0;
361
362 // VERTEX 3
363 gridVertices[currentVertex++] = x1;
364 gridVertices[currentVertex++] = y2;
365 gridVertices[currentVertex++] = z;
366 gridColors[currentColor++] = 1.0 - (x1 + y2 + 2.0) / 4.0;
367 gridColors[currentColor++] = (x1 + 1.0) / 2.0;
368 gridColors[currentColor++] = (y2 + 1.0) / 2.0;
369 gridSecColors[currentSecColor++] = 1.0 - (x2 + y1 + 2.0) / 4.0;
370 gridSecColors[currentSecColor++] = (x2 + 1.0) / 2.0;
371 gridSecColors[currentSecColor++] = (y1 + 1.0) / 2.0;
372 gridTexCoords0[currentTexCoord0++] = (x1 + 1.0) / 2.0;
373 gridTexCoords0[currentTexCoord0++] = (y2 + 1.0) / 2.0;
374 gridNormals[currentNormal++] = 1.0 - (x2 + y1 + 2.0) / 4.0;
375 gridNormals[currentNormal++] = (x2 + 1.0) / 2.0;
376 gridNormals[currentNormal++] = (y1 + 1.0) / 2.0;
377 gridFogCoords[currentFogCoord++] = (y2 + 1.0) / 2.0;
378
379 // VERTEX 0
380 gridVertices[currentVertex++] = x1;
381 gridVertices[currentVertex++] = y1;
382 gridVertices[currentVertex++] = z;
383 gridColors[currentColor++] = 1.0 - (x1 + y1 + 2.0) / 4.0;
384 gridColors[currentColor++] = (x1 + 1.0) / 2.0;
385 gridColors[currentColor++] = (y1 + 1.0) / 2.0;
386 gridSecColors[currentSecColor++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
387 gridSecColors[currentSecColor++] = (x2 + 1.0) / 2.0;
388 gridSecColors[currentSecColor++] = (y2 + 1.0) / 2.0;
389 gridTexCoords0[currentTexCoord0++] = (x1 + 1.0) / 2.0;
390 gridTexCoords0[currentTexCoord0++] = (y1 + 1.0) / 2.0;
391 gridNormals[currentNormal++] = 1.0 - (x2 + y2 + 2.0) / 4.0;
392 gridNormals[currentNormal++] = (x2 + 1.0) / 2.0;
393 gridNormals[currentNormal++] = (y2 + 1.0) / 2.0;
394 gridFogCoords[currentFogCoord++] = (y1 + 1.0) / 2.0;
395 }
396 }
397
398 var buffers = {
399 "gtf_Vertex": { data: gridVertices, numComponents: 3 },
400 "gtf_Color": { data: gridColors, numComponents: 3 },
401 "gtf_SecondaryColor": { data: gridSecColors, numComponents: 3 },
402 "gtf_Normal": { data: gridNormals, numComponents: 3 },
403 "gtf_FogCoord": { data: gridFogCoords, numComponents: 1 },
404 "gtf_MultiTexCoord0": { data: gridTexCoords0, numComponents: 2 }
405 };
406 setAttribs(attribs, buffers);
407 gl.drawArrays(gl.TRIANGLES, 0, numVertices);
408 }
409
410 var MODEL_FUNCS = {
411 square: drawSquare,
412 frontbacksquare: drawFrontBackSquare,
413 grid: drawGrid
414 };
415
416 function drawWithProgram(program, programInfo, test) {
417 gl.useProgram(program);
418 var attribs = { };
419
420 var numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
421 for (var ii = 0; ii < numAttribs; ++ii) {
422 var info = gl.getActiveAttrib(program, ii);
423 var name = info.name;
424 var location = gl.getAttribLocation(program, name);
425 attribs[name] = location;
426
427 if (KNOWN_ATTRIBS.indexOf(name) < 0) {
428 testFailed("unknown attrib:" + name)
429 }
430 }
431
432 var uniforms = { };
433 var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
434 for (var ii = 0; ii < numUniforms; ++ii) {
435 var info = gl.getActiveUniform(program, ii);
436 var name = info.name;
437 if (name.match(/\[0\]$/)) {
438 name = name.substr(0, name.length - 3);
439 }
440 var location = gl.getUniformLocation(program, name);
441 uniforms[name] = {location: location};
442 }
443
444 var getUniformLocation = function(name) {
445 var uniform = uniforms[name];
446 if (uniform) {
447 uniform.used = true;
448 return uniform.location;
449 }
450 return null;
451 }
452
453 // Set known uniforms
454 var loc = getUniformLocation("gtf_ModelViewProjectionMatrix");
455 if (loc) {
456 gl.uniformMatrix4fv(
457 loc,
458 false,
459 persp(60, 1, 1, 30));
460 }
461 var loc = getUniformLocation("viewportwidth");
462 if (loc) {
463 gl.uniform1f(loc, gl.canvas.width);
464 }
465 var loc = getUniformLocation("viewportheight");
466 if (loc) {
467 gl.uniform1f(loc, gl.canvas.height);
468 }
469
470 // Set test specific uniforms
471 for (var name in programInfo.uniforms) {
472 var location = getUniformLocation(name);
473 if (!location) {
474 continue;
475 }
476 var uniform = programInfo.uniforms[name];
477 var type = uniform.type;
478 var value = uniform.value;
479 var transpose = uniform.transpose;
480 if (transpose !== undefined) {
481 log("gl." + type + '("' + name + '", ' + transpose + ", " + value + ")");
482 gl[type](location, transpose, value);
483 } else if (!type.match("v$")) {
484 var args = [location];
485 for (var ii = 0; ii < value.length; ++ii) {
486 args.push(value[ii]);
487 }
488 gl[type].apply(gl, args);
489 log("gl." + type + '("' + name + '", ' + args.slice(1) + ")");
490 } else {
491 log("gl." + type + '("' + name + '", ' + value + ")");
492 gl[type](location, value);
493 }
494 var err = gl.getError();
495 if (err != gl.NO_ERROR) {
496 testFailed(wtu.glEnumToString(gl, err) + " generated setting uniform: " + name);
497 }
498 }
499
500 // Check for unset uniforms
501 for (var name in uniforms) {
502 var uniform = uniforms[name];
503 if (!uniform.used) {
504 testFailed("uniform " + name + " never set");
505 }
506 }
507
508
509 for (var state in test.state) {
510 var fields = test.state[state];
511 switch (state) {
512 case 'depthrange':
513 gl.depthRange(fields.near, fields.far);
514 break;
515 default:
516 testFailed("unknown state: " + state)
517 }
518 }
519
520 gl.clearColor(0, 0, 0, 0);
521 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
522
523 var model = test.model || "square";
524 var fn = MODEL_FUNCS[model];
525 if (!fn) {
526 testFailed("unknown model type: " + model)
527 } else {
528 log("draw as: " + model)
529 fn(attribs, gl.canvas.width, gl.canvas.height);
530 }
531
532 var pixels = new Uint8Array(gl.canvas.width * gl.canvas.height * 4);
533 gl.readPixels(0, 0, gl.canvas.width, gl.canvas.height, gl.RGBA, gl.UNSIGNED_BY TE, pixels);
534 return {
535 width: gl.canvas.width,
536 height: gl.canvas.height,
537 pixels: pixels,
538 img: wtu.makeImage(gl.canvas)
539 };
540 }
541
542 function runProgram(programInfo, test, label, callback) {
543 var shaders = [];
544 var source = [];
545 var count = 0;
546
547 function loadShader(path, type, index) {
548 wtu.loadTextFileAsync(path, function(success, text) {
549 addShader(success, text, type, path, index);
550 });
551 }
552
553 function addShader(success, text, type, path, index) {
554 ++count;
555 if (!success) {
556 testFailed("could not load: " + path);
557 } else {
558 var shader = wtu.loadShader(gl, text, type);
559 shaders.push(shader);
560 source[index] = text;
561 }
562 if (count == 2) {
563 var result;
564 if (shaders.length == 2) {
565 debug("");
566 var console = document.getElementById("console");
567 wtu.addShaderSource(
568 console, label + " vertex shader", source[0], programInfo.vertexShad er);
569 wtu.addShaderSource(
570 console, label + " fragment shader", source[1], programInfo.fragment Shader);
571 var program = wtu.createProgram(gl, shaders[0], shaders[1]);
572 result = drawWithProgram(program, programInfo, test);
573 }
574 callback(result);
575 }
576 }
577
578 loadShader(programInfo.vertexShader, gl.VERTEX_SHADER, 0);
579 loadShader(programInfo.fragmentShader, gl.FRAGMENT_SHADER, 1);
580 }
581
582 function compareResults(expected, actual) {
583 var width = expected.width;
584 var height = expected.height;
585 var canvas = document.createElement("canvas");
586 canvas.width = width;
587 canvas.height = height;
588 var ctx = canvas.getContext("2d");
589 var imgData = ctx.getImageData(0, 0, width, height);
590 var tolerance = 0;
591
592 var expData = expected.pixels;
593 var actData = actual.pixels;
594
595 var same = compareImages(expData, actData, width, height, imgData.data);
596
597 var console = document.getElementById("console");
598 var diffImg = null;
599 if (!same) {
600 ctx.putImageData(imgData, 0, 0);
601 diffImg = wtu.makeImage(canvas);
602 }
603
604 var div = document.createElement("div");
605 div.className = "testimages";
606 wtu.insertImage(div, "reference", expected.img);
607 wtu.insertImage(div, "test", actual.img);
608 if (diffImg) {
609 wtu.insertImage(div, "diff", diffImg);
610 }
611 div.appendChild(document.createElement('br'));
612
613 console.appendChild(div);
614
615 if (!same) {
616 testFailed("images are different");
617 } else {
618 testPassed("images are the same");
619 }
620
621 console.appendChild(document.createElement('hr'));
622 }
623
624 function runCompareTest(test, callback) {
625 debug("");
626 debug("test: " + test.name);
627 var results = [];
628 var count = 0;
629
630 function storeResults(index) {
631 return function(result) {
632 results[index] = result;
633 ++count;
634 if (count == 2) {
635 compareResults(results[0], results[1]);
636 glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
637 callback();
638 }
639 }
640 }
641
642 runProgram(test.referenceProgram, test, "reference", storeResults(0));
643 runProgram(test.testProgram, test, "test", storeResults(1));
644 }
645
646 function runBuildTest(test, callback) {
647 debug("");
648 debug("test: " + test.name);
649
650 var shaders = [null, null];
651 var source = ["",""];
652 var success = [undefined, undefined];
653 var count = 0;
654
655 function loadShader(path, type, index) {
656 if (path == "empty") {
657 shaders[index] = gl.createShader();
658 success[index] = true;
659 source[index] = "/* empty */";
660 attachAndLink();
661 } else {
662 wtu.loadTextFileAsync(path, function(loadSuccess, text) {
663 if (!loadSuccess) {
664 success[index] = false;
665 source[index] = "/* could not load */";
666 testFailed("could not load:" + path);
667 } else {
668 source[index] = text;
669 shaders[index] = wtu.loadShader(gl, text, type, function(index) {
670 return function(msg) {
671 success[index] = false
672 }
673 }(index));
674 if (success[index] === undefined) {
675 success[index] = true;
676 }
677 }
678 attachAndLink();
679 });
680 }
681 }
682
683 function attachAndLink() {
684 ++count;
685 if (count == 2) {
686 debug("");
687 var c = document.getElementById("console");
688 wtu.addShaderSource(
689 c, "vertex shader", source[0], test.testProgram.vertexShader);
690 debug("compile: " + (success[0] ? "success" : "fail"));
691 wtu.addShaderSource(
692 c, "fragment shader", source[1], test.testProgram.fragmentShader);
693 debug("compile: " + (success[1] ? "success" : "fail"));
694 compileSuccess = (success[0] && success[1]);
695 if (!test.compstat) {
696 if (compileSuccess) {
697 testFailed("expected compile failure but was successful");
698 } else {
699 testPassed("expected compile failure and it failed");
700 }
701 } else {
702 if (compileSuccess) {
703 testPassed("expected compile success and it was successful");
704 } else {
705 testFailed("expected compile success but it failed");
706 }
707 var linkSuccess = true;
708 var program = wtu.createProgram(gl, shaders[0], shaders[1], function() {
709 linkSuccess = false;
710 });
711 if (linkSuccess !== test.linkstat) {
712 testFailed("expected link to " + (test.linkstat ? "succeed" : "fail")) ;
713 } else {
714 testPassed("shaders compiled and linked as expected.");
715 }
716 }
717 callback();
718 }
719 }
720
721 loadShader(test.testProgram.vertexShader, gl.VERTEX_SHADER, 0);
722 loadShader(test.testProgram.fragmentShader, gl.FRAGMENT_SHADER, 1);
723 }
724
725 var testPatterns = {
726 compare: runCompareTest,
727 build: runBuildTest,
728
729 dummy: null // just here to mark the end
730 };
731
732 function LogGLCall(functionName, args) {
733 console.log("gl." + functionName + "(" +
734 WebGLDebugUtils.glFunctionArgsToString(functionName, args) + ")");
735 }
736
737 // Runs the tests async since they will load shaders.
738 function run(obj) {
739 description();
740
741 var canvas = document.getElementById("example");
742 gl = wtu.create3DContext(canvas);
743 if (window.WebGLDebugUtils) {
744 gl = WebGLDebugUtils.makeDebugContext(gl, undefined, LogGLCall);
745 }
746 if (!gl) {
747 testFailed("context does not exist");
748 finishTest();
749 return;
750 }
751
752 if (gl.canvas.width != 500 || gl.canvas.height != 500) {
753 testFailed("canvas must be 500x500 pixels: Several shaders are hard coded to this size.");
754 }
755
756 var tests = obj.tests;
757 var ndx = 0;
758
759 function runNextTest() {
760 if (ndx < tests.length) {
761 var test = tests[ndx++];
762 var fn = testPatterns[test.pattern];
763 if (!fn) {
764 testFailed("test pattern: " + test.pattern + " not supoprted")
765 runNextTest();
766 } else {
767 fn(test, runNextTest);
768 }
769 } else {
770 finishTest();
771 }
772 }
773 runNextTest();
774 }
775
776 return {
777 run: run,
778 };
779 }());
780
OLDNEW
« no previous file with comments | « conformance/ogles/mustpass.run.txt ('k') | conformance/ogles/process-ogles2-tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698