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

Side by Side Diff: conformance/textures/texture-size.html

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 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
+ LF
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>WebGL texture size conformance test.</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../resources/js-test-pre.js"></script>
13 <script src="../resources/webgl-test.js"> </script>
14 <script src="../resources/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <canvas id="example" width="256" height="256" style="width: 40px; height: 40px;" ></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script id="vshader" type="x-shader/x-vertex">
21 attribute vec4 vPosition;
22 attribute vec3 texCoord0;
23 varying vec3 texCoord;
24 void main()
25 {
26 gl_Position = vPosition;
27 texCoord = texCoord0;
28 }
29 </script>
30
31 <script id="fshader" type="x-shader/x-fragment">
32 precision mediump float;
33 uniform samplerCube tex;
34 varying vec3 texCoord;
35 void main()
36 {
37 gl_FragColor = textureCube(tex, normalize(texCoord));
38 }
39 </script>
40 <script>
41 description("Checks that various sizes of textures render")
42 var canvas;
43
44 var wtu = WebGLTestUtils;
45 canvas = document.getElementById("example");
46 gl = wtu.create3DContext(canvas);
47 var program2D = wtu.setupTexturedQuad(gl);
48 var programCubeMap = wtu.setupProgram(
49 gl,
50 [wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER),
51 wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER)],
52 ['vPosition', 'texCoord0'], [0, 1]);
53 gl.disable(gl.DEPTH_TEST);
54 gl.disable(gl.BLEND);
55 var tex = gl.createTexture();
56 var max2DSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
57 var maxCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
58 debug("MAX_TEXTURE_SIZE:" + max2DSize);
59 debug("MAX_CUBE_MAP_TEXTURE_SIZE:" + maxCubeMapSize);
60 // Assuming 2048x2048xRGBA (22meg with mips) will run on all WebGL platforms
61 var max2DSquareSize = Math.min(max2DSize, 2048);
62 // I'd prefer this to be 2048 but that's 16meg x 6 faces or 128meg (with mips)
63 // 1024 is 33.5 meg (with mips)
64 var maxCubeMapSize = Math.min(maxCubeMapSize, 1024);
65
66 var colors = [
67 { name: "green", rgba: [0, 0, 255, 255] },
68 { name: "red", rgba: [255, 0, 0, 255] },
69 { name: "blue", rgba: [0, 255, 0, 255] },
70 { name: "yellow", rgba: [255, 255, 0, 255] },
71 { name: "magenta", rgba: [255, 0, 255, 255] },
72 { name: "cyan", rgba: [0, 255, 255, 255] }
73 ];
74
75 var count = 0;
76 var power = 0;
77 runTest();
78
79 function runTest() {
80 function doTest() {
81 var size = Math.pow(2, power);
82 if (size > max2DSize) {
83 return false;
84 }
85 gl.useProgram(program2D);
86 if (!checkTexture(size, 1, false)) return false;
87 if (!checkTexture(1, size, false)) return false;
88 if (size <= max2DSquareSize) {
89 if (!checkTexture(size, size, false)) {
90 return false;
91 }
92 }
93 if (size <= maxCubeMapSize) {
94 gl.useProgram(programCubeMap);
95 if (!checkTexture(size, size, true)) {
96 return false;
97 }
98 }
99 return true;
100 }
101
102 if (doTest()) {
103 ++power;
104 setTimeout(runTest, 100);
105 } else {
106 finishTest();
107 }
108 }
109
110 function checkTexture(width, height, cubeMap) {
111 count = (count + 1) % colors.length;
112 var color = colors[count];
113 var tex = gl.createTexture();
114 var target = cubeMap ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
115 var type = cubeMap ? "cube map" : "2D texture";
116 gl.bindTexture(target, tex);
117 gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
118 gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
119 gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
120 fillLevel(0, width, height, color.rgba, cubeMap);
121 var err = gl.getError();
122 if (err == gl.OUT_OF_MEMORY) {
123 return false;
124 }
125 if (err != gl.NO_ERROR) {
126 testFailed("unexpected gl error: " + wtu.glEnumToString(gl, err));
127 }
128 wtu.drawQuad(gl);
129 wtu.checkCanvas(gl, color.rgba,
130 type + " of size " + width + "x" + height + " with no mips should draw wit h " + color.name);
131 count = (count + 1) % colors.length;
132 color = colors[count];
133 fillLevel(0, width, height, color.rgba, cubeMap);
134 gl.generateMipmap(target);
135 var err = gl.getError();
136 if (err == gl.OUT_OF_MEMORY) {
137 return false;
138 }
139 if (err != gl.NO_ERROR) {
140 testFailed("unexpected gl error: " + wtu.glEnumToString(gl, err));
141 }
142 gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
143 wtu.drawQuad(gl);
144 wtu.checkCanvas(gl, color.rgba,
145 type + " of size " + width + "x" + height + " with mips should draw with " + color.name);
146 gl.deleteTexture(tex);
147 return true;
148 }
149
150 function fillLevel(level, width, height, color, opt_cubemap) {
151 var numPixels = width * height;
152 var pixels = new Uint8Array(numPixels * 4);
153 for (var jj = 0; jj < numPixels; ++jj) {
154 var off = jj * 4;
155 pixels[off + 0] = color[0];
156 pixels[off + 1] = color[1];
157 pixels[off + 2] = color[2];
158 pixels[off + 3] = color[3];
159 }
160 var targets = opt_cubemap ? [
161 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
162 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
163 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
164 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
165 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
166 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z] :
167 [gl.TEXTURE_2D];
168
169 for (var ii = 0; ii < targets.length; ++ii) {
170 // debug(wtu.glEnumToString(gl, targets[ii]));
171 gl.texImage2D(
172 targets[ii], level, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE ,
173 pixels);
174 }
175 }
176
177 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
178
179 successfullyParsed = true;
180 </script>
181 </body>
182 </html>
183
OLDNEW
« no previous file with comments | « conformance/textures/texture-npot-video.html ('k') | conformance/textures/texture-size-cube-maps.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698