Class StreamBuffer

java.lang.Object
lol.trq.helios.gl.StreamBuffer
All Implemented Interfaces:
AutoCloseable

public final class StreamBuffer extends Object implements AutoCloseable
Streamed vertex data, the one place that decides how per-frame uploads reach the GPU.

The strategy keeps a ring of array buffers. Each frame appends its data to one buffer, so no upload touches a region the GPU may still be reading. The write itself is glBufferSubData by default, or an unsynchronized glMapBufferRange with -Dhelios.stream=map; the fences make the mapping safe. endFrame() fences the buffer and moves to the next, waiting on that one's fence from ring frames ago (normally long signalled). A frame that outgrows its buffer orphans it and starts again at offset 0.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Buffers in the ring.
    static final String
    -Dhelios.stream: subdata (default) or map.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StreamBuffer(GlBackend gl, long capacity)
    Creates the ring lazily on first use.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the buffer the last upload went to.
    void
    Deletes the buffers and fences.
    void
    Fences this frame's buffer and moves to the next, waiting until the GPU has finished with it.
    int
    Returns how often a frame outgrew its buffer and orphaned it.
    long
    upload(ByteBuffer data, int alignment)
    Uploads data into the current buffer and leaves it bound to GlBackend.ARRAY_BUFFER.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • StreamBuffer

      public StreamBuffer(GlBackend gl, long capacity)
      Creates the ring lazily on first use.
      Parameters:
      gl - the backend
      capacity - bytes per buffer
  • Method Details

    • upload

      public long upload(ByteBuffer data, int alignment)
      Uploads data into the current buffer and leaves it bound to GlBackend.ARRAY_BUFFER.
      Parameters:
      data - the bytes, from position to limit; at most the capacity
      alignment - the start offset is a multiple of this, such as the vertex stride
      Returns:
      the byte offset the data starts at
    • buffer

      public int buffer()
      Returns the buffer the last upload went to.
      Returns:
      the buffer name, 0 before the first upload
    • endFrame

      public void endFrame()
      Fences this frame's buffer and moves to the next, waiting until the GPU has finished with it.
    • orphans

      public int orphans()
      Returns how often a frame outgrew its buffer and orphaned it.
      Returns:
      the count since creation
    • close

      public void close()
      Deletes the buffers and fences.
      Specified by:
      close in interface AutoCloseable