Skip to content

IRenderBridge

interface IRenderBridge
Extends: IBridge
Known subtypes: RenderBridge
Package: dev.joid.lib.bridge.render · Module: core · Source: IRenderBridge.java

The bridge that draws every pixel of JOID: it clears targets, draws triangles and lines, and creates textures, framebuffers and shaders.

The core reads it from BridgeHandler.RENDER; DrawUtils goes through it. A backend extends RenderBridge, which implements the state, the matrices and the frame and leaves the GPU calls to write. Every method runs on the render thread. Let the host draw inside a frame reads it from a node to find the area of the node in screen pixels.

ReturnsSignatureSummary
booleanisFrameActive() defaultIf true, a frame is begun; true by default.
booleancanWrap(TextureWrap wrap) defaultIf true, the API samples with that wrap; true by default.
ReturnsSignatureSummary
voidwithState(Consumer body) defaultRuns the body between pushState() and popState(), even when it throws.
ReturnsSignatureSummary
voidscreen(int width, int height) abstractTargets 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) abstractMoves the modelview so that a node that moves by that offset, in the current coordinates, lands on whole screen pixels.
voidpushState() abstractSaves a copy of the render state.
voidpopState() abstractLoads the last saved copy back into the same render state instance.
intgetStateDepth() abstractReturns the number of saved render states.
voidclearDepth() abstractClears the depth of the current target to 1.
voidclearStencil() abstractClears the stencil of the window to 0; does nothing when a framebuffer is the target.
voidclearColor(float red, float green, float blue, float alpha) abstractClears the color of the current target, each channel from 0F to 1F; does nothing while color writes are off.
voiddraw(Primitive primitive, VertexBuffer buffer) abstractDraws the vertices as triangles or lines with the current shader, or the default one, and the current state.
ITexturecreateTexture() abstractReturns an empty texture, to allocate then upload.
IFrameBuffercreateFrameBuffer(int width, int height) abstractReturns a framebuffer of that size in pixels, with a color texture and a depth buffer.
IShadercreateShader(ShaderSource vertex, ShaderSource fragment, BlendState blend) abstractReturns a shader for the two parsed stages and that blend state.
voidsuspend(Runnable draw) abstractRuns a drawing of the host with its own state, inside a JOID frame: the state and the pass in progress are set aside until the drawing returns.
voidraster(IFrameBuffer target, int width, int height, Runnable draw) abstractRuns a drawing of the host into a framebuffer of JOID at that pixel size, for DrawUtils.RASTER.
RenderStategetState() abstractReturns the live render state.
PixelGridgetPixelGrid() abstractReturns the screen pixel grid of the current matrices and viewport.
MatrixStackgetModelView() abstractReturns the modelview matrix stack.
MatrixStackgetProjection() abstractReturns the projection matrix stack.
voidbeginFrame() hook defaultBegins a frame; drawing and clearing happen only between beginFrame() and endFrame().
voidendFrame() hook defaultEnds the frame and submits what it recorded; does nothing by default.

boolean isFrameActive() default

If true, a frame is begun; true by default.

boolean canWrap(TextureWrap wrap) default

If true, the API samples with that wrap; true by default. When it returns false, JOID samples with CLAMP_TO_EDGE, and emulates CLAMP_TO_BORDER in the shaders.

void withState(Consumer<IRenderBridge> body) default

Runs the body between pushState() and popState(), even when it throws.

void screen(int width, int height) abstract

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. UIBridgeRegistry.frame calls it when the window changes size.

void quantize(double motionX, double motionY) abstract

Moves the modelview so that a node that moves by that offset, in the current coordinates, lands on whole screen pixels.

void pushState() abstract

Saves a copy of the render state.

void popState() abstract

Loads the last saved copy back into the same render state instance.

int getStateDepth() abstract

Returns the number of saved render states.

void clearDepth() abstract

Clears the depth of the current target to 1.

void clearStencil() abstract

Clears the stencil of the window to 0; does nothing when a framebuffer is the target.

void clearColor(float red, float green, float blue, float alpha) abstract

Clears the color of the current target, each channel from 0F to 1F; does nothing while color writes are off.

void draw(Primitive primitive, VertexBuffer buffer) abstract

Draws the vertices as triangles or lines with the current shader, or the default one, and the current state. Skips the draw when the shader is not active, the buffer is empty or the viewport has no area.

ITexture createTexture() abstract

Returns an empty texture, to allocate then upload.

IFrameBuffer createFrameBuffer(int width, int height) abstract

Returns a framebuffer of that size in pixels, with a color texture and a depth buffer.

IShader createShader(ShaderSource vertex, ShaderSource fragment, BlendState blend) abstract

Returns a shader for the two parsed stages and that blend state.

void suspend(Runnable draw) abstract

Runs a drawing of the host with its own state, inside a JOID frame: the state and the pass in progress are set aside until the drawing returns.

void raster(IFrameBuffer target, int width, int height, Runnable draw) abstract

Runs a drawing of the host into a framebuffer of JOID at that pixel size, for DrawUtils.RASTER. Throws an IllegalStateException outside a frame.

RenderState getState() abstract

Returns the live render state.

PixelGrid getPixelGrid() abstract

Returns the screen pixel grid of the current matrices and viewport.

MatrixStack getModelView() abstract

Returns the modelview matrix stack.

MatrixStack getProjection() abstract

Returns the projection matrix stack.

void beginFrame() hook default

Begins a frame; drawing and clearing happen only between beginFrame() and endFrame(). Does nothing by default.

void endFrame() hook default

Ends the frame and submits what it recorded; does nothing by default.


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