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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/texture-npot.html

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

Powered by Google App Engine
This is Rietveld 408576698