Package graphics.renderer
Class RenderBatch
java.lang.Object
graphics.renderer.RenderBatch
- All Implemented Interfaces:
Comparable<RenderBatch>
Azurite
A render batch is a collection of elements that are "batched" together into
a single object. This objects conglomerates the vertex data associated with
a specified primitive and prepares it to be rendered by it's associated
renderer. The pipeline of a RenderBatch object is as follows:
-
The
RenderBatchclass is extended by another class intended to be a batch of a certain primitive; for this example let's say it's a quadrilateral. -
The
Rendererclass is extended by a class intended to render the aforementioned quadrilateral render batch, where the type parameter is specified as ourRenderBatch. -
Now that all classes are set up, a quadrilateral render batch is created,
and several quadrilateral vertices are loaded into its
datafield via an overloadedloadVertexPropertiesfunction (which specifies if the quads will have color, what texture they would use, etc.) This is also when element indices are created, which specify in what order the GPU should process/render vertices. - This data is then submitted to the GPU, any associated metadata about the vertices and the quads are rendered.
graphics.renderer API pre-specifies
some useful renderers (hopefully so that most developers don't have to make their
own renderers.)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected float[]The data which is uploaded to the GPUprotected intThe internal data offsetbooleanIs this batch full due to filled up geometrybooleanIs this batch full due to having 8 textures occupied alreadyprotected final intMax number of primitives a batch can holdfinal PrimitiveThe primitive that this batch drawsprotected float[]Vertices of one primitiveThe List of submitted texturesprotected intVertex Array idprotected intVertex Buffer idprotected intHow many floats/ints in a single vertexprotected intHow many bytes for a single vertex -
Constructor Summary
ConstructorsConstructorDescriptionRenderBatch(int maxBatchSize, int zIndex, Primitive primitive, ShaderDatatype... attributes) -
Method Summary
Modifier and TypeMethodDescriptionintaddTexture(Texture texture) Add a texture to this batchvoidbind()Binds the vertex array and all the textures to the required slotsintvoiddelete()Delete the vertex array, vertex buffer and index buffer (element buffer)voidfinish()Finish setting batch data.intGet the number of vertices to be drawnbooleanhasTexture(Texture tex) voidinit()Create the GPU resources.voidPush four floats to the data arrayvoidpushFloat(float f) Push a float to the data arrayvoidpushInt(int i) Push an int to the data arrayvoidpushVec2(float x, float y) Push two floats to the data arrayvoidpushVec2(org.joml.Vector2f v) Push two floats to the data arrayvoidpushVec3(float x, float y, float z) Push three floats to the data arrayvoidpushVec3(org.joml.Vector3f v) Push three floats to the data arrayvoidpushVec4(float x, float y, float z, float w) Push four floats to the data arrayvoidpushVec4(org.joml.Vector4f v) Push four floats to the data arrayvoidstart()Get batch ready for submission of datavoidunbind()intzIndex()
-
Field Details
-
primitive
The primitive that this batch draws -
maxBatchSize
protected final int maxBatchSizeMax number of primitives a batch can hold -
isFull
public boolean isFullIs this batch full due to filled up geometry -
isFull_Textures
public boolean isFull_TexturesIs this batch full due to having 8 textures occupied already -
vertexCount
protected int vertexCountHow many floats/ints in a single vertex -
vertexSize
protected int vertexSizeHow many bytes for a single vertex -
primitiveVertices
protected float[] primitiveVerticesVertices of one primitive -
textures
The List of submitted textures -
data
protected float[] dataThe data which is uploaded to the GPU -
dataOffset
protected int dataOffsetThe internal data offset -
vao
protected int vaoVertex Array id -
vbo
protected int vboVertex Buffer id
-
-
Constructor Details
-
RenderBatch
- Parameters:
maxBatchSize- the maximum number of primitives in a batchzIndex- the zIndex of the batch. Used to sort the batches in order of which sprites appear above others.primitive- the primitiveattributes- attributes for the Vertex array
-
-
Method Details
-
init
public void init()Create the GPU resources. Generates a vao, a dynamic vbo, and a static buffer of indices. -
start
public void start()Get batch ready for submission of data -
finish
public void finish()Finish setting batch data. upload to gpu -
addTexture
Add a texture to this batch- Parameters:
texture- the texture to be rendered- Returns:
- the index at which texture is placed. The texture will be bound to this texture slot. Hence, set the texture attribute to this value.
-
bind
public void bind()Binds the vertex array and all the textures to the required slots -
unbind
public void unbind() -
delete
public void delete()Delete the vertex array, vertex buffer and index buffer (element buffer) -
getVertexCount
public int getVertexCount()Get the number of vertices to be drawn- Returns:
- the number of vertices to be drawn
-
hasTexture
-
zIndex
public int zIndex() -
compareTo
- Specified by:
compareToin interfaceComparable<RenderBatch>
-
pushFloat
public void pushFloat(float f) Push a float to the data array- Parameters:
f- the value
-
pushInt
public void pushInt(int i) Push an int to the data array- Parameters:
i- the value
-
pushVec2
public void pushVec2(float x, float y) Push two floats to the data array- Parameters:
x- x valuey- y value
-
pushVec2
public void pushVec2(org.joml.Vector2f v) Push two floats to the data array- Parameters:
v- the 2d vector
-
pushVec3
public void pushVec3(float x, float y, float z) Push three floats to the data array- Parameters:
x- x valuey- y valuez- z value
-
pushVec3
public void pushVec3(org.joml.Vector3f v) Push three floats to the data array- Parameters:
v- the 3d vector
-
pushVec4
public void pushVec4(float x, float y, float z, float w) Push four floats to the data array- Parameters:
x- x valuey- y valuez- z valuew- w value
-
pushVec4
public void pushVec4(org.joml.Vector4f v) Push four floats to the data array- Parameters:
v- the 4d vector
-
pushColor
Push four floats to the data array- Parameters:
c- the color
-