Implementation:Google deepmind Mujoco Render Context Header
| Knowledge Sources | |
|---|---|
| Domains | OpenGL, Graphics, Rendering, Resource Management |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Header declaring the rendering context management API for creating, configuring, and freeing OpenGL resources used by MuJoCo's rendering pipeline.
Description
This header defines the public API for managing mjrContext objects, which hold all GPU-side rendering resources. It provides functions to initialize a default context, allocate resources from a model (including textures, meshes, height fields, display lists, and framebuffers), change fonts, add auxiliary framebuffers, resize offscreen renderbuffers, and upload individual assets (textures, meshes, height fields) to the GPU. It also declares builtin display list address enumerations for primitive shapes (sphere, cylinder, box, cone, haze).
Usage
Called during application startup to create an OpenGL rendering context from an mjModel, and during runtime to upload modified assets or resize offscreen buffers. The context must be freed when the OpenGL context is destroyed.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/render/render_context.h
- Lines: 1-72
Key Functions
// Builtin display list addresses (relative to base)
enum {
mjrSPHERE = 0, mjrSPHERETOP, mjrSPHEREBOTTOM,
mjrCYLINDER, mjrCYLINDEROPEN, mjrHAZE,
mjrBOX, mjrCONE, mjrNUM
};
// Set default mjrContext values
MJAPI void mjr_defaultContext(mjrContext* con);
// Allocate GPU resources from model; fontscale is mjtFontScale
MJAPI void mjr_makeContext(const mjModel* m, mjrContext* con, int fontscale);
// Change font of existing context
MJAPI void mjr_changeFont(int fontscale, mjrContext* con);
// Add auxiliary framebuffer at given index
MJAPI void mjr_addAux(int index, int width, int height, int samples, mjrContext* con);
// Free all GPU resources, reset to default
MJAPI void mjr_freeContext(mjrContext* con);
// Resize offscreen renderbuffer
MJAPI void mjr_resizeOffscreen(int offwidth, int offheight, mjrContext* con);
// Upload individual assets to GPU
MJAPI void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid);
MJAPI void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid);
MJAPI void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid);
Import
#include "render/render_context.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes (for makeContext, upload*) | Model containing asset data to upload |
| con | mjrContext* | Yes | Rendering context to initialize, modify, or free |
| fontscale | int | Yes (for makeContext, changeFont) | Font scale constant (mjtFontScale) |
| index | int | Yes (for addAux) | Auxiliary buffer index |
| width, height | int | Yes (for addAux, resizeOffscreen) | Dimensions in pixels |
| texid, meshid, hfieldid | int | Yes (for upload*) | Asset ID to upload |
Outputs
| Name | Type | Description |
|---|---|---|
| con | mjrContext* | Populated rendering context with GPU resources (textures, VBOs, FBOs, display lists) |