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

Side by Side Diff: conformance/textures/texture-npot.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
« no previous file with comments | « conformance/textures/texture-mips.html ('k') | conformance/textures/texture-npot-video.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Non-Power of 2 texture 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="4" height="4" style="width: 40px; height: 30px;"></c anvas>
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 vec2 texCoord0;
23 varying vec2 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 vec2 texCoord;
35 void main()
36 {
37 gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1)));
38 }
39 </script>
40 <script>
41 var wtu = WebGLTestUtils;
42 var canvas = document.getElementById("example");
43 var gl = wtu.create3DContext(canvas);
44 var program = wtu.setupTexturedQuad(gl);
45
46 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
47
48 var tex = gl.createTexture();
49
50 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
51 wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1);
52 glErrorShouldBe(gl, gl.INVALID_VALUE,
53 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE" );
54
55 // Check that an NPOT texture on level 0 succeeds
56 wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255]);
57 glErrorShouldBe(gl, gl.NO_ERROR,
58 "gl.texImage2D with NPOT texture at level 0 should succeed");
59
60 // Check that generateMipmap fails on NPOT
61 gl.generateMipmap(gl.TEXTURE_2D);
62 glErrorShouldBe(gl, gl.INVALID_OPERATION,
63 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION");
64
65 var loc = gl.getUniformLocation(program, "tex");
66 gl.uniform1i(loc, 0);
67
68 // Check that nothing is drawn if filtering is not correct for NPOT
69 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
70 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
73
74 wtu.drawQuad(gl);
75 wtu.checkCanvas(
76 gl, [0, 0, 0, 255],
77 "NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255");
78 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
79
80 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
81 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
82 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR) ;
83
84 wtu.drawQuad(gl);
85 wtu.checkCanvas(
86 gl, [0, 0, 0, 255],
87 "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
88 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
89
90 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
91
92 wtu.drawQuad(gl);
93 wtu.checkCanvas(
94 gl, [0, 192, 128, 255],
95 "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw.");
96
97 gl.copyTexImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 0, 0, 5, 3, 0);
98 glErrorShouldBe(gl, gl.INVALID_VALUE,
99 "copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE .");
100
101 // Check that generateMipmap for an POT texture succeeds
102 wtu.fillTexture(gl, tex, 4, 4, [0, 192, 128, 255]);
103 gl.generateMipmap(gl.TEXTURE_2D);
104 glErrorShouldBe(gl, gl.NO_ERROR,
105 "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succ eed");
106
107 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
108 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
109 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
110 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
111
112 wtu.drawQuad(gl);
113 wtu.checkCanvas(
114 gl, [0, 192, 128, 255],
115 "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw .");
116 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
117
118 debug("");
119 debug("check using cubemap");
120 var program = wtu.setupProgram(
121 gl,
122 [wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER),
123 wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER)],
124 ['vPosition', 'texCoord0'], [0, 1]);
125 var tex = gl.createTexture();
126
127 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
128 fillCubeTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1);
129 glErrorShouldBe(gl, gl.INVALID_VALUE,
130 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE" );
131
132 // Check that an NPOT texture on level 0 succeeds
133 fillCubeTexture(gl, tex, 5, 5, [0, 192, 128, 255]);
134 glErrorShouldBe(gl, gl.NO_ERROR,
135 "gl.texImage2D with NPOT texture at level 0 should succeed");
136
137 // Check that generateMipmap fails on NPOT
138 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
139 glErrorShouldBe(gl, gl.INVALID_OPERATION,
140 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION");
141
142 var loc = gl.getUniformLocation(program, "tex");
143 gl.uniform1i(loc, 0);
144
145 // Check that nothing is drawn if filtering is not correct for NPOT
146 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
147 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
148 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT);
149 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT);
150
151 wtu.drawQuad(gl);
152 wtu.checkCanvas(
153 gl, [0, 0, 0, 255],
154 "NPOT cubemap with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255");
155 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
156
157 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
158 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
159 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_L INEAR);
160
161 wtu.drawQuad(gl);
162 wtu.checkCanvas(
163 gl, [0, 0, 0, 255],
164 "NPOT cubemap with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
165 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
166
167 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
168
169 wtu.drawQuad(gl);
170 wtu.checkCanvas(
171 gl, [0, 192, 128, 255],
172 "NPOT cubemap with TEXTURE_MIN_FILTER set to LINEAR should draw.");
173
174 // Check that an POT texture on level 0 succeeds
175 fillCubeTexture(gl, tex, 4, 4, [0, 192, 128, 255]);
176 glErrorShouldBe(gl, gl.NO_ERROR,
177 "gl.texImage2D with POT texture at level 0 should succeed");
178
179 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LI NEAR);
180 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
181 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT);
182 gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT);
183
184 wtu.drawQuad(gl);
185 wtu.checkCanvas(
186 gl, [0, 0, 0, 255],
187 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR but no mips draw with 0,0,0,255");
188
189 // Check that generateMipmap succeeds on POT
190 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
191 glErrorShouldBe(gl, gl.NO_ERROR,
192 "gl.generateMipmap with POT texture should return succeed");
193
194 wtu.drawQuad(gl);
195 wtu.checkCanvas(
196 gl, [0, 192, 128, 255],
197 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw .");
198
199 successfullyParsed = true;
200
201 function fillCubeTexture(gl, tex, width, height, color, opt_level) {
202 opt_level = opt_level || 0;
203 var canvas = document.createElement('canvas');
204 canvas.width = width;
205 canvas.height = height;
206 var ctx2d = canvas.getContext('2d');
207 ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")";
208 ctx2d.fillRect(0, 0, width, height);
209 gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex);
210 var targets = [
211 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
212 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
213 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
214 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
215 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
216 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];
217 for (var tt = 0; tt < targets.length; ++tt) {
218 gl.texImage2D(
219 targets[tt], opt_level, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
220 }
221 };
222
223 </script>
224 <script src="../../resources/js-test-post.js"></script>
225
226 </body>
227 </html>
228
OLDNEW
« no previous file with comments | « conformance/textures/texture-mips.html ('k') | conformance/textures/texture-npot-video.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698