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

Side by Side Diff: conformance/extensions/webgl-compressed-texture-atc.html

Issue 41893003: Add ToT WebGL conformance tests : part 12 (last one) (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
Property Changes:
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
OLDNEW
(Empty)
1 <!--
2
3 /*
4 ** Copyright (c) 2013 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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
33 <script src="../../resources/js-test-pre.js"></script>
34 <script src="../resources/webgl-test.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
36 <title>WebGL WEBGL_compressed_texture_atc Conformance Tests</title>
37 <style>
38 img {
39 border: 1px solid black;
40 margin-right: 1em;
41 }
42 .testimages {
43 }
44
45 .testimages br {
46 clear: both;
47 }
48
49 .testimages > div {
50 float: left;
51 margin: 1em;
52 }
53 </style>
54 </head>
55 <body>
56 <div id="description"></div>
57 <canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canv as>
58 <div id="console"></div>
59 <script>
60 "use strict";
61 description("This test verifies the functionality of the WEBGL_compressed_textur e_atc extension, if it is available.");
62
63 debug("");
64
65 // Compressed textures generated with AMD's Compressonator tool
66 // http://developer.amd.com/resources/archive/archived-tools/gpu-tools-archive/t he-compressonator/
67 var img_4x4_rgba_raw = new Uint8Array([
68 0xff,0x00,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
69 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
70 0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
71 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0 xff,
72 ]);
73 var img_4x4_rgb_atc = new Uint8Array([
74 0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0xff,
75 ]);
76 var img_4x4_rgba_atc_explicit = new Uint8Array([
77 0xf6,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0 xff,
78 ]);
79 var img_4x4_rgba_atc_implicit = new Uint8Array([
80 0xff,0x6a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0 xff,
81 ]);
82 var img_8x8_rgba_raw = new Uint8Array([
83 0xff,0x00,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
84 0xff,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0 xff,
85 0x00,0xff,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
86 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0 xff,
87 0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0 xff,
88 0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0 xff,
89 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0 xff,
90 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0 xff,
91 0x00,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0 xff,
92 0x00,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0 xff,
93 0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0 xff,
94 0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0 xff,
95 0x00,0xff,0x00,0x69,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0 xff,
96 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0 xff,
97 0xff,0x00,0xff,0x69,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0 xff,
98 0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0 xff,
99 ]);
100 var img_8x8_rgb_atc = new Uint8Array([
101 0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0xff,0x1f,0x00,0xe0,0xff,0x33,0x30,0x3f,0 x00,
102 0x1f,0x7c,0xe0,0x07,0x33,0x30,0x3f,0x00,0x1f,0x00,0xff,0x07,0xcc,0xcf,0xc0,0 xff,
103 ]);
104 var img_8x8_rgba_atc_explicit = new Uint8Array([
105 0xf6,0xff,0xf6,0xff,0xff,0xff,0xff,0xff,0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0 xff,
106 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0x00,0xe0,0xff,0x33,0x30,0x3f,0 x00,
107 0xff,0xff,0xff,0xff,0xf6,0xff,0xf6,0xff,0x1f,0x7c,0xe0,0x07,0x33,0x30,0x3f,0 x00,
108 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0x00,0xff,0x07,0xcc,0xcf,0xc0,0 xff,
109 ]);
110 var img_8x8_rgba_atc_implicit = new Uint8Array([
111 0xff,0x6a,0x01,0x10,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0x07,0xcc,0xcf,0xc0,0 xff,
112 0x00,0xff,0x49,0x92,0x24,0x49,0x92,0x24,0x1f,0x00,0xe0,0xff,0x33,0x30,0x3f,0 x00,
113 0xff,0x69,0x00,0x00,0x00,0x01,0x10,0x00,0x1f,0x7c,0xe0,0x07,0x33,0x30,0x3f,0 x00,
114 0x00,0xff,0x49,0x92,0x24,0x49,0x92,0x24,0x1f,0x00,0xff,0x07,0xcc,0xcf,0xc0,0 xff,
115 ]);
116
117 var wtu = WebGLTestUtils;
118 var canvas = document.getElementById("canvas");
119 var gl = wtu.create3DContext(canvas, {antialias: false});
120 var program = wtu.setupTexturedQuad(gl);
121 var ext = null;
122 var vao = null;
123 var validFormats = {
124 COMPRESSED_RGB_ATC_WEBGL : 0x8C92,
125 COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL : 0x8C93,
126 COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL : 0x87EE,
127 };
128 var name;
129 var supportedFormats;
130
131 if (!gl) {
132 testFailed("WebGL context does not exist");
133 } else {
134 testPassed("WebGL context exists");
135
136 // Run tests with extension disabled
137 runTestDisabled();
138
139 // Query the extension and store globally so shouldBe can access it
140 ext = wtu.getExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_atc");
141 if (!ext) {
142 testPassed("No WEBGL_compressed_texture_atc support -- this is legal");
143 runSupportedTest(false);
144 } else {
145 testPassed("Successfully enabled WEBGL_compressed_texture_atc extension" );
146
147 runSupportedTest(true);
148 runTestExtension();
149 }
150 }
151
152 function runSupportedTest(extensionEnabled) {
153 var name = wtu.getSupportedExtensionWithKnownPrefixes(gl, "WEBGL_compressed_ texture_atc");
154 if (name !== undefined) {
155 if (extensionEnabled) {
156 testPassed("WEBGL_compressed_texture_atc listed as supported and get Extension succeeded");
157 } else {
158 testFailed("WEBGL_compressed_texture_atc listed as supported but get Extension failed");
159 }
160 } else {
161 if (extensionEnabled) {
162 testFailed("WEBGL_compressed_texture_atc not listed as supported but getExtension succeeded");
163 } else {
164 testPassed("WEBGL_compressed_texture_atc not listed as supported and getExtension failed -- this is legal");
165 }
166 }
167 }
168
169
170 function runTestDisabled() {
171 debug("Testing binding enum with extension disabled");
172
173 shouldBe('gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)', '[]');
174 }
175
176 function formatExists(format, supportedFormats) {
177 for (var ii = 0; ii < supportedFormats.length; ++ii) {
178 if (format == supportedFormats[ii]) {
179 testPassed("supported format " + formatToString(format) + " is exist s");
180 return;
181 }
182 }
183 testFailed("supported format " + formatToString(format) + " does not exist") ;
184 }
185
186 function formatToString(format) {
187 for (var p in ext) {
188 if (ext[p] == format) {
189 return p;
190 }
191 }
192 return "0x" + format.toString(16);
193 }
194
195 function runTestExtension() {
196 debug("Testing WEBGL_compressed_texture_atc");
197
198 // check that all format enums exist.
199 for (name in validFormats) {
200 var expected = "0x" + validFormats[name].toString(16);
201 var actual = "ext['" + name + "']";
202 shouldBe(actual, expected);
203 }
204
205 supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
206 // There should be exactly 3 formats
207 shouldBe("supportedFormats.length", "3");
208
209 // check that all 3 formats exist
210 for (var name in validFormats.length) {
211 formatExists(validFormats[name], supportedFormats);
212 }
213
214 // Test each format
215 testATC_RGB();
216 testATC_RGBA_Explicit();
217 testATC_RGBA_Interpolated();
218 }
219
220 function testATC_RGB() {
221 var tests = [
222 { width: 4,
223 height: 4,
224 channels: 3,
225 data: img_4x4_rgb_atc,
226 raw: img_4x4_rgba_raw,
227 format: ext.COMPRESSED_RGB_ATC_WEBGL
228 },
229 { width: 8,
230 height: 8,
231 channels: 3,
232 data: img_8x8_rgb_atc,
233 raw: img_8x8_rgba_raw,
234 format: ext.COMPRESSED_RGB_ATC_WEBGL
235 }
236 ];
237 testACTTextures(tests);
238 }
239
240 function testATC_RGBA_Explicit() {
241 var tests = [
242 { width: 4,
243 height: 4,
244 channels: 4,
245 data: img_4x4_rgba_atc_explicit,
246 raw: img_4x4_rgba_raw,
247 format: ext.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL
248 },
249 { width: 8,
250 height: 8,
251 channels: 4,
252 data: img_8x8_rgba_atc_explicit,
253 raw: img_8x8_rgba_raw,
254 format: ext.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL
255 }
256 ];
257 testACTTextures(tests);
258 }
259
260 function testATC_RGBA_Interpolated() {
261 var tests = [
262 { width: 4,
263 height: 4,
264 channels: 4,
265 data: img_4x4_rgba_atc_interpolated,
266 raw: img_4x4_rgba_raw,
267 format: ext.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
268 },
269 { width: 8,
270 height: 8,
271 channels: 4,
272 data: img_8x8_rgba_atc_interpolated,
273 raw: img_8x8_rgba_raw,
274 format: ext.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
275 }
276 ];
277 testACTTextures(tests);
278 }
279
280 function testACTTextures(tests) {
281 debug("<hr/>");
282 for (var ii = 0; ii < tests.length; ++ii) {
283 testACTTexture(tests[ii]);
284 }
285 }
286
287 function testACTTexture(test) {
288 var data = new Uint8Array(test.data);
289 var width = test.width;
290 var height = test.height;
291 var format = test.format;
292 var uncompressedData = test.raw;
293
294 canvas.width = width;
295 canvas.height = height;
296 gl.viewport(0, 0, width, height);
297 debug("testing " + formatToString(format) + " " + width + "x" + height);
298
299 var tex = gl.createTexture();
300 gl.bindTexture(gl.TEXTURE_2D, tex);
301 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
302 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
303 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
304 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
305 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, data);
306 glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture");
307 gl.generateMipmap(gl.TEXTURE_2D);
308 glErrorShouldBe(gl, gl.INVALID_OPERATION, "trying to generate mipmaps from c ompressed texture");
309 wtu.clearAndDrawUnitQuad(gl);
310 compareRect(width, height, test.channels, width, height, uncompressedData, d ata, format);
311
312 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width + 4, height, 0, data );
313 glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions") ;
314 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height + 4, 0, data );
315 glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions") ;
316 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 4, height, 0, data );
317 glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions") ;
318 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 4, 0, data );
319 glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions") ;
320
321 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 1, height, 0, data );
322 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
323 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 2, height, 0, data );
324 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
325 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 1, 0, data );
326 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
327 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 2, 0, data );
328 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
329
330 gl.compressedTexImage2D(gl.TEXTURE_2D, -1, format, 1, height, 0, data);
331 glErrorShouldBe(gl, gl.NO_ERROR, "cannot specify negative mip level");
332
333 // ATC Does not allow use of CompressedTexSubImage
334 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, format, da ta);
335 glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allow ed");
336 }
337
338 function insertImg(element, caption, img) {
339 var div = document.createElement("div");
340 div.appendChild(img);
341 var label = document.createElement("div");
342 label.appendChild(document.createTextNode(caption));
343 div.appendChild(label);
344 element.appendChild(div);
345 }
346
347 function makeImage(imageWidth, imageHeight, dataWidth, data, alpha) {
348 var scale = 8;
349 var c = document.createElement("canvas");
350 c.width = imageWidth * scale;
351 c.height = imageHeight * scale;
352 var ctx = c.getContext("2d");
353 for (var yy = 0; yy < imageHeight; ++yy) {
354 for (var xx = 0; xx < imageWidth; ++xx) {
355 var offset = (yy * dataWidth + xx) * 4;
356 ctx.fillStyle = "rgba(" +
357 data[offset + 0] + "," +
358 data[offset + 1] + "," +
359 data[offset + 2] + "," +
360 (alpha ? data[offset + 3] / 255 : 1) + ")";
361 ctx.fillRect(xx * scale, yy * scale, scale, scale);
362 }
363 }
364 var img = document.createElement("img");
365 img.src = c.toDataURL();
366 return img;
367 }
368 function compareRect(
369 actualWidth, actualHeight, actualChannels,
370 dataWidth, dataHeight, expectedData,
371 testData, testFormat, tolerance) {
372 if(typeof(tolerance) == 'undefined') { tolerance = 5; }
373 var actual = new Uint8Array(actualWidth * actualHeight * 4);
374 gl.readPixels(
375 0, 0, actualWidth, actualHeight, gl.RGBA, gl.UNSIGNED_BYTE, actual);
376
377 var div = document.createElement("div");
378 div.className = "testimages";
379 insertImg(div, "expected", makeImage(
380 actualWidth, actualHeight, dataWidth, expectedData,
381 actualChannels == 4));
382 insertImg(div, "actual", makeImage(
383 actualWidth, actualHeight, actualWidth, actual,
384 actualChannels == 4));
385 div.appendChild(document.createElement('br'));
386 document.getElementById("console").appendChild(div);
387
388 var failed = false;
389 for (var yy = 0; yy < actualHeight; ++yy) {
390 for (var xx = 0; xx < actualWidth; ++xx) {
391 var actualOffset = (yy * actualWidth + xx) * 4;
392 var expectedOffset = (yy * dataWidth + xx) * 4;
393 var expected = [
394 expectedData[expectedOffset + 0],
395 expectedData[expectedOffset + 1],
396 expectedData[expectedOffset + 2],
397 (actualChannels == 3 ? 255 : expectedData[expectedOffset + 3 ])
398 ];
399 for (var jj = 0; jj < 4; ++jj) {
400 if (Math.abs(actual[actualOffset + jj] - expected[jj]) > toleran ce) {
401 failed = true;
402 var was = actual[actualOffset + 0].toString();
403 for (j = 1; j < 4; ++j) {
404 was += "," + actual[actualOffset + j];
405 }
406 testFailed('at (' + xx + ', ' + yy +
407 ') expected: ' + expected + ' was ' + w as);
408 }
409 }
410 }
411 }
412 if (!failed) {
413 testPassed("texture rendered correctly");
414 }
415 }
416
417 debug("");
418 var successfullyParsed = true;
419 </script>
420 <script src="../../resources/js-test-post.js"></script>
421
422 </body>
423 </html>
OLDNEW
« no previous file with comments | « conformance/extensions/oes-vertex-array-object.html ('k') | conformance/extensions/webgl-compressed-texture-pvrtc.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698