Class Renderer

java.lang.Object
graphics.renderer.Renderer
Direct Known Subclasses:
DebugRenderer, DefaultRenderer, LightmapRenderer, TextRenderer

public abstract class Renderer extends Object

Azurite

A renderer is responsible for taking collected data of a specified type, formatting it for a selected shader, and rendering it. Every renderer has an associated RenderBatch to render. The pipeline for processing the metadata of a render batch and drawing batched data is as follows:

  1. The Renderer class is extended by another class specified to render a certain type of data batch; for the sake of example, let's use a quadrilateral render batch. A shader is also created with the same vertex properties specified in the render batch.
  2. A Shader object is then created, encapsulating the uniforms and layouts of the shader's source code. It is then attached to this renderer.
  3. Based on the uniforms of the shader, various bits of data is submitted to the GPU, like camera position, pointlight position, etc.
  4. After shader parsing and handling, the data is rendered.
A renderer also specifies a framebuffer, which acts as, well, a buffer which GPU pixel data is stored in to be drawn all at once on the monitor.

See Also:
  • Field Details

    • textureSlots

      protected final int[] textureSlots
      Texture slots to be uploaded to the shader. You don't have to upload them in your custom renderer.
    • batches

      protected final List<RenderBatch> batches
      A list of batches
    • framebuffer

      public Framebuffer framebuffer
      Framebuffer to which this renderer will render
    • noRebuffer

      protected boolean noRebuffer
  • Constructor Details

    • Renderer

      public Renderer()
  • Method Details

    • createShader

      protected abstract Shader createShader()
      Create a shader
      Returns:
      the created shader
    • createFramebuffer

      protected abstract Framebuffer createFramebuffer()
      Create a framebuffer
      Returns:
      the created fbo
    • createBatch

      protected abstract RenderBatch createBatch(int zIndex)
      Create a new Batch with appropriate parameters
      Returns:
      a new batch
    • uploadUniforms

      protected abstract void uploadUniforms(Shader shader)
      Upload the required uniforms
      Parameters:
      shader - the shader
    • rebuffer

      protected abstract void rebuffer()
      Rebuffer all the data into batches
    • getAvailableBatch

      public RenderBatch getAvailableBatch(Texture texture, int reqdZ)
      Get the batch in which the current data can be submitted Has to be called PER PRIMITIVE SUBMISSION
      Parameters:
      texture -
    • add

      public void add(GameObject gameObject)
      Add a gameObject to the renderer, and if it contains a component that affects rendering, like a sprite or light, those are added to a batch.
      Parameters:
      gameObject - the GameObject with renderable components
    • remove

      public void remove(GameObject gameObject)
      Remove a gameObject from the renderer if it contains the component that gets rendered.
      Parameters:
      gameObject - the GameObject with renderable componentsl
    • init

      public void init()
      Creates the renderer's shader and framebuffer
    • fetchColorAttachment

      public Texture fetchColorAttachment(int index)
      Get a color attachment texture from the framebuffer
      Parameters:
      index - index of the required color attachment texture. Will return -1 if there is no attachment at that index.
      Returns:
      the texture ID of the attachment
    • render

      public void render()
      Loop through all render batches and render them
    • prepare

      protected abstract void prepare()
      Prepare for rendering. Do anything like setting background here.
    • clean

      public void clean()
      Delete all the Batches.