1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
5 <title>WebGL Non-Power of
2 texture conformance test.
</title>
6 <script src=
"../../../resources/js-test.js"></script>
7 <script src=
"resources/webgl-test.js"> </script>
8 <script src=
"resources/webgl-test-utils.js"> </script>
11 <canvas id=
"example" width=
"4" height=
"4" style=
"width: 40px; height: 30px;"></canvas>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
14 <script id=
"vshader" type=
"x-shader/x-vertex">
15 attribute vec4 vPosition;
16 attribute vec2 texCoord0;
17 varying vec2 texCoord;
20 gl_Position = vPosition;
25 <script id=
"fshader" type=
"x-shader/x-fragment">
27 precision mediump float;
29 uniform samplerCube tex;
30 varying vec2 texCoord;
33 gl_FragColor = textureCube(tex, normalize(vec3(texCoord,
1)));
38 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
40 var wtu
= WebGLTestUtils
;
41 var canvas
= document
.getElementById("example");
42 var gl
= wtu
.create3DContext(canvas
);
43 var program
= wtu
.setupTexturedQuad(gl
);
45 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
47 var tex
= gl
.createTexture();
49 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
50 wtu
.fillTexture(gl
, tex
, 5, 3, [0, 192, 128, 255], 1);
51 glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
52 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE");
54 // Check that an NPOT texture on level 0 succeeds
55 wtu
.fillTexture(gl
, tex
, 5, 3, [0, 192, 128, 255]);
56 glErrorShouldBe(gl
, gl
.NO_ERROR
,
57 "gl.texImage2D with NPOT texture at level 0 should succeed");
59 // Check that generateMipmap fails on NPOT
60 gl
.generateMipmap(gl
.TEXTURE_2D
);
61 glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
62 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION");
64 var loc
= gl
.getUniformLocation(program
, "tex");
67 // Check that nothing is drawn if filtering is not correct for NPOT
68 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
69 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
70 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.REPEAT
);
71 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.REPEAT
);
76 "NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255");
77 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
79 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
80 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
81 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST_MIPMAP_LINEAR
);
86 "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
87 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
89 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
93 gl
, [0, 192, 128, 255],
94 "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw.");
96 gl
.copyTexImage2D(gl
.TEXTURE_2D
, 1, gl
.RGBA
, 0, 0, 5, 3, 0);
97 glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
98 "copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.");
100 // Check that generateMipmap for an POT texture succeeds
101 wtu
.fillTexture(gl
, tex
, 4, 4, [0, 192, 128, 255]);
102 gl
.generateMipmap(gl
.TEXTURE_2D
);
103 glErrorShouldBe(gl
, gl
.NO_ERROR
,
104 "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succeed");
106 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR_MIPMAP_LINEAR
);
107 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
108 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.REPEAT
);
109 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.REPEAT
);
113 gl
, [0, 192, 128, 255],
114 "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw.");
115 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
118 debug("check using cubemap");
119 var program
= wtu
.setupProgram(
121 [wtu
.loadShaderFromScript(gl
, 'vshader', gl
.VERTEX_SHADER
),
122 wtu
.loadShaderFromScript(gl
, 'fshader', gl
.FRAGMENT_SHADER
)],
123 ['vPosition', 'texCoord0'], [0, 1]);
124 var tex
= gl
.createTexture();
126 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
127 fillCubeTexture(gl
, tex
, 5, 3, [0, 192, 128, 255], 1);
128 glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
129 "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE");
131 // Check that an NPOT texture on level 0 succeeds
132 fillCubeTexture(gl
, tex
, 5, 5, [0, 192, 128, 255]);
133 glErrorShouldBe(gl
, gl
.NO_ERROR
,
134 "gl.texImage2D with NPOT texture at level 0 should succeed");
136 // Check that generateMipmap fails on NPOT
137 gl
.generateMipmap(gl
.TEXTURE_CUBE_MAP
);
138 glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
139 "gl.generateMipmap with NPOT texture should return INVALID_OPERATION");
141 var loc
= gl
.getUniformLocation(program
, "tex");
142 gl
.uniform1i(loc
, 0);
144 // Check that nothing is drawn if filtering is not correct for NPOT
145 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
146 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
147 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_S
, gl
.REPEAT
);
148 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_T
, gl
.REPEAT
);
153 "NPOT cubemap with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255");
154 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
156 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
157 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
158 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST_MIPMAP_LINEAR
);
163 "NPOT cubemap with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
164 glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
166 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
170 gl
, [0, 192, 128, 255],
171 "NPOT cubemap with TEXTURE_MIN_FILTER set to LINEAR should draw.");
173 // Check that an POT texture on level 0 succeeds
174 fillCubeTexture(gl
, tex
, 4, 4, [0, 192, 128, 255]);
175 glErrorShouldBe(gl
, gl
.NO_ERROR
,
176 "gl.texImage2D with POT texture at level 0 should succeed");
178 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR_MIPMAP_LINEAR
);
179 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
180 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_S
, gl
.REPEAT
);
181 gl
.texParameteri(gl
.TEXTURE_CUBE_MAP
, gl
.TEXTURE_WRAP_T
, gl
.REPEAT
);
186 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR but no mips draw with 0,0,0,255");
188 // Check that generateMipmap succeeds on POT
189 gl
.generateMipmap(gl
.TEXTURE_CUBE_MAP
);
190 glErrorShouldBe(gl
, gl
.NO_ERROR
,
191 "gl.generateMipmap with POT texture should return succeed");
195 gl
, [0, 192, 128, 255],
196 "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw.");
198 function fillCubeTexture(gl
, tex
, width
, height
, color
, opt_level
) {
199 opt_level
= opt_level
|| 0;
200 var canvas
= document
.createElement('canvas');
201 canvas
.width
= width
;
202 canvas
.height
= height
;
203 var ctx2d
= canvas
.getContext('2d');
204 ctx2d
.fillStyle
= "rgba(" + color
[0] + "," + color
[1] + "," + color
[2] + "," + color
[3] + ")";
205 ctx2d
.fillRect(0, 0, width
, height
);
206 gl
.bindTexture(gl
.TEXTURE_CUBE_MAP
, tex
);
208 gl
.TEXTURE_CUBE_MAP_POSITIVE_X
,
209 gl
.TEXTURE_CUBE_MAP_NEGATIVE_X
,
210 gl
.TEXTURE_CUBE_MAP_POSITIVE_Y
,
211 gl
.TEXTURE_CUBE_MAP_NEGATIVE_Y
,
212 gl
.TEXTURE_CUBE_MAP_POSITIVE_Z
,
213 gl
.TEXTURE_CUBE_MAP_NEGATIVE_Z
];
214 for (var tt
= 0; tt
< targets
.length
; ++tt
) {
216 targets
[tt
], opt_level
, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas
);