Skip to content

Architecture and layers

JOID is split into three layers, so that one interface runs unchanged on OpenGL, Vulkan or the renderer of an engine. A module depends only on the layers above it, and a base module on no other one, except a library module on the API module it binds, as base-lwjgl3-openal on base-openal.

Three bands of boxes. At the top, joid-core: UIs, nodes, signals, the bridge contracts and the generic half of every backend. In the middle, the base modules: on a first row, the API modules base-openal (audio bridge over IAlBinding) and base-opengl (render bridge over IGlBinding), each with an arrow up to the core; a note reads: library modules below bind their library to the API modules above; on the rows below, the library modules base-lwjgl2 (bindings and bridges of LWJGL 2), base-lwjgl3-glfw (window, input and keys of GLFW), base-lwjgl3-openal (binding of base-openal), base-lwjgl3-opengl (binding of base-opengl) and base-lwjgl3-sdl (keys and mouse buttons of SDL). A note reads: each backend uses the base modules named in its box. At the bottom, four backends on two rows: backend-lwjgl2 (lwjgl2, openal, opengl), backend-lwjgl3 (lwjgl3-glfw, lwjgl3-openal, lwjgl3-opengl, openal, opengl), backend-vulkan (lwjgl3-glfw, lwjgl3-openal, openal) and, highlighted in blue, your backend with the modules it reuses. A line under them reads: a backend depends on the core and on the base modules it names.

A backend picks the base modules it needs and adds only what is specific to its library. Nothing below the core is visible to the code of a UI.

joid-core holds everything that does not depend on a graphics, window or audio library:

  • the UI engine: UIs, nodes, layout, signals, effects, animation, text and resources;
  • the contracts that a backend implements, in dev.joid.lib.bridge: one interface per bridge, and the registries of BridgeHandler;
  • the generic half of every backend: RenderBridge keeps the matrices, the render state and the frame in Java, Texture computes the mipmap chain, ShaderSource parses each stage and Shader translates it, and Backend registers the bridges in a fixed order.

The core never calls OpenGL, Vulkan, GLFW or OpenAL. It reaches them only through the bridges.

The base modules share one library between backends

Section titled “The base modules share one library between backends”

A base module holds the code that several backends would otherwise copy, for one library:

ModuleLibraryGives
base-openalOpenAL, through IAlBindingthe audio bridge and its streaming sources
base-openglOpenGL 2.1 and later, through IGlBindingthe render bridge, the state guard, textures, framebuffers, shaders and mipmaps
base-lwjgl2LWJGL 2, a single jarthe bindings of base-opengl and base-openal, the Display window bridge with its native cursors, the input forwarder, the key table
base-lwjgl3-glfwGLFW of LWJGL 3the window bridge, the input forwarder, the key table
base-lwjgl3-openalOpenAL of LWJGL 3the binding of base-openal
base-lwjgl3-openglOpenGL of LWJGL 3the binding of base-opengl
base-lwjgl3-sdlSDL 3 of LWJGLthe key table, the mouse buttons

base-openal and base-opengl are API modules: they call their library only through these binding interfaces, so they declare no LWJGL dependency, and the binding you give them decides which library they call. The other base modules are library modules, one for each jar of a library, so that a backend takes exactly the libraries it already runs on.

A final backend picks its base modules, adds what is specific to its library, and registers everything through a subclass of Backend:

BackendBase modulesIts own code
LWJGL 2lwjgl2, openal, openglthe natives
LWJGL 3lwjgl3-glfw, lwjgl3-openal, lwjgl3-opengl, openal, openglthe context hints
Vulkanlwjgl3-glfw, lwjgl3-openal, openalthe whole renderer, and the hosts that own the device and the frame

Each jar of a backend embeds the core and its base modules, with Gson, Guava, Commons IO, Commons Lang, JSVG, TwelveMonkeys and ASM relocated under dev.joid.shaded; JavaCV, JavaCPP and FFmpeg keep their own packages, and so does JNA in the LWJGL 2 jars. An application declares one JOID jar, next to the libraries of its backend (LWJGL, for the official ones).

ModuleRole
tool-msdfGenerates the MSDF atlases of the fonts; the core embeds it.
tool-testkitRenders scenarios on a hidden surface and runs the contract suites that every backend passes (Testing a backend).

The snapshot packages of base-lwjgl3-glfw, base-opengl and of each final backend hold the hidden surfaces and the captures of the tests; those of base-opengl and of the backends use the testkit; Three jars per module says which jars carry them.

The code of a UI never adapts to its backend. Rules that hold for every backend, such as the mipmap chain, the vertex layout or the depth conversion, already live in the core, so a backend only translates them for its library.

When a host has data of its own (its textures, its asset paths, its key bindings, its text objects), the backend feeds a registry of the core and the UI keeps calling the core API:

RegistryTurnsPage
ResourceResolveran object of the host (a sprite, a texture handle) into a resourceResource resolvers
AssetLocatora path of the host into a streamCustom formats
KeyResolvera key binding of the host into keysKeyboard and shortcuts
TextConvertera text object of the host into a stringText markup and effects

Report a problem with this page