19 FEB 2026

rahulmnavneeth

opengl backend

homedocs

Status

Not yet implemented. This document defines the contract for the OpenGL backend. Enable with make MOP_ENABLE_OPENGL=1 once implemented.

Location

src/backend/opengl/
  opengl_backend.c    — RHI function table implementation

Design

Context Creation

The OpenGL backend creates an offscreen rendering context:

No window or display server connection is required.

Framebuffer

An FBO with three attachments:

AttachmentFormatPurpose
Color 0RGBA8Color output
DepthDEPTH24Depth testing
Color 1R32UIObject ID buffer

Shaders

Vertex shader:

Fragment shader:

Draw Call

  1. Bind VAO with vertex buffer
  2. Upload uMVP, uModel, uObjectId uniforms
  3. glDrawElements(GL_TRIANGLES, ...)

Readback

glReadPixels from the FBO. Color is read as GL_RGBA / GL_UNSIGNED_BYTE. Object ID is read as GL_RED_INTEGER / GL_UNSIGNED_INT. Depth is read as GL_DEPTH_COMPONENT / GL_FLOAT.

RHI Handle Mapping

RHI HandleOpenGL Concrete Type
MopRhiDeviceGL context + shader program + VAO state
MopRhiBufferGLuint buffer object
MopRhiFramebufferFBO + texture/renderbuffer attachments