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
RenderBatch
class 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
Renderer
class 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
data
field via an overloadedloadVertexProperties
function (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
Modifier and TypeFieldDescriptionprotected float[]
The data which is uploaded to the GPUprotected int
The internal data offsetboolean
Is this batch full due to filled up geometryboolean
Is this batch full due to having 8 textures occupied alreadyprotected final int
Max number of primitives a batch can holdfinal Primitive
The primitive that this batch drawsprotected float[]
Vertices of one primitiveThe List of submitted texturesprotected int
Vertex Array idprotected int
Vertex Buffer idprotected int
How many floats/ints in a single vertexprotected int
How many bytes for a single vertex -
Constructor Summary
ConstructorDescriptionRenderBatch
(int maxBatchSize, int zIndex, Primitive primitive, ShaderDatatype... attributes) -
Method Summary
Modifier and TypeMethodDescriptionint
addTexture
(Texture texture) Add a texture to this batchvoid
bind()
Binds the vertex array and all the textures to the required slotsint
void
delete()
Delete the vertex array, vertex buffer and index buffer (element buffer)void
finish()
Finish setting batch data.int
Get the number of vertices to be drawnboolean
hasTexture
(Texture tex) void
init()
Create the GPU resources.void
Push four floats to the data arrayvoid
pushFloat
(float f) Push a float to the data arrayvoid
pushInt
(int i) Push an int to the data arrayvoid
pushVec2
(float x, float y) Push two floats to the data arrayvoid
pushVec2
(org.joml.Vector2f v) Push two floats to the data arrayvoid
pushVec3
(float x, float y, float z) Push three floats to the data arrayvoid
pushVec3
(org.joml.Vector3f v) Push three floats to the data arrayvoid
pushVec4
(float x, float y, float z, float w) Push four floats to the data arrayvoid
pushVec4
(org.joml.Vector4f v) Push four floats to the data arrayvoid
start()
Get batch ready for submission of datavoid
unbind()
int
zIndex()
-
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:
compareTo
in 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
-