OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (C) 2009 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 <html> | |
26 <head> | |
27 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
28 <script src="../resources/js-test-pre.js"></script> | |
29 <script src="resources/webgl-test.js"></script> | |
30 </head> | |
31 <body> | |
32 <div id="description"></div> | |
33 <div id="console"></div> | |
34 | |
35 <script> | |
36 description("Test of drawArrays with out-of-bounds parameters"); | |
37 | |
38 var context = create3DContext(); | |
39 var program = loadStandardProgram(context); | |
40 | |
41 context.useProgram(program); | |
42 var vertexObject = context.createBuffer(); | |
43 context.bindBuffer(context.ARRAY_BUFFER, vertexObject); | |
44 context.enableVertexAttribArray(0); | |
45 | |
46 debug("Test empty buffer") | |
47 context.bufferData(context.ARRAY_BUFFER, new Float32Array([ ]), context.STATIC_
DRAW); | |
48 context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); | |
49 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 1)"); | |
50 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000)"); | |
51 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000000000000)"); | |
52 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -1)"); | |
53 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 1, 0)"); | |
54 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 0)"); | |
55 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 0)"); | |
56 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 100, 0)"); | |
57 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 1, -1)"); | |
58 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 1)"); | |
59 | |
60 debug("") | |
61 debug("Test buffer with 3 float vectors") | |
62 context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0
, 0.5,-0.5,0 ]), context.STATIC_DRAW); | |
63 context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0); | |
64 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 3)"); | |
65 shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawArrays(0x0009,
0, 3)"); // GL_POLYGON | |
66 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 3, 2)"); | |
67 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000)"); | |
68 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 10000000000000)"); | |
69 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -1)"); | |
70 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 0)"); | |
71 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 0)"); | |
72 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 100, 0)"); | |
73 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 1, -1)"); | |
74 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -1, 1)"); | |
75 | |
76 debug("") | |
77 debug("Test buffer with interleaved (3+2) float vectors") | |
78 | |
79 var program2 = createProgram(context, | |
80 "attribute vec3 aOne;" + | |
81 "attribute vec2 aTwo;" + | |
82 "void main() { gl_Position = vec4(aOne, 1.0) + vec4
(aTwo, 0.0, 1.0); }", | |
83 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1
.0); }", | |
84 [ "aOne", "aTwo" ]); | |
85 if (!program2) { | |
86 testFailed("failed to create test program"); | |
87 } | |
88 | |
89 context.useProgram(program2); | |
90 | |
91 var vbo = context.createBuffer(); | |
92 context.bindBuffer(context.ARRAY_BUFFER, vbo); | |
93 // enough for 9 vertices, so 3 triangles | |
94 context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_D
RAW); | |
95 | |
96 // bind first 3 elements, with a stride of 5 float elements | |
97 context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0); | |
98 // bind 2 elements, starting after the first 3; same stride of 5 float elements | |
99 context.vertexAttribPointer(1, 2, context.FLOAT, false, 5*4, 3*4); | |
100 | |
101 context.enableVertexAttribArray(0); | |
102 context.enableVertexAttribArray(1); | |
103 | |
104 shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRI
ANGLES, 0, 9)"); | |
105 | |
106 // negative values must generate INVALID_VALUE; they can never be valid | |
107 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, -500)"); | |
108 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -200, 1)"); | |
109 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, -200, -500)"); | |
110 | |
111 // 0xffffffff needs to convert to a 'long' IDL argument as -1, as per | |
112 // WebIDL 4.1.7. JS ToInt32(0xffffffff) == -1, which is the first step | |
113 // of the conversion. Thus INVALID_VALUE. | |
114 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0, 0xffffffff)"); | |
115 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0xffffffff, 1)"); | |
116 shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(contex
t.TRIANGLES, 0xffffffff, 0xffffffff)"); | |
117 | |
118 // values that could otherwise be valid but aren't due to bindings generate | |
119 // INVALID_OPERATION | |
120 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 200)"); | |
121 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0, 0x7fffffff)"); | |
122 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0x7fffffff, 1)"); | |
123 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
ntext.TRIANGLES, 0x7fffffff, 0x7fffffff)"); | |
124 | |
125 debug("") | |
126 successfullyParsed = true; | |
127 </script> | |
128 | |
129 <script src="../resources/js-test-post.js"></script> | |
130 </body> | |
131 </html> | |
OLD | NEW |