Skip to main content
LibGL is SerenityOS’s implementation of OpenGL 1.5, providing hardware-accelerated 3D graphics rendering capabilities. It implements the standard OpenGL API and integrates with the GPU subsystem through LibGPU.

Architecture

LibGL implements the OpenGL fixed-function pipeline with support for modern features:
  • GLContext: Central context management for all OpenGL state
  • GPU Integration: Hardware-accelerated rendering via LibGPU device drivers
  • Shader Pipeline: Vertex and fragment shader compilation and linking
  • Buffer Objects: VBOs and element array buffers for efficient geometry handling

Core Components

GLContext

The main context class that manages all OpenGL state and operations.
class
Central OpenGL context managing rendering state, matrices, textures, and shaders.Key Members:
  • Model-view and projection matrix stacks
  • Texture units and texture objects
  • Lighting and material state
  • Shader programs and buffer objects
  • Blending, depth, and stencil configuration

Matrix Operations

LibGL maintains separate matrix stacks for different transformation types:
Stack Limits:
  • Modelview: 64 matrices
  • Projection: 8 matrices
  • Texture: 8 matrices per unit

Rendering Pipeline

Immediate mode and vertex array rendering:

Texture Management

LibGL supports 2D textures with multiple texture units.
function
Generate texture object names.
function
Bind a texture to a target.
function
Specify a two-dimensional texture image.

Shader Support

OpenGL 2.0 programmable pipeline support.

Lighting

Fixed-function lighting with up to 8 light sources.
function
Set light source parameters.
function
Set material properties.

Buffer Objects

Vertex Buffer Objects (VBOs) for efficient geometry storage.

State Management

LibGL maintains extensive state for the OpenGL fixed-function pipeline:
  • Depth testing and depth buffer configuration
  • Stencil testing with separate front/back face operations
  • Alpha testing and blending modes
  • Culling and polygon offset
  • Scissor testing and clipping planes
  • Color masking and depth masking

Enable/Disable Capabilities

Common Capabilities:
  • GL_DEPTH_TEST: Depth buffer testing
  • GL_BLEND: Alpha blending
  • GL_CULL_FACE: Backface culling
  • GL_LIGHTING: Fixed-function lighting
  • GL_TEXTURE_2D: 2D texturing
  • GL_STENCIL_TEST: Stencil buffer testing
  • GL_SCISSOR_TEST: Scissor testing
  • GL_ALPHA_TEST: Alpha testing

Display Lists

Compiled display lists for efficient repeated rendering.

Error Handling

function
Retrieve the current error code.
Error Codes:
  • GL_NO_ERROR: No error
  • GL_INVALID_ENUM: Invalid enumeration value
  • GL_INVALID_VALUE: Invalid parameter value
  • GL_INVALID_OPERATION: Invalid operation
  • GL_STACK_OVERFLOW: Matrix stack overflow
  • GL_STACK_UNDERFLOW: Matrix stack underflow
  • GL_OUT_OF_MEMORY: Out of memory

Source Location

Directory: Userland/Libraries/LibGL/ Key Files:
  • GLContext.h / GLContext.cpp: Main context implementation
  • GL/gl.h: OpenGL API definitions
  • Buffer/Buffer.h: Buffer object management
  • Shaders/Program.h: Shader program handling
  • Tex/Texture.h: Texture object implementation