Package graphics.renderer
Class Renderer
java.lang.Object
graphics.renderer.Renderer
- Direct Known Subclasses:
DebugRenderer,DefaultRenderer,LightmapRenderer,TextRenderer
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:
-
The
Rendererclass 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. -
A
Shaderobject is then created, encapsulating theuniforms andlayouts of the shader's source code. It is then attached to this renderer. -
Based on the
uniforms of the shader, various bits of data is submitted to the GPU, like camera position, pointlight position, etc. - After shader parsing and handling, the data is rendered.
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final List<RenderBatch>A list of batchesFramebuffer to which this renderer will renderprotected booleanprotected final int[]Texture slots to be uploaded to the shader. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(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.voidclean()Delete all the Batches.protected abstract RenderBatchcreateBatch(int zIndex) Create a new Batch with appropriate parametersprotected abstract FramebufferCreate a framebufferprotected abstract ShaderCreate a shaderfetchColorAttachment(int index) Get a color attachment texture from the framebuffergetAvailableBatch(Texture texture, int reqdZ) Get the batch in which the current data can be submitted Has to be called PER PRIMITIVE SUBMISSIONvoidinit()Creates the renderer's shader and framebufferprotected abstract voidprepare()Prepare for rendering.protected abstract voidrebuffer()Rebuffer all the data into batchesvoidremove(GameObject gameObject) Remove a gameObject from the renderer if it contains the component that gets rendered.voidrender()Loop through all render batches and render themprotected abstract voiduploadUniforms(Shader shader) Upload the required uniforms
-
Field Details
-
textureSlots
protected final int[] textureSlotsTexture slots to be uploaded to the shader. You don't have to upload them in your custom renderer. -
batches
A list of batches -
framebuffer
Framebuffer to which this renderer will render -
noRebuffer
protected boolean noRebuffer
-
-
Constructor Details
-
Renderer
public Renderer()
-
-
Method Details
-
createShader
Create a shader- Returns:
- the created shader
-
createFramebuffer
Create a framebuffer- Returns:
- the created fbo
-
createBatch
Create a new Batch with appropriate parameters- Returns:
- a new batch
-
uploadUniforms
Upload the required uniforms- Parameters:
shader- the shader
-
rebuffer
protected abstract void rebuffer()Rebuffer all the data into batches -
getAvailableBatch
Get the batch in which the current data can be submitted Has to be called PER PRIMITIVE SUBMISSION- Parameters:
texture-
-
add
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
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
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.
-