public final class VertexBuffer

  1. Object
  2. VertexBuffer

Holds interleaved vertex data for a Mesh. The backing store is allocated through the platform SIMD allocator (Simd.allocFloat(int)) so that on ParparVM the array lives at a fixed, aligned native address and can be handed to the GPU with no intermediate copy. On other platforms the same array is an ordinary float[].

Mutate the data through setData or by writing into getData() and then calling setDirty(); the bound GraphicsDevice re-uploads dirty buffers before the next draw.

Constructors

public VertexBuffer(VertexFormat format, int vertexCount)Allocates a vertex buffer for the supplied format and vertex count.

Methods

public VertexFormat getFormat()Returns the vertex layout of this buffer.
public int getVertexCount()Returns the number of vertices this buffer holds.
public int getFloatCount()Returns the number of meaningful floats in the backing array (vertexCount * format.getFloatsPerVertex()).
public float[] getData()Returns the SIMD aligned backing array.
public void setData(float[] src)Copies src into the backing array starting at float index 0 and marks the buffer dirty.
public void setDirty()Marks the buffer as needing re-upload to the GPU before the next draw.
public boolean isDirty()Returns true if the buffer has pending changes that must be uploaded.
public void clearDirty()Clears the dirty flag.
public Object getHandle()Returns the opaque backend GPU handle, or null if not yet uploaded.
public void setHandle(Object handle)Stores the opaque backend GPU handle.

Inherited methods

Constructor details

VertexBuffer

public VertexBuffer(VertexFormat format, int vertexCount)
Allocates a vertex buffer for the supplied format and vertex count. The backing array is SIMD aligned. Prefer creating buffers through GraphicsDevice.createVertexBuffer(VertexFormat, int) so the GPU handle is tracked by the device.

Parameters

format VertexFormat
the interleaved vertex layout
vertexCount int
the number of vertices the buffer can hold

Method details

getFormat

public VertexFormat getFormat()
Returns the vertex layout of this buffer.

getVertexCount

public int getVertexCount()
Returns the number of vertices this buffer holds.

getFloatCount

public int getFloatCount()
Returns the number of meaningful floats in the backing array (vertexCount * format.getFloatsPerVertex()). The array itself may be padded to a larger SIMD friendly size.

getData

public float[] getData()
Returns the SIMD aligned backing array. Write vertex floats directly here for maximum throughput, then call setDirty().

setData

public void setData(float[] src)
Copies src into the backing array starting at float index 0 and marks the buffer dirty.

Parameters

src float[]
the interleaved float data; length must not exceed the buffer

setDirty

public void setDirty()
Marks the buffer as needing re-upload to the GPU before the next draw.

isDirty

public boolean isDirty()
Returns true if the buffer has pending changes that must be uploaded. Intended for backend use.

clearDirty

public void clearDirty()
Clears the dirty flag. Intended for backend use after an upload.

getHandle

public Object getHandle()
Returns the opaque backend GPU handle, or null if not yet uploaded. Intended for backend use.

setHandle

public void setHandle(Object handle)
Stores the opaque backend GPU handle. Intended for backend use.

Parameters

handle Object
the backend specific GPU resource handle