Skip to content

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.

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.

ReturnsSignatureSummary
RenderBridge() protectedCreates the bridge with empty matrix stacks and a default render state.

ReturnsSignatureSummary
intgetStateDepth()Returns the number of saved render states.
PixelGridgetPixelGrid()Returns the screen pixel grid of the current matrices and viewport (Pixel alignment).
MatrixStackgetModelView()Returns the modelview matrix stack.
MatrixStackgetProjection()Returns the projection matrix stack.
RenderStategetState()Returns the live render state; popState() loads into this same instance, so a reference to it stays valid.
booleanisFrameActive()If true, beginFrame() ran and endFrame() has not.
ReturnsSignatureSummary
voidscreen(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.
voidquantize(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.
voidpushState()Pushes a copy of the render state.
voidpopState()Loads the last pushed copy into the render state.
voidclearDepth()Calls clearDepthBuffer().
voidclearStencil()Calls clearStencilBuffer() when the window is the target; framebuffers have no stencil.
voidclearColor(float red, float green, float blue, float alpha)Calls clearColorBuffer while color writes are on.
voiddraw(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.
ReturnsSignatureSummary
voidbeginFrame() hookMarks the frame as begun and calls beginFrameCommands().
voidendFrame() hookCalls submitFrameCommands() and marks the frame as ended.
voidbeginFrameCommands() hook protectedJOID calls it at each beginFrame(); it does nothing by default.
voidsubmitFrameCommands() hook protectedJOID calls it at each endFrame(), even when the frame failed; it does nothing by default.
voidclearDepthBuffer() hook abstract protectedJOID calls it from clearDepth().
voidclearStencilBuffer() hook abstract protectedJOID calls it from clearStencil(), only when the window is the target.
voidclearColorBuffer(float red, float green, float blue, float alpha) hook abstract protectedJOID calls it from clearColor, only while color writes are on.
voiddrawPrimitive(Primitive primitive, VertexBuffer buffer, IShader shader) hook abstract protectedJOID calls it from draw with a shader that is active and a buffer that is not empty.
voidrequireFrame() protectedThrows an IllegalStateException when no frame is begun, with the message that the render contract expects.
SamplerBindingresolveTexture() protectedReturns the texture of the state with its filter and wrap, or a 1×1 opaque white texture when the state has none.
SamplerBindingresolveSampler(UniformSampler sampler) protectedReturns the texture of the sampler with its filter and wrap, or else resolveTexture(); a wrap that canWrap refuses becomes CLAMP_TO_EDGE.
IShadergetDefaultShader() protectedReturns the shader that draw uses when the state has none, created on first use.
ITexturegetEmptyTexture() protectedReturns the 1×1 opaque white texture, created on first use.
Inherited from IRenderBridge (2)

canWrap · withState

RenderBridge() protected

Creates the bridge with empty matrix stacks and a default render state.

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.

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.

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.

void endFrame() hook

Calls submitFrameCommands() and marks the frame as ended. Throws an IllegalStateException when no frame is begun.

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.

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.

void clearDepthBuffer() hook abstract protected

JOID calls it from clearDepth(). Clear the depth of the current target to 1, with depth writes on.

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.

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.

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.

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.

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.


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

Report a problem with this page