GrowableMappableRingBuffer

class GrowableMappableRingBuffer @JvmOverloads constructor(val label: String, val usage: Int, val growPolicy: GrowableMappableRingBuffer.GrowPolicy = GrowPolicy.DEFAULT)

A growable GpuBuffer wrapper for streaming GPU data (e.g. dynamic VBO/IBO uploads).

This class acts like a simple linear allocator on top of MappableRingBuffer: multiple uploads can append to the current buffer until it runs out of space, then it automatically rotates to the next backing buffer. If the requested upload is larger than the backing buffer size, the ring is grown.

Behavior for each upload(data):

  1. If there is enough space after the last write, append to the current buffer.

  2. If the buffer is large enough but the remaining space is not, rotate() and write from offset 0.

  3. If the entire ring buffer is too small, grow it and write from offset 0.

Author

MukjepScarlet

Constructors

Link copied to clipboard
constructor(label: String, usage: Int, growPolicy: GrowableMappableRingBuffer.GrowPolicy = GrowPolicy.DEFAULT)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface GrowPolicy

Properties

Link copied to clipboard
Link copied to clipboard
val usage: Int

Functions

Link copied to clipboard
fun clear()

Clear the ring buffer and release all GPU resources.

Link copied to clipboard
fun rotate()

Manually rotate the ring buffer to the next backing buffer and reset the current write offset. This is useful for per-frame usage patterns where each frame starts writing from a fresh buffer.

Link copied to clipboard
fun upload(data: ByteBuffer): GpuBufferSlice

Upload data into the ring buffer and return a slice covering the written region.