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 drawElements 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
.enableVertexAttribArray(0);
22 context
.bindBuffer(context
.ARRAY_BUFFER
, vertexObject
);
23 context
.bufferData(context
.ARRAY_BUFFER
, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context
.STATIC_DRAW
);
24 context
.vertexAttribPointer(0, 3, context
.FLOAT
, false, 0, 0);
26 var indexObject
= context
.createBuffer();
28 debug("Test empty index buffer")
29 context
.bindBuffer(context
.ELEMENT_ARRAY_BUFFER
, indexObject
);
30 context
.bufferData(context
.ELEMENT_ARRAY_BUFFER
, new Uint8Array([ ]), context
.STATIC_DRAW
);
31 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
32 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
33 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
34 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
35 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)");
36 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
37 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)");
38 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
39 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
42 debug("Test buffer with 3 byte indexes")
43 context
.bindBuffer(context
.ELEMENT_ARRAY_BUFFER
, indexObject
);
44 context
.bufferData(context
.ELEMENT_ARRAY_BUFFER
, new Uint8Array([ 0, 1, 2 ]), context
.STATIC_DRAW
);
45 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
46 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_INT, 0)");
47 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawElements(0x0009, 3, context.UNSIGNED_BYTE, 0)"); // GL_POLYGON
48 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)");
49 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
50 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
51 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
52 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
53 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
54 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
55 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4)");
56 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 0xffffffff, context.UNSIGNED_BYTE, 0)");
57 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0)");
58 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0x7fffffff)");
60 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.bufferData(context.ELEMENT_ARRAY_BUFFER, (new Uint8Array([ 3, 0, 1, 2 ])).subarray(1), context.STATIC_DRAW)");
61 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
62 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.bufferSubData(context.ELEMENT_ARRAY_BUFFER, 0, new Uint8Array([ 3, 0, 1]))");
63 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
64 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.bufferSubData(context.ELEMENT_ARRAY_BUFFER, 0, (new Uint8Array([ 3, 0, 1, 2 ])).subarray(1))");
65 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
66 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)");
69 debug("Test buffer with interleaved (3+2) float vectors")
71 var program2
= createProgram(context
,
72 "attribute vec3 aOne;" +
73 "attribute vec2 aTwo;" +
74 "void main() { gl_Position = vec4(aOne, 1.0) + vec4(aTwo, 0.0, 1.0); }",
75 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }",
78 testFailed("failed to create test program");
81 context
.useProgram(program2
);
83 var vbo
= context
.createBuffer();
84 context
.bindBuffer(context
.ARRAY_BUFFER
, vbo
);
85 // enough for 9 vertices, so 3 triangles
86 context
.bufferData(context
.ARRAY_BUFFER
, new Float32Array(9*5), context
.STATIC_DRAW
);
88 // bind first 3 elements, with a stride of 5 float elements
89 context
.vertexAttribPointer(0, 3, context
.FLOAT
, false, 5*4, 0);
90 // bind 2 elements, starting after the first 3; same stride of 5 float elements
91 context
.vertexAttribPointer(1, 2, context
.FLOAT
, false, 5*4, 3*4);
93 context
.enableVertexAttribArray(0);
94 context
.enableVertexAttribArray(1);
96 var ebo
= context
.createBuffer();
97 context
.bindBuffer(context
.ELEMENT_ARRAY_BUFFER
, ebo
);
98 context
.bufferData(context
.ELEMENT_ARRAY_BUFFER
, new Uint16Array([ 0, 1, 2,
102 0x7fff, 0x7fff, 0x7fff,
103 0xffff, 0xffff, 0xffff ]),
104 context
.STATIC_DRAW
);
106 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_SHORT, 0)");
108 // invalid type arguments
109 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawElements(context.TRIANGLES, 9, context.FLOAT, 0)");
110 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawElements(context.TRIANGLES, 9, context.SHORT, 0)");
111 shouldGenerateGLError(context
, context
.INVALID_ENUM
, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_INT, 0)");
113 // invalid operation with indices that would be valid with correct bindings
114 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 9, context.UNSIGNED_SHORT, 1000)");
115 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 12, context.UNSIGNED_SHORT, 0)");
116 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 15, context.UNSIGNED_SHORT, 0)");
117 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 18, context.UNSIGNED_SHORT, 0)");
118 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 2*15)");
120 shouldGenerateGLError(context
, context
.INVALID_VALUE
, "context.drawElements(context.TRIANGLES, 0xffffffff, context.UNSIGNED_SHORT, 0)");
121 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_SHORT, 0)");
123 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_SHORT, 0)");
125 // invalid operation with offset that's not a multiple of the type size
126 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 0)");
127 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 1)");
128 shouldGenerateGLError(context
, context
.NO_ERROR
, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 2)");
130 // invalid operation if no buffer is bound to ELEMENT_ARRAY_BUFFER
131 context
.bindBuffer(context
.ELEMENT_ARRAY_BUFFER
, null);
132 shouldGenerateGLError(context
, context
.INVALID_OPERATION
, "context.drawElements(context.TRIANGLES, 6, context.UNSIGNED_SHORT, 0)");