content/canvas/test/webgl-conformance/conformance/rendering/draw-arrays-out-of-bounds.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/rendering/draw-arrays-out-of-bounds.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +<!--
     1.5 +Copyright (C) 2011 Apple Computer, Inc.  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
     1.9 +are met:
    1.10 +1. Redistributions of source code must retain the above copyright
    1.11 +   notice, this list of conditions and the following disclaimer.
    1.12 +2. Redistributions in binary form must reproduce the above copyright
    1.13 +   notice, this list of conditions and the following disclaimer in the
    1.14 +   documentation and/or other materials provided with the distribution.
    1.15 +
    1.16 +THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
    1.17 +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.19 +PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
    1.20 +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.21 +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.22 +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.23 +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    1.24 +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.25 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.26 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.27 +-->
    1.28 +<!DOCTYPE html>
    1.29 +<html>
    1.30 +<head>
    1.31 +<meta charset="utf-8">
    1.32 +<link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.33 +<script src="../../resources/js-test-pre.js"></script>
    1.34 +<script src="../resources/webgl-test.js"></script>
    1.35 +</head>
    1.36 +<body>
    1.37 +<div id="description"></div>
    1.38 +<div id="console"></div>
    1.39 +
    1.40 +<script>
    1.41 +description("Test of drawArrays with out-of-bounds parameters");
    1.42 +
    1.43 +var context = create3DContext();
    1.44 +var program = loadStandardProgram(context);
    1.45 +
    1.46 +context.useProgram(program);
    1.47 +var vertexObject = context.createBuffer();
    1.48 +context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
    1.49 +context.enableVertexAttribArray(0);
    1.50 +
    1.51 +debug("Test empty buffer")
    1.52 +context.bufferData(context.ARRAY_BUFFER, new Float32Array([  ]), context.STATIC_DRAW);
    1.53 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
    1.54 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 1)");
    1.55 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
    1.56 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
    1.57 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
    1.58 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 1, 0)");
    1.59 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
    1.60 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
    1.61 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
    1.62 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
    1.63 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
    1.64 +
    1.65 +debug("")
    1.66 +debug("Test buffer with 3 float vectors")
    1.67 +context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
    1.68 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
    1.69 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 3)");
    1.70 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawArrays(0x0009, 0, 3)"); // GL_POLYGON
    1.71 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 3, 2)");
    1.72 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
    1.73 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
    1.74 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
    1.75 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
    1.76 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
    1.77 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
    1.78 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
    1.79 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
    1.80 +
    1.81 +debug("")
    1.82 +debug("Test buffer with interleaved (3+2) float vectors")
    1.83 +
    1.84 +var program2 = createProgram(context,
    1.85 +                             "attribute vec3 aOne;" +
    1.86 +                             "attribute vec2 aTwo;" +
    1.87 +                             "void main() { gl_Position = vec4(aOne, 1.0) + vec4(aTwo, 0.0, 1.0); }",
    1.88 +                             "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }",
    1.89 +                             [ "aOne", "aTwo" ]);
    1.90 +if (!program2) {
    1.91 +    testFailed("failed to create test program");
    1.92 +}
    1.93 +
    1.94 +context.useProgram(program2);
    1.95 +
    1.96 +var vbo = context.createBuffer();
    1.97 +context.bindBuffer(context.ARRAY_BUFFER, vbo);
    1.98 +// enough for 9 vertices, so 3 triangles
    1.99 +context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_DRAW);
   1.100 +
   1.101 +// bind first 3 elements, with a stride of 5 float elements
   1.102 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0);
   1.103 +// bind 2 elements, starting after the first 3; same stride of 5 float elements
   1.104 +context.vertexAttribPointer(1, 2, context.FLOAT, false, 5*4, 3*4);
   1.105 +
   1.106 +context.enableVertexAttribArray(0);
   1.107 +context.enableVertexAttribArray(1);
   1.108 +
   1.109 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 9)");
   1.110 +
   1.111 +// negative values must generate INVALID_VALUE; they can never be valid
   1.112 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -500)");
   1.113 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -200, 1)");
   1.114 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -200, -500)");
   1.115 +
   1.116 +// 0xffffffff needs to convert to a 'long' IDL argument as -1, as per
   1.117 +// WebIDL 4.1.7.  JS ToInt32(0xffffffff) == -1, which is the first step
   1.118 +// of the conversion.  Thus INVALID_VALUE.
   1.119 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, 0xffffffff)");
   1.120 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0xffffffff, 1)");
   1.121 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0xffffffff, 0xffffffff)");
   1.122 +
   1.123 +// values that could otherwise be valid but aren't due to bindings generate
   1.124 +// INVALID_OPERATION
   1.125 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 200)");
   1.126 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 0x7fffffff)");
   1.127 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0x7fffffff, 1)");
   1.128 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0x7fffffff, 0x7fffffff)");
   1.129 +
   1.130 +debug("")
   1.131 +successfullyParsed = true;
   1.132 +</script>
   1.133 +
   1.134 +<script>finishTest();</script>
   1.135 +</body>
   1.136 +</html>

mercurial