content/canvas/test/webgl-conformance/conformance/buffers/index-validation.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/conformance/buffers/index-validation.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +<!--
     1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.6 +
     1.7 +Redistribution and use in source and binary forms, with or without
     1.8 +modification, are permitted provided that the following conditions are
     1.9 +met:
    1.10 +
    1.11 +   * Redistributions of source code must retain the above copyright
    1.12 +notice, this list of conditions and the following disclaimer.
    1.13 +   * Redistributions in binary form must reproduce the above
    1.14 +copyright notice, this list of conditions and the following disclaimer
    1.15 +in the documentation and/or other materials provided with the
    1.16 +distribution.
    1.17 +   * Neither the name of Google Inc. nor the names of its
    1.18 +contributors may be used to endorse or promote products derived from
    1.19 +this software without specific prior written permission.
    1.20 +
    1.21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +-->
    1.33 +<!DOCTYPE html>
    1.34 +<html>
    1.35 +<head>
    1.36 +<meta charset="utf-8">
    1.37 +<link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.38 +<script src="../../resources/js-test-pre.js"></script>
    1.39 +<script src="../resources/webgl-test.js"></script>
    1.40 +</head>
    1.41 +<body>
    1.42 +<div id="description"></div>
    1.43 +<div id="console"></div>
    1.44 +
    1.45 +<script>
    1.46 +description("Tests that index validation verifies the correct number of indices");
    1.47 +
    1.48 +function sizeInBytes(type) {
    1.49 +  switch (type) {
    1.50 +  case gl.BYTE:
    1.51 +  case gl.UNSIGNED_BYTE:
    1.52 +    return 1;
    1.53 +  case gl.SHORT:
    1.54 +  case gl.UNSIGNED_SHORT:
    1.55 +    return 2;
    1.56 +  case gl.INT:
    1.57 +  case gl.UNSIGNED_INT:
    1.58 +  case gl.FLOAT:
    1.59 +    return 4;
    1.60 +  default:
    1.61 +    throw "unknown type";
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +var gl = create3DContext();
    1.66 +var program = loadStandardProgram(gl);
    1.67 +
    1.68 +// 3 vertices => 1 triangle, interleaved data
    1.69 +var dataComplete = new Float32Array([0, 0, 0, 1,
    1.70 +                                     0, 0, 1,
    1.71 +                                     1, 0, 0, 1,
    1.72 +                                     0, 0, 1,
    1.73 +                                     1, 1, 1, 1,
    1.74 +                                     0, 0, 1]);
    1.75 +var dataIncomplete = new Float32Array([0, 0, 0, 1,
    1.76 +                                       0, 0, 1,
    1.77 +                                       1, 0, 0, 1,
    1.78 +                                       0, 0, 1,
    1.79 +                                       1, 1, 1, 1]);
    1.80 +var indices = new Uint16Array([0, 1, 2]);
    1.81 +
    1.82 +debug("Testing with valid indices");
    1.83 +
    1.84 +var bufferComplete = gl.createBuffer();
    1.85 +gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
    1.86 +gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
    1.87 +var elements = gl.createBuffer();
    1.88 +gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
    1.89 +gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
    1.90 +gl.useProgram(program);
    1.91 +var vertexLoc = gl.getAttribLocation(program, "a_vertex");
    1.92 +var normalLoc = gl.getAttribLocation(program, "a_normal");
    1.93 +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
    1.94 +gl.enableVertexAttribArray(vertexLoc);
    1.95 +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
    1.96 +gl.enableVertexAttribArray(normalLoc);
    1.97 +shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
    1.98 +glErrorShouldBe(gl, gl.NO_ERROR);
    1.99 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.100 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.101 +
   1.102 +debug("Testing with out-of-range indices");
   1.103 +
   1.104 +var bufferIncomplete = gl.createBuffer();
   1.105 +gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
   1.106 +gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
   1.107 +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
   1.108 +gl.enableVertexAttribArray(vertexLoc);
   1.109 +gl.disableVertexAttribArray(normalLoc);
   1.110 +debug("Enable vertices, valid");
   1.111 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.112 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.113 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.114 +debug("Enable normals, out-of-range");
   1.115 +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
   1.116 +gl.enableVertexAttribArray(normalLoc);
   1.117 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.118 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.119 +glErrorShouldBe(gl, gl.INVALID_OPERATION);
   1.120 +
   1.121 +debug("Test with enabled attribute that does not belong to current program");
   1.122 +
   1.123 +gl.disableVertexAttribArray(normalLoc);
   1.124 +var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
   1.125 +gl.enableVertexAttribArray(extraLoc);
   1.126 +debug("Enable an extra attribute with null");
   1.127 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.128 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.129 +glErrorShouldBe(gl, gl.INVALID_OPERATION);
   1.130 +debug("Enable an extra attribute with insufficient data buffer");
   1.131 +gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
   1.132 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.133 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.134 +debug("Pass large negative index to vertexAttribPointer");
   1.135 +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT));
   1.136 +glErrorShouldBe(gl, gl.INVALID_VALUE);
   1.137 +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
   1.138 +
   1.139 +successfullyParsed = true;
   1.140 +</script>
   1.141 +
   1.142 +<script>finishTest();</script>
   1.143 +</body>
   1.144 +</html>

mercurial