OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2010 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 <html> | |
7 <head> | |
8 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
9 <script src="../resources/js-test-pre.js"></script> | |
10 <script src="resources/webgl-test.js"></script> | |
11 <script src="resources/webgl-test-utils.js"></script> | |
12 </head> | |
13 <body> | |
14 <div id="description"></div> | |
15 <div id="console"></div> | |
16 | |
17 <script> | |
18 var wtu = WebGLTestUtils; | |
19 var gl = null; | |
20 var tex = null; | |
21 var error = 0; | |
22 | |
23 function enumToString(value) { | |
24 return wtu.glEnumToString(gl, value); | |
25 } | |
26 | |
27 function testTexImage2D(testCase) | |
28 { | |
29 var level = 0; | |
30 var width = 16; | |
31 var height = 16; | |
32 var msg = "" + | |
33 " internalFormat: " + enumToString(testCase.internalFormat) + | |
34 " target: " + enumToString(testCase.target) + | |
35 " format: " + enumToString(testCase.format) + | |
36 " type: " + enumToString(testCase.type) + | |
37 " border: " + testCase.border; | |
38 | |
39 gl.texImage2D(testCase.target, level, testCase.internalFormat, width, height
, testCase.border, testCase.format, testCase.type, null); | |
40 error = testCase.expectedError; | |
41 glErrorShouldBe(gl, error, msg); | |
42 } | |
43 | |
44 function testTexSubImage2D(testCase) | |
45 { | |
46 var level = 0; | |
47 var xoffset = 0; | |
48 var yoffset = 0; | |
49 var width = 16; | |
50 var height = 16; | |
51 var msg = ""+ | |
52 " format: " + enumToString(testCase.format) + | |
53 " type: " + enumToString(testCase.type); | |
54 var array = new Uint8Array(width * height * 4); | |
55 gl.texSubImage2D(testCase.target, level, xoffset, yoffset, width, height, te
stCase.format, testCase.type, array); | |
56 error = testCase.expectedError; | |
57 glErrorShouldBe(gl, error, msg); | |
58 } | |
59 | |
60 function testTexParameter(testCase) | |
61 { | |
62 var msg = "paramName: " + enumToString(testCase.pname); | |
63 error = testCase.expectedError; | |
64 gl.texParameteri(testCase.target, testCase.pname, testCase.param); | |
65 glErrorShouldBe(gl, error, msg); | |
66 gl.texParameterf(testCase.target, testCase.pname, testCase.param); | |
67 glErrorShouldBe(gl, error, msg); | |
68 } | |
69 | |
70 function testGetTexParameter(testCase) | |
71 { | |
72 var msg = "paramName: " + enumToString(testCase.pname); | |
73 error = testCase.expectedError; | |
74 gl.getTexParameter(testCase.target, testCase.pname); | |
75 glErrorShouldBe(gl, error, msg); | |
76 } | |
77 | |
78 function testCopyTexImage2D(testCase) | |
79 { | |
80 var level = 0; | |
81 var x = 0; | |
82 var y = 0; | |
83 var width = 16; | |
84 var height = 16; | |
85 | |
86 var msg = "" + | |
87 " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) + | |
88 " internalFormat: " + enumToString(testCase.internalFormat) + | |
89 " target: " + enumToString(testCase.target) + | |
90 " border: " + testCase.border; | |
91 | |
92 gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, h
eight); | |
93 glErrorShouldBe(gl, gl.NO_ERROR); | |
94 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLE
TE"); | |
95 | |
96 gl.copyTexImage2D(testCase.target, level, testCase.internalFormat, x, y, wid
th, height, testCase.border); | |
97 error = testCase.expectedError; | |
98 glErrorShouldBe(gl, error, msg); | |
99 } | |
100 | |
101 function testCopyTexSubImage2D(testCase) | |
102 { | |
103 var level = 0; | |
104 var x = 0; | |
105 var y = 0; | |
106 var width = 16; | |
107 var height = 16; | |
108 var xoffset = 0; | |
109 var yoffset = 0; | |
110 var border = 0; | |
111 var type = gl.UNSIGNED_BYTE; | |
112 var msg = "" + | |
113 " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) + | |
114 " internalFormat: " + enumToString(testCase.internalFormat) + | |
115 " target: " + enumToString(testCase.target); | |
116 | |
117 gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, h
eight); | |
118 glErrorShouldBe(gl, gl.NO_ERROR); | |
119 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLE
TE"); | |
120 | |
121 gl.texImage2D(testCase.target, level, testCase.internalFormat, xoffset + wid
th, yoffset + height, border, testCase.internalFormat, type, null); | |
122 glErrorShouldBe(gl, gl.NO_ERROR); | |
123 | |
124 gl.copyTexSubImage2D(testCase.target, level, xoffset, yoffset, x, y, width,
height); | |
125 error = testCase.expectedError; | |
126 glErrorShouldBe(gl, error, msg); | |
127 } | |
128 | |
129 function testCopyFromInternalFBO(testCase) | |
130 { | |
131 var target = gl.TEXTURE_2D; | |
132 var level = 0; | |
133 var x = 0; | |
134 var y = 0; | |
135 var width = 16; | |
136 var height = 16; | |
137 var xoffset = 0; | |
138 var yoffset = 0; | |
139 var border = 0; | |
140 var type = gl.UNSIGNED_BYTE; | |
141 var msg = "" + | |
142 " colorBufferFormat: " + enumToString(testCase.contextAlpha ? gl.RGBA : gl
.RGB) + | |
143 " internalFormat: " + enumToString(testCase.internalFormat); | |
144 | |
145 if (testCase.contextAlpha) | |
146 gl = create3DContext(null, { alpha: true }); | |
147 else | |
148 gl = create3DContext(null, { alpha: false }); | |
149 shouldBeNonNull("gl"); | |
150 shouldBeNonNull("tex = gl.createTexture()"); | |
151 gl.bindTexture(target, tex); | |
152 if (testCase.subImage) { | |
153 gl.texImage2D(target, level, testCase.internalFormat, xoffset + width, y
offset + height, border, testCase.internalFormat, type, null); | |
154 glErrorShouldBe(gl, gl.NO_ERROR); | |
155 gl.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, heigh
t); | |
156 } else { | |
157 glErrorShouldBe(gl, gl.NO_ERROR); | |
158 gl.copyTexImage2D(target, level, testCase.internalFormat, x, y, width, h
eight, border); | |
159 } | |
160 error = testCase.expectedError; | |
161 glErrorShouldBe(gl, error, msg); | |
162 } | |
163 | |
164 description("Validate tex functions input parameters"); | |
165 | |
166 shouldBeNonNull("gl = create3DContext()"); | |
167 shouldBeNonNull("tex = gl.createTexture()"); | |
168 gl.bindTexture(gl.TEXTURE_2D, tex); | |
169 glErrorShouldBe(gl, gl.NO_ERROR); | |
170 | |
171 debug(""); | |
172 debug("Checking TexImage2D: a set of inputs that are valid in GL but invalid in
GLES2"); | |
173 | |
174 var testCases = | |
175 [ {target: 0x8064, // GL_PROXY_TEXTURE_2D | |
176 internalFormat: gl.RGBA, | |
177 border: 0, | |
178 format: gl.RGBA, | |
179 type: gl.UNSIGNED_BYTE, | |
180 expectedError: gl.INVALID_ENUM}, | |
181 {target: gl.TEXTURE_2D, | |
182 internalFormat: 0x1903, // GL_RED | |
183 border: 0, | |
184 format: 0x1903, // GL_RED | |
185 type: gl.UNSIGNED_BYTE, | |
186 expectedError: gl.INVALID_ENUM}, | |
187 {target: gl.TEXTURE_2D, | |
188 internalFormat: gl.RGBA, | |
189 border: 1, | |
190 format: gl.RGBA, | |
191 type: gl.UNSIGNED_BYTE, | |
192 expectedError: gl.INVALID_VALUE}, | |
193 {target: gl.TEXTURE_2D, | |
194 internalFormat: gl.RGBA, | |
195 border: 0, | |
196 format: gl.RGB, | |
197 type: gl.UNSIGNED_BYTE, | |
198 expectedError: gl.INVALID_OPERATION}, | |
199 {target: gl.TEXTURE_2D, | |
200 internalFormat: gl.RGBA, | |
201 border: 0, | |
202 format: gl.RGBA, | |
203 type: gl.BYTE, | |
204 expectedError: gl.INVALID_ENUM}, | |
205 {target: gl.TEXTURE_2D, | |
206 internalFormat: gl.RGBA, | |
207 border: 0, | |
208 format: gl.RGBA, | |
209 type: gl.UNSIGNED_BYTE, | |
210 expectedError: gl.NO_ERROR} ]; | |
211 | |
212 for (var ii = 0; ii < testCases.length; ++ii) | |
213 testTexImage2D(testCases[ii]); | |
214 | |
215 debug(""); | |
216 debug("Checking TexSubImage2D: a set of inputs that are valid in GL but invalid
in GLES2"); | |
217 | |
218 testCases = | |
219 [ {target: gl.TEXTURE_2D, | |
220 format: 0x1903, // GL_RED | |
221 type: gl.UNSIGNED_BYTE, | |
222 expectedError: gl.INVALID_ENUM}, | |
223 {target: gl.TEXTURE_2D, | |
224 format: gl.RGBA, | |
225 type: gl.BYTE, | |
226 expectedError: gl.INVALID_ENUM}, | |
227 {target: gl.TEXTURE_2D, | |
228 format: gl.RGBA, | |
229 type: gl.UNSIGNED_BYTE, | |
230 expectedError: gl.NO_ERROR} ]; | |
231 | |
232 for (var ii = 0; ii < testCases.length; ++ii) | |
233 testTexSubImage2D(testCases[ii]); | |
234 | |
235 debug(""); | |
236 debug("Checking TexParameter: a set of inputs that are valid in GL but invalid i
n GLES2"); | |
237 | |
238 testCases = | |
239 [ {target: 0x0DE0, // GL_TEXTURE_1D | |
240 pname: gl.TEXTURE_WRAP_T, | |
241 param: gl.REPEAT, | |
242 expectedError: gl.INVALID_ENUM}, | |
243 {target: gl.TEXTURE_2D, | |
244 pname: 0x813A, // GL_TEXTURE_MIN_LOD | |
245 param: 0, | |
246 expectedError: gl.INVALID_ENUM}, | |
247 {target: gl.TEXTURE_2D, | |
248 pname: gl.TEXTURE_WRAP_T, | |
249 param: 0x2900, // GL_CLAMP | |
250 expectedError: gl.INVALID_ENUM}, | |
251 {target: gl.TEXTURE_2D, | |
252 pname: gl.TEXTURE_WRAP_T, | |
253 param: gl.REPEAT, | |
254 expectedError: gl.NO_ERROR} ]; | |
255 | |
256 for (var ii = 0; ii < testCases.length; ++ii) | |
257 testTexParameter(testCases[ii]); | |
258 | |
259 debug(""); | |
260 debug("Checking GetTexParameter: a set of inputs that are valid in GL but invali
d in GLES2"); | |
261 | |
262 testCases = | |
263 [ {target: 0x0DE0, // GL_TEXTURE_1D | |
264 pname: gl.TEXTURE_WRAP_T, | |
265 expectedError: gl.INVALID_ENUM}, | |
266 {target: gl.TEXTURE_2D, | |
267 pname: 0x813A, // GL_TEXTURE_MIN_LOD | |
268 expectedError: gl.INVALID_ENUM}, | |
269 {target: gl.TEXTURE_2D, | |
270 pname: gl.TEXTURE_WRAP_T, | |
271 expectedError: gl.NO_ERROR} ]; | |
272 | |
273 for (var ii = 0; ii < testCases.length; ++ii) | |
274 testGetTexParameter(testCases[ii]); | |
275 | |
276 debug(""); | |
277 debug("Checking CopyTexImage2D: a set of inputs that are valid in GL but invalid
in GLES2"); | |
278 | |
279 var colorBuffer = null; | |
280 var fbo = null; | |
281 | |
282 shouldBeNonNull("fbo = gl.createFramebuffer()"); | |
283 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); | |
284 shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); | |
285 gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); | |
286 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER
, colorBuffer); | |
287 glErrorShouldBe(gl, gl.NO_ERROR); | |
288 | |
289 testCases = | |
290 [ {target: gl.TEXTURE_2D, | |
291 colorBufferFormat: gl.RGB565, | |
292 internalFormat: 0x8054, // GL_RGB16 | |
293 border: 0, | |
294 expectedError: gl.INVALID_ENUM}, | |
295 {target: gl.TEXTURE_2D, | |
296 colorBufferFormat: gl.RGB565, | |
297 internalFormat: gl.RGBA, | |
298 border: 1, | |
299 expectedError: gl.INVALID_VALUE}, | |
300 {target: gl.TEXTURE_2D, | |
301 colorBufferFormat: gl.RGB565, | |
302 internalFormat: gl.RGBA, | |
303 border: 0, | |
304 expectedError: gl.INVALID_OPERATION}, | |
305 {target: gl.TEXTURE_2D, | |
306 colorBufferFormat: gl.RGB565, | |
307 internalFormat: gl.RGB, | |
308 border: 0, | |
309 expectedError: gl.NO_ERROR} ]; | |
310 | |
311 for (var ii = 0; ii < testCases.length; ++ii) | |
312 testCopyTexImage2D(testCases[ii]); | |
313 | |
314 debug(""); | |
315 debug("Checking CopyTexSubImage2D: a set of inputs that are valid in GL but inva
lid in GLES2"); | |
316 | |
317 testCases = | |
318 [ {target: gl.TEXTURE_2D, | |
319 colorBufferFormat: gl.RGB5_A1, | |
320 internalFormat: gl.RGBA, | |
321 expectedError: gl.NO_ERROR}, | |
322 {target: gl.TEXTURE_2D, | |
323 colorBufferFormat: gl.RGB565, | |
324 internalFormat: gl.RGBA, | |
325 expectedError: gl.INVALID_OPERATION} ]; | |
326 | |
327 for (var ii = 0; ii < testCases.length; ++ii) | |
328 testCopyTexSubImage2D(testCases[ii]); | |
329 | |
330 debug(""); | |
331 debug("Checking CopyTex{Sub}Image2D: copy from WebGL internal framebuffer"); | |
332 | |
333 testCases = | |
334 [ {contextAlpha: true, | |
335 internalFormat: gl.RGBA, | |
336 subImage: false, | |
337 expectedError: gl.NO_ERROR}, | |
338 {contextAlpha: false, | |
339 internalFormat: gl.RGBA, | |
340 subImage: false, | |
341 expectedError: gl.INVALID_OPERATION}, | |
342 {contextAlpha: true, | |
343 internalFormat: gl.RGBA, | |
344 subImage: true, | |
345 expectedError: gl.NO_ERROR}, | |
346 {contextAlpha: false, | |
347 internalFormat: gl.RGBA, | |
348 subImage: true, | |
349 expectedError: gl.INVALID_OPERATION} ]; | |
350 | |
351 for (var ii = 0; ii < testCases.length; ++ii) | |
352 testCopyFromInternalFBO(testCases[ii]); | |
353 | |
354 successfullyParsed = true; | |
355 </script> | |
356 | |
357 <script src="../resources/js-test-post.js"></script> | |
358 </body> | |
359 </html> | |
OLD | NEW |