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

Side by Side Diff: conformance/extensions/webgl-compressed-texture-size-limit.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 <title>WebGL compressed texture size limit 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="32" height="32" style="width: 40px; height: 40px;">< /canvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script>
43 "use strict";
44 description("Checks size limit of the webgl compressed textures")
45 var canvas;
46
47 function numLevelsFromSize(size) {
48 var levels = 0;
49 while ((size >> levels) > 0) {
50 ++levels;
51 }
52 return levels;
53 }
54
55 // More formats can be added here when more texture compression extensions is en abled in WebGL.
56 var validFormats = {
57 COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
58 COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
59 COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
60 COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,
61 };
62
63 // format specific restrictions for COMPRESSED_RGB_S3TC_DXT1_EXT and COMPRESSED_ RGBA_S3TC_DXT1_EXT
64 // on the byteLength of the ArrayBufferView, pixels
65 function func1 (width, height)
66 {
67 return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
68 }
69
70 // format specific restrictions for COMPRESSED_RGBA_S3TC_DXT3_EXT and COMPRESSED _RGBA_S3TC_DXT5_EXT
71 // on the byteLength of the ArrayBufferView, pixels
72 function func2 (width, height)
73 {
74 return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
75 }
76
77 var wtu = WebGLTestUtils;
78 var gl = wtu.create3DContext("example");
79 var tests = [
80 // More tests can be added here when more texture compression extensions is en abled in WebGL.
81 { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_ RGB_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1},
82 { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_ RGBA_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1},
83 { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_ RGBA_S3TC_DXT3_EXT, dataType: Uint8Array, func: func2},
84 { extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_ RGBA_S3TC_DXT5_EXT, dataType: Uint8Array, func: func2},
85 ];
86
87 // Note: We expressly only use 2 textures because first a texture will be define d
88 // as using all mips of 1 format, then for a moment it will have mixed formats w hich
89 // may uncover bugs.
90 var targets = [
91 { target: gl.TEXTURE_2D,
92 maxSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
93 tex: gl.createTexture(),
94 targets: [gl.TEXTURE_2D]
95 },
96 { target: gl.TEXTURE_CUBE_MAP,
97 maxSize: gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE),
98 tex: gl.createTexture(),
99 targets: [
100 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
101 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
102 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
103 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
104 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
105 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
106 ]
107 }
108 ];
109
110 gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
111
112 var trg = 0;
113 var tt = 0;
114 runNextTest();
115
116 function runNextTest() {
117 var t = targets[trg];
118
119 if (tt == 0) {
120 var tex = t.tex;
121 gl.bindTexture(t.target, tex);
122
123 debug("");
124 debug("max size for " + wtu.glEnumToString(gl, t.target) + ": " + t.maxSize) ;
125 var numLevels = numLevelsFromSize(t.maxSize);
126 debug("num levels " + numLevels);
127 }
128
129 var test = tests[tt];
130 testFormatType(t, test);
131 ++tt;
132 if (tt == tests.length) {
133 tt = 0;
134 ++trg;
135 if (trg == targets.length) {
136 finishTest();
137 return;
138 }
139 }
140 wtu.waitForComposite(gl, runNextTest)
141 }
142
143 function testFormatType(t, test) {
144 debug("");
145
146 // Query the extension and store globally so shouldBe can access it
147 var ext = wtu.getExtensionWithKnownPrefixes(gl, test.extension);
148 if (ext) {
149 testPassed("Successfully enabled " + test.extension + " extension");
150
151 for (var j = 0; j < t.targets.length; ++j) {
152 var target = t.targets[j];
153 debug("");
154 debug(wtu.glEnumToString(gl, target));
155 var numLevels = numLevelsFromSize(t.maxSize);
156
157 // positive test
158 for (var i = 0, size = t.maxSize; i < numLevels; i++, size /= 2) {
159 var pixels = new test.dataType(test.func(size, size));
160 gl.compressedTexImage2D(target, i, test.format, size, size, 0, pixels);
161 glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture should ge nerate NO_ERROR."
162 + "level is " + i + ", size is " + size + "x" + size);
163 }
164
165 // out of bound test
166 // width or height out of bound
167 var pixelsNegativeTest1 = new test.dataType(test.func(t.maxSize * 2, t.max Size * 2));
168 gl.compressedTexImage2D(target, 0, test.format, t.maxSize * 2, t.maxSize * 2, 0, pixelsNegativeTest1);
169 glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bound: shoul d generate INVALID_VALUE."
170 + " level is 0, size is " + (t.maxSize * 2) + "x" + (t.maxSize * 2));
171 // level out of bound
172 var pixelsNegativeTest2 = new test.dataType(test.func(256, 256));
173 gl.compressedTexImage2D(target, numLevels, test.format, 256, 256, 0, pixel sNegativeTest2);
174 glErrorShouldBe(gl, gl.INVALID_VALUE, "level out of bound: should generate INVALID_VALUE."
175 + " level is " + numLevels + ", size is 256x256");
176 //width or height out of bound for specified level
177 gl.compressedTexImage2D(target, numLevels - 1, test.format, 256, 256, 0, p ixelsNegativeTest2);
178 glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bound for sp ecified level: should generate INVALID_VALUE."
179 + " level is " + (numLevels - 1) + ", size is 256x256");
180 }
181 }
182 else
183 testPassed("No " + test.extension + " extension support -- this is legal");
184 }
185
186 var successfullyParsed = true;
187 </script>
188 </body>
189 </html>
190
OLDNEW
« no previous file with comments | « conformance/extensions/webgl-compressed-texture-s3tc.html ('k') | conformance/extensions/webgl-debug-renderer-info.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698