Skip to content

base-opengl

joid-base-opengl is a complete render bridge for OpenGL. It calls OpenGL only through an IGlBinding, so the LWJGL 2 and LWJGL 3 backends share it, and an engine that exposes OpenGL can use it too.

GlRenderBridge reads the current context in its constructor, new GlRenderBridge(binding), so the context must be current on the calling thread; without one, it throws an IllegalStateException.

BindingLibrary
Lwjgl3GlBinding.instLWJGL 3 OpenGL, in base-lwjgl3-opengl
Lwjgl2GlBinding.instLWJGL 2 OpenGL, in base-lwjgl2
your IGlBindingthe OpenGL functions of your engine

An IGlBinding gives the queries and the calls of OpenGL, one method for one function, and an IGlFrameBufferBinding for each family of framebuffer objects, the core one and the EXT one. canPointClientMemory() returns false for a binding that cannot hand OpenGL a pointer into client memory: the state guard then leaves the client arrays of the host alone. Return null from getString for GlConstants.VERSION when no context is current, as the official bindings do: the bridge then throws its IllegalStateException.

At creation, GlCapabilities reads the version, the GLSL version, the GlProfile (compatibility, core, forward-compatible core), the renderer, the extensions and the maximum texture size. The bridge picks one path per feature:

FeaturePathFallback
GLSL dialectthe highest desktop dialect of the context, up to GLSL 3.30, with loose uniformsGLSL 1.20
FramebuffersOpenGL 3.0 or GL_ARB_framebuffer_objectGL_EXT_framebuffer_object
Vertex inputa vertex array object, pointed once (GlVertexInput)attributes pointed at each draw
Mipmapsa framebuffer blit per level (BlitGlMipmapBuilder)a quad drawn per level (DrawGlMipmapBuilder), with a dev warning

Below OpenGL 2.1 with GLSL 1.20, or without any framebuffer object, creation throws an IllegalStateException that names what the context offers.

Every call of the bridge that changes the state goes through a GlStateGuard, which notes the state of the host and gives it back at the end of the frame and around a drawing of the host. The state journal explains it.

ClassHolds
GlTextureRGBA8 storage for every level, uploaded as BGRA; a texture larger than the maximum size of the context throws an IllegalArgumentException.
GlFrameBufferA color texture and a 24-bit depth renderbuffer, without stencil (Framebuffers and depth).
GlShaderA program linked from the translation, with the attribute locations bound before linking; a compilation or link error prints the log of the driver and leaves the shader inactive.
GlBorrowedTextureA texture of the host, by name or by IntSupplier (Resource resolvers).

The bridge draws into the framebuffer that the host had bound when the frame began (Embedding in a host), and binds only the samplers that the shader declares.

ClassRole
FixedMatrixImportLoads the fixed-function matrices of a compatibility context into JOID (Embedding in a host).
GlSnapshotCaptureReads the back buffer into a snapshot image, for the snapshot backends.
GlBorrowedTextureBackendRuns the borrowed texture suite on any OpenGL context, over your snapshot backend and your binding.
GlStateGuardBackendThe base of the backends of the state guard suite on OpenGL: Lwjgl2StateGuardBackend and Lwjgl3StateGuardBackend set the traps with the functions of their library.
GlStateSnapshotReads the state that the guard must preserve, for those backends.

The test tools live in the snapshot package, which the joid-base-opengl jar leaves out: a host that runs the suites on its own context takes the joid-base-opengl-<version>-snapshot.jar of the release, next to joid-tool-testkit.

Report a problem with this page