BatchBuilder2D

class BatchBuilder2D(val ctx: RenderContext, val reqMaxQuads: Int = DEFAULT_BATCH_QUADS)

Allows to draw quads and sprites buffering the geometry to limit the draw batches executed calling AG (Accelerated Graphics). This class handles a vertex structure of: x, y, u, v, colorMul. Allowing to draw texturized and tinted primitives.

You should call: drawQuad, drawQuadFast, drawNinePatch, drawVertices for buffering the geometries.

For performance the actual drawing/rendering doesn't happen until the flush method is called (normally that happens automatically). Then the engine will call flush when required, automatically once the buffer is filled, at the end of the frame, or when RenderContext.flush is executed by other renderers.

Constructors

Link copied to clipboard
constructor(ctx: RenderContext, reqMaxQuads: Int = DEFAULT_BATCH_QUADS)

Types

Link copied to clipboard
Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val ag: AG
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The current color mask state. If you change it, you must call the flush method to ensure everything has been drawn.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Maximum number of indices that can be buffered here in a single batch. It depens on the maxQuads parameter

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Maximum number of vertices that can be buffered here in a single batch. It depens on the maxQuads parameter

Link copied to clipboard
Link copied to clipboard

Maximum number of quads that could be drawn in a single batch. Bigger numbers will increase memory usage, but might reduce the number of batches per frame when using the same texture and properties.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The current stencil state. If you change it, you must call the flush method to ensure everything has been drawn.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun _addQuadVerticesFastNormal(vp: Int, vd: Buffer, x0: Float, y0: Float, x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, tx0: Float, ty0: Float, tx1: Float, ty1: Float, colorMul: Int, texIndex: Int = currentTexIndex): Int
Link copied to clipboard
fun _addQuadVerticesFastNormalNonRotated(vp: Int, vd: Buffer, x0: Float, y0: Float, x1: Float, y1: Float, tx0: Float, ty0: Float, tx1: Float, ty1: Float, colorMul: Int, texIndex: Int = currentTexIndex): Int
Link copied to clipboard
fun _addVertex(vd: Buffer, vp: Int, x: Float, y: Float, u: Float, v: Float, colorMul: Int, texIndex: Int = currentTexIndex): Int
Link copied to clipboard
inline fun addIndex(idx: Int)
Link copied to clipboard
inline fun addIndexRelative(idx: Int)
Link copied to clipboard
fun addQuadIndices(vc: Int = vertexCount)
Link copied to clipboard
fun addQuadIndicesBatch(batchSize: Int)
Link copied to clipboard
fun addQuadVerticesFastNormal(x0: Float, y0: Float, x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, tx0: Float, ty0: Float, tx1: Float, ty1: Float, colorMul: Int, texIndex: Int = currentTexIndex)
Link copied to clipboard
fun addVertex(x: Float, y: Float, u: Float, v: Float, colorMul: RGBA, texIndex: Int = currentTexIndex)
Link copied to clipboard
Link copied to clipboard
fun drawQuad(tex: TextureCoords, x: Float = 0.0f, y: Float = 0.0f, width: Float = tex.width.toFloat(), height: Float = tex.height.toFloat(), m: Matrix = Matrix.IDENTITY, filtering: Boolean = true, colorMul: RGBA = Colors.WHITE, blendMode: BlendMode = BlendMode.NORMAL, program: Program? = null)

fun drawQuad(tex: TextureCoords, x: Float, y: Float, width: Float, height: Float, m: Matrix = Matrix.IDENTITY, filtering: Boolean = true, colorMul: RGBA = Colors.WHITE, blendMode: BlendMode = BlendMode.NORMAL, program: Program? = null, unit: Unit = Unit)

Draws a textured tex quad at x, y and size widthxheight.

Link copied to clipboard
fun drawQuadFast(x: Float, y: Float, width: Float, height: Float, m: Matrix, tex: BmpCoords, colorMul: RGBA)
fun drawQuadFast(x0: Float, y0: Float, x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, tx0: Float, ty0: Float, tx1: Float, ty1: Float, colorMul: RGBA, texIndex: Int = currentTexIndex)

fun drawQuadFast(x0: Float, y0: Float, x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float, tex: BmpCoords, colorMul: RGBA, texIndex: Int = currentTexIndex)

Draws/buffers a textured (tex) and colored colorMul quad with this shape:

Link copied to clipboard
fun drawVertices(array: TexturedVertexArray, matrix: Matrix, vcount: Int = array.vcount, icount: Int = array.icount, texIndex: Int = currentTexIndex)

Draws/buffers a set of textured and colorized array of vertices array with the current state previously set by calling setStateFast.

inline fun drawVertices(array: TexturedVertexArray, tex: TextureBase, smoothing: Boolean, blendMode: BlendMode, vcount: Int = array.vcount, icount: Int = array.icount, program: Program? = null, matrix: Matrix = Matrix.NIL)

Draws/buffers a set of textured and colorized array of vertices array with the specified texture tex and optionally smoothing it and an optional program.

Link copied to clipboard
fun ensure(indices: Int, vertices: Int): Boolean
Link copied to clipboard
inline fun flush(block: () -> Unit)
fun flush(uploadVertices: Boolean = true, uploadIndices: Boolean = true)
Link copied to clipboard
fun flushPartial(uploadVertices: Boolean = true, uploadIndices: Boolean = true)

When there are vertices pending, this performs a AG.draw call flushing all the buffered geometry pending to draw

Link copied to clipboard
Link copied to clipboard
fun readVertex(n: Int, out: VertexInfo = VertexInfo()): VertexInfo
Link copied to clipboard
Link copied to clipboard
inline fun <T> scissor(scissor: AGScissor, block: () -> T): T
Link copied to clipboard
inline fun setStateFast(tex: AGTexture?, smoothing: Boolean, blendMode: BlendMode, program: Program?, icount: Int, vcount: Int)
fun setStateFast(tex: TextureBase, smoothing: Boolean, blendMode: BlendMode, program: Program?, icount: Int, vcount: Int)

Sets the current texture tex, smoothing, blendMode and program that will be used by the following drawing calls not specifying these attributes.

fun setStateFast(tex: Bitmap, smoothing: Boolean, blendMode: BlendMode, program: Program?, icount: Int, vcount: Int)
fun setStateFast(tex: BmpSlice, smoothing: Boolean, blendMode: BlendMode, program: Program?, icount: Int, vcount: Int)
Link copied to clipboard
inline fun setViewMatrixTemp(matrix: Matrix, crossinline callback: () -> Unit)

Executes callback while setting temporarily the view matrix to matrix

Link copied to clipboard
fun simulateBatchStats(vertexCount: Int)
Link copied to clipboard
inline fun <T> temporalTextureUnit(sampler: Sampler, tex: AGTexture?, info: AGTextureUnitInfo = AGTextureUnitInfo.DEFAULT, block: () -> T): T
inline fun <T> temporalTextureUnit(sampler1: Sampler, tex1: AGTexture?, sampler2: Sampler, tex2: AGTexture?, info: AGTextureUnitInfo = AGTextureUnitInfo.DEFAULT, block: () -> T): T
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun use(block: (BatchBuilder2D) -> Unit)