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