Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Dm control EGL Context

From Leeroopedia
Knowledge Sources
Domains Rendering, OpenGL
Last Updated 2026-02-15 04:00 GMT

Overview

EGLContext implements the EGL-backed OpenGL rendering context for headless GPU-accelerated rendering of MuJoCo scenes, enabling rendering without a display server.

Description

At module load time, the PYOPENGL_PLATFORM environment variable is set to "egl" if not already set. A headless EGL display is then created and initialized via create_initialized_headless_egl_display(), which queries all available EGL devices (or a specific one via the MUJOCO_EGL_DEVICE_ID environment variable), attempts to create a platform display on each candidate device, and initializes it. The display is registered for cleanup via atexit.

EGLContext extends ContextBase and configures an EGL context with 8-bit RGBA color, 24-bit depth, and 8-bit stencil buffers using eglChooseConfig. It binds the OpenGL API via eglBindAPI and creates a surfaceless context with eglCreateContext. The _platform_make_current method activates the context without any surface (EGL_NO_SURFACE), and _platform_free destroys the context after releasing it as current. Uses PassthroughRenderExecutor for thread management.

Usage

Use this context for headless GPU rendering on servers without display servers. This is the primary backend for training reinforcement learning agents on GPU-equipped machines. The MUJOCO_EGL_DEVICE_ID environment variable allows selecting a specific GPU device, which is useful in multi-GPU distributed training setups.

Code Reference

Source Location

Signature

def create_initialized_headless_egl_display():
    """Creates an initialized EGL display directly on a device."""

class EGLContext(base.ContextBase):
    def __init__(self, max_width, max_height):
    def _platform_init(self, unused_max_width, unused_max_height):
    def _platform_make_current(self):
    def _platform_free(self):

Import

from dm_control._render.pyopengl.egl_renderer import EGLContext

I/O Contract

Inputs

Name Type Required Description
max_width int Yes Maximum framebuffer width in pixels (not used by EGL init but passed to base class)
max_height int Yes Maximum framebuffer height in pixels (not used by EGL init but passed to base class)

Outputs

Name Type Description
instance EGLContext A fully initialized headless OpenGL context backed by EGL

Environment Variables

Name Description
PYOPENGL_PLATFORM Set to "egl" automatically if not already set
MUJOCO_EGL_DEVICE_ID Optional integer specifying which GPU device to use (0-indexed)

Usage Examples

import os
# Optionally select a specific GPU
os.environ['MUJOCO_EGL_DEVICE_ID'] = '0'

from dm_control._render.pyopengl.egl_renderer import EGLContext

# Create a headless EGL context
context = EGLContext(max_width=640, max_height=480)

with context.make_current() as ctx:
    ctx.call(render_function, scene)

context.free()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment