Context, State and Resource in OpenGL

OpenGL is fundamentally a state machine, and these three concepts—Context, State, and Resource—play a crucial role in its operation.

1. Introduction

Context
An OpenGL context is an encapsulation of the OpenGL state and resources tied to a specific rendering instance (like a window). It is created and managed by the windowing system (e.g., GLFW, GLUT, WGL, GLX, EGL).

State
OpenGL is a state machine, meaning it remembers configurations until explicitly changed.

Resource
OpenGL resources refer to objects that get created on GPU and store data used for rendering.

At its core, OpenGL maintains all states and buffer bindings. When a drawing command is issued, it relies on the current state of these settings to determine what and how to render. As illustrated in the flowchart above, modifying its static state or buffer bindings—whether for existing or newly created buffers—directly affects the rendering output. This characteristic makes OpenGL a state machine, as its rendering results depend on its current state.

2. Shared Context

A shared OpenGL context allows multiple OpenGL contexts to share certain GPU resources, such as textures, buffers, shaders, and VAOs, across different threads or windows. This enables efficient resource management and avoids redundant duplication of data.

While the context can be shared across threads/windows, each thread/window should maintain its own state, which means that the states are not shared.

It is worth noting that FBOs are not shared across OpenGL contexts. They are context-specific objects designed to handle off-screen rendering for a specific OpenGL context.

Author

Joe Chu

Posted on

2025-03-03

Updated on

2025-03-03

Licensed under

Comments