content/canvas/test/webgl-conformance/conformance/buffers/index-validation.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
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions are
michael@0 6 met:
michael@0 7
michael@0 8 * Redistributions of source code must retain the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer.
michael@0 10 * Redistributions in binary form must reproduce the above
michael@0 11 copyright notice, this list of conditions and the following disclaimer
michael@0 12 in the documentation and/or other materials provided with the
michael@0 13 distribution.
michael@0 14 * Neither the name of Google Inc. nor the names of its
michael@0 15 contributors may be used to endorse or promote products derived from
michael@0 16 this software without specific prior written permission.
michael@0 17
michael@0 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 -->
michael@0 30 <!DOCTYPE html>
michael@0 31 <html>
michael@0 32 <head>
michael@0 33 <meta charset="utf-8">
michael@0 34 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 35 <script src="../../resources/js-test-pre.js"></script>
michael@0 36 <script src="../resources/webgl-test.js"></script>
michael@0 37 </head>
michael@0 38 <body>
michael@0 39 <div id="description"></div>
michael@0 40 <div id="console"></div>
michael@0 41
michael@0 42 <script>
michael@0 43 description("Tests that index validation verifies the correct number of indices");
michael@0 44
michael@0 45 function sizeInBytes(type) {
michael@0 46 switch (type) {
michael@0 47 case gl.BYTE:
michael@0 48 case gl.UNSIGNED_BYTE:
michael@0 49 return 1;
michael@0 50 case gl.SHORT:
michael@0 51 case gl.UNSIGNED_SHORT:
michael@0 52 return 2;
michael@0 53 case gl.INT:
michael@0 54 case gl.UNSIGNED_INT:
michael@0 55 case gl.FLOAT:
michael@0 56 return 4;
michael@0 57 default:
michael@0 58 throw "unknown type";
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 var gl = create3DContext();
michael@0 63 var program = loadStandardProgram(gl);
michael@0 64
michael@0 65 // 3 vertices => 1 triangle, interleaved data
michael@0 66 var dataComplete = new Float32Array([0, 0, 0, 1,
michael@0 67 0, 0, 1,
michael@0 68 1, 0, 0, 1,
michael@0 69 0, 0, 1,
michael@0 70 1, 1, 1, 1,
michael@0 71 0, 0, 1]);
michael@0 72 var dataIncomplete = new Float32Array([0, 0, 0, 1,
michael@0 73 0, 0, 1,
michael@0 74 1, 0, 0, 1,
michael@0 75 0, 0, 1,
michael@0 76 1, 1, 1, 1]);
michael@0 77 var indices = new Uint16Array([0, 1, 2]);
michael@0 78
michael@0 79 debug("Testing with valid indices");
michael@0 80
michael@0 81 var bufferComplete = gl.createBuffer();
michael@0 82 gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
michael@0 83 gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
michael@0 84 var elements = gl.createBuffer();
michael@0 85 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
michael@0 86 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
michael@0 87 gl.useProgram(program);
michael@0 88 var vertexLoc = gl.getAttribLocation(program, "a_vertex");
michael@0 89 var normalLoc = gl.getAttribLocation(program, "a_normal");
michael@0 90 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
michael@0 91 gl.enableVertexAttribArray(vertexLoc);
michael@0 92 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
michael@0 93 gl.enableVertexAttribArray(normalLoc);
michael@0 94 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
michael@0 95 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 96 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 97 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 98
michael@0 99 debug("Testing with out-of-range indices");
michael@0 100
michael@0 101 var bufferIncomplete = gl.createBuffer();
michael@0 102 gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
michael@0 103 gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
michael@0 104 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
michael@0 105 gl.enableVertexAttribArray(vertexLoc);
michael@0 106 gl.disableVertexAttribArray(normalLoc);
michael@0 107 debug("Enable vertices, valid");
michael@0 108 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 109 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 110 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 111 debug("Enable normals, out-of-range");
michael@0 112 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
michael@0 113 gl.enableVertexAttribArray(normalLoc);
michael@0 114 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 115 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 116 glErrorShouldBe(gl, gl.INVALID_OPERATION);
michael@0 117
michael@0 118 debug("Test with enabled attribute that does not belong to current program");
michael@0 119
michael@0 120 gl.disableVertexAttribArray(normalLoc);
michael@0 121 var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
michael@0 122 gl.enableVertexAttribArray(extraLoc);
michael@0 123 debug("Enable an extra attribute with null");
michael@0 124 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 125 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 126 glErrorShouldBe(gl, gl.INVALID_OPERATION);
michael@0 127 debug("Enable an extra attribute with insufficient data buffer");
michael@0 128 gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
michael@0 129 glErrorShouldBe(gl, gl.NO_ERROR);
michael@0 130 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 131 debug("Pass large negative index to vertexAttribPointer");
michael@0 132 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT));
michael@0 133 glErrorShouldBe(gl, gl.INVALID_VALUE);
michael@0 134 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
michael@0 135
michael@0 136 successfullyParsed = true;
michael@0 137 </script>
michael@0 138
michael@0 139 <script>finishTest();</script>
michael@0 140 </body>
michael@0 141 </html>

mercurial