Class RenderBatch

java.lang.Object
graphics.renderer.RenderBatch
All Implemented Interfaces:
Comparable<RenderBatch>

public class RenderBatch extends Object implements 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:

  1. 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.
  2. The Renderer class is extended by a class intended to render the aforementioned quadrilateral render batch, where the type parameter is specified as our RenderBatch.
  3. 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 overloaded loadVertexProperties 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.
  4. This data is then submitted to the GPU, any associated metadata about the vertices and the quads are rendered.
Of course, one doesn't necessarily have to use quads for rendering; one could get as inventive as they'd like. The 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

    Fields
    Modifier and Type
    Field
    Description
    protected float[]
    The data which is uploaded to the GPU
    protected int
    The internal data offset
    boolean
    Is this batch full due to filled up geometry
    boolean
    Is this batch full due to having 8 textures occupied already
    protected final int
    Max number of primitives a batch can hold
    final Primitive
    The primitive that this batch draws
    protected float[]
    Vertices of one primitive
    protected List<Texture>
    The List of submitted textures
    protected int
    Vertex Array id
    protected int
    Vertex Buffer id
    protected int
    How many floats/ints in a single vertex
    protected int
    How many bytes for a single vertex
  • Constructor Summary

    Constructors
    Constructor
    Description
    RenderBatch(int maxBatchSize, int zIndex, Primitive primitive, ShaderDatatype... attributes)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Add a texture to this batch
    void
    Binds the vertex array and all the textures to the required slots
    int
     
    void
    Delete the vertex array, vertex buffer and index buffer (element buffer)
    void
    Finish setting batch data.
    int
    Get the number of vertices to be drawn
    boolean
     
    void
    Create the GPU resources.
    void
    Push four floats to the data array
    void
    pushFloat(float f)
    Push a float to the data array
    void
    pushInt(int i)
    Push an int to the data array
    void
    pushVec2(float x, float y)
    Push two floats to the data array
    void
    pushVec2(org.joml.Vector2f v)
    Push two floats to the data array
    void
    pushVec3(float x, float y, float z)
    Push three floats to the data array
    void
    pushVec3(org.joml.Vector3f v)
    Push three floats to the data array
    void
    pushVec4(float x, float y, float z, float w)
    Push four floats to the data array
    void
    pushVec4(org.joml.Vector4f v)
    Push four floats to the data array
    void
    Get batch ready for submission of data
    void
     
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • primitive

      public final Primitive primitive
      The primitive that this batch draws
    • maxBatchSize

      protected final int maxBatchSize
      Max number of primitives a batch can hold
    • isFull

      public boolean isFull
      Is this batch full due to filled up geometry
    • isFull_Textures

      public boolean isFull_Textures
      Is this batch full due to having 8 textures occupied already
    • vertexCount

      protected int vertexCount
      How many floats/ints in a single vertex
    • vertexSize

      protected int vertexSize
      How many bytes for a single vertex
    • primitiveVertices

      protected float[] primitiveVertices
      Vertices of one primitive
    • textures

      protected List<Texture> textures
      The List of submitted textures
    • data

      protected float[] data
      The data which is uploaded to the GPU
    • dataOffset

      protected int dataOffset
      The internal data offset
    • vao

      protected int vao
      Vertex Array id
    • vbo

      protected int vbo
      Vertex Buffer id
  • Constructor Details

    • RenderBatch

      public RenderBatch(int maxBatchSize, int zIndex, Primitive primitive, ShaderDatatype... attributes)
      Parameters:
      maxBatchSize - the maximum number of primitives in a batch
      zIndex - the zIndex of the batch. Used to sort the batches in order of which sprites appear above others.
      primitive - the primitive
      attributes - 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

      public int addTexture(Texture texture)
      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

      public boolean hasTexture(Texture tex)
    • zIndex

      public int zIndex()
    • compareTo

      public int compareTo(RenderBatch a)
      Specified by:
      compareTo in interface Comparable<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 value
      y - 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 value
      y - y value
      z - 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 value
      y - y value
      z - z value
      w - w value
    • pushVec4

      public void pushVec4(org.joml.Vector4f v)
      Push four floats to the data array
      Parameters:
      v - the 4d vector
    • pushColor

      public void pushColor(Color c)
      Push four floats to the data array
      Parameters:
      c - the color