RenderBridge
abstract class RenderBridge
Implements: IRenderBridge
Known subtypes: GlRenderBridge, VulkanRenderBridge
Package: dev.joid.lib.bridge.render · Module: core · Source: RenderBridge.java
The base class of a render bridge, which keeps the matrices, the render state and the frame in Java and leaves the GPU calls to its subclass.
Description
Section titled “Description”A subclass implements the three clears, drawPrimitive, the three create... methods, suspend and raster, and calls requireFrame() before it touches the GPU in a frame.
Its drawPrimitive reads the render state and the samplers that the base class resolved, then draws, as Implement the render bridge shows.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| RenderBridge() protected | Creates the bridge with empty matrix stacks and a default render state. |
Methods
Section titled “Methods”Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
int | getStateDepth() | Returns the number of saved render states. |
PixelGrid | getPixelGrid() | Returns the screen pixel grid of the current matrices and viewport (Pixel alignment). |
MatrixStack | getModelView() | Returns the modelview matrix stack. |
MatrixStack | getProjection() | Returns the projection matrix stack. |
RenderState | getState() | Returns the live render state; popState() loads into this same instance, so a reference to it stays valid. |
boolean | isFrameActive() | If true, beginFrame() ran and endFrame() has not. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
void | screen(int width, int height) | Targets the window: no framebuffer, a viewport of that size in screen pixels, and an orthographic projection from the top-left corner with depth from 0 to 10000. |
void | quantize(double motionX, double motionY) | Translates the modelview by the distance between that motion and the same motion rounded to screen pixels; does nothing for no motion. |
void | pushState() | Pushes a copy of the render state. |
void | popState() | Loads the last pushed copy into the render state. |
void | clearDepth() | Calls clearDepthBuffer(). |
void | clearStencil() | Calls clearStencilBuffer() when the window is the target; framebuffers have no stencil. |
void | clearColor(float red, float green, float blue, float alpha) | Calls clearColorBuffer while color writes are on. |
void | draw(Primitive primitive, VertexBuffer buffer) | Picks the shader of the state, or the default shader, and calls drawPrimitive, unless the shader is not active, the buffer is empty or the viewport has no area. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | beginFrame() hook | Marks the frame as begun and calls beginFrameCommands(). |
void | endFrame() hook | Calls submitFrameCommands() and marks the frame as ended. |
void | beginFrameCommands() hook protected | JOID calls it at each beginFrame(); it does nothing by default. |
void | submitFrameCommands() hook protected | JOID calls it at each endFrame(), even when the frame failed; it does nothing by default. |
void | clearDepthBuffer() hook abstract protected | JOID calls it from clearDepth(). |
void | clearStencilBuffer() hook abstract protected | JOID calls it from clearStencil(), only when the window is the target. |
void | clearColorBuffer(float red, float green, float blue, float alpha) hook abstract protected | JOID calls it from clearColor, only while color writes are on. |
void | drawPrimitive(Primitive primitive, VertexBuffer buffer, IShader shader) hook abstract protected | JOID calls it from draw with a shader that is active and a buffer that is not empty. |
void | requireFrame() protected | Throws an IllegalStateException when no frame is begun, with the message that the render contract expects. |
SamplerBinding | resolveTexture() protected | Returns the texture of the state with its filter and wrap, or a 1×1 opaque white texture when the state has none. |
SamplerBinding | resolveSampler(UniformSampler sampler) protected | Returns the texture of the sampler with its filter and wrap, or else resolveTexture(); a wrap that canWrap refuses becomes CLAMP_TO_EDGE. |
IShader | getDefaultShader() protected | Returns the shader that draw uses when the state has none, created on first use. |
ITexture | getEmptyTexture() protected | Returns the 1×1 opaque white texture, created on first use. |
Inherited from IRenderBridge (2)
Creation details
Section titled “Creation details”RenderBridge
Section titled “RenderBridge”RenderBridge() protected
Creates the bridge with empty matrix stacks and a default render state.
Method details
Section titled “Method details”getStateDepth
Section titled “getStateDepth”int getStateDepth()
Returns the number of saved render states.
getPixelGrid
Section titled “getPixelGrid”PixelGrid getPixelGrid()
Returns the screen pixel grid of the current matrices and viewport (Pixel alignment).
getModelView
Section titled “getModelView”MatrixStack getModelView()
Returns the modelview matrix stack.
getProjection
Section titled “getProjection”MatrixStack getProjection()
Returns the projection matrix stack.
getState
Section titled “getState”RenderState getState()
Returns the live render state; popState() loads into this same instance, so a reference to it stays valid.
isFrameActive
Section titled “isFrameActive”boolean isFrameActive()
If true, beginFrame() ran and endFrame() has not.
screen
Section titled “screen”void screen(int width, int height)
Targets the window: no framebuffer, a viewport of that size in screen pixels, and an orthographic projection from the top-left corner with depth from 0 to 10000.
quantize
Section titled “quantize”void quantize(double motionX, double motionY)
Translates the modelview by the distance between that motion and the same motion rounded to screen pixels; does nothing for no motion.
pushState
Section titled “pushState”void pushState()
Pushes a copy of the render state.
popState
Section titled “popState”void popState()
Loads the last pushed copy into the render state.
clearDepth
Section titled “clearDepth”void clearDepth()
Calls clearDepthBuffer().
clearStencil
Section titled “clearStencil”void clearStencil()
Calls clearStencilBuffer() when the window is the target; framebuffers have no stencil.
clearColor
Section titled “clearColor”void clearColor(float red, float green, float blue, float alpha)
Calls clearColorBuffer while color writes are on.
void draw(Primitive primitive, VertexBuffer buffer)
Picks the shader of the state, or the default shader, and calls drawPrimitive, unless the shader is not active, the buffer is empty or the viewport has no area.
beginFrame
Section titled “beginFrame”void beginFrame() hook
Throws:
IllegalStateException: The JOID frame has already begun, call endFrame() first
Marks the frame as begun and calls beginFrameCommands().
Throws an IllegalStateException when a frame is already begun.
endFrame
Section titled “endFrame”void endFrame() hook
Calls submitFrameCommands() and marks the frame as ended.
Throws an IllegalStateException when no frame is begun.
beginFrameCommands
Section titled “beginFrameCommands”void beginFrameCommands() hook protected
JOID calls it at each beginFrame(); it does nothing by default.
Override it to start recording the commands of a frame, or to save the state of a host.
submitFrameCommands
Section titled “submitFrameCommands”void submitFrameCommands() hook protected
JOID calls it at each endFrame(), even when the frame failed; it does nothing by default.
Override it to submit the commands of the frame, or to give a host its state back.
clearDepthBuffer
Section titled “clearDepthBuffer”void clearDepthBuffer() hook abstract protected
JOID calls it from clearDepth().
Clear the depth of the current target to 1, with depth writes on.
clearStencilBuffer
Section titled “clearStencilBuffer”void clearStencilBuffer() hook abstract protected
JOID calls it from clearStencil(), only when the window is the target.
Clear the stencil to 0, with every bit writable.
clearColorBuffer
Section titled “clearColorBuffer”void clearColorBuffer(float red, float green, float blue, float alpha) hook abstract protected
JOID calls it from clearColor, only while color writes are on.
Clear the color of the current target to that color.
drawPrimitive
Section titled “drawPrimitive”void drawPrimitive(Primitive primitive, VertexBuffer buffer, IShader shader) hook abstract protected
JOID calls it from draw with a shader that is active and a buffer that is not empty.
Apply the whole current state, bind the samplers of the shader and draw the vertices; call requireFrame() first.
requireFrame
Section titled “requireFrame”void requireFrame() protected
Throws:
IllegalStateException: … draws only inside a frame and no frame has begun: draw between beginFrame() and endFrame(), from the draw of a UI or of the backend loop
Throws an IllegalStateException when no frame is begun, with the message that the render contract expects.
resolveTexture
Section titled “resolveTexture”SamplerBinding resolveTexture() protected
Returns the texture of the state with its filter and wrap, or a 1×1 opaque white texture when the state has none.
resolveSampler
Section titled “resolveSampler”SamplerBinding resolveSampler(UniformSampler sampler) protected
Returns the texture of the sampler with its filter and wrap, or else resolveTexture(); a wrap that canWrap refuses becomes CLAMP_TO_EDGE.
getDefaultShader
Section titled “getDefaultShader”IShader getDefaultShader() protected
Returns the shader that draw uses when the state has none, created on first use.
getEmptyTexture
Section titled “getEmptyTexture”ITexture getEmptyTexture() protected
Returns the 1×1 opaque white texture, created on first use.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
