IndexBuffer
An index buffer stores index values into a VertexBuffer. Indexed graphical primitives can normally utilize less memory that unindexed primitives (if vertices are shared).
Typically, index buffers are set on Mesh objects.
// Create an index buffer holding 3 16-bit indices. The buffer is marked as
// static, hinting that the buffer will never be modified.
const indices = new UInt16Array([0, 1, 2]);
const indexBuffer = new pc.IndexBuffer(graphicsDevice,
pc.INDEXFORMAT_UINT16,
3,
pc.BUFFER_STATIC,
indices);
Summary
Methods
destroy | Frees resources associated with this index buffer. |
getFormat | Returns the data format of the specified index buffer. |
getNumIndices | Returns the number of indices stored in the specified index buffer. |
lock | Gives access to the block of memory that stores the buffer's indices. |
unlock | Signals that the block of memory returned by a call to the lock function is ready to be given to the graphics hardware. |
Details
Constructor
IndexBuffer(graphicsDevice, format, numIndices, [usage], [initialData])
Create a new IndexBuffer instance.
// Create an index buffer holding 3 16-bit indices. The buffer is marked as
// static, hinting that the buffer will never be modified.
const indices = new UInt16Array([0, 1, 2]);
const indexBuffer = new pc.IndexBuffer(graphicsDevice,
pc.INDEXFORMAT_UINT16,
3,
pc.BUFFER_STATIC,
indices);
Parameters
graphicsDevice | GraphicsDevice | The graphics device used to manage this index buffer. |
format | number | The type of each index to be stored in the index buffer. Can be: |
numIndices | number | The number of indices to be stored in the index buffer. |
usage | number | The usage type of the vertex buffer. Can be: Defaults to BUFFER_STATIC. |
initialData | ArrayBuffer | Initial data. If left unspecified, the index buffer will be initialized to zeros. |
Methods
destroy()
Frees resources associated with this index buffer.
getFormat()
Returns the data format of the specified index buffer.
Returns
numberThe data format of the specified index buffer. Can be:
getNumIndices()
Returns the number of indices stored in the specified index buffer.
Returns
numberThe number of indices stored in the specified index buffer.
lock()
Gives access to the block of memory that stores the buffer's indices.
Returns
ArrayBufferA contiguous block of memory where index data can be written to.
unlock()
Signals that the block of memory returned by a call to the lock function is ready to be given to the graphics hardware. Only unlocked index buffers can be set on the currently active device.