Implementation:Google deepmind Dm control Render Backend Selection
| Metadata | Value |
|---|---|
| Implementation | Render Backend Selection |
| Domain | Reinforcement_Learning, Physics_Simulation, Computer_Graphics |
| Source | dm_control |
| Workflow | Control_Suite_RL_Training |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for selecting and instantiating the OpenGL rendering context used by MuJoCo inside dm_control, supporting GLFW, EGL, and OSMesa backends.
Description
The dm_control._render package initialises a module-level Renderer callable and a BACKEND string at import time. If the MUJOCO_GL environment variable is set, the module attempts to import the corresponding backend and raises a RuntimeError if the value is unrecognised or the import fails. If MUJOCO_GL is not set, the module tries GLFW, EGL, and OSMesa in that order, selecting the first that imports successfully. If no backend can be imported, Renderer is set to a stub that raises RuntimeError on invocation.
The module also exposes USING_GPU, a boolean that is True when the active backend is either GLFW or EGL.
Usage
Use this implementation when:
- You need to configure rendering before loading a Control Suite environment that produces pixel observations.
- You want to verify which rendering backend is active in a running process.
- You need to force a specific backend for reproducibility or hardware compatibility.
Code Reference
| Attribute | Detail |
|---|---|
| Source Location | dm_control/_render/__init__.py:L1-109
|
| Module-level Variables | BACKEND (str or None), Renderer (callable), USING_GPU (bool)
|
| Import | from dm_control._render import BACKEND, Renderer, USING_GPU
|
The MUJOCO_GL environment variable accepts the following values:
| Backend | Accepted Values | Context Type |
|---|---|---|
| GLFW | glfw, on, enable, enabled, true, 1, "" |
GLFWContext
|
| EGL | egl |
EGLContext
|
| OSMesa | osmesa |
OSMesaContext
|
| Disabled | off, disable, disabled, false, 0 |
Raises RuntimeError on use
|
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
MUJOCO_GL (env var) |
str | Optional. One of the accepted backend values listed above. Controls which OpenGL backend is loaded. |
Outputs
| Name | Type | Description |
|---|---|---|
BACKEND |
str or None | Canonical name of the active backend ("glfw", "egl", "osmesa"), or None if no backend could be imported.
|
Renderer |
callable | A context-manager class (e.g. GLFWContext, EGLContext, OSMesaContext) that can be called with (max_width, max_height) to create an OpenGL context.
|
USING_GPU |
bool | True if BACKEND is "glfw" or "egl".
|
Usage Examples
Force EGL for headless GPU rendering:
export MUJOCO_GL=egl
python train.py
Force OSMesa for CPU-only rendering:
export MUJOCO_GL=osmesa
python train.py
Query the active backend in Python:
from dm_control._render import BACKEND, USING_GPU
print(f"Active rendering backend: {BACKEND}")
print(f"GPU rendering available: {USING_GPU}")
Disable rendering entirely (useful when only collecting state observations):
export MUJOCO_GL=off
python train_state_only.py
Related Pages
- Principle:Google_deepmind_Dm_control_Rendering_Backend_Configuration
- Environment:Google_deepmind_Dm_control_GLFW_Desktop_Rendering
- Environment:Google_deepmind_Dm_control_EGL_Headless_Rendering
- Environment:Google_deepmind_Dm_control_OSMesa_Software_Rendering
- Heuristic:Google_deepmind_Dm_control_Rendering_Backend_Selection_Tips