struct Diorite::ArenaVertexBuffer(T)

Overview

Stack-allocated, pass-by-value vertex/color buffer view backed by a Slice(T) and an arena-allocated Pointer(Int32) element counter carved out of Lapis::Core::FrameArena.

Because @size_ptr points to a 4-byte Int32 slot in the FrameArena, passing an ArenaVertexBuffer(T) by value into GeometryBuilder, ChartBuilder, and TelemetryGraph methods mutates the shared element count in-place with strictly zero heap allocations and zero struct boxing.

Defined in:

diorite/core/frame_arena_batch.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(raw_slice : Slice(T), size_ptr : Pointer(Int32)) #

Class Method Detail

def self.from_arena(arena : Lapis::Core::FrameArena = Lapis::Core::FrameArena.current, capacity : Int32 = 1024, alignment : Int32 = Lapis::Core::FrameArena::DEFAULT_ALIGNMENT) : ArenaVertexBuffer(T) #

Carves an ArenaVertexBuffer(T) with #capacity elements and an arena-backed size counter directly from arena.


def self.from_parts(raw_slice : Slice(T), size_ptr : Pointer(Int32)) : ArenaVertexBuffer(T) #

Instance Method Detail

def <<(value : T) : self #

Fluent append operator (verts << pt), drop-in compatible with Array(T)#<<.


def [](index : Int32) : T #

def []=(index : Int32, value : T) : T #

def []?(index : Int32) : T | Nil #

def capacity : Int32 #

Maximum number of elements this buffer can hold.


def clear : self #

Resets the logical element count to 0 while retaining the underlying arena slice.


def each(& : T -> ) : Nil #

def empty? : Bool #

Returns true if no elements have been written.


def full? : Bool #

Returns true if the buffer has reached capacity.


def push(value : T) : Bool #

Appends a single element to the arena buffer if space remains.


def push_line(a : T, b : T) : Bool #

Appends a pair of elements (start/end vertices or colors for a line segment) atomically if at least 2 slots remain.


def raw_slice : Slice(T) #

def remaining : Int32 #

Remaining unwritten element slots.


def size : Int32 #

Current number of written elements.


def size_ptr : Pointer(Int32) #

def to_arena_buffer : Lapis::Core::ArenaBuffer(T) #

Returns a Lapis::Core::ArenaBuffer(T) snapshot of the written elements.


def to_slice : Slice(T) #

Returns a zero-allocation Slice(T) view over the written elements (0...size).


def to_unsafe : Pointer(T) #

def unsafe_fetch(index : Int32) : T #