content/canvas/test/webgl-conformance/conformance/extensions/oes-vertex-array-object.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial