Creates an index buffer, which contains typed indices in GPU-controlled memory.
An index buffer can be attached to a vertex array to select vertices for rendering.
Context.draw
can render using the entire index buffer or a subset
of the index buffer defined by an offset and count.
Name |
Type |
Description |
options |
Object
|
An object containing the following properties:
Name |
Type |
Description |
context |
Context
|
The context in which to create the buffer |
typedArray |
ArrayBufferView
|
optional
A typed array containing the data to copy to the buffer. |
sizeInBytes |
Number
|
optional
A Number defining the size of the buffer in bytes. Required if options.typedArray is not given. |
usage |
BufferUsage
|
Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See BufferUsage . |
indexDatatype |
IndexDatatype
|
The datatype of indices in the buffer. |
|
Returns:
The index buffer, ready to be attached to a vertex array.
Throws:
-
-
DeveloperError
: IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.
-
-
-
Examples:
// Example 1. Create a stream index buffer of unsigned shorts that is
// 16 bytes in size.
var buffer = Buffer.createIndexBuffer({
context : context,
sizeInBytes : 16,
usage : BufferUsage.STREAM_DRAW,
indexDatatype : IndexDatatype.UNSIGNED_SHORT
});
// Example 2. Create a static index buffer containing three unsigned shorts.
var buffer = Buffer.createIndexBuffer({
context : context,
typedArray : new Uint16Array([0, 1, 2]),
usage : BufferUsage.STATIC_DRAW,
indexDatatype : IndexDatatype.UNSIGNED_SHORT
});
See:
Creates a vertex buffer, which contains untyped vertex data in GPU-controlled memory.
A vertex array defines the actual makeup of a vertex, e.g., positions, normals, texture coordinates,
etc., by interpreting the raw data in one or more vertex buffers.
Name |
Type |
Description |
options |
Object
|
An object containing the following properties:
Name |
Type |
Description |
context |
Context
|
The context in which to create the buffer |
typedArray |
ArrayBufferView
|
optional
A typed array containing the data to copy to the buffer. |
sizeInBytes |
Number
|
optional
A Number defining the size of the buffer in bytes. Required if options.typedArray is not given. |
usage |
BufferUsage
|
Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See BufferUsage . |
|
Returns:
The vertex buffer, ready to be attached to a vertex array.
Throws:
Examples:
// Example 1. Create a dynamic vertex buffer 16 bytes in size.
var buffer = Buffer.createVertexBuffer({
context : context,
sizeInBytes : 16,
usage : BufferUsage.DYNAMIC_DRAW
});
// Example 2. Create a dynamic vertex buffer from three floating-point values.
// The data copied to the vertex buffer is considered raw bytes until it is
// interpreted as vertices using a vertex array.
var positionBuffer = buffer.createVertexBuffer({
context : context,
typedArray : new Float32Array([0, 0, 0]),
usage : BufferUsage.STATIC_DRAW
});
See: