A Buffer stores all graphic elements and handles the data for an OpenGL-vertex buffer, for <T> it has to use a macro generated Element type.
Used by a Program all contained elements will be rendered by the corresponding shaders/textures and the same buffer can also be shared by several programs.

Constructor

@:value({ autoShrink : false, growSize : 0 })new(minSize:Int, growSize:Int = 0, autoShrink:Bool = false)

Creates a new Buffer instance.

Parameters:

minSize

how many elements a buffer should contain as a minimum

growSize

the size by which the buffer should grow when it is full

autoShrink

whether the buffer should also automatically shrink again (by the growsize)

Variables

read onlylength:Int

The number of elements inside the buffer.

Methods

addElement(element:T):T

Adds an element to the buffer for rendering and returns it.

Parameters:

element

Element instance

updateElement(element:T):Void

Updates the changes of an contained element to the rendering process.

Parameters:

element

Element instance

update():Void

Updates the complete buffer, so the changes of all contained elements at once to the rendering process.

removeElement(element:T):Void

Removes an element from the buffer, so it will not be rendered anymore.

Parameters:

element

Element instance

@:value({ notUseElementsLater : false, clearElementsRefs : false })clear(clearElementsRefs:Bool = false, notUseElementsLater:Bool = false):Void

Removes all elements from the buffer, so they will not be rendered anymore. For GC you can use clear(true) to set all element references to null (a bit faster by clear(true, true)).

Parameters:

clearElementsRefs

true to also set all element-references to null (false by default)

notUseElementsLater

true a bit faster if you can not need to add the elements to a Buffer again (false by default)

getElement(elementIndex:Int):T

Returns the element from buffer at index position.

Parameters:

elementIndex

index of the element inside the buffer

getElementIndex(element:T):Int

Returns the index position of an element inside the buffer.

Parameters:

element

Element instance

swapElements(element1:T, element2:T):Void

Swaps the order of two elements inside the buffer. This will change the drawing order if no z-index is used.

Parameters:

element1

first Element instance

element2

second Element instance