1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/rendering/draw-elements-out-of-bounds.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 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 drawElements 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.enableVertexAttribArray(0); 1.49 +context.bindBuffer(context.ARRAY_BUFFER, vertexObject); 1.50 +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.51 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); 1.52 + 1.53 +var indexObject = context.createBuffer(); 1.54 + 1.55 +debug("Test empty index buffer") 1.56 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject); 1.57 +context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint8Array([ ]), context.STATIC_DRAW); 1.58 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)"); 1.59 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)"); 1.60 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)"); 1.61 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)"); 1.62 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)"); 1.63 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)"); 1.64 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)"); 1.65 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)"); 1.66 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)"); 1.67 + 1.68 +debug("") 1.69 +debug("Test buffer with 3 byte indexes") 1.70 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject); 1.71 +context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint8Array([ 0, 1, 2 ]), context.STATIC_DRAW); 1.72 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)"); 1.73 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_INT, 0)"); 1.74 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(0x0009, 3, context.UNSIGNED_BYTE, 0)"); // GL_POLYGON 1.75 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)"); 1.76 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)"); 1.77 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)"); 1.78 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)"); 1.79 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)"); 1.80 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)"); 1.81 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)"); 1.82 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4)"); 1.83 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0xffffffff, context.UNSIGNED_BYTE, 0)"); 1.84 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0)"); 1.85 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0x7fffffff)"); 1.86 + 1.87 +shouldGenerateGLError(context, context.NO_ERROR, "context.bufferData(context.ELEMENT_ARRAY_BUFFER, (new Uint8Array([ 3, 0, 1, 2 ])).subarray(1), context.STATIC_DRAW)"); 1.88 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)"); 1.89 +shouldGenerateGLError(context, context.NO_ERROR, "context.bufferSubData(context.ELEMENT_ARRAY_BUFFER, 0, new Uint8Array([ 3, 0, 1]))"); 1.90 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)"); 1.91 +shouldGenerateGLError(context, context.NO_ERROR, "context.bufferSubData(context.ELEMENT_ARRAY_BUFFER, 0, (new Uint8Array([ 3, 0, 1, 2 ])).subarray(1))"); 1.92 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)"); 1.93 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)"); 1.94 + 1.95 +debug("") 1.96 +debug("Test buffer with interleaved (3+2) float vectors") 1.97 + 1.98 +var program2 = createProgram(context, 1.99 + "attribute vec3 aOne;" + 1.100 + "attribute vec2 aTwo;" + 1.101 + "void main() { gl_Position = vec4(aOne, 1.0) + vec4(aTwo, 0.0, 1.0); }", 1.102 + "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }", 1.103 + [ "aOne", "aTwo" ]); 1.104 +if (!program2) { 1.105 + testFailed("failed to create test program"); 1.106 +} 1.107 + 1.108 +context.useProgram(program2); 1.109 + 1.110 +var vbo = context.createBuffer(); 1.111 +context.bindBuffer(context.ARRAY_BUFFER, vbo); 1.112 +// enough for 9 vertices, so 3 triangles 1.113 +context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_DRAW); 1.114 + 1.115 +// bind first 3 elements, with a stride of 5 float elements 1.116 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0); 1.117 +// bind 2 elements, starting after the first 3; same stride of 5 float elements 1.118 +context.vertexAttribPointer(1, 2, context.FLOAT, false, 5*4, 3*4); 1.119 + 1.120 +context.enableVertexAttribArray(0); 1.121 +context.enableVertexAttribArray(1); 1.122 + 1.123 +var ebo = context.createBuffer(); 1.124 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, ebo); 1.125 +context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint16Array( 1.126 + [ 0, 1, 2, 1.127 + 1, 2, 0, 1.128 + 2, 0, 1, 1.129 + 200, 200, 200, 1.130 + 0x7fff, 0x7fff, 0x7fff, 1.131 + 0xffff, 0xffff, 0xffff ]), 1.132 + context.STATIC_DRAW); 1.133 + 1.134 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_SHORT, 0)"); 1.135 + 1.136 +// invalid type arguments 1.137 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 9, context.FLOAT, 0)"); 1.138 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 9, context.SHORT, 0)"); 1.139 +shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_INT, 0)"); 1.140 + 1.141 +// invalid operation with indices that would be valid with correct bindings 1.142 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_SHORT, 1000)"); 1.143 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 12, context.UNSIGNED_SHORT, 0)"); 1.144 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 15, context.UNSIGNED_SHORT, 0)"); 1.145 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 18, context.UNSIGNED_SHORT, 0)"); 1.146 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 2*15)"); 1.147 + 1.148 +shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0xffffffff, context.UNSIGNED_SHORT, 0)"); 1.149 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_SHORT, 0)"); 1.150 + 1.151 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_SHORT, 0)"); 1.152 + 1.153 +// invalid operation with offset that's not a multiple of the type size 1.154 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 0)"); 1.155 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 1)"); 1.156 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 2)"); 1.157 + 1.158 +// invalid operation if no buffer is bound to ELEMENT_ARRAY_BUFFER 1.159 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, null); 1.160 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 0)"); 1.161 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, ebo); 1.162 + 1.163 +debug("") 1.164 +debug("Test buffer setting attrib 0 to a buffer too small and disable it."); 1.165 +var smallVBO = context.createBuffer(); 1.166 +shouldBeNonNull('smallVBO'); 1.167 +context.bindBuffer(context.ARRAY_BUFFER, smallVBO); 1.168 +context.bufferData(context.ARRAY_BUFFER, 1, context.STATIC_DRAW); 1.169 +context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0x10); 1.170 +context.disableVertexAttribArray(0); 1.171 +shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 2)"); 1.172 +context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, null); 1.173 +shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 2)"); 1.174 +debug("") 1.175 +successfullyParsed = true; 1.176 +</script> 1.177 + 1.178 +<script>finishTest();</script> 1.179 +</body> 1.180 +</html>