diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/canvas/test/webgl-conf/checkout/conformance/buffers | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance/buffers')
12 files changed, 1126 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/00_test_list.txt new file mode 100644 index 000000000..a13bcae9c --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/00_test_list.txt @@ -0,0 +1,12 @@ +buffer-bind-test.html +buffer-data-and-buffer-sub-data.html +--min-version 1.0.3 buffer-data-array-buffer-delete.html +--min-version 1.0.4 buffer-uninitialized.html +--min-version 1.0.2 element-array-buffer-delete-recreate.html +index-validation-copies-indices.html +index-validation-crash-with-buffer-sub-data.html +--min-version 1.0.2 index-validation-large-buffer.html +index-validation-verifies-too-many-indices.html +index-validation-with-resized-buffer.html +index-validation.html + diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-bind-test.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-bind-test.html new file mode 100644 index 000000000..e86c9e9fa --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-bind-test.html @@ -0,0 +1,87 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> + <head> +<meta charset="utf-8"> + <title>WebGL BindBuffer conformance test.</title> + <link rel="stylesheet" href="../../resources/js-test-style.css"/> + <script src="../../js/js-test-pre.js"></script> + <script src="../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="40" height="40" style="width: 40px; height: 40px;"></canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +description("Checks a buffer can only be bound to 1 target."); + +debug(""); +debug("Canvas.getContext"); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example"); +if (!gl) { + testFailed("context does not exist"); +} else { + testPassed("context exists"); + + debug(""); + + var buf = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buf); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "should be able to bind array buffer."); + gl.bindBuffer(gl.ARRAY_BUFFER, null); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "should be able to unbind array buffer."); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buf); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "should get INVALID_OPERATION if attempting to bind array buffer to different target"); + + var buf = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buf); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "should be able to bind element array buffer."); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "should be able to unbind element array buffer."); + gl.bindBuffer(gl.ARRAY_BUFFER, buf); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "should get INVALID_OPERATION if attempting to bind element array buffer to different target"); +} + +debug(""); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> + diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html new file mode 100644 index 000000000..444719c38 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html @@ -0,0 +1,188 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description("Test bufferData/bufferSubData with or without ArrayBuffer input"); + +debug('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=41884">https://bugs.webkit.org/show_bug.cgi?id=41884</a> : <code>Implement bufferData and bufferSubData with ArrayBuffer as input</code>'); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(); +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + + bufferDataTest(); + bufferDataSizesTest(); + + bufferSubDataTest(); +} + +function bufferDataTest() { + debug(""); + debug("Test bufferData without ArrayBuffer input"); + + var buf = gl.createBuffer(); + shouldBeNonNull(buf); + + gl.bufferData(gl.ARRAY_BUFFER, 4, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "no buffer bound"); + + gl.bindBuffer(gl.ARRAY_BUFFER, buf); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + gl.bufferData(gl.ARRAY_BUFFER, -4, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling bufferData when buffer size is negative should generate INVALID_VALUE"); + + gl.bufferData(gl.ARRAY_BUFFER, null, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling bufferData when BufferDataSource is null should generate INVALID_VALUE"); + + gl.bufferData(gl.ARRAY_BUFFER, undefined, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling bufferData when BufferDataSource is undefined should generate INVALID_VALUE"); + + gl.bindBuffer(gl.ARRAY_BUFFER, null); +} + +function bufferDataSizesTest() { + debug(""); + debug("Test bufferData overloads"); + + // bufferData has an integer overload and an ArrayBuffer overload. + // Per the WebIDL spec, the overload resolution algorithm should resolve types as follows: + // - If the argument is null or undefined, pick the nullable type, which is ArrayBuffer. + // Per the WebGL spec, null should flag INVALID_VALUE. + // - If the argument is an ArrayBuffer, then pick the ArrayBuffer overload + // - Everything else should pick the numeric overload. This means things like objects, strings, + // floating point numbers, arrays of numbers and strings, etc should convert themselves to a number. + var bufferDataParams = [ + { parameter: 0, expectedBufferSize: 0 }, + { parameter: 4, expectedBufferSize: 4 }, + { parameter: 5.1, expectedBufferSize: 5 }, + { parameter: 5.8, expectedBufferSize: 5 }, + { parameter: 5.5, expectedBufferSize: 5 }, + + { parameter: "4", expectedBufferSize: 4 }, + { parameter: "5.1", expectedBufferSize: 5 }, + { parameter: "5.8", expectedBufferSize: 5 }, + { parameter: "5.5", expectedBufferSize: 5 }, + { parameter: "0", expectedBufferSize: 0 }, + + { parameter: [42, 64], expectedBufferSize: 0 }, + { parameter: [42], expectedBufferSize: 42 }, + { parameter: ["42"], expectedBufferSize: 42 }, + { parameter: ["42", "64"], expectedBufferSize: 0 }, + + { parameter: new ArrayBuffer(0), expectedBufferSize: 0 }, + { parameter: new ArrayBuffer(4), expectedBufferSize: 4 }, + + { parameter: "WebGL Rocks!", expectedBufferSize: 0 }, + { parameter: { mystring: "WebGL Rocks!" }, expectedBufferSize: 0 }, + ]; + + bufferDataParams.forEach(function (bufferDataParam) { + var buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + + gl.bufferData(gl.ARRAY_BUFFER, bufferDataParam.parameter, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Passing " + bufferDataParam.parameter + " to bufferData"); + + shouldEvaluateTo("gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)", bufferDataParam.expectedBufferSize); + }); + + gl.bindBuffer(gl.ARRAY_BUFFER, null); +} + +function bufferSubDataTest() { + debug(""); + debug("Test bufferSubData"); + + var buf = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buf); + + gl.bufferSubData(gl.ARRAY_BUFFER, 0, new ArrayBuffer(1)); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Calling bufferSubData before bufferData should fail"); + + gl.bufferData(gl.ARRAY_BUFFER, 128, gl.STATIC_DRAW); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + var array = new ArrayBuffer(64); + + gl.bufferSubData(gl.ARRAY_BUFFER, -10, array); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling bufferSubData with ArrayBuffer when offset is negative should INVALID_VALUE"); + + gl.bufferSubData(gl.ARRAY_BUFFER, 65, array); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "buffer overflow"); + + gl.bufferSubData(gl.ARRAY_BUFFER, -10, new Float32Array(8)); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling bufferSubData with ArrayBufferView when offset is negative should generate INVALID_VALUE"); + + gl.bufferSubData(gl.ARRAY_BUFFER, 10, array); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "calling bufferSubData with ArrayBuffer should succeed"); + + gl.bufferSubData(gl.ARRAY_BUFFER, 10, new Float32Array(0)); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "calling bufferSubData with zero-sized ArrayBufferView should succeed"); + + // Arguments that are not ArrayBuffers, null or undefined should throw a TypeError exception + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 42);"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 5.5);"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, \"5.5\");"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, [4]);"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, { mynumber: 42});"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, null)"); + shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, undefined)"); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should generate no GL error"); + + gl.bindBuffer(gl.ARRAY_BUFFER, null); +} + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-array-buffer-delete.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-array-buffer-delete.html new file mode 100644 index 000000000..fc9ccb0b8 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-array-buffer-delete.html @@ -0,0 +1,80 @@ +<!-- + +/* +** Copyright (c) 2014 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description("Test ARRAY_BUFFER deletion when a vertex attrib array with location != 0 is pointing to it and preserveDrawingBuffer is true."); + +var canvas = document.createElement('canvas'); +document.body.appendChild(canvas); + +canvas.addEventListener( + "webglcontextlost", + function(event) { + testFailed("Context lost"); + event.preventDefault(); + }, + false); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(canvas, {preserveDrawingBuffer: true}); +shouldBeNonNull("gl"); + +var array = new Float32Array([0]); +var buf = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, buf); +gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); + +var attribLocation = 1; +gl.enableVertexAttribArray(attribLocation); +gl.vertexAttribPointer(attribLocation, 1, gl.FLOAT, false, 0, 0); + +gl.deleteBuffer(buf); + +setTimeout(function() { + // Wait for possible context loss + finishTest(); +}, 2000); + +var successfullyParsed = true; +</script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-uninitialized.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-uninitialized.html new file mode 100644 index 000000000..7eb19de8d --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-uninitialized.html @@ -0,0 +1,123 @@ +<!-- +/* +** Copyright (c) 2016 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ +--> +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<canvas id="canvas" width="1" height="1"></canvas> + +<script id="vshader" type="x-shader/x-vertex"> +attribute float a_vertex; +void main() +{ + gl_Position = a_vertex == 0.0 ? vec4(9, 9, 9, 1) : vec4(0.5, 0.5, 0.5, 1); +} +</script> + +<script id="fshader" type="x-shader/x-fragment"> +void main() +{ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +} +</script> + +<script> +"use strict"; +description("Tests that uninitialized WebGLBuffers are zeroed out"); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(document.getElementById("canvas")); +var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_vertex"]); +shouldBeTrue("program != null"); + +var TEST_LENGTH = 1024; +var TEST_BUFSIZE = TEST_LENGTH * 4; +var data = new Float32Array(TEST_LENGTH / 4); // this array is zeroed + +var indices = new Uint16Array(TEST_LENGTH); +for (var i = 0; i < TEST_LENGTH; i++) { + indices[i] = i; +} + +gl.clearColor(0, 1, 0, 1); + +function test(initFunction) { + var uninitializedBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, uninitializedBuffer); + initFunction(); + + var elements = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); + + gl.useProgram(program); + var vertexLoc = gl.getAttribLocation(program, "a_vertex"); + gl.vertexAttribPointer(vertexLoc, 1, gl.FLOAT, gl.FALSE, 0, 0); + gl.enableVertexAttribArray(vertexLoc); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no error should result from setup"); + + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + gl.drawElements(gl.POINTS, TEST_LENGTH, gl.UNSIGNED_SHORT, 0); + wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 255, 0, 255], "buffer should be initialized to zero"); + + gl.deleteBuffer(uninitializedBuffer); +} + +var REPETITIONS = 50; + +var j; +debug(""); +debug("testing bufferData(..., size, ...)"); +for (j = 0; j < REPETITIONS; j++) { + test(function() { + gl.bufferData(gl.ARRAY_BUFFER, TEST_BUFSIZE, gl.STATIC_DRAW); + }); +} + +debug(""); +debug("testing bufferSubData(..., offset, data) of uninitialized buffer"); +for (j = 0; j < REPETITIONS; j++) { + test(function() { + gl.bufferData(gl.ARRAY_BUFFER, TEST_BUFSIZE, gl.STATIC_DRAW); + // bufferSubData the second quarter of the buffer + gl.bufferSubData(gl.ARRAY_BUFFER, TEST_BUFSIZE / 4, data); + }); +} + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/element-array-buffer-delete-recreate.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/element-array-buffer-delete-recreate.html new file mode 100644 index 000000000..75f1289c4 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/element-array-buffer-delete-recreate.html @@ -0,0 +1,90 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> + <title>Element Array Buffer Deletion and Recreation Test</title> + <link rel="stylesheet" href="../../resources/js-test-style.css"/> + <script src="../../js/js-test-pre.js"></script> + <script src="../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="32" height="32"></canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +var wtu = WebGLTestUtils; +function init() +{ + description(); + + // Clear the background with red. + var gl = wtu.create3DContext("example"); + wtu.setupSimpleColorProgram(gl); + var color = [0, 255, 0, 255]; + wtu.setUByteDrawColor(gl, color); + + var vertexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ + -1, -1, + 1, -1, + -1, 1, + 1, 1 + ]), gl.STATIC_DRAW); + gl.enableVertexAttribArray(0); + gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); + + // Create an element array buffer. + var indexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([0, 1, 2, 3]), gl.STATIC_DRAW); + + // Delete the element array buffer. + gl.deleteBuffer(indexBuffer); + + // Create a new element array buffer. + indexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([0, 1, 2, 3]), gl.STATIC_DRAW); + + // Draw with the new element array buffer. + // If the geometry is drawn successfully, the fragment shader will color it green. + gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from draw"); + wtu.checkCanvas(gl, color, "should be green") +} + +init(); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-copies-indices.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-copies-indices.html new file mode 100644 index 000000000..e25a25932 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-copies-indices.html @@ -0,0 +1,73 @@ +<!-- +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ +--> +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description('Test that client data is always copied during bufferData and bufferSubData calls, because otherwise the data the GL uses to draw may differ from that checked by the index validation code.') + +var wtu = WebGLTestUtils; +var context = wtu.create3DContext(); +var program = wtu.loadStandardProgram(context); + +context.useProgram(program); +var vertexObject = context.createBuffer(); +context.enableVertexAttribArray(0); +context.bindBuffer(context.ARRAY_BUFFER, vertexObject); +// 4 vertices -> 2 triangles +context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW); +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); + +var indexObject = context.createBuffer(); + +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject); +var indices = new Uint16Array([ 10000, 0, 1, 2, 3, 10000 ]); +context.bufferData(context.ELEMENT_ARRAY_BUFFER, indices, context.STATIC_DRAW); +wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)"); +indices[0] = 2; +indices[5] = 1; +wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)"); + +debug("") +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-crash-with-buffer-sub-data.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-crash-with-buffer-sub-data.html new file mode 100644 index 000000000..d6a6d8828 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-crash-with-buffer-sub-data.html @@ -0,0 +1,59 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description('Verifies that the index validation code which is within bufferSubData does not crash.') + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(); + +var elementBuffer = gl.createBuffer(); +gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer); +gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 256, gl.STATIC_DRAW); +var data = new Uint8Array(127); +gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 63, data); +testPassed("bufferSubData, when buffer object was initialized with null, did not crash"); + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-large-buffer.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-large-buffer.html new file mode 100644 index 000000000..75d727733 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-large-buffer.html @@ -0,0 +1,77 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description('Tests that index validation for drawElements works with large attribute buffers'); + +var wtu = WebGLTestUtils; +var context = wtu.create3DContext(); +var program = wtu.loadStandardProgram(context); + +context.useProgram(program); + +// Create a small index buffer. +var indexObject = context.createBuffer(); +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject); +var indexArray = new Uint16Array([0, 1, 2]); +context.bufferData(context.ELEMENT_ARRAY_BUFFER, indexArray, context.STATIC_DRAW); + +// Create a large attribute buffer. +var vertexObject = context.createBuffer(); +context.enableVertexAttribArray(0); +context.bindBuffer(context.ARRAY_BUFFER, vertexObject); +context.bufferData(context.ARRAY_BUFFER, new Float32Array(3 * 65536), context.STATIC_DRAW); +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); + +debug("Test large attribute buffer") +wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 0)"); + +// Enlarge the attribute buffer slightly. +debug("Test even larger attribute buffer") +context.bufferData(context.ARRAY_BUFFER, new Float32Array(3 * 65536 + 3), context.STATIC_DRAW); +wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 0)"); + +debug("") +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-verifies-too-many-indices.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-verifies-too-many-indices.html new file mode 100644 index 000000000..687b556c2 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-verifies-too-many-indices.html @@ -0,0 +1,71 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description('Tests that index validation for drawElements does not examine too many indices'); + +var wtu = WebGLTestUtils; +var context = wtu.create3DContext(); +var program = wtu.loadStandardProgram(context); + +context.useProgram(program); +var vertexObject = context.createBuffer(); +context.enableVertexAttribArray(0); +context.bindBuffer(context.ARRAY_BUFFER, vertexObject); +// 4 vertices -> 2 triangles +context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW); +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); + +var indexObject = context.createBuffer(); + +debug("Test out of range indices") +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject); +context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 10000, 0, 1, 2, 3, 10000 ]), context.STATIC_DRAW); +wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)"); +wtu.shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)"); + +debug("") +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-with-resized-buffer.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-with-resized-buffer.html new file mode 100644 index 000000000..cc0c1fda4 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation-with-resized-buffer.html @@ -0,0 +1,128 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<canvas id="example" width="1" height="1"></canvas> +<div id="description"></div> +<div id="console"></div> + +<script id="vs" type="x-shader/x-vertex"> +attribute vec4 vPosition; +attribute vec4 vColor; +varying vec4 color; +void main() { + gl_Position = vPosition; + color = vColor; +} +</script> +<script id="fs" type="x-shader/x-fragment"> +precision mediump float; +varying vec4 color; +void main() { + gl_FragColor = color; +} +</script> +<script> +"use strict"; +description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.') + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example"); +var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vColor"]); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initialization"); + +var vertexObject = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); +gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( + [-1,1,0, 1,1,0, -1,-1,0, + -1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW); +gl.enableVertexAttribArray(0); +gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup"); + +var texCoordObject = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); +gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( + [0,0, 1,0, 0,1, + 0,1, 1,0, 1,1]), gl.STATIC_DRAW); +gl.enableVertexAttribArray(1); +gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup"); + +// Now resize these buffers because we want to change what we're drawing. +gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); +gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ + -1,1,0, 1,1,0, -1,-1,0, 1,-1,0, + -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition"); +gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); +gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([ + 255, 0, 0, 255, + 255, 0, 0, 255, + 255, 0, 0, 255, + 255, 0, 0, 255, + 0, 255, 0, 255, + 0, 255, 0, 255, + 0, 255, 0, 255, + 0, 255, 0, 255]), gl.STATIC_DRAW); +gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition"); + +var numQuads = 2; +var indices = new Uint8Array(numQuads * 6); +for (var ii = 0; ii < numQuads; ++ii) { + var offset = ii * 6; + var quad = (ii == (numQuads - 1)) ? 4 : 0; + indices[offset + 0] = quad + 0; + indices[offset + 1] = quad + 1; + indices[offset + 2] = quad + 2; + indices[offset + 3] = quad + 2; + indices[offset + 4] = quad + 1; + indices[offset + 5] = quad + 3; +} +var indexObject = gl.createBuffer(); +gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject); +gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices"); +gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); + +debug("") +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html new file mode 100644 index 000000000..4b14be215 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html @@ -0,0 +1,138 @@ +<!-- +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ +--> +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +description("Tests that index validation verifies the correct number of indices"); + +function sizeInBytes(type) { + switch (type) { + case gl.BYTE: + case gl.UNSIGNED_BYTE: + return 1; + case gl.SHORT: + case gl.UNSIGNED_SHORT: + return 2; + case gl.INT: + case gl.UNSIGNED_INT: + case gl.FLOAT: + return 4; + default: + throw "unknown type"; + } +} + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(); +var program = wtu.loadStandardProgram(gl); + +// 3 vertices => 1 triangle, interleaved data +var dataComplete = new Float32Array([0, 0, 0, 1, + 0, 0, 1, + 1, 0, 0, 1, + 0, 0, 1, + 1, 1, 1, 1, + 0, 0, 1]); +var dataIncomplete = new Float32Array([0, 0, 0, 1, + 0, 0, 1, + 1, 0, 0, 1, + 0, 0, 1, + 1, 1, 1, 1]); +var indices = new Uint16Array([0, 1, 2]); + +debug("Testing with valid indices"); + +var bufferComplete = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete); +gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW); +var elements = gl.createBuffer(); +gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); +gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); +gl.useProgram(program); +var vertexLoc = gl.getAttribLocation(program, "a_vertex"); +var normalLoc = gl.getAttribLocation(program, "a_normal"); +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0); +gl.enableVertexAttribArray(vertexLoc); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +gl.enableVertexAttribArray(normalLoc); +shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); + +debug("Testing with out-of-range indices"); + +var bufferIncomplete = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete); +gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW); +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0); +gl.enableVertexAttribArray(vertexLoc); +gl.disableVertexAttribArray(normalLoc); +debug("Enable vertices, valid"); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +debug("Enable normals, out-of-range"); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +gl.enableVertexAttribArray(normalLoc); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION); + +debug("Test with enabled attribute that does not belong to current program"); + +gl.disableVertexAttribArray(normalLoc); +var extraLoc = Math.max(vertexLoc, normalLoc) + 1; +gl.enableVertexAttribArray(extraLoc); +debug("Enable an extra attribute with null"); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION); +debug("Enable an extra attribute with insufficient data buffer"); +gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +debug("Pass large negative index to vertexAttribPointer"); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT)); +wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> |