1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/extensions/oes-vertex-array-object.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,414 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL OES_vertex_array_object Conformance Tests</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> 1.16 +<script src="../../resources/js-test-pre.js"></script> 1.17 +<script src="../resources/webgl-test.js"></script> 1.18 +<script src="../resources/webgl-test-utils.js"></script> 1.19 +<!-- comment in the script tag below to test through JS emualation of the extension. --> 1.20 +<!-- 1.21 +<script src="../../../demos/google/resources/OESVertexArrayObject.js"></script> 1.22 +--> 1.23 +</head> 1.24 +<body> 1.25 +<div id="description"></div> 1.26 +<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> 1.27 +<div id="console"></div> 1.28 +<!-- Shaders for testing standard derivatives --> 1.29 + 1.30 +<script> 1.31 +description("This test verifies the functionality of the OES_vertex_array_object extension, if it is available."); 1.32 + 1.33 +debug(""); 1.34 + 1.35 +var wtu = WebGLTestUtils; 1.36 +var canvas = document.getElementById("canvas"); 1.37 +var gl = create3DContext(canvas); 1.38 +var ext = null; 1.39 +var vao = null; 1.40 + 1.41 +if (!gl) { 1.42 + testFailed("WebGL context does not exist"); 1.43 +} else { 1.44 + testPassed("WebGL context exists"); 1.45 + 1.46 + // Setup emulated OESVertexArrayObject if it has been included. 1.47 + if (window.setupVertexArrayObject) { 1.48 + debug("using emuated OES_vertex_array_object"); 1.49 + setupVertexArrayObject(gl); 1.50 + } 1.51 + 1.52 + // Run tests with extension disabled 1.53 + runBindingTestDisabled(); 1.54 + 1.55 + // Query the extension and store globally so shouldBe can access it 1.56 + ext = gl.getExtension("OES_vertex_array_object"); 1.57 + if (!ext) { 1.58 + testPassed("No OES_vertex_array_object support -- this is legal"); 1.59 + 1.60 + runSupportedTest(false); 1.61 + } else { 1.62 + testPassed("Successfully enabled OES_vertex_array_object extension"); 1.63 + 1.64 + runSupportedTest(true); 1.65 + runBindingTestEnabled(); 1.66 + runObjectTest(); 1.67 + runAttributeTests(); 1.68 + runAttributeValueTests(); 1.69 + runDrawTests(); 1.70 + } 1.71 +} 1.72 + 1.73 +function runSupportedTest(extensionEnabled) { 1.74 + var supported = gl.getSupportedExtensions(); 1.75 + if (supported.indexOf("OES_vertex_array_object") >= 0) { 1.76 + if (extensionEnabled) { 1.77 + testPassed("OES_vertex_array_object listed as supported and getExtension succeeded"); 1.78 + } else { 1.79 + testFailed("OES_vertex_array_object listed as supported but getExtension failed"); 1.80 + } 1.81 + } else { 1.82 + if (extensionEnabled) { 1.83 + testFailed("OES_vertex_array_object not listed as supported but getExtension succeeded"); 1.84 + } else { 1.85 + testPassed("OES_vertex_array_object not listed as supported and getExtension failed -- this is legal"); 1.86 + } 1.87 + } 1.88 +} 1.89 + 1.90 +function runBindingTestDisabled() { 1.91 + debug("Testing binding enum with extension disabled"); 1.92 + 1.93 + // Use the constant directly as we don't have the extension 1.94 + var VERTEX_ARRAY_BINDING_OES = 0x85B5; 1.95 + 1.96 + gl.getParameter(VERTEX_ARRAY_BINDING_OES); 1.97 + glErrorShouldBe(gl, gl.INVALID_ENUM, "VERTEX_ARRAY_BINDING_OES should not be queryable if extension is disabled"); 1.98 +} 1.99 + 1.100 +function runBindingTestEnabled() { 1.101 + debug("Testing binding enum with extension enabled"); 1.102 + 1.103 + shouldBe("ext.VERTEX_ARRAY_BINDING_OES", "0x85B5"); 1.104 + 1.105 + gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES); 1.106 + glErrorShouldBe(gl, gl.NO_ERROR, "VERTEX_ARRAY_BINDING_OES query should succeed if extension is enable"); 1.107 + 1.108 + // Default value is null 1.109 + if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) === null) { 1.110 + testPassed("Default value of VERTEX_ARRAY_BINDING_OES is null"); 1.111 + } else { 1.112 + testFailed("Default value of VERTEX_ARRAY_BINDING_OES is not null"); 1.113 + } 1.114 + 1.115 + debug("Testing binding a VAO"); 1.116 + var vao0 = ext.createVertexArrayOES(); 1.117 + var vao1 = ext.createVertexArrayOES(); 1.118 + shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); 1.119 + ext.bindVertexArrayOES(vao0); 1.120 + if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao0) { 1.121 + testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO"); 1.122 + } else { 1.123 + testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO") 1.124 + } 1.125 + ext.bindVertexArrayOES(vao1); 1.126 + if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao1) { 1.127 + testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO"); 1.128 + } else { 1.129 + testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO") 1.130 + } 1.131 + ext.deleteVertexArrayOES(vao1); 1.132 + shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); 1.133 + ext.bindVertexArrayOES(vao1); 1.134 + glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted vertex array object"); 1.135 + ext.bindVertexArrayOES(null); 1.136 + shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)"); 1.137 + ext.deleteVertexArrayOES(vao1); 1.138 +} 1.139 + 1.140 +function runObjectTest() { 1.141 + debug("Testing object creation"); 1.142 + 1.143 + vao = ext.createVertexArrayOES(); 1.144 + glErrorShouldBe(gl, gl.NO_ERROR, "createVertexArrayOES should not set an error"); 1.145 + shouldBeNonNull("vao"); 1.146 + 1.147 + // Expect false if never bound 1.148 + shouldBeFalse("ext.isVertexArrayOES(vao)"); 1.149 + ext.bindVertexArrayOES(vao); 1.150 + shouldBeTrue("ext.isVertexArrayOES(vao)"); 1.151 + ext.bindVertexArrayOES(null); 1.152 + shouldBeTrue("ext.isVertexArrayOES(vao)"); 1.153 + 1.154 + /* 1.155 + * Issue found in the conformance test. The public webgl mailing list has been notified about it. 1.156 + * The tests have already been fixed upstream. 1.157 + */ 1.158 + //shouldBeFalse("ext.isVertexArrayOES()"); 1.159 + shouldBeFalse("ext.isVertexArrayOES(null)"); 1.160 + 1.161 + ext.deleteVertexArrayOES(vao); 1.162 + vao = null; 1.163 +} 1.164 + 1.165 +function runAttributeTests() { 1.166 + debug("Testing attributes work across bindings"); 1.167 + 1.168 + var states = []; 1.169 + 1.170 + var attrCount = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); 1.171 + for (var n = 0; n < attrCount; n++) { 1.172 + gl.bindBuffer(gl.ARRAY_BUFFER, null); 1.173 + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); 1.174 + 1.175 + var state = {}; 1.176 + states.push(state); 1.177 + 1.178 + var vao = state.vao = ext.createVertexArrayOES(); 1.179 + ext.bindVertexArrayOES(vao); 1.180 + 1.181 + if (n % 2 == 0) { 1.182 + gl.enableVertexAttribArray(n); 1.183 + } else { 1.184 + gl.disableVertexAttribArray(n); 1.185 + } 1.186 + 1.187 + if (n % 2 == 0) { 1.188 + var buffer = state.buffer = gl.createBuffer(); 1.189 + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1.190 + gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW); 1.191 + 1.192 + gl.vertexAttribPointer(n, 1 + n % 4, gl.FLOAT, true, n * 4, n * 4); 1.193 + } 1.194 + 1.195 + if (n % 2 == 0) { 1.196 + var elbuffer = state.elbuffer = gl.createBuffer(); 1.197 + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elbuffer); 1.198 + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 1024, gl.STATIC_DRAW); 1.199 + } 1.200 + 1.201 + ext.bindVertexArrayOES(null); 1.202 + } 1.203 + 1.204 + var anyMismatch = false; 1.205 + for (var n = 0; n < attrCount; n++) { 1.206 + var state = states[n]; 1.207 + 1.208 + ext.bindVertexArrayOES(state.vao); 1.209 + 1.210 + var isEnabled = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_ENABLED); 1.211 + if ((n % 2 == 1) || isEnabled) { 1.212 + // Valid 1.213 + } else { 1.214 + testFailed("VERTEX_ATTRIB_ARRAY_ENABLED not preserved"); 1.215 + anyMismatch = true; 1.216 + } 1.217 + 1.218 + var buffer = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING); 1.219 + if (n % 2 == 0) { 1.220 + if (buffer == state.buffer) { 1.221 + // Matched 1.222 + if ((gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_SIZE) == 1 + n % 4) && 1.223 + (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_TYPE) == gl.FLOAT) && 1.224 + (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED) == true) && 1.225 + (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == n * 4) && 1.226 + (gl.getVertexAttribOffset(n, gl.VERTEX_ATTRIB_ARRAY_POINTER) == n * 4)) { 1.227 + // Matched 1.228 + } else { 1.229 + testFailed("VERTEX_ATTRIB_ARRAY_* not preserved"); 1.230 + anyMismatch = true; 1.231 + } 1.232 + } else { 1.233 + testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved"); 1.234 + anyMismatch = true; 1.235 + } 1.236 + } else { 1.237 + // GL_CURRENT_VERTEX_ATTRIB is not preserved 1.238 + if (buffer) { 1.239 + testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved"); 1.240 + anyMismatch = true; 1.241 + } 1.242 + } 1.243 + 1.244 + var elbuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING); 1.245 + if (n % 2 == 0) { 1.246 + if (elbuffer == state.elbuffer) { 1.247 + // Matched 1.248 + } else { 1.249 + testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved"); 1.250 + anyMismatch = true; 1.251 + } 1.252 + } else { 1.253 + if (elbuffer == null) { 1.254 + // Matched 1.255 + } else { 1.256 + testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved"); 1.257 + anyMismatch = true; 1.258 + } 1.259 + } 1.260 + } 1.261 + ext.bindVertexArrayOES(null); 1.262 + if (!anyMismatch) { 1.263 + testPassed("All attributes preserved across bindings"); 1.264 + } 1.265 + 1.266 + for (var n = 0; n < attrCount; n++) { 1.267 + var state = states[n]; 1.268 + ext.deleteVertexArrayOES(state.vao); 1.269 + } 1.270 +} 1.271 + 1.272 +function runAttributeValueTests() { 1.273 + debug("Testing that attribute values are not attached to bindings"); 1.274 + 1.275 + var v; 1.276 + var vao0 = ext.createVertexArrayOES(); 1.277 + var anyFailed = false; 1.278 + 1.279 + ext.bindVertexArrayOES(null); 1.280 + gl.vertexAttrib4f(0, 0, 1, 2, 3); 1.281 + 1.282 + v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); 1.283 + if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) { 1.284 + testFailed("Vertex attrib value not round-tripped?"); 1.285 + anyFailed = true; 1.286 + } 1.287 + 1.288 + ext.bindVertexArrayOES(vao0); 1.289 + 1.290 + v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); 1.291 + if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) { 1.292 + testFailed("Vertex attrib value reset across bindings"); 1.293 + anyFailed = true; 1.294 + } 1.295 + 1.296 + gl.vertexAttrib4f(0, 4, 5, 6, 7); 1.297 + ext.bindVertexArrayOES(null); 1.298 + 1.299 + v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB); 1.300 + if (!(v[0] == 4 && v[1] == 5 && v[2] == 6 && v[3] == 7)) { 1.301 + testFailed("Vertex attrib value bound to buffer"); 1.302 + anyFailed = true; 1.303 + } 1.304 + 1.305 + if (!anyFailed) { 1.306 + testPassed("Vertex attribute values are not attached to bindings") 1.307 + } 1.308 + 1.309 + ext.bindVertexArrayOES(null); 1.310 + ext.deleteVertexArrayOES(vao0); 1.311 +} 1.312 + 1.313 +function runDrawTests() { 1.314 + debug("Testing draws with various VAO bindings"); 1.315 + 1.316 + canvas.width = 50; canvas.height = 50; 1.317 + gl.viewport(0, 0, canvas.width, canvas.height); 1.318 + 1.319 + var vao0 = ext.createVertexArrayOES(); 1.320 + var vao1 = ext.createVertexArrayOES(); 1.321 + 1.322 + var program = wtu.setupSimpleTextureProgram(gl, 0, 1); 1.323 + 1.324 + function setupQuad(s) { 1.325 + var opt_positionLocation = 0; 1.326 + var opt_texcoordLocation = 1; 1.327 + var vertexObject = gl.createBuffer(); 1.328 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.329 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 1.330 + 1.0 * s, 1.0 * s, 0.0, 1.331 + -1.0 * s, 1.0 * s, 0.0, 1.332 + -1.0 * s, -1.0 * s, 0.0, 1.333 + 1.0 * s, 1.0 * s, 0.0, 1.334 + -1.0 * s, -1.0 * s, 0.0, 1.335 + 1.0 * s, -1.0 * s, 0.0]), gl.STATIC_DRAW); 1.336 + gl.enableVertexAttribArray(opt_positionLocation); 1.337 + gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0); 1.338 + 1.339 + var vertexObject = gl.createBuffer(); 1.340 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.341 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 1.342 + 1.0 * s, 1.0 * s, 1.343 + 0.0 * s, 1.0 * s, 1.344 + 0.0 * s, 0.0 * s, 1.345 + 1.0 * s, 1.0 * s, 1.346 + 0.0 * s, 0.0 * s, 1.347 + 1.0 * s, 0.0 * s]), gl.STATIC_DRAW); 1.348 + gl.enableVertexAttribArray(opt_texcoordLocation); 1.349 + gl.vertexAttribPointer(opt_texcoordLocation, 2, gl.FLOAT, false, 0, 0); 1.350 + }; 1.351 + 1.352 + function readLocation(x, y) { 1.353 + var pixels = new Uint8Array(1 * 1 * 4); 1.354 + gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels); 1.355 + return pixels; 1.356 + }; 1.357 + function testPixel(blackList, whiteList) { 1.358 + function testList(list, expected) { 1.359 + for (var n = 0; n < list.length; n++) { 1.360 + var l = list[n]; 1.361 + var x = -Math.floor(l * canvas.width / 2) + canvas.width / 2; 1.362 + var y = -Math.floor(l * canvas.height / 2) + canvas.height / 2; 1.363 + var source = readLocation(x, y); 1.364 + if (Math.abs(source[0] - expected) > 2) { 1.365 + return false; 1.366 + } 1.367 + } 1.368 + return true; 1.369 + } 1.370 + return testList(blackList, 0) && testList(whiteList, 255); 1.371 + }; 1.372 + function verifyDraw(drawNumber, s) { 1.373 + wtu.drawQuad(gl); 1.374 + var blackList = []; 1.375 + var whiteList = []; 1.376 + var points = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]; 1.377 + for (var n = 0; n < points.length; n++) { 1.378 + if (points[n] <= s) { 1.379 + blackList.push(points[n]); 1.380 + } else { 1.381 + whiteList.push(points[n]); 1.382 + } 1.383 + } 1.384 + if (testPixel(blackList, whiteList)) { 1.385 + testPassed("Draw " + drawNumber + " passed pixel test"); 1.386 + } else { 1.387 + testFailed("Draw " + drawNumber + " failed pixel test"); 1.388 + } 1.389 + }; 1.390 + 1.391 + // Setup all bindings 1.392 + setupQuad(1); 1.393 + ext.bindVertexArrayOES(vao0); 1.394 + setupQuad(0.5); 1.395 + ext.bindVertexArrayOES(vao1); 1.396 + setupQuad(0.25); 1.397 + 1.398 + // Verify drawing 1.399 + ext.bindVertexArrayOES(null); 1.400 + verifyDraw(0, 1); 1.401 + ext.bindVertexArrayOES(vao0); 1.402 + verifyDraw(1, 0.5); 1.403 + ext.bindVertexArrayOES(vao1); 1.404 + verifyDraw(2, 0.25); 1.405 + 1.406 + ext.bindVertexArrayOES(null); 1.407 + ext.deleteVertexArrayOES(vao0); 1.408 + ext.deleteVertexArrayOES(vao1); 1.409 +} 1.410 + 1.411 +debug(""); 1.412 +successfullyParsed = true; 1.413 +</script> 1.414 +<script>finishTest();</script> 1.415 + 1.416 +</body> 1.417 +</html>