3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
5 <script src=
"resources/webgl-test-utils.js"></script>
8 <div id=
"description"></div>
9 <div id=
"console"></div>
13 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
15 var wtu
= WebGLTestUtils
;
20 function enumToString(value
) {
21 return wtu
.glEnumToString(gl
, value
);
24 function testTexImage2D(testCase
)
30 " internalFormat: " + enumToString(testCase
.internalFormat
) +
31 " target: " + enumToString(testCase
.target
) +
32 " format: " + enumToString(testCase
.format
) +
33 " type: " + enumToString(testCase
.type
) +
34 " border: " + testCase
.border
;
36 gl
.texImage2D(testCase
.target
, level
, testCase
.internalFormat
, width
, height
, testCase
.border
, testCase
.format
, testCase
.type
, null);
37 error
= testCase
.expectedError
;
38 glErrorShouldBe(gl
, error
, msg
);
41 function testTexSubImage2D(testCase
)
49 " format: " + enumToString(testCase
.format
) +
50 " type: " + enumToString(testCase
.type
);
51 var array
= new Uint8Array(width
* height
* 4);
52 gl
.texSubImage2D(testCase
.target
, level
, xoffset
, yoffset
, width
, height
, testCase
.format
, testCase
.type
, array
);
53 error
= testCase
.expectedError
;
54 glErrorShouldBe(gl
, error
, msg
);
57 function testTexParameter(testCase
)
59 var msg
= "paramName: " + enumToString(testCase
.pname
);
60 error
= testCase
.expectedError
;
61 gl
.texParameteri(testCase
.target
, testCase
.pname
, testCase
.param
);
62 glErrorShouldBe(gl
, error
, msg
);
63 gl
.texParameterf(testCase
.target
, testCase
.pname
, testCase
.param
);
64 glErrorShouldBe(gl
, error
, msg
);
67 function testGetTexParameter(testCase
)
69 var msg
= "paramName: " + enumToString(testCase
.pname
);
70 error
= testCase
.expectedError
;
71 gl
.getTexParameter(testCase
.target
, testCase
.pname
);
72 glErrorShouldBe(gl
, error
, msg
);
75 function testCopyTexImage2D(testCase
)
84 " colorBufferFormat: " + enumToString(testCase
.colorBufferFormat
) +
85 " internalFormat: " + enumToString(testCase
.internalFormat
) +
86 " target: " + enumToString(testCase
.target
) +
87 " border: " + testCase
.border
;
89 gl
.renderbufferStorage(gl
.RENDERBUFFER
, testCase
.colorBufferFormat
, width
, height
);
90 glErrorShouldBe(gl
, gl
.NO_ERROR
);
91 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
93 gl
.copyTexImage2D(testCase
.target
, level
, testCase
.internalFormat
, x
, y
, width
, height
, testCase
.border
);
94 error
= testCase
.expectedError
;
95 glErrorShouldBe(gl
, error
, msg
);
98 function testCopyTexSubImage2D(testCase
)
108 var type
= gl
.UNSIGNED_BYTE
;
110 " colorBufferFormat: " + enumToString(testCase
.colorBufferFormat
) +
111 " internalFormat: " + enumToString(testCase
.internalFormat
) +
112 " target: " + enumToString(testCase
.target
);
114 gl
.renderbufferStorage(gl
.RENDERBUFFER
, testCase
.colorBufferFormat
, width
, height
);
115 glErrorShouldBe(gl
, gl
.NO_ERROR
);
116 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
118 gl
.texImage2D(testCase
.target
, level
, testCase
.internalFormat
, xoffset
+ width
, yoffset
+ height
, border
, testCase
.internalFormat
, type
, null);
119 glErrorShouldBe(gl
, gl
.NO_ERROR
);
121 gl
.copyTexSubImage2D(testCase
.target
, level
, xoffset
, yoffset
, x
, y
, width
, height
);
122 error
= testCase
.expectedError
;
123 glErrorShouldBe(gl
, error
, msg
);
126 function testCopyFromInternalFBO(testCase
)
128 var target
= gl
.TEXTURE_2D
;
137 var type
= gl
.UNSIGNED_BYTE
;
139 " colorBufferFormat: " + enumToString(testCase
.contextAlpha
? gl
.RGBA
: gl
.RGB
) +
140 " internalFormat: " + enumToString(testCase
.internalFormat
);
142 if (testCase
.contextAlpha
)
143 gl
= create3DContext(null, { alpha
: true });
145 gl
= create3DContext(null, { alpha
: false });
146 shouldBeNonNull("gl");
147 shouldBeNonNull("tex = gl.createTexture()");
148 gl
.bindTexture(target
, tex
);
149 if (testCase
.subImage
) {
150 gl
.texImage2D(target
, level
, testCase
.internalFormat
, xoffset
+ width
, yoffset
+ height
, border
, testCase
.internalFormat
, type
, null);
151 glErrorShouldBe(gl
, gl
.NO_ERROR
);
152 gl
.copyTexSubImage2D(target
, level
, xoffset
, yoffset
, x
, y
, width
, height
);
154 glErrorShouldBe(gl
, gl
.NO_ERROR
);
155 gl
.copyTexImage2D(target
, level
, testCase
.internalFormat
, x
, y
, width
, height
, border
);
157 error
= testCase
.expectedError
;
158 glErrorShouldBe(gl
, error
, msg
);
161 description("Validate tex functions input parameters");
163 shouldBeNonNull("gl = create3DContext()");
164 shouldBeNonNull("tex = gl.createTexture()");
165 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
166 glErrorShouldBe(gl
, gl
.NO_ERROR
);
169 debug("Checking TexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
172 [ {target
: 0x8064, // GL_PROXY_TEXTURE_2D
173 internalFormat
: gl
.RGBA
,
176 type
: gl
.UNSIGNED_BYTE
,
177 expectedError
: gl
.INVALID_ENUM
},
178 {target
: gl
.TEXTURE_2D
,
179 internalFormat
: 0x1903, // GL_RED
181 format
: 0x1903, // GL_RED
182 type
: gl
.UNSIGNED_BYTE
,
183 expectedError
: gl
.INVALID_ENUM
},
184 {target
: gl
.TEXTURE_2D
,
185 internalFormat
: gl
.RGBA
,
188 type
: gl
.UNSIGNED_BYTE
,
189 expectedError
: gl
.INVALID_VALUE
},
190 {target
: gl
.TEXTURE_2D
,
191 internalFormat
: gl
.RGBA
,
194 type
: gl
.UNSIGNED_BYTE
,
195 expectedError
: gl
.INVALID_OPERATION
},
196 {target
: gl
.TEXTURE_2D
,
197 internalFormat
: gl
.RGBA
,
201 expectedError
: gl
.INVALID_ENUM
},
202 {target
: gl
.TEXTURE_2D
,
203 internalFormat
: gl
.RGBA
,
206 type
: gl
.UNSIGNED_BYTE
,
207 expectedError
: gl
.NO_ERROR
} ];
209 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
210 testTexImage2D(testCases
[ii
]);
213 debug("Checking TexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
216 [ {target
: gl
.TEXTURE_2D
,
217 format
: 0x1903, // GL_RED
218 type
: gl
.UNSIGNED_BYTE
,
219 expectedError
: gl
.INVALID_ENUM
},
220 {target
: gl
.TEXTURE_2D
,
223 expectedError
: gl
.INVALID_ENUM
},
224 {target
: gl
.TEXTURE_2D
,
226 type
: gl
.UNSIGNED_BYTE
,
227 expectedError
: gl
.NO_ERROR
} ];
229 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
230 testTexSubImage2D(testCases
[ii
]);
233 debug("Checking TexParameter: a set of inputs that are valid in GL but invalid in GLES2");
236 [ {target
: 0x0DE0, // GL_TEXTURE_1D
237 pname
: gl
.TEXTURE_WRAP_T
,
239 expectedError
: gl
.INVALID_ENUM
},
240 {target
: gl
.TEXTURE_2D
,
241 pname
: 0x813A, // GL_TEXTURE_MIN_LOD
243 expectedError
: gl
.INVALID_ENUM
},
244 {target
: gl
.TEXTURE_2D
,
245 pname
: gl
.TEXTURE_WRAP_T
,
246 param
: 0x2900, // GL_CLAMP
247 expectedError
: gl
.INVALID_ENUM
},
248 {target
: gl
.TEXTURE_2D
,
249 pname
: gl
.TEXTURE_WRAP_T
,
251 expectedError
: gl
.NO_ERROR
} ];
253 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
254 testTexParameter(testCases
[ii
]);
257 debug("Checking GetTexParameter: a set of inputs that are valid in GL but invalid in GLES2");
260 [ {target
: 0x0DE0, // GL_TEXTURE_1D
261 pname
: gl
.TEXTURE_WRAP_T
,
262 expectedError
: gl
.INVALID_ENUM
},
263 {target
: gl
.TEXTURE_2D
,
264 pname
: 0x813A, // GL_TEXTURE_MIN_LOD
265 expectedError
: gl
.INVALID_ENUM
},
266 {target
: gl
.TEXTURE_2D
,
267 pname
: gl
.TEXTURE_WRAP_T
,
268 expectedError
: gl
.NO_ERROR
} ];
270 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
271 testGetTexParameter(testCases
[ii
]);
274 debug("Checking CopyTexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
276 var colorBuffer
= null;
279 shouldBeNonNull("fbo = gl.createFramebuffer()");
280 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
281 shouldBeNonNull("colorBuffer = gl.createRenderbuffer()");
282 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, colorBuffer
);
283 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, colorBuffer
);
284 glErrorShouldBe(gl
, gl
.NO_ERROR
);
287 [ {target
: gl
.TEXTURE_2D
,
288 colorBufferFormat
: gl
.RGB565
,
289 internalFormat
: 0x8054, // GL_RGB16
291 expectedError
: gl
.INVALID_ENUM
},
292 {target
: gl
.TEXTURE_2D
,
293 colorBufferFormat
: gl
.RGB565
,
294 internalFormat
: gl
.RGBA
,
296 expectedError
: gl
.INVALID_VALUE
},
297 {target
: gl
.TEXTURE_2D
,
298 colorBufferFormat
: gl
.RGB565
,
299 internalFormat
: gl
.RGBA
,
301 expectedError
: gl
.INVALID_OPERATION
},
302 {target
: gl
.TEXTURE_2D
,
303 colorBufferFormat
: gl
.RGB565
,
304 internalFormat
: gl
.RGB
,
306 expectedError
: gl
.NO_ERROR
} ];
308 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
309 testCopyTexImage2D(testCases
[ii
]);
312 debug("Checking CopyTexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
315 [ {target
: gl
.TEXTURE_2D
,
316 colorBufferFormat
: gl
.RGB5_A1
,
317 internalFormat
: gl
.RGBA
,
318 expectedError
: gl
.NO_ERROR
},
319 {target
: gl
.TEXTURE_2D
,
320 colorBufferFormat
: gl
.RGB565
,
321 internalFormat
: gl
.RGBA
,
322 expectedError
: gl
.INVALID_OPERATION
} ];
324 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
325 testCopyTexSubImage2D(testCases
[ii
]);
328 debug("Checking CopyTex{Sub}Image2D: copy from WebGL internal framebuffer");
331 [ {contextAlpha
: true,
332 internalFormat
: gl
.RGBA
,
334 expectedError
: gl
.NO_ERROR
},
335 {contextAlpha
: false,
336 internalFormat
: gl
.RGBA
,
338 expectedError
: gl
.INVALID_OPERATION
},
340 internalFormat
: gl
.RGBA
,
342 expectedError
: gl
.NO_ERROR
},
343 {contextAlpha
: false,
344 internalFormat
: gl
.RGBA
,
346 expectedError
: gl
.INVALID_OPERATION
} ];
348 for (var ii
= 0; ii
< testCases
.length
; ++ii
)
349 testCopyFromInternalFBO(testCases
[ii
]);