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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/gl-teximage.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 texImage2D conformance test.</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test.js"> </script>
36 <script src="../resources/webgl-test-utils.js"> </script>
37 </head>
38 <body>
39 <canvas id="example" width="256" height="16" style="width: 256px; height: 48px;" ></canvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script>
43 description("Test texImage2D conversions.");
44 var wtu = WebGLTestUtils;
45 var gl = wtu.create3DContext("example");
46 gl.disable(gl.DITHER);
47 var program = wtu.setupTexturedQuad(gl);
48
49 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
50
51 var imgURLs = [
52 '../resources/gray-ramp-256-with-128-alpha.png',
53 '../resources/gray-ramp-256.png',
54 '../resources/gray-ramp-default-gamma.png',
55 '../resources/gray-ramp-gamma0.1.png',
56 '../resources/gray-ramp-gamma1.0.png',
57 '../resources/gray-ramp-gamma2.0.png',
58 '../resources/gray-ramp-gamma4.0.png',
59 '../resources/gray-ramp-gamma9.0.png',
60 '../resources/gray-ramp.png',
61 '../resources/zero-alpha.png',
62 '../resources/3x3.png',
63 '../resources/blue-1x1.jpg',
64 '../resources/red-indexed.png',
65 '../resources/green-2x2-16bit.png',
66 '../resources/small-square-with-colorspin-profile.jpg',
67 '../resources/small-square-with-colorspin-profile.png',
68 '../resources/small-square-with-cie-rgb-profile.png',
69 '../resources/small-square-with-colormatch-profile.png',
70 '../resources/small-square-with-e-srgb-profile.png',
71 '../resources/small-square-with-smpte-c-profile.png',
72 '../resources/small-square-with-srgb-iec61966-2.1-profile.png'];
73
74
75 wtu.loadImagesAsync(imgURLs, runTests);
76
77 function runTests(imgs) {
78 var loc = gl.getUniformLocation(program, "tex");
79 gl.uniform1i(loc, 0);
80
81 gl.disable(gl.BLEND);
82 gl.disable(gl.DEPTH_TEST);
83
84 var width = gl.canvas.width;
85 var height = gl.canvas.height;
86
87 function checkPixel(buf, x, y, color) {
88 var off = (y * width + x) * 4;
89 var msg = "pixel " + x + ", " + y + " should be " +
90 color[0] + ", " +
91 color[1] + ", " +
92 color[2] + ", " +
93 color[3] + " was " +
94 buf[off + 0] + ", " +
95 buf[off + 1] + ", " +
96 buf[off + 2] + ", " +
97 buf[off + 3];
98
99 for (var ii = 0; ii < 4; ++ii) {
100 if (buf[off + ii] != color[ii]) {
101 testFailed(msg);
102 return;
103 }
104 }
105 testPassed(msg);
106 }
107
108 function checkPixelRange(buf, x, y, color, allowedRange) {
109 var off = (y * width + x) * 4;
110 var msg = "pixel " + x + ", " + y + " should be within " +
111 allowedRange + " units of " +
112 color[0] + ", " +
113 color[1] + ", " +
114 color[2] + ", " +
115 color[3];
116 var subMsg = " was " +
117 buf[off + 0] + ", " +
118 buf[off + 1] + ", " +
119 buf[off + 2] + ", " +
120 buf[off + 3];
121 // When running in WebKit's test harness, we don't want to print the
122 // pixel value when the test passes, because different machines might
123 // have different results and we record the text output.
124 var inDumpRenderTree = window.layoutTestController;
125 for (var ii = 0; ii < 4; ++ii) {
126 if (Math.abs(buf[off + ii] - color[ii]) > allowedRange) {
127 testFailed(msg + subMsg);
128 return;
129 }
130 }
131 testPassed(msg + (inDumpRenderTree ? "" : subMsg));
132 }
133
134 var tex = gl.createTexture();
135 gl.bindTexture(gl.TEXTURE_2D, tex);
136 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
137 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
138 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
139 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
140
141 var buf = new Uint8Array(width * height * 4);
142
143 debug("");
144 debug("check pixels are NOT pre-multiplied");
145 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
146 imgs['../resources/zero-alpha.png']);
147 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
148 wtu.drawQuad(gl);
149 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
150
151 var left = 0;
152 var middle = Math.floor(width / 2);
153 var right = width - 1;
154 var bottom = 0;
155 var center = Math.floor(height / 2);
156 var top = height - 1;
157 checkPixel(buf, left, top, [ 0, 0, 0, 255]);
158 checkPixel(buf, middle, top, [255, 0, 255, 255]);
159 checkPixel(buf, right, top, [ 0, 0, 255, 255]);
160 checkPixel(buf, left, center, [128, 128, 128, 255]);
161 checkPixel(buf, middle, center, [255, 255, 255, 255]);
162 checkPixel(buf, right, center, [ 0, 255, 255, 255]);
163 checkPixel(buf, left, bottom, [255, 0, 0, 255]);
164 checkPixel(buf, middle, bottom, [255, 255, 0, 255]);
165 checkPixel(buf, right, bottom, [ 0, 255, 0, 255]);
166
167 debug("");
168 debug("check quantization");
169 var quantInfo = [
170 {format: gl.RGBA, type: gl.UNSIGNED_BYTE, counts: [256, 256, 256, 2 56]},
171 {format: gl.RGBA, type: gl.UNSIGNED_SHORT_4_4_4_4, counts: [ 16, 16, 16, 16]},
172 {format: gl.RGB, type: gl.UNSIGNED_SHORT_5_6_5, counts: [ 32, 64, 32, 1]},
173 {format: gl.RGBA, type: gl.UNSIGNED_SHORT_5_5_5_1, counts: [ 32, 32, 32, 2]}];
174 for (var qq = 0; qq < quantInfo.length; ++qq) {
175 var info = quantInfo[qq];
176 gl.texImage2D(
177 gl.TEXTURE_2D, 0, info.format, info.format, info.type,
178 imgs['../resources/gray-ramp-256.png']);
179 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
180 wtu.drawQuad(gl);
181 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
182 var counts = [{ }, { }, { }, { }];
183 var numUniqueValues = [0, 0, 0, 0];
184 // Count the number of unique values in each channel.
185 for (var ii = 0; ii < width * height * 4; ii += 4) {
186 for (var jj = 0; jj < 4; ++jj) {
187 var v = buf[ii + jj];
188 if (!counts[jj][v]) {
189 counts[jj][v] = 1;
190 ++numUniqueValues[jj];
191 } else {
192 ++counts[jj][v];
193 }
194 }
195 }
196 for (var ii = 0; ii < 4; ++ii) {
197 assertMsg(numUniqueValues[ii] == info.counts[ii],
198 "There should be " + info.counts[ii] +
199 " unique values in channel " + ii + ". Found " +
200 numUniqueValues[ii]);
201 }
202 }
203
204 debug("");
205 debug("Check that gamma settings don't effect 8bit pngs");
206 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
207 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
208 imgs['../resources/gray-ramp-default-gamma.png']);
209 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
210 wtu.drawQuad(gl);
211 var ref = new Uint8Array(width * height * 4);
212 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, ref);
213
214 var gammaImages = [
215 '../resources/gray-ramp-gamma0.1.png',
216 '../resources/gray-ramp-gamma1.0.png',
217 '../resources/gray-ramp-gamma2.0.png',
218 '../resources/gray-ramp-gamma4.0.png',
219 '../resources/gray-ramp-gamma9.0.png'];
220 for (var ii = 0; ii < gammaImages.length; ++ii) {
221 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
222 imgs[gammaImages[ii]]);
223 wtu.drawQuad(gl);
224 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
225 var same = true;
226 for (var jj = 0; jj < width * height * 4; ++jj) {
227 if (buf[jj] != ref[jj]) {
228 same = false;
229 break;
230 }
231 }
232 assertMsg(same, "pixels should be same regardless of gamma settings.");
233 }
234
235 debug("");
236 debug("check pixels are UN pre-multiplied");
237 for (var ii = 0; ii < 2; ++ii) {
238 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
239 if (ii == 0) {
240 var canvas2d = document.createElement("canvas");
241 canvas2d.width = 256;
242 canvas2d.height = 1;
243 var ctx = canvas2d.getContext("2d");
244 ctx.drawImage(imgs['../resources/gray-ramp-256-with-128-alpha.png'], 0, 0) ;
245 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, canvas2d );
246 } else {
247 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
248 imgs['../resources/gray-ramp-256-with-128-alpha.png']);
249 }
250 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
251 wtu.drawQuad(gl);
252 var buf = new Uint8Array(width * height * 4);
253 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
254 var lt128Count = [0, 0, 0];
255 var ge128Count = [0, 0, 0];
256 for (var jj = 0; jj < width; ++jj) {
257 var off = jj * 4;
258 for (var cc = 0; cc < 3; ++cc) {
259 if (buf[off + cc] < 128) {
260 ++lt128Count[cc];
261 } else {
262 ++ge128Count[cc];
263 }
264 }
265 }
266 // Not sure the exact count here because gamma does effect drawing into the
267 // canvas but it should be close to 50% so I'll pass 45%
268 for (var jj = 0; jj < 3; ++jj) {
269 assertMsg(ge128Count[jj] > 256 * 0.45,
270 "Half the pixels in channel " + jj +
271 " should be >= 128,128,128. found " +
272 ((ge128Count[jj] / 256) * 100).toFixed() + "%");
273 assertMsg(lt128Count[jj] > 256 * 0.45,
274 "Half the pixels in channel " + jj +
275 " should be < 128,128,128. found " +
276 ((lt128Count[jj] / 256) * 100).toFixed() + "%");
277 }
278 }
279
280 debug("");
281 debug("check canvas pixels are UN pre-multiplied");
282 var canvas2d = document.createElement("canvas");
283 canvas2d.width = 1;
284 canvas2d.height = 1;
285 var ctx = canvas2d.getContext("2d");
286 ctx.fillStyle ="rgba(255,255,255,0.5)";
287 ctx.fillRect(0, 0, 256, 1);
288 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
289 wtu.drawQuad(gl);
290 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
291 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
292 checkPixelRange(buf, 0, 0, [255, 255, 255, 127], 4);
293
294 debug("");
295 debug("check canvas pixels are pre-multiplied");
296 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
297 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
298 wtu.drawQuad(gl);
299 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
300 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
301 checkPixelRange(buf, 0, 0, [127, 127, 127, 127], 4);
302
303
304 debug("");
305 debug("check pixels are pre-multiplied");
306 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
307 // TODO(gman): use different texture that won't pass on failure
308 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
309 imgs['../resources/zero-alpha.png']);
310 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
311 wtu.drawQuad(gl);
312 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
313
314 var same = true;
315 for (var jj = 0; jj < width * height * 4; ++jj) {
316 if (buf[jj] != 0) {
317 same = false;
318 break;
319 }
320 }
321 assertMsg(same, "pixels should all be 0.");
322
323 debug("");
324 debug("check pixels are flipped");
325 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
326 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
327 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
328 imgs['../resources/3x3.png']);
329 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
330 wtu.drawQuad(gl);
331 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
332
333 checkPixel(buf, left, top, [255, 0, 0, 255]);
334 checkPixel(buf, middle, top, [255, 255, 0, 255]);
335 checkPixel(buf, right, top, [255, 0, 0, 255]);
336 checkPixel(buf, left, center, [255, 0, 255, 255]);
337 checkPixel(buf, middle, center, [255, 0, 0, 255]);
338 checkPixel(buf, right, center, [ 0, 255, 0, 255]);
339 checkPixel(buf, left, bottom, [ 0, 0, 0, 255]);
340 checkPixel(buf, middle, bottom, [ 0, 0, 255, 255]);
341 checkPixel(buf, right, bottom, [255, 0, 0, 255]);
342
343 debug("");
344 debug("check uploading of images with no alpha channel works");
345 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
346 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
347 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
348 imgs['../resources/blue-1x1.jpg']);
349 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
350 wtu.drawQuad(gl);
351 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
352 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
353 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
354
355 debug("");
356 debug("check uploading of 16-bit images");
357 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
358 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
359 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
360 imgs['../resources/green-2x2-16bit.png']);
361 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
362 wtu.drawQuad(gl);
363 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
364 checkPixelRange(buf, middle, center, [ 15, 121, 0, 255], 10);
365 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
366
367 debug("");
368 debug("check uploading of images with ICC profiles");
369 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
370 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
371 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
372
373 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
374 imgs['../resources/small-square-with-colorspin-profile.jpg']);
375 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
376 wtu.drawQuad(gl);
377 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
378 // The image is red. However, if we ignore the color profile, it is blue.
379 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
380
381 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
382 imgs['../resources/small-square-with-colorspin-profile.png']);
383 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
384 wtu.drawQuad(gl);
385 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
386 // The image is red. However, if we ignore the color profile, it is blue.
387 checkPixelRange(buf, middle, center, [ 0, 0, 255, 255], 10);
388
389 var iccPNGs = [
390 '../resources/small-square-with-cie-rgb-profile.png',
391 '../resources/small-square-with-colormatch-profile.png',
392 '../resources/small-square-with-e-srgb-profile.png',
393 '../resources/small-square-with-smpte-c-profile.png',
394 '../resources/small-square-with-srgb-iec61966-2.1-profile.png'];
395 for (var ii = 0; ii < iccPNGs.length; ++ii) {
396 var buf2 = new Uint8Array(width * height * 4);
397 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
398 imgs[iccPNGs[ii]]);
399 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
400 wtu.drawQuad(gl);
401 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf2);
402 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
403 var same = true;
404 for (var jj = 0; jj < buf.length; ++jj) {
405 if (buf[jj] != buf2[jj]) {
406 same = false;
407 break;
408 }
409 }
410 assertMsg(same, "uploading PNGs with same data but various ICC profiles shou ld generate the same results");
411 }
412
413 debug("");
414 debug("check uploading of indexed PNG images");
415 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
416 imgs['../resources/red-indexed.png']);
417 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
418 wtu.drawQuad(gl);
419 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
420 // The image should be red.
421 checkPixelRange(buf, middle, center, [ 255, 0, 0, 255 ], 10);
422
423 debug("")
424 debug("check calling texImage2D with NULL clears the texture");
425 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB,
426 imgs['../resources/red-indexed.png'].width,
427 imgs['../resources/red-indexed.png'].height,
428 0, gl.RGB, gl.UNSIGNED_BYTE, null);
429 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
430 wtu.drawQuad(gl);
431 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
432 // The image should be white.
433 checkPixelRange(buf, middle, center, [ 0, 0, 0, 255 ], 10);
434
435 debug("");
436 successfullyParsed = true;
437 shouldBeTrue("successfullyParsed");
438 debug('<br /><span class="pass">TEST COMPLETE</span>');
439 notifyFinishedToHarness();
440 }
441 </script>
442 </body>
443 </html>
444
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698