Class VertexBuffer

java.lang.Object
com.codename1.gpu.VertexBuffer

public final class VertexBuffer extends Object

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.

  • Constructor Summary

    Constructors
    Constructor
    Description
    VertexBuffer(VertexFormat format, int vertexCount)
    Allocates a vertex buffer for the supplied format and vertex count.
  • Method Summary

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

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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: the interleaved vertex layout

      • vertexCount: 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: 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: the backend specific GPU resource handle