Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/extensions/oes-vertex-array-object.html

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

Powered by Google App Engine
This is Rietveld 408576698