OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 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> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <title>WebGL OES_vertex_array_object Conformance Tests</title> | |
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
12 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s
cript> | |
13 <script src="../../resources/js-test-pre.js"></script> | |
14 <script src="../resources/webgl-test.js"></script> | |
15 <script src="../resources/webgl-test-utils.js"></script> | |
16 <!-- comment in the script tag below to test through JS emualation of the extens
ion. --> | |
17 <!-- | |
18 <script src="../../../demos/google/resources/OESVertexArrayObject.js"></script> | |
19 --> | |
20 </head> | |
21 <body> | |
22 <div id="description"></div> | |
23 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> | |
24 <div id="console"></div> | |
25 <!-- Shaders for testing standard derivatives --> | |
26 | |
27 <script> | |
28 description("This test verifies the functionality of the OES_vertex_array_object
extension, if it is available."); | |
29 | |
30 debug(""); | |
31 | |
32 var wtu = WebGLTestUtils; | |
33 var canvas = document.getElementById("canvas"); | |
34 var gl = create3DContext(canvas); | |
35 var ext = null; | |
36 var vao = null; | |
37 | |
38 if (!gl) { | |
39 testFailed("WebGL context does not exist"); | |
40 } else { | |
41 testPassed("WebGL context exists"); | |
42 | |
43 // Setup emulated OESVertexArrayObject if it has been included. | |
44 if (window.setupVertexArrayObject) { | |
45 debug("using emuated OES_vertex_array_object"); | |
46 setupVertexArrayObject(gl); | |
47 } | |
48 | |
49 // Run tests with extension disabled | |
50 runBindingTestDisabled(); | |
51 | |
52 // Query the extension and store globally so shouldBe can access it | |
53 ext = gl.getExtension("OES_vertex_array_object"); | |
54 if (!ext) { | |
55 testPassed("No OES_vertex_array_object support -- this is legal"); | |
56 | |
57 runSupportedTest(false); | |
58 } else { | |
59 testPassed("Successfully enabled OES_vertex_array_object extension"); | |
60 | |
61 runSupportedTest(true); | |
62 runBindingTestEnabled(); | |
63 runObjectTest(); | |
64 runAttributeTests(); | |
65 runAttributeValueTests(); | |
66 runDrawTests(); | |
67 } | |
68 } | |
69 | |
70 function runSupportedTest(extensionEnabled) { | |
71 var supported = gl.getSupportedExtensions(); | |
72 if (supported.indexOf("OES_vertex_array_object") >= 0) { | |
73 if (extensionEnabled) { | |
74 testPassed("OES_vertex_array_object listed as supported and getExten
sion succeeded"); | |
75 } else { | |
76 testFailed("OES_vertex_array_object listed as supported but getExten
sion failed"); | |
77 } | |
78 } else { | |
79 if (extensionEnabled) { | |
80 testFailed("OES_vertex_array_object not listed as supported but getE
xtension succeeded"); | |
81 } else { | |
82 testPassed("OES_vertex_array_object not listed as supported and getE
xtension failed -- this is legal"); | |
83 } | |
84 } | |
85 } | |
86 | |
87 function runBindingTestDisabled() { | |
88 debug("Testing binding enum with extension disabled"); | |
89 | |
90 // Use the constant directly as we don't have the extension | |
91 var VERTEX_ARRAY_BINDING_OES = 0x85B5; | |
92 | |
93 gl.getParameter(VERTEX_ARRAY_BINDING_OES); | |
94 glErrorShouldBe(gl, gl.INVALID_ENUM, "VERTEX_ARRAY_BINDING_OES should not be
queryable if extension is disabled"); | |
95 } | |
96 | |
97 function runBindingTestEnabled() { | |
98 debug("Testing binding enum with extension enabled"); | |
99 | |
100 shouldBe("ext.VERTEX_ARRAY_BINDING_OES", "0x85B5"); | |
101 | |
102 gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES); | |
103 glErrorShouldBe(gl, gl.NO_ERROR, "VERTEX_ARRAY_BINDING_OES query should succ
eed if extension is enable"); | |
104 | |
105 // Default value is null | |
106 if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) === null) { | |
107 testPassed("Default value of VERTEX_ARRAY_BINDING_OES is null"); | |
108 } else { | |
109 testFailed("Default value of VERTEX_ARRAY_BINDING_OES is not null"); | |
110 } | |
111 | |
112 debug("Testing binding a VAO"); | |
113 var vao0 = ext.createVertexArrayOES(); | |
114 var vao1 = ext.createVertexArrayOES(); | |
115 shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); | |
116 ext.bindVertexArrayOES(vao0); | |
117 if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao0) { | |
118 testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VA
O"); | |
119 } else { | |
120 testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expecte
d VAO") | |
121 } | |
122 ext.bindVertexArrayOES(vao1); | |
123 if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao1) { | |
124 testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VA
O"); | |
125 } else { | |
126 testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expecte
d VAO") | |
127 } | |
128 ext.deleteVertexArrayOES(vao1); | |
129 shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); | |
130 ext.bindVertexArrayOES(vao1); | |
131 glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted vertex array ob
ject"); | |
132 ext.bindVertexArrayOES(null); | |
133 shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); | |
134 ext.deleteVertexArrayOES(vao1); | |
135 } | |
136 | |
137 function runObjectTest() { | |
138 debug("Testing object creation"); | |
139 | |
140 vao = ext.createVertexArrayOES(); | |
141 glErrorShouldBe(gl, gl.NO_ERROR, "createVertexArrayOES should not set an err
or"); | |
142 shouldBeNonNull("vao"); | |
143 | |
144 // Expect false if never bound | |
145 shouldBeFalse("ext.isVertexArrayOES(vao)"); | |
146 ext.bindVertexArrayOES(vao); | |
147 shouldBeTrue("ext.isVertexArrayOES(vao)"); | |
148 ext.bindVertexArrayOES(null); | |
149 shouldBeTrue("ext.isVertexArrayOES(vao)"); | |
150 | |
151 shouldBeFalse("ext.isVertexArrayOES()"); | |
152 shouldBeFalse("ext.isVertexArrayOES(null)"); | |
153 | |
154 ext.deleteVertexArrayOES(vao); | |
155 vao = null; | |
156 } | |
157 | |
158 function runAttributeTests() { | |
159 debug("Testing attributes work across bindings"); | |
160 | |
161 var states = []; | |
162 | |
163 var attrCount = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); | |
164 for (var n = 0; n < attrCount; n++) { | |
165 gl.bindBuffer(gl.ARRAY_BUFFER, null); | |
166 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); | |
167 | |
168 var state = {}; | |
169 states.push(state); | |
170 | |
171 var vao = state.vao = ext.createVertexArrayOES(); | |
172 ext.bindVertexArrayOES(vao); | |
173 | |
174 if (n % 2 == 0) { | |
175 gl.enableVertexAttribArray(n); | |
176 } else { | |
177 gl.disableVertexAttribArray(n); | |
178 } | |
179 | |
180 if (n % 2 == 0) { | |
181 var buffer = state.buffer = gl.createBuffer(); | |
182 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); | |
183 gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW); | |
184 | |
185 gl.vertexAttribPointer(n, 1 + n % 4, gl.FLOAT, true, n * 4, n * 4); | |
186 } | |
187 | |
188 if (n % 2 == 0) { | |
189 var elbuffer = state.elbuffer = gl.createBuffer(); | |
190 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elbuffer); | |
191 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 1024, gl.STATIC_DRAW); | |
192 } | |
193 | |
194 ext.bindVertexArrayOES(null); | |
195 } | |
196 | |
197 var anyMismatch = false; | |
198 for (var n = 0; n < attrCount; n++) { | |
199 var state = states[n]; | |
200 | |
201 ext.bindVertexArrayOES(state.vao); | |
202 | |
203 var isEnabled = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_ENABLED); | |
204 if ((n % 2 == 1) || isEnabled) { | |
205 // Valid | |
206 } else { | |
207 testFailed("VERTEX_ATTRIB_ARRAY_ENABLED not preserved"); | |
208 anyMismatch = true; | |
209 } | |
210 | |
211 var buffer = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
); | |
212 if (n % 2 == 0) { | |
213 if (buffer == state.buffer) { | |
214 // Matched | |
215 if ((gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_SIZE) == 1 + n
% 4) && | |
216 (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_TYPE) == gl.FL
OAT) && | |
217 (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED) ==
true) && | |
218 (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == n *
4) && | |
219 (gl.getVertexAttribOffset(n, gl.VERTEX_ATTRIB_ARRAY_POINTER)
== n * 4)) { | |
220 // Matched | |
221 } else { | |
222 testFailed("VERTEX_ATTRIB_ARRAY_* not preserved"); | |
223 anyMismatch = true; | |
224 } | |
225 } else { | |
226 testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved"); | |
227 anyMismatch = true; | |
228 } | |
229 } else { | |
230 // GL_CURRENT_VERTEX_ATTRIB is not preserved | |
231 if (buffer) { | |
232 testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved"); | |
233 anyMismatch = true; | |
234 } | |
235 } | |
236 | |
237 var elbuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING); | |
238 if (n % 2 == 0) { | |
239 if (elbuffer == state.elbuffer) { | |
240 // Matched | |
241 } else { | |
242 testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved"); | |
243 anyMismatch = true; | |
244 } | |
245 } else { | |
246 if (elbuffer == null) { | |
247 // Matched | |
248 } else { | |
249 testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved"); | |
250 anyMismatch = true; | |
251 } | |
252 } | |
253 } | |
254 ext.bindVertexArrayOES(null); | |
255 if (!anyMismatch) { | |
256 testPassed("All attributes preserved across bindings"); | |
257 } | |
258 | |
259 for (var n = 0; n < attrCount; n++) { | |
260 var state = states[n]; | |
261 ext.deleteVertexArrayOES(state.vao); | |
262 } | |
263 } | |
264 | |
265 function runAttributeValueTests() { | |
266 debug("Testing that attribute values are not attached to bindings"); | |
267 | |
268 var v; | |
269 var vao0 = ext.createVertexArrayOES(); | |
270 var anyFailed = false; | |
271 | |
272 ext.bindVertexArrayOES(null); | |
273 gl.vertexAttrib4f(0, 0, 1, 2, 3); | |
274 | |
275 v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); | |
276 if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) { | |
277 testFailed("Vertex attrib value not round-tripped?"); | |
278 anyFailed = true; | |
279 } | |
280 | |
281 ext.bindVertexArrayOES(vao0); | |
282 | |
283 v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); | |
284 if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) { | |
285 testFailed("Vertex attrib value reset across bindings"); | |
286 anyFailed = true; | |
287 } | |
288 | |
289 gl.vertexAttrib4f(0, 4, 5, 6, 7); | |
290 ext.bindVertexArrayOES(null); | |
291 | |
292 v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); | |
293 if (!(v[0] == 4 && v[1] == 5 && v[2] == 6 && v[3] == 7)) { | |
294 testFailed("Vertex attrib value bound to buffer"); | |
295 anyFailed = true; | |
296 } | |
297 | |
298 if (!anyFailed) { | |
299 testPassed("Vertex attribute values are not attached to bindings") | |
300 } | |
301 | |
302 ext.bindVertexArrayOES(null); | |
303 ext.deleteVertexArrayOES(vao0); | |
304 } | |
305 | |
306 function runDrawTests() { | |
307 debug("Testing draws with various VAO bindings"); | |
308 | |
309 canvas.width = 50; canvas.height = 50; | |
310 gl.viewport(0, 0, canvas.width, canvas.height); | |
311 | |
312 var vao0 = ext.createVertexArrayOES(); | |
313 var vao1 = ext.createVertexArrayOES(); | |
314 | |
315 var program = wtu.setupSimpleTextureProgram(gl, 0, 1); | |
316 | |
317 function setupQuad(s) { | |
318 var opt_positionLocation = 0; | |
319 var opt_texcoordLocation = 1; | |
320 var vertexObject = gl.createBuffer(); | |
321 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
322 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ | |
323 1.0 * s, 1.0 * s, 0.0, | |
324 -1.0 * s, 1.0 * s, 0.0, | |
325 -1.0 * s, -1.0 * s, 0.0, | |
326 1.0 * s, 1.0 * s, 0.0, | |
327 -1.0 * s, -1.0 * s, 0.0, | |
328 1.0 * s, -1.0 * s, 0.0]), gl.STATIC_DRAW); | |
329 gl.enableVertexAttribArray(opt_positionLocation); | |
330 gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0); | |
331 | |
332 var vertexObject = gl.createBuffer(); | |
333 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
334 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ | |
335 1.0 * s, 1.0 * s, | |
336 0.0 * s, 1.0 * s, | |
337 0.0 * s, 0.0 * s, | |
338 1.0 * s, 1.0 * s, | |
339 0.0 * s, 0.0 * s, | |
340 1.0 * s, 0.0 * s]), gl.STATIC_DRAW); | |
341 gl.enableVertexAttribArray(opt_texcoordLocation); | |
342 gl.vertexAttribPointer(opt_texcoordLocation, 2, gl.FLOAT, false, 0, 0); | |
343 }; | |
344 | |
345 function readLocation(x, y) { | |
346 var pixels = new Uint8Array(1 * 1 * 4); | |
347 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels); | |
348 return pixels; | |
349 }; | |
350 function testPixel(blackList, whiteList) { | |
351 function testList(list, expected) { | |
352 for (var n = 0; n < list.length; n++) { | |
353 var l = list[n]; | |
354 var x = -Math.floor(l * canvas.width / 2) + canvas.width / 2; | |
355 var y = -Math.floor(l * canvas.height / 2) + canvas.height / 2; | |
356 var source = readLocation(x, y); | |
357 if (Math.abs(source[0] - expected) > 2) { | |
358 return false; | |
359 } | |
360 } | |
361 return true; | |
362 } | |
363 return testList(blackList, 0) && testList(whiteList, 255); | |
364 }; | |
365 function verifyDraw(drawNumber, s) { | |
366 wtu.drawQuad(gl); | |
367 var blackList = []; | |
368 var whiteList = []; | |
369 var points = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]; | |
370 for (var n = 0; n < points.length; n++) { | |
371 if (points[n] <= s) { | |
372 blackList.push(points[n]); | |
373 } else { | |
374 whiteList.push(points[n]); | |
375 } | |
376 } | |
377 if (testPixel(blackList, whiteList)) { | |
378 testPassed("Draw " + drawNumber + " passed pixel test"); | |
379 } else { | |
380 testFailed("Draw " + drawNumber + " failed pixel test"); | |
381 } | |
382 }; | |
383 | |
384 // Setup all bindings | |
385 setupQuad(1); | |
386 ext.bindVertexArrayOES(vao0); | |
387 setupQuad(0.5); | |
388 ext.bindVertexArrayOES(vao1); | |
389 setupQuad(0.25); | |
390 | |
391 // Verify drawing | |
392 ext.bindVertexArrayOES(null); | |
393 verifyDraw(0, 1); | |
394 ext.bindVertexArrayOES(vao0); | |
395 verifyDraw(1, 0.5); | |
396 ext.bindVertexArrayOES(vao1); | |
397 verifyDraw(2, 0.25); | |
398 | |
399 ext.bindVertexArrayOES(null); | |
400 ext.deleteVertexArrayOES(vao0); | |
401 ext.deleteVertexArrayOES(vao1); | |
402 } | |
403 | |
404 debug(""); | |
405 successfullyParsed = true; | |
406 </script> | |
407 <script src="../../resources/js-test-post.js"></script> | |
408 | |
409 </body> | |
410 </html> | |
OLD | NEW |