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 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
11 <title>WebGL Texture Format Conformance Tests</title> | |
12 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri
pt> | |
14 <script src="../../debug/webgl-debug.js" type="text/javascript"></script> | |
15 <script src="../resources/js-test-pre.js"></script> | |
16 <script src="resources/webgl-test.js"></script> | |
17 <script src="resources/webgl-test-utils.js"></script> | |
18 </head> | |
19 <body> | |
20 <div id="description"></div> | |
21 <div id="console"></div> | |
22 <canvas id="canvas2d" width="2" height="2" style="width: 50px; height: 50px; bor
der: 1px solid black;"></canvas> | |
23 <canvas id="canvas" width="2" height="2" style="width: 100px; height:100px; bord
er: 1px solid black;"> </canvas> | |
24 <script> | |
25 description("This test ensures WebGL implementations allow the OpenGL ES 2.0 tex
ture formats and do not allow DesktopGL texture formats."); | |
26 | |
27 debug(""); | |
28 debug("Canvas.getContext"); | |
29 | |
30 var wtu = WebGLTestUtils; | |
31 var gl = wtu.create3DContext(document.getElementById("canvas")); | |
32 if (!gl) { | |
33 testFailed("context does not exist"); | |
34 } else { | |
35 testPassed("context exists"); | |
36 if ("WebGLDebugUtils" in window) | |
37 WebGLDebugUtils.init(gl); | |
38 else | |
39 WebGLDebugUtils = false; | |
40 | |
41 debug(""); | |
42 debug("Checking texture formats."); | |
43 | |
44 function createTexture(internalFormat, format, opt_border) { | |
45 var border = (opt_border === undefined) ? 0 : opt_border; | |
46 var tex = gl.createTexture(); | |
47 gl.bindTexture(gl.TEXTURE_2D, tex); | |
48 gl.texImage2D(gl.TEXTURE_2D, | |
49 0, // level | |
50 internalFormat, // internalFormat | |
51 16, // width | |
52 16, // height | |
53 border, // border | |
54 format, // format | |
55 gl.UNSIGNED_BYTE, // type | |
56 null); // data | |
57 } | |
58 | |
59 function testValidFormat(internalFormat, formatName) { | |
60 createTexture(internalFormat, internalFormat); | |
61 glErrorShouldBe(gl, gl.NO_ERROR, | |
62 "was able to create texture of " + formatName); | |
63 } | |
64 | |
65 function testInvalidFormat(internalFormat, formatName) { | |
66 createTexture(internalFormat, internalFormat); | |
67 var err = gl.getError(); | |
68 if (err == gl.NO_ERROR) { | |
69 testFailed("should NOT be able to create texture of type " + formatNam
e); | |
70 } else if (err == gl.INVALID_OPERATION) { | |
71 testFailed("should return gl.INVALID_ENUM for type " + formatName); | |
72 } else if (err == gl.INVALID_ENUM) { | |
73 testPassed("not able to create invalid format: " + formatName); | |
74 } | |
75 } | |
76 | |
77 var invalidEnums = [ | |
78 '1', | |
79 '2', | |
80 '3', | |
81 '4', | |
82 'RGB4', | |
83 'RGB5', | |
84 'RGB8', | |
85 'RGB10', | |
86 'RGB12', | |
87 'RGB16', | |
88 'RGBA2', | |
89 'RGBA4', | |
90 'RGB5_A1', | |
91 'RGBA8', | |
92 'RGB10_A2', | |
93 'RGBA12', | |
94 'RGBA16', | |
95 'BGR', | |
96 'BGRA', | |
97 'ALPHA4_EXT', | |
98 'ALPHA8_EXT', | |
99 'ALPHA12_EXT', | |
100 'ALPHA16_EXT', | |
101 'COMPRESSED_ALPHA', | |
102 'COMPRESSED_LUMINANCE', | |
103 'COMPRESSED_LUMINANCE_ALPHA', | |
104 'COMPRESSED_INTENSITY', | |
105 'COMPRESSED_RGB', | |
106 'COMPRESSED_RGBA', | |
107 'DEPTH_COMPONENT16', | |
108 'DEPTH_COMPONENT24', | |
109 'DEPTH_COMPONENT32', | |
110 'LUMINANCE4_EXT', | |
111 'LUMINANCE8_EXT', | |
112 'LUMINANCE12_EXT', | |
113 'LUMINANCE16_EXT', | |
114 'LUMINANCE4_ALPHA4_EXT', | |
115 'LUMINANCE6_ALPHA2_EXT', | |
116 'LUMINANCE8_ALPHA8_EXT', | |
117 'LUMINANCE12_ALPHA4_EXT', | |
118 'LUMINANCE12_ALPHA12_EXT', | |
119 'LUMINANCE16_ALPHA16_EXT', | |
120 'INTENSITY_EXT', | |
121 'INTENSITY4_EXT', | |
122 'INTENSITY8_EXT', | |
123 'INTENSITY12_EXT', | |
124 'INTENSITY16_EXT', | |
125 'RGB4_EXT', | |
126 'RGB5_EXT', | |
127 'RGB8_EXT', | |
128 'RGB10_EXT', | |
129 'RGB12_EXT', | |
130 'RGB16_EXT', | |
131 'RGBA2_EXT', | |
132 'RGBA4_EXT', | |
133 'RGB5_A1_EXT', | |
134 'RGBA8_EXT', | |
135 'RGB10_A2_EXT', | |
136 'RGBA12_EXT', | |
137 'RGBA16_EXT', | |
138 'SLUMINANCE_EXT', | |
139 'SLUMINANCE8_EXT', | |
140 'SLUMINANCE_ALPHA_EXT', | |
141 'SLUMINANCE8_ALPHA8_EXT', | |
142 'SRGB_EXT', | |
143 'SRGB8_EXT', | |
144 'SRGB_ALPHA_EXT', | |
145 'SRGB8_ALPHA8' | |
146 ]; | |
147 | |
148 for (var ii = 0; ii < invalidEnums.length; ++ii) { | |
149 var formatName = invalidEnums[ii] | |
150 if (desktopGL[formatName] === undefined) { | |
151 debug("bad format" + formatName) | |
152 } else { | |
153 testInvalidFormat(desktopGL[formatName], "GL_" + formatName); | |
154 } | |
155 } | |
156 | |
157 var validEnums = [ | |
158 'ALPHA', | |
159 'RGB', | |
160 'RGBA', | |
161 'LUMINANCE', | |
162 'LUMINANCE_ALPHA' | |
163 ]; | |
164 | |
165 for (var ii = 0; ii < validEnums.length; ++ii) { | |
166 var formatName = validEnums[ii] | |
167 testValidFormat(gl[formatName], "gl." + formatName); | |
168 } | |
169 | |
170 debug(""); | |
171 debug("checking non 0 border parameter to gl.TexImage2D"); | |
172 createTexture(gl['RGBA'], gl['RGBA'], 1); | |
173 glErrorShouldBe(gl, gl.INVALID_VALUE, | |
174 "non 0 border to gl.TexImage2D should return INVALID_VALUE"); | |
175 | |
176 | |
177 function checkTypes() { | |
178 var canvas = document.getElementById("canvas"); | |
179 gl = wtu.create3DContext(canvas); | |
180 var program = wtu.setupTexturedQuad(gl); | |
181 | |
182 gl.disable(gl.DEPTH_TEST); | |
183 gl.disable(gl.BLEND); | |
184 | |
185 var tex = gl.createTexture(); | |
186 gl.bindTexture(gl.TEXTURE_2D, tex); | |
187 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
188 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
189 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); | |
190 | |
191 var loc = gl.getUniformLocation(program, "tex"); | |
192 gl.uniform1i(loc, 0); | |
193 | |
194 function checkType(r, g, b, a, type, format, buf) { | |
195 var typeName = WebGLDebugUtils ? WebGLDebugUtils.glEnumToString(type) : ty
pe; | |
196 debug(""); | |
197 debug("checking gl.texImage2D with type: " + typeName); | |
198 gl.texImage2D(gl.TEXTURE_2D, | |
199 0, // level | |
200 format, // internalFormat | |
201 2, // width | |
202 2, // height | |
203 0, // border | |
204 format, // format | |
205 type, // type | |
206 buf); // data | |
207 | |
208 glErrorShouldBe(gl, gl.NO_ERROR, | |
209 "gl.texImage2D with " + typeName + " should generate NO_ERROR"); | |
210 | |
211 wtu.drawQuad(gl, [255, 0, 0, 255]); | |
212 wtu.checkCanvas(gl, [r,g,b,a], | |
213 "texture type " + typeName + " should draw with " + | |
214 r + ", " + g + ", " + b + ", " + a); | |
215 | |
216 } | |
217 checkType(0, 255, 0, 255, gl.UNSIGNED_BYTE, gl.RGBA, | |
218 new Uint8Array([ | |
219 0, 255, 0, 255, | |
220 0, 255, 0, 255, | |
221 0, 255, 0, 255, | |
222 0, 255, 0, 255])); | |
223 checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_4_4_4_4, gl.RGBA, | |
224 new Uint16Array([ | |
225 255, 255, | |
226 255, 255, | |
227 255, 255, | |
228 255, 255])); | |
229 checkType(0, 255, 0, 255, gl.UNSIGNED_SHORT_5_6_5, gl.RGB, | |
230 new Uint16Array([ | |
231 2016, 2016, | |
232 2016, 2016, | |
233 2016, 2016, | |
234 2016, 2016])); | |
235 checkType(0, 0, 255, 255, gl.UNSIGNED_SHORT_5_5_5_1, gl.RGBA, | |
236 new Uint16Array([ | |
237 63, 63, | |
238 63, 63, | |
239 63, 63, | |
240 63, 63])); | |
241 } | |
242 checkTypes(); | |
243 } | |
244 | |
245 debug(""); | |
246 successfullyParsed = true; | |
247 | |
248 </script> | |
249 <script src="../resources/js-test-post.js"></script> | |
250 | |
251 <script> | |
252 </script> | |
253 | |
254 </body> | |
255 </html> | |
OLD | NEW |