Implementation:ARISE Initiative Robosuite EGLContext
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Rendering, GPU Computing |
| Last Updated | 2026-02-15 07:00 GMT |
Overview
The EGLContext module provides headless GPU-accelerated OpenGL rendering context management using EGL, enabling offscreen rendering on servers without displays.
Description
This module implements the EGLGLContext class and the create_initialized_egl_device_display helper function for creating headless OpenGL rendering contexts using EGL (Embedded-System Graphics Library). This is essential for running MuJoCo rendering on headless servers and GPU clusters where no display is available.
The create_initialized_egl_device_display function queries available EGL devices and initializes a display on the specified GPU device. It respects the MUJOCO_EGL_DEVICE_ID and CUDA_VISIBLE_DEVICES environment variables for device selection, supporting multi-GPU setups and containerized environments. When device_id is -1, it selects the first available device.
The EGLGLContext class manages the lifecycle of an EGL rendering context. It configures the framebuffer with 8 bits per color channel (RGBA), 24-bit depth buffer, 8-bit stencil buffer, and OpenGL compatibility. The class uses a global EGL_DISPLAY singleton to ensure the EGL display is only initialized once per process, with cleanup registered via atexit.
The module automatically sets the PYOPENGL_PLATFORM environment variable to "egl" if not already set, and raises an error if it is set to a conflicting value. This ensures that PyOpenGL uses the EGL backend throughout the process.
Usage
Use this module when you need to render MuJoCo scenes on a headless server or in a Docker container without a display. It is automatically used by robosuite when offscreen rendering is enabled. Set the MUJOCO_EGL_DEVICE_ID environment variable to control which GPU device is used for rendering.
Code Reference
Source Location
- Repository: ARISE_Initiative_Robosuite
- File: robosuite/renderers/context/egl_context.py
Signature
def create_initialized_egl_device_display(device_id=0) -> EGL.EGLDisplay
class EGLGLContext:
def __init__(self, max_width, max_height, device_id=0)
def make_current(self) -> None
def free(self) -> None
Import
from robosuite.renderers.context.egl_context import EGLGLContext, create_initialized_egl_device_display
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| max_width | int | Yes | Maximum framebuffer width (unused by EGL, accepted for interface compatibility) |
| max_height | int | Yes | Maximum framebuffer height (unused by EGL, accepted for interface compatibility) |
| device_id | int | No | GPU device index to use; -1 for first available (default: 0) |
Outputs
| Name | Type | Description |
|---|---|---|
| EGLGLContext | context object | An initialized EGL OpenGL context for headless rendering |
| create_initialized_egl_device_display() | EGL.EGLDisplay | An initialized EGL display on the specified device, or EGL_NO_DISPLAY on failure |
Usage Examples
from robosuite.renderers.context.egl_context import EGLGLContext
# Create an EGL context on GPU device 0
ctx = EGLGLContext(max_width=1920, max_height=1080, device_id=0)
# Make the context current for rendering
ctx.make_current()
# ... perform OpenGL rendering operations ...
# Free the context when done
ctx.free()
# Environment variable control:
# export MUJOCO_EGL_DEVICE_ID=1 # Use GPU device 1
# export CUDA_VISIBLE_DEVICES=0,1 # Make GPUs 0 and 1 visible