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

Side by Side Diff: conformance/extensions/webgl-compressed-texture-pvrtc.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, 2 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
## -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_pvrtc 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_pvrtc extension, if it is available.");
62
63 debug("");
64
65 // Compressed textures generated with thw PowerVR SDK
66 // http://www.imgtec.com/powervr/insider/sdkdownloads/index.asp
67 var pvrtc_4x4_rgba_2bpp = new Uint8Array([
68 0x77, 0x22, 0x77, 0x22, 0xbb, 0x2b, 0x00, 0x80, 0x77, 0x22, 0x77, 0x22, 0xbb, 0x2b, 0x00, 0x80,
69 0x77, 0x22, 0x77, 0x22, 0xbb, 0x2b, 0x00, 0x80, 0x77, 0x22, 0x77, 0x22, 0xbb, 0x2b, 0x00, 0x80,
70 ]);
71
72 var pvrtc_4x4_rgba_2bpp_decoded = new Uint8Array([
73 0x00, 0x00, 0x00, 0xff, 0x35, 0x35, 0x32, 0xca, 0x76, 0x76, 0x71, 0x8a, 0x70, 0x70, 0x6b, 0x8f,
74 0x35, 0x35, 0x32, 0xca, 0x46, 0x46, 0x43, 0xb8, 0x70, 0x70, 0x6b, 0x8f, 0xbd, 0xbd, 0xb5, 0x44,
75 0x00, 0x00, 0x00, 0xff, 0x35, 0x35, 0x32, 0xca, 0x76, 0x76, 0x71, 0x8a, 0x70, 0x70, 0x6b, 0x8f,
76 0x35, 0x35, 0x32, 0xca, 0x46, 0x46, 0x43, 0xb8, 0x70, 0x70, 0x6b, 0x8f, 0xbd, 0xbd, 0xb5, 0x44,
77 ]);
78
79 var pvrtc_4x4_rgba_4bpp = new Uint8Array([
80 0x1b, 0x1b, 0x1b, 0x1b, 0xba, 0x2b, 0x00, 0x80, 0x1b, 0x1b, 0x1b, 0x1b, 0xba, 0x2b, 0x00, 0x80,
81 0x1b, 0x1b, 0x1b, 0x1b, 0xba, 0x2b, 0x00, 0x80, 0x1b, 0x1b, 0x1b, 0x1b, 0xbc, 0x2b, 0x00, 0x80,
82 ]);
83
84 var pvrtc_4x4_rgba_4bpp_decoded = new Uint8Array([
85 0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x49, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xba, 0x44,
86 0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x4c, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xbc, 0x44,
87 0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x43, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xb5, 0x44,
88 0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x46, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xb7, 0x44,
89 ]);
90
91 // FIXME: The PowerVR SDK tools do not generate RGB only textures, so we current ly do not have
92 // sample data for COMPRESSED_RGB_PVRTC_4BPPV1_IMG and COMPRESSED_RGB_PVRTC_2BPP V1_IMG
93
94 var wtu = WebGLTestUtils;
95 var canvas = document.getElementById("canvas");
96 var gl = wtu.create3DContext(canvas, {antialias: false});
97 var program = wtu.setupTexturedQuad(gl);
98 var ext = null;
99 var vao = null;
100 var validFormats = {
101 COMPRESSED_RGB_PVRTC_4BPPV1_IMG : 0x8C00,
102 COMPRESSED_RGB_PVRTC_2BPPV1_IMG : 0x8C01,
103 COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : 0x8C02,
104 COMPRESSED_RGBA_PVRTC_2BPPV1_IMG : 0x8C03,
105 };
106 var name;
107 var supportedFormats;
108
109 if (!gl) {
110 testFailed("WebGL context does not exist");
111 } else {
112 testPassed("WebGL context exists");
113
114 // Run tests with extension disabled
115 runTestDisabled();
116
117 // Query the extension and store globally so shouldBe can access it
118 ext = wtu.getExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_pvrtc" );
119 if (!ext) {
120 testPassed("No WEBGL_compressed_texture_pvrtc support -- this is legal") ;
121 runSupportedTest(false);
122 } else {
123 testPassed("Successfully enabled WEBGL_compressed_texture_pvrtc extensio n");
124
125 runSupportedTest(true);
126 runTestExtension();
127 }
128 }
129
130 function runSupportedTest(extensionEnabled) {
131 var name = wtu.getSupportedExtensionWithKnownPrefixes(gl, "WEBGL_compressed_ texture_pvrtc");
132 if (name !== undefined) {
133 if (extensionEnabled) {
134 testPassed("WEBGL_compressed_texture_pvrtc listed as supported and g etExtension succeeded");
135 } else {
136 testFailed("WEBGL_compressed_texture_pvrtc listed as supported but g etExtension failed");
137 }
138 } else {
139 if (extensionEnabled) {
140 testFailed("WEBGL_compressed_texture_pvrtc not listed as supported b ut getExtension succeeded");
141 } else {
142 testPassed("WEBGL_compressed_texture_pvrtc not listed as supported a nd getExtension failed -- this is legal");
143 }
144 }
145 }
146
147
148 function runTestDisabled() {
149 debug("Testing binding enum with extension disabled");
150
151 shouldBe('gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)', '[]');
152 }
153
154 function formatExists(format, supportedFormats) {
155 for (var ii = 0; ii < supportedFormats.length; ++ii) {
156 if (format == supportedFormats[ii]) {
157 testPassed("supported format " + formatToString(format) + " is exist s");
158 return;
159 }
160 }
161 testFailed("supported format " + formatToString(format) + " does not exist") ;
162 }
163
164 function formatToString(format) {
165 for (var p in ext) {
166 if (ext[p] == format) {
167 return p;
168 }
169 }
170 return "0x" + format.toString(16);
171 }
172
173 function runTestExtension() {
174 debug("Testing WEBGL_compressed_texture_pvrtc");
175
176 // check that all format enums exist.
177 for (name in validFormats) {
178 var expected = "0x" + validFormats[name].toString(16);
179 var actual = "ext['" + name + "']";
180 shouldBe(actual, expected);
181 }
182
183 supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
184 // There should be exactly 3 formats
185 shouldBe("supportedFormats.length", "3");
186
187 // check that all 3 formats exist
188 for (var name in validFormats.length) {
189 formatExists(validFormats[name], supportedFormats);
190 }
191
192 // Test each format
193 testPVRTC_RGBA_2BPP();
194 testPVRTC_RGBA_4BPP();
195 }
196
197 function testPVRTC_RGBA_2BPP() {
198 var tests = [
199 { width: 4,
200 height: 4,
201 channels: 4,
202 data: pvrtc_4x4_rgba_2bpp,
203 raw: pvrtc_4x4_rgba_2bpp_decoded,
204 format: ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
205 }
206 ];
207 testPVRTCTextures(tests);
208 }
209
210 function testPVRTC_RGBA_4BPP() {
211 var tests = [
212 { width: 4,
213 height: 4,
214 channels: 4,
215 data: pvrtc_4x4_rgba_4bpp,
216 raw: pvrtc_4x4_rgba_4bpp_decoded,
217 format: ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
218 }
219 ];
220 testPVRTCTextures(tests);
221 }
222
223 function testPVRTCTextures(tests) {
224 debug("<hr/>");
225 for (var ii = 0; ii < tests.length; ++ii) {
226 testPVRTCTexture(tests[ii]);
227 }
228 }
229
230 function testPVRTCTexture(test) {
231 var data = new Uint8Array(test.data);
232 var width = test.width;
233 var height = test.height;
234 var format = test.format;
235 var uncompressedData = test.raw;
236
237 canvas.width = width;
238 canvas.height = height;
239 gl.viewport(0, 0, width, height);
240 debug("testing " + formatToString(format) + " " + width + "x" + height);
241
242 var tex = gl.createTexture();
243 gl.bindTexture(gl.TEXTURE_2D, tex);
244 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
245 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
246 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
247 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
248 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, data);
249 glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture");
250 gl.generateMipmap(gl.TEXTURE_2D);
251 glErrorShouldBe(gl, gl.INVALID_OPERATION, "trying to generate mipmaps from c ompressed texture");
252 wtu.clearAndDrawUnitQuad(gl);
253 compareRect(width, height, test.channels, width, height, uncompressedData, d ata, format);
254
255 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 1, data);
256 glErrorShouldBe(gl, gl.INVALID_VALUE, "non 0 border");
257
258 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 1, height, 0, data );
259 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
260 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 2, height, 0, data );
261 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
262 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 1, 0, data );
263 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
264 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 2, 0, data );
265 glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
266
267 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, format, da ta);
268 glErrorShouldBe(gl, gl.NO_ERROR, "compressedTexSubImage2D allowed for reload ing of complete textures");
269
270 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width - 2, height, format , data);
271 glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allow ed for partial texture updates");
272 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height - 2, format , data);
273 glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allow ed for partial texture updates");
274 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 2, 0, width - 2, height, format , data);
275 glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allow ed for partial texture updates");
276 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 2, width, height - 2, format , data);
277 glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allow ed for partial texture updates");
278 }
279
280 function insertImg(element, caption, img) {
281 var div = document.createElement("div");
282 div.appendChild(img);
283 var label = document.createElement("div");
284 label.appendChild(document.createTextNode(caption));
285 div.appendChild(label);
286 element.appendChild(div);
287 }
288
289 function makeImage(imageWidth, imageHeight, dataWidth, data, alpha) {
290 var scale = 8;
291 var c = document.createElement("canvas");
292 c.width = imageWidth * scale;
293 c.height = imageHeight * scale;
294 var ctx = c.getContext("2d");
295 for (var yy = 0; yy < imageHeight; ++yy) {
296 for (var xx = 0; xx < imageWidth; ++xx) {
297 var offset = (yy * dataWidth + xx) * 4;
298 ctx.fillStyle = "rgba(" +
299 data[offset + 0] + "," +
300 data[offset + 1] + "," +
301 data[offset + 2] + "," +
302 (alpha ? data[offset + 3] / 255 : 1) + ")";
303 ctx.fillRect(xx * scale, yy * scale, scale, scale);
304 }
305 }
306 var img = document.createElement("img");
307 img.src = c.toDataURL();
308 return img;
309 }
310 function compareRect(
311 actualWidth, actualHeight, actualChannels,
312 dataWidth, dataHeight, expectedData,
313 testData, testFormat, tolerance) {
314 if(typeof(tolerance) == 'undefined') { tolerance = 5; }
315 var actual = new Uint8Array(actualWidth * actualHeight * 4);
316 gl.readPixels(
317 0, 0, actualWidth, actualHeight, gl.RGBA, gl.UNSIGNED_BYTE, actual);
318
319 var div = document.createElement("div");
320 div.className = "testimages";
321 insertImg(div, "expected", makeImage(
322 actualWidth, actualHeight, dataWidth, expectedData,
323 actualChannels == 4));
324 insertImg(div, "actual", makeImage(
325 actualWidth, actualHeight, actualWidth, actual,
326 actualChannels == 4));
327 div.appendChild(document.createElement('br'));
328 document.getElementById("console").appendChild(div);
329
330 var failed = false;
331 for (var yy = 0; yy < actualHeight; ++yy) {
332 for (var xx = 0; xx < actualWidth; ++xx) {
333 var actualOffset = (yy * actualWidth + xx) * 4;
334 var expectedOffset = (yy * dataWidth + xx) * 4;
335 var expected = [
336 expectedData[expectedOffset + 0],
337 expectedData[expectedOffset + 1],
338 expectedData[expectedOffset + 2],
339 (actualChannels == 3 ? 255 : expectedData[expectedOffset + 3 ])
340 ];
341 for (var jj = 0; jj < 4; ++jj) {
342 if (Math.abs(actual[actualOffset + jj] - expected[jj]) > toleran ce) {
343 failed = true;
344 var was = actual[actualOffset + 0].toString();
345 for (j = 1; j < 4; ++j) {
346 was += "," + actual[actualOffset + j];
347 }
348 testFailed('at (' + xx + ', ' + yy +
349 ') expected: ' + expected + ' was ' + w as);
350 }
351 }
352 }
353 }
354 if (!failed) {
355 testPassed("texture rendered correctly");
356 }
357 }
358
359 debug("");
360 var successfullyParsed = true;
361 </script>
362 <script src="../../resources/js-test-post.js"></script>
363
364 </body>
365 </html>
OLDNEW
« no previous file with comments | « conformance/extensions/webgl-compressed-texture-atc.html ('k') | conformance/extensions/webgl-compressed-texture-s3tc.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698