OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (C) 2011 Apple Computer, Inc. All rights reserved. |
| 3 |
| 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions |
| 6 are met: |
| 7 1. Redistributions of source code must retain the above copyright |
| 8 notice, this list of conditions and the following disclaimer. |
| 9 2. Redistributions in binary form must reproduce the above copyright |
| 10 notice, this list of conditions and the following disclaimer in the |
| 11 documentation and/or other materials provided with the distribution. |
| 12 |
| 13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 --> |
| 25 <!DOCTYPE html> |
| 26 <html> |
| 27 <head> |
| 28 <meta charset="utf-8"> |
| 29 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 30 <script src="../../resources/js-test-pre.js"></script> |
| 31 <script src="../resources/webgl-test.js"></script> |
| 32 </head> |
| 33 <body> |
| 34 <div id="description"></div> |
| 35 <div id="console"></div> |
| 36 |
| 37 <script> |
| 38 description("Test of drawArrays with out-of-bounds parameters"); |
| 39 |
| 40 var context = create3DContext(); |
| 41 var program = loadStandardProgram(context); |
| 42 |
| 43 context.useProgram(program); |
| 44 var vertexObject = context.createBuffer(); |
| 45 context.bindBuffer(context.ARRAY_BUFFER, vertexObject); |
| 46 context.enableVertexAttribArray(0); |
| 47 |
| 48 debug("Test empty buffer") |
| 49 context.bufferData(context.ARRAY_BUFFER, new Float32Array([ ]), context.STATIC_
DRAW); |
| 50 context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); |
| 51 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 1)"); |
| 52 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000)"); |
| 53 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000000000000)"); |
| 54 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -1)"); |
| 55 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 1, 0)"); |
| 56 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 0)"); |
| 57 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 0)"); |
| 58 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 100, 0)"); |
| 59 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 1, -1)"); |
| 60 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 1)"); |
| 61 |
| 62 debug("") |
| 63 debug("Test buffer with 3 float vectors") |
| 64 context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0
, 0.5,-0.5,0 ]), context.STATIC_DRAW); |
| 65 context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); |
| 66 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 3)"); |
| 67 shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawArrays(0x0009,
0, 3)"); // GL_POLYGON |
| 68 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 3, 2)"); |
| 69 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000)"); |
| 70 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000000000000)"); |
| 71 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -1)"); |
| 72 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 0)"); |
| 73 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 0)"); |
| 74 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 100, 0)"); |
| 75 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 1, -1)"); |
| 76 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 1)"); |
| 77 |
| 78 debug("") |
| 79 debug("Test buffer with interleaved (3+2) float vectors") |
| 80 |
| 81 var program2 = createProgram(context, |
| 82 "attribute vec3 aOne;" + |
| 83 "attribute vec2 aTwo;" + |
| 84 "void main() { gl_Position = vec4(aOne, 1.0) + vec4
(aTwo, 0.0, 1.0); }", |
| 85 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1
.0); }", |
| 86 [ "aOne", "aTwo" ]); |
| 87 if (!program2) { |
| 88 testFailed("failed to create test program"); |
| 89 } |
| 90 |
| 91 context.useProgram(program2); |
| 92 |
| 93 var vbo = context.createBuffer(); |
| 94 context.bindBuffer(context.ARRAY_BUFFER, vbo); |
| 95 // enough for 9 vertices, so 3 triangles |
| 96 context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_D
RAW); |
| 97 |
| 98 // bind first 3 elements, with a stride of 5 float elements |
| 99 context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0); |
| 100 // bind 2 elements, starting after the first 3; same stride of 5 float elements |
| 101 context.vertexAttribPointer(1, 2, context.FLOAT, false, 5*4, 3*4); |
| 102 |
| 103 context.enableVertexAttribArray(0); |
| 104 context.enableVertexAttribArray(1); |
| 105 |
| 106 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 9)"); |
| 107 |
| 108 // negative values must generate INVALID_VALUE; they can never be valid |
| 109 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -500)"); |
| 110 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -200, 1)"); |
| 111 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -200, -500)"); |
| 112 |
| 113 // 0xffffffff needs to convert to a 'long' IDL argument as -1, as per |
| 114 // WebIDL 4.1.7. JS ToInt32(0xffffffff) == -1, which is the first step |
| 115 // of the conversion. Thus INVALID_VALUE. |
| 116 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, 0xffffffff)"); |
| 117 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0xffffffff, 1)"); |
| 118 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0xffffffff, 0xffffffff)"); |
| 119 |
| 120 // values that could otherwise be valid but aren't due to bindings generate |
| 121 // INVALID_OPERATION |
| 122 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 200)"); |
| 123 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 0x7fffffff)"); |
| 124 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0x7fffffff, 1)"); |
| 125 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0x7fffffff, 0x7fffffff)"); |
| 126 |
| 127 debug("") |
| 128 successfullyParsed = true; |
| 129 </script> |
| 130 |
| 131 <script src="../../resources/js-test-post.js"></script> |
| 132 </body> |
| 133 </html> |
OLD | NEW |