Skip to content

Render pipeline

Every pixel of JOID, from a rectangle to a 3D model, reaches the render bridge through one method: draw(primitive, buffer). This page follows a drawing from the node to the API of the backend, then describes each piece of data the bridge reads. The contract itself is on Render bridge; the user side of drawing is on Drawing shapes and text.

Two columns of boxes linked by arrows, from top to bottom. The left column: Nodes and DrawUtils describe vertices, the Tessellator turns them into TRIANGLES or LINES, RenderBridge.draw picks the shader, then the highlighted drawPrimitive hook makes one draw call; a box below it, read at each draw, lists getState(), the matrices and resolveSampler(). The right column: JOID GLSL, one source per stage, parsed into a ShaderSource, translated once by the Shader, then given to the highlighted compileProgram hook in your dialect.

Your two hooks: drawPrimitive receives each draw with the state of that moment, compileProgram receives each shader once, translated from JOID GLSL.

For the render bridge, a frame of UIBridgeRegistry.frame is screen(...) on a resize, the updates of the UIs outside the frame, then beginFrame(), the draws of every UI bridge and endFrame() (Render bridge, The frame lifecycle).

Nodes and the drawing API never build GPU commands: they describe vertices to the Tessellator, which turns every mode into one of the two primitives that a bridge draws.

Mode of the tessellatorReaches the bridge as
TRIANGLESTRIANGLES
QUADSTRIANGLES, two per quad
POLYGONTRIANGLES, a fan from the first vertex
LINES, LINE_STRIP, LINE_LOOPLINES, two vertices per segment
any line mode with a width other than 1 or smoothing onTRIANGLES, drawn by the line variant of the shader

RenderBridge.draw then picks the shader and calls your RenderBridge.drawPrimitive with the primitive, the buffer and the shader.

A VertexBuffer holds getCount() vertices of 32 bytes each, in a direct ByteBuffer in native order. VertexAttribute describes the layout:

AttributeLocationOffsetContent
POSITION003 × float
TEXTURE_COORDINATE1122 × float
COLOR2204 × unsigned byte, normalized, RGBA
NORMAL3243 × signed byte, normalized

Bytes 27 to 31 are padding. isTexture(), isColor() and isNormal() tell which attributes the drawing filled, and a missing attribute takes a default:

  • texture coordinates (0, 0) and normal (0, 0, 1): on OpenGL, constant vertex attributes; on an API without them, VertexFill.complete copies the buffer and writes the defaults;
  • color: the current color of the state, which the translated shader picks when the buffer has no color, so the bridge does nothing.

RenderState is the whole fixed-function state of a draw, held by RenderBridge.getState and changed by the core between draws.

PropertyDefaultMeaning
color(red, green, blue, alpha)opaque whiteThe color of the vertices without a color.
blendBlendState.DISABLEDEquation and factors; BlendState.NORMAL and BlendState.PREMULTIPLIED are the usual ones.
depthTest, depthWriteoff, onDepth comparison LESS, and depth writes.
colorWriteonWrites to the color buffer.
culloffBack-face culling, counter-clockwise front faces.
stencilStencilState.DISABLEDFunction, reference, mask and operations, for the screen only.
alphaCutoff0FDiscards the fragments whose alpha is at most this value; 0F turns the test off.
lightingoffDiffuse lighting from the normals, applied by the shaders.
lineWidth, lineSmooth1F, offRead by the tessellator, which turns wide or smooth lines into triangles.
viewport(x, y, width, height)set by screenThe viewport, in pixels of the target.
frameBuffernullThe target framebuffer; null is the screen.
texture, textureFilter, textureWrap, textureMipmapnone, NEAREST, REPEAT, onThe texture of the state, how to sample it, and whether its mip levels may be used.
shadernullThe bound shader; null draws with the default one.

Several values never reach a draw as such: the shader turns the alpha cutoff, the line width and the current color into uniforms (Shader translation).

Read RenderBridge.getProjection and RenderBridge.getModelView at the draw; Shader.builtins writes them, with the normal matrix, into the uniforms of the shader.

The clip space is the one of OpenGL: x and y from -1 to 1, with y up. An API whose y goes down flips its viewport, and the depth range is on Depth.

In drawPrimitive, bind resolveSampler(sampler) on the unit of each sampler that the shader declares (Render bridge gives its fallbacks). Each returns a SamplerBinding: the texture, and a TextureSampling with its filter, its wrap and whether it has mip levels.

  • TextureSampling.isMipmapFiltered is true for a LINEAR filter on a texture with mip levels: sample with linear filtering between the levels too.
  • A NEAREST sampling reads level 0 only, even on a texture with mip levels: only isMipmapFiltered() turns the levels on, as the OpenGL and Vulkan backends do.
  • A wrap that IRenderBridge.canWrap refuses reaches you as CLAMP_TO_EDGE; when the refused wrap is CLAMP_TO_BORDER, the shaders also emulate its transparent border.

JOID computes the mip chain in the core, so that every backend fills the same levels. A texture has no mip levels until mipmap(true); then its MipmapChain has floor(log2(max(width, height))) + 1 levels, each half the size of the previous one and at least 1×1. Override getMaxLevels(width, height) in your Texture to cap the chain.

Each level is a linear copy of the level before it, never of level 0, and never through a driver function that picks its own filter. MipmapChain.forEachStep calls you once per level with both sizes: copy level n - 1 into level n with a linear filter.

Hook of TextureCalled whenFill
allocateStorage(chain)The size or the number of levels changes.Storage for every level of the chain, before any copy.
uploadPixels(pixels, chain)New pixels arrive for level 0.Level 0, then every other level with forEachStep.
generateMipmapLevels(chain, allocatedLevels)Mipmaps are turned on for a texture that is already allocated.The missing storage when allocatedLevels differs, then the levels, keeping level 0.
deleteStorage()The texture is deleted, once.Nothing: release the storage.

The OpenGL module copies each level with a framebuffer blit, or with a drawn quad when the context cannot blit (base-opengl).

At the start of its drawing, each UI bridge releases the resources whose owners were collected and the framebuffers of the effects unused for a while. A backend that defers destruction until the GPU is done (Vulkan does) receives these deletions in the middle of a frame: keep them until the GPU has finished reading the object.

Report a problem with this page