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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/gl-teximage.html

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

Powered by Google App Engine
This is Rietveld 408576698