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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/texture-size.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 texture size 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 id="vshader" type="x-shader/x-vertex">
43 attribute vec4 vPosition;
44 attribute vec3 texCoord0;
45 varying vec3 texCoord;
46 void main()
47 {
48 gl_Position = vPosition;
49 texCoord = texCoord0;
50 }
51 </script>
52
53 <script id="fshader" type="x-shader/x-fragment">
54 precision mediump float;
55 uniform samplerCube tex;
56 varying vec3 texCoord;
57 void main()
58 {
59 gl_FragColor = textureCube(tex, normalize(texCoord));
60 }
61 </script>
62 <script>
63 description("Checks that various sizes of textures render")
64 var canvas;
65
66 var wtu = WebGLTestUtils;
67 gl = wtu.create3DContext("example");
68 var program2D = wtu.setupTexturedQuad(gl);
69 var programCubeMap = wtu.setupProgram(
70 gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]);
71 gl.disable(gl.DEPTH_TEST);
72 gl.disable(gl.BLEND);
73 var tex = gl.createTexture();
74 var max2DSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
75 var maxCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
76 debug("MAX_TEXTURE_SIZE:" + max2DSize);
77 debug("MAX_CUBE_MAP_TEXTURE_SIZE:" + maxCubeMapSize);
78 // Assuming 2048x2048xRGBA (22meg with mips) will run on all WebGL platforms
79 var max2DSquareSize = Math.min(max2DSize, 2048);
80 // I'd prefer this to be 2048 but that's 16meg x 6 faces or 128meg (with mips)
81 // 1024 is 33.5 meg (with mips)
82 var maxCubeMapSize = Math.min(maxCubeMapSize, 1024);
83
84 var colors = [
85 { name: "green", rgba: [0, 0, 255, 255] },
86 { name: "red", rgba: [255, 0, 0, 255] },
87 { name: "blue", rgba: [0, 255, 0, 255] },
88 { name: "yellow", rgba: [255, 255, 0, 255] },
89 { name: "magenta", rgba: [255, 0, 255, 255] },
90 { name: "cyan", rgba: [0, 255, 255, 255] }
91 ];
92
93 var count = 0;
94 var power = 0;
95 runTest();
96
97 function runTest() {
98 function doTest() {
99 var size = Math.pow(2, power);
100 if (size > max2DSize) {
101 return false;
102 }
103 gl.useProgram(program2D);
104 if (!checkTexture(size, 1, false)) return false;
105 if (!checkTexture(1, size, false)) return false;
106 if (size <= max2DSquareSize) {
107 if (!checkTexture(size, size, false)) {
108 return false;
109 }
110 }
111 if (size <= maxCubeMapSize) {
112 gl.useProgram(programCubeMap);
113 if (!checkTexture(size, size, true)) {
114 return false;
115 }
116 }
117 return true;
118 }
119
120 if (doTest()) {
121 ++power;
122 setTimeout(runTest, 100);
123 } else {
124 finishTest();
125 }
126 }
127
128 function checkTexture(width, height, cubeMap) {
129 debug("");
130 count = (count + 1) % colors.length;
131 var color = colors[count];
132 var tex = gl.createTexture();
133 var target = cubeMap ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
134 var type = cubeMap ? "cube map" : "2D texture";
135 debug("check " + width + ", " + height + " " + type);
136 gl.bindTexture(target, tex);
137 gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
138 gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
139 gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
140 fillLevel(0, width, height, color.rgba, cubeMap);
141 var err = gl.getError();
142 if (err == gl.OUT_OF_MEMORY) {
143 debug("out of memory");
144 return false;
145 }
146 if (err != gl.NO_ERROR) {
147 testFailed("unexpected gl error: " + wtu.glEnumToString(gl, err));
148 }
149 wtu.drawQuad(gl);
150 wtu.checkCanvas(gl, color.rgba,
151 type + " of size " + width + "x" + height + " with no mips should draw wit h " + color.name);
152 count = (count + 1) % colors.length;
153 color = colors[count];
154 fillLevel(0, width, height, color.rgba, cubeMap);
155 gl.generateMipmap(target);
156 var err = gl.getError();
157 if (err == gl.OUT_OF_MEMORY) {
158 debug("out of memory");
159 return false;
160 }
161 if (err != gl.NO_ERROR) {
162 testFailed("unexpected gl error: " + wtu.glEnumToString(gl, err));
163 }
164 gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
165 wtu.drawQuad(gl);
166 wtu.checkCanvas(gl, color.rgba,
167 type + " of size " + width + "x" + height + " with mips should draw with " + color.name);
168
169 count = (count + 1) % colors.length;
170 color = colors[count];
171 fillLevel(0, width, height, color.rgba, cubeMap, true);
172 gl.generateMipmap(target);
173
174 wtu.drawQuad(gl);
175 wtu.checkCanvas(gl, color.rgba,
176 type + " of size " + width + "x" + height + " with mips should draw with " + color.name);
177
178 gl.deleteTexture(tex);
179 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
180 return true;
181 }
182
183 function fillLevel(level, width, height, color, opt_cubemap, opt_subTex) {
184 var numPixels = width * height;
185 var pixels = null;
186 var largeDim = Math.max(width, height);
187 var smallDim = Math.min(width, height);
188
189 var pixelRow = new Uint8Array(largeDim * 4);
190 for (var jj = 0; jj < largeDim; ++jj) {
191 var off = jj * 4;
192 pixelRow[off + 0] = color[0];
193 pixelRow[off + 1] = color[1];
194 pixelRow[off + 2] = color[2];
195 pixelRow[off + 3] = color[3];
196 }
197
198 if (largeDim == numPixels) {
199 pixels = pixelRow;
200 } else {
201 var pixels = new Uint8Array(numPixels * 4);
202 for (var jj = 0; jj < smallDim; ++jj) {
203 var off = jj * largeDim * 4;
204 pixels.set(pixelRow, off);
205 }
206 }
207
208 var targets = opt_cubemap ? [
209 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
210 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
211 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
212 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
213 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
214 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z] :
215 [gl.TEXTURE_2D];
216
217 for (var ii = 0; ii < targets.length; ++ii) {
218 // debug(wtu.glEnumToString(gl, targets[ii]));
219 var index = (ii + power) % targets.length;
220 var target = targets[index];
221 if (opt_subTex) {
222 gl.texSubImage2D(
223 target, level, 0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE,
224 pixels);
225 } else {
226 gl.texImage2D(
227 target, level, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE,
228 pixels);
229 }
230 }
231 }
232
233 successfullyParsed = true;
234 </script>
235 </body>
236 </html>
237
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698