Automates buffer segmentation when rendering 2D geometry with multiple unique textures.
Primary use-case is to allow usage of multiple textures without the need to manually manage them. Causes extra draw call each time a texture is swapped. Due to that, for production it is recommended to combine assets in atlases for optimal performance.
Depending on geometry type, vertex count should be in groups of 4 vertices per quad or 3 indices per triangle.
Constructor
Variables
read onlycurrentTexture:Texture
Current active texture of the BatchDrawState.
Represents the most recent texture that was set with setTile
or setTexture
.
Always null after state initialization or after clear
call.
Methods
inlineadd(count:Int):Void
Add vertices to the state using currently active texture. Should be called when rendering buffers add more data in order to properly render the geometry.
Parameters:
count | The amount of vertices to add. |
---|
clear():Void
Resets the BatchDrawState by removing all texture references and zeroing vertex counter.
drawIndexed(ctx:RenderContext, buffer:Buffer, indices:Indexes, offset:Int = 0, length:Int = -1):Void
Renders given indices as a set of triangles. Index data should be in groups of 3 vertices per quad.
Parameters:
ctx | The render context which performs the rendering. Rendering object should call |
---|---|
buffer | The vertex buffer used to render the state. |
indices | Vertex indices used to render the state. |
offset | An optional starting offset of the buffer to render in triangles. |
length | An optional maximum limit of triangles to render.
When |
drawQuads(ctx:RenderContext, buffer:Buffer, offset:Int = 0, length:Int = -1):Void
Renders given buffer as a set of quads. Buffer data should be in groups of 4 vertices per quad.
Parameters:
ctx | The render context which performs the rendering. Rendering object should call |
---|---|
buffer | The quad buffer used to render the state. |
offset | An optional starting offset of the buffer to render in triangles (2 per quad). |
length | An optional maximum limit of triangles to render.
When |
setTexture(texture:Texture):Void
Switches currently active texture to the given texture
if it differs and splits the render state.
Parameters:
texture | The texture that should be used for the next set of vertices. Does nothing if |
---|