3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
7 <div id=
"description"></div>
8 <div id=
"console"></div>
11 description("Test of drawArrays with out-of-bounds parameters");
14 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
16 var context
= create3DContext();
17 var program
= loadStandardProgram(context
);
19 context
.useProgram(program
);
20 var vertexObject
= context
.createBuffer();
21 context
.bindBuffer(context
.ARRAY_BUFFER
, vertexObject
);
22 context
.enableVertexAttribArray(0);
24 debug("Test empty buffer")
25 context
.bufferData(context
.ARRAY_BUFFER
, new Float32Array([ ]), context
.STATIC_DRAW
);
26 context
.vertexAttribPointer(0, 3, context
.FLOAT
, false, 0, 0);
27 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 1)");
28 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 10000)");
29 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
30 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0, -1)");
31 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 1, 0)");
32 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -1, 0)");
33 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 0, 0)");
34 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 100, 0)");
35 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 1, -1)");
36 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -1, 1)");
39 debug("Test buffer with 3 float vectors")
40 context
.bufferData(context
.ARRAY_BUFFER
, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context
.STATIC_DRAW
);
41 context
.vertexAttribPointer(0, 3, context
.FLOAT
, false, 0, 0);
42 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 0, 3)");
43 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawArrays(0x0009, 0, 3)"); // GL_POLYGON
44 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 3, 2)");
45 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 10000)");
46 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
47 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0, -1)");
48 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -1, 0)");
49 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 0, 0)");
50 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 100, 0)");
51 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 1, -1)");
52 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -1, 1)");
55 debug("Test buffer with interleaved (3+2) float vectors")
57 var program2
= createProgram(context
,
58 "attribute vec3 aOne;" +
59 "attribute vec2 aTwo;" +
60 "void main() { gl_Position = vec4(aOne, 1.0) + vec4(aTwo, 0.0, 1.0); }",
61 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }",
64 testFailed("failed to create test program");
67 context
.useProgram(program2
);
69 var vbo
= context
.createBuffer();
70 context
.bindBuffer(context
.ARRAY_BUFFER
, vbo
);
71 // enough for 9 vertices, so 3 triangles
72 context
.bufferData(context
.ARRAY_BUFFER
, new Float32Array(9*5), context
.STATIC_DRAW
);
74 // bind first 3 elements, with a stride of 5 float elements
75 context
.vertexAttribPointer(0, 3, context
.FLOAT
, false, 5*4, 0);
76 // bind 2 elements, starting after the first 3; same stride of 5 float elements
77 context
.vertexAttribPointer(1, 2, context
.FLOAT
, false, 5*4, 3*4);
79 context
.enableVertexAttribArray(0);
80 context
.enableVertexAttribArray(1);
82 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawArrays(context.TRIANGLES, 0, 9)");
84 // negative values must generate INVALID_VALUE; they can never be valid
85 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0, -500)");
86 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -200, 1)");
87 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, -200, -500)");
89 // 0xffffffff needs to convert to a 'long' IDL argument as -1, as per
90 // WebIDL 4.1.7. JS ToInt32(0xffffffff) == -1, which is the first step
91 // of the conversion. Thus INVALID_VALUE.
92 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0, 0xffffffff)");
93 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0xffffffff, 1)");
94 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawArrays(context.TRIANGLES, 0xffffffff, 0xffffffff)");
96 // values that could otherwise be valid but aren't due to bindings generate
98 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 200)");
99 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0, 0x7fffffff)");
100 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0x7fffffff, 1)");
101 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawArrays(context.TRIANGLES, 0x7fffffff, 0x7fffffff)");