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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/texture-mips.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 mips 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="2" height="2" style="width: 40px; height: 40px;"></c anvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script id="vshader" type="x-shader/x-vertex">
43 uniform vec4 uMult;
44 attribute vec4 vPosition;
45 attribute vec2 texCoord0;
46 varying vec2 texCoord;
47 void main()
48 {
49 gl_Position = vPosition * uMult;
50 texCoord = texCoord0;
51 }
52 </script>
53
54 <script id="fshader" type="x-shader/x-fragment">
55 precision mediump float;
56 uniform sampler2D tex;
57 varying vec2 texCoord;
58 void main()
59 {
60 gl_FragColor = texture2D(tex, texCoord);
61 }
62 </script>
63 <script>
64 var canvas;
65 var wtu = WebGLTestUtils;
66 function init()
67 {
68 if (window.initNonKhronosFramework) {
69 window.initNonKhronosFramework(false);
70 }
71
72 description("Checks mip issues");
73
74 canvas = document.getElementById("example");
75 shouldBe("canvas.width", "2");
76 shouldBe("canvas.height", "2");
77
78 gl = wtu.create3DContext(canvas);
79
80 var tex = gl.createTexture();
81 gl.bindTexture(gl.TEXTURE_2D, tex);
82 gl.generateMipmap(gl.TEXTURE_2D);
83 glErrorShouldBe(gl, gl.INVALID_OPERATION, "for generateMipmap with mip 0 is 0x 0");
84 gl.texImage2D(
85 gl.TEXTURE_2D, 1, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
86 new Uint8Array(4));
87 gl.generateMipmap(gl.TEXTURE_2D);
88 glErrorShouldBe(gl, gl.INVALID_OPERATION, "for generateMipmap with mip 0 is 0x 0");
89
90 tex = gl.createTexture();
91 gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex);
92 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
93 glErrorShouldBe(gl, gl.INVALID_OPERATION, "for generateMipmap with mip 0 is 0x 0");
94
95 var faces = [
96 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
97 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
98 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
99 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
100 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
101 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
102 ];
103 for (var ii = 0; ii < faces.length; ++ii) {
104 gl.texImage2D(
105 faces[ii], 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
106 new Uint8Array(4 * 2 * 2));
107 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
108 glErrorShouldBe(gl, ii == 5 ? gl.NO_ERROR : gl.INVALID_OPERATION, "for gener ateMipmap with " + (ii + 1) + " faces");
109 }
110
111 wtu.setupUnitQuad(gl, 0, 1);
112 var program = wtu.setupProgram(
113 gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]);
114
115 gl.disable(gl.DEPTH_TEST);
116 gl.disable(gl.BLEND);
117
118 var colors = {
119 blue: [0, 0, 255, 255],
120 red: [255, 0, 0, 255],
121 green: [0, 255, 0, 255],
122 cyan: [128, 255, 255, 255],
123 black: [0, 0, 0, 255],
124 blank: [0, 0, 0, 0]
125 };
126
127 var mips = [
128 ];
129
130 var texLoc = gl.getUniformLocation(program, "tex");
131 gl.uniform1i(texLoc, 0);
132 var multLoc = gl.getUniformLocation(program, "uMult");
133
134 // ----------------------------------------------------
135 var clearTex = createTexture();
136 gl.uniform4f(multLoc, 1, 1, 1, 1);
137 gl.bindTexture(gl.TEXTURE_2D, clearTex);
138 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
139 debug('gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNE D_BYTE, null);');
140 setMipData(0, 16, 'blank');
141 makeDivMipChain();
142 generateMipmap();
143 check('blank', "texture created with null that has all mips");
144
145 // ----------------------------------------------------
146 var tex = createTexture();
147 gl.uniform4f(multLoc, 1, 1, 1, 1);
148
149 gl.bindTexture(gl.TEXTURE_2D, tex);
150 // 16x16 texture no mips
151 fillLevel(tex, 0, 16, 'cyan');
152
153 check('black',
154 "texture that is missing mips when TEXTURE_MIN_FILTER not NEAREST or LIN EAR");
155
156 generateMipmap();
157
158 check('cyan', "texture that has all mips");
159
160 // Fill in the bottom 2 mips with a different color.
161 fillLevel(tex, 4, 1, 'green');
162 fillLevel(tex, 3, 2, 'green');
163
164 // Choose the nearest mip
165 texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
166
167 check('green', "texture that is only using the smallest 2 mips");
168
169 gl.uniform4f(multLoc, 16, 16, 1, 1);
170
171 check('cyan', "texture that is using only the largest 2 mips");
172
173 // Set the top level
174 fillLevel(tex, 0, 1, 'red');
175 check('red',
176 "texture that is only using the top level even though other levels are d efined");
177
178 // Set the top 2 levels using generateMipmap
179 fillLevel(tex, 0, 2, 'blue');
180 generateMipmap();
181
182 check('blue',
183 "texture that is only using the top 2 levels even though other levels ar e defined");
184
185 // Set the top 2 levels back to sizes that end up using levels 2, 3, and 4 aga in.
186 fillLevel(tex, 0, 16, 'blue');
187 fillLevel(tex, 1, 8, 'blue');
188 check('blue', "texture that is only using the largest 2 mips");
189 gl.uniform4f(multLoc, 1, 1, 1, 1);
190 check('green', "texture that is only using the smallest 2 mips");
191
192 // ----------------------------------------------------
193 var tex = createTexture();
194 gl.uniform4f(multLoc, 1, 1, 1, 1);
195 fillLevel(tex, 0, 8, 'cyan');
196 generateMipmap();
197 check('cyan', "texture that has 3 mips");
198
199 fillLevel(tex, 0, 16, 'blue');
200 texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
201 check('blue', "texture that is only using top mips");
202
203 fillLevel(tex, 0, 8, 'red');
204 texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
205 check('cyan', "texture that is only using smallest mips");
206
207 gl.uniform4f(multLoc, 16, 16, 1, 1);
208 check('red', "texture that is using only the largest mip");
209
210 // ----------------------------------------------------
211 var tex = createTexture();
212 gl.uniform4f(multLoc, 1, 1, 1, 1);
213 fillLevel(tex, 2, 1, 'green');
214 fillLevel(tex, 1, 2, 'green');
215 fillLevel(tex, 0, 4, 'green');
216 check('green', "texture that was built smallest mip first");
217
218 // ----------------------------------------------------
219 var tex = createTexture();
220 gl.uniform4f(multLoc, 1, 1, 1, 1);
221 fillLevel(tex, 0, 16, 'red');
222 generateMipmap();
223 check('red', "texture with 1 genmipmaps");
224 fillLevel(tex, 0, 16, 'blue');
225 generateMipmap();
226 fillLevel(tex, 0, 16, 'green');
227 generateMipmap();
228 check('green', "texture with 2 genmipmaps");
229
230 // ----------------------------------------------------
231 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
232
233 function createTexture() {
234 debug("<hr/>gl.createTexture()");
235 mips = [];
236 makeDivMipChain();
237 return gl.createTexture();
238 }
239
240 function texParameteri(target, pname, value) {
241 debug("gl.texParameteri(" +
242 wtu.glEnumToString(gl, target) + ", " +
243 wtu.glEnumToString(gl, pname) + ", " +
244 wtu.glEnumToString(gl, value) + ")")
245 gl.texParameteri(target, pname, value);
246 }
247
248 function generateMipmap() {
249 debug("gl.generateMipmap(gl.TEXTURE_2D)");
250 gl.generateMipmap(gl.TEXTURE_2D);
251 var mip0 = mips[0];
252 var size = mip0.size;
253 var level = 1;
254 for(;;) {
255 size = Math.floor(size / 2);
256 if (!size) {
257 break;
258 }
259 setMipData(level, size, mip0.color);
260 ++level;
261 }
262 makeDivMipChain();
263 }
264
265 function check(color, msg) {
266 wtu.drawQuad(gl);
267 wtu.checkCanvas(gl, colors[color], msg + " should draw with " + color);
268 }
269
270 function fillLevel(tex, level, size, color) {
271 setMipData(level, size, color);
272 debug("gl.texImage2D(gl.TEXTURE_2D, " + level + ", gl.RGBA, " + size + ", " + size +
273 ", 0, gl.RGBA, gl.UNSIGNED_BYTE, " + color + ");");
274 wtu.fillTexture(gl, tex, size, size, colors[color], level);
275 makeDivMipChain();
276 }
277
278 function setMipData(level, size, color) {
279 mips[level] = {
280 size: size,
281 color: color
282 };
283 }
284
285 function makeDivMipChain(color) {
286 var html = [
287 '<div style="height: 68px; margin-top: 5px">',
288 '<div style="float:left;">mips: </div>'];
289 for (var ii = 0; ii < 5; ++ii) {
290 var mip = mips[ii];
291 if (mip) {
292 html.push(makeDivSquare(mip.size, mip.color));
293 } else {
294 html.push(makeDivSquare(16, undefined));
295 }
296 }
297 html.push("</div>");
298 debug(html.join(""));
299 }
300
301 function makeDivSquare(size, color) {
302 size *= 4;
303 var c = color ? colors[color] : [255,255,255];
304 var border = color ? 'solid' : 'dashed';
305 return '<div style="float:left; width: ' + size + 'px; height: ' + size +
306 'px; background-color: ' + rgb(c) +
307 '; border: 1px ' + border + ' black; margin-right: 3px;"></div>';
308 }
309
310 function rgb(c) {
311 return 'rgb(' + c[0] + ',' + c[1] + ',' + c[2] +')';
312 }
313 }
314
315 init();
316 successfullyParsed = true;
317 </script>
318
319 <script src="../../resources/js-test-post.js"></script>
320 </body>
321 </html>
322
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698