This module documents the internal architecture of xeokit’s WebGL2 rendering backend.
It is intended for contributors and maintainers of the renderer, not for public API usage.
The WebGLRenderer follows SOLID principles and is structured as a hierarchy
of specialized managers, each responsible for a clearly defined aspect of the rendering
pipeline.
Internal Structure
The public WebGLRenderer owns a set of high-level facilities and a single internal
ViewManager, which coordinates all rendering work.
The following class diagram shows the main internal components and how they interact.
Ownership relationships are shown as compositions, while data flow and notifications
are shown as directed associations.
Internal pooling APIs for caching and reusing DrawOps instances.
Inspection APIs (Diagnostics)
The WebGLRenderer provides read-only diagnostics APIs for inspecting all GPU-resident renderer state.
These APIs are intended for debugging, profiling, and validation by xeokit developers, and are not part of
the public API surface.
GPUMemoryManager allocates buffers and uploads geometry data.
MeshManager adds RendererMesh to MeshBatch.
RendererMesh is ready for use by any subsequently-created RendererObject.
SceneObject Creation
Whenever SceneObjects are created, they automatically get loaded into the Viewer and the WebGLRenderer.
A SceneObject is created in the Scene.
Viewer is notified via SceneEvents.onSceneObjectCreated.
The Viewer creates a ViewObject in each existing View for the SceneObject.
WebGLRenderer is also notified via SceneEvents.onSceneObjectCreated.
ViewManager.sceneObjectCreated(sceneObject)
MeshManager.sceneObjectCreated(sceneObject)
MeshManager finds pre-created RendererMesh instances for each of the SceneObject's SceneMeshes (see SceneMesh Creation).
MeshManager creates a RendererObject and links it to the RendererMesh instances.
On the next render, the new object will appear in the view.
SceneObject Deletion
Whenever SceneObjects are deleted, they get automatically get unloaded from the Viewer and the WebGLRenderer. The RendererMesh and
RendererObject instances are not unloaded immediately, but are instead kept in memory
for potential reuse. This is actually a useful way to cache content for any objects
that repeatedly get created and destroyed.
A SceneObject is destroyed.
Viewer is notified via SceneEvents.onSceneObjectDestroyed.
MeshManager marks the RendererObject as visible/invisible, which updates
the visibility states of its RendererMesh instances, which each their visibility states to GPUMemoryManager.
On next render, the object will be rendered or skipped based on its visibility.
SceneMesh Matrix Update
Whenever a SceneMesh's matrix is updated, the renderer updates
the matrix data in GPU memory.
The matrix of a SceneMesh is updated in the Scene.
WebGLRenderer is notified via SceneEvents.onSceneMeshMatrixUpdated.
ViewManager.sceneMeshMatrixChanged(sceneMesh)
MeshManager.sceneMeshMatrixChanged(sceneMesh)
MeshManager updates matrix data in GPUMemoryManager.
GPUMemoryManager uploads updated matrix to GPU.
On next render, the mesh will be transformed using the updated matrix.
SceneMesh Color Update
Whenever a SceneMesh's color is updated, the renderer updates
the color data in GPU memory.
The color of a SceneMesh is updated in the Scene.
WebGLRenderer is notified via SceneEvents.onSceneMeshColorUpdated.
ViewManager.sceneMeshColorChanged(sceneMesh)
MeshManager.sceneMeshColorChanged(sceneMesh)
MeshManager updates color data in GPUMemoryManager.
GPUMemoryManager uploads updated color to GPU.
On next render, the mesh will be rendered using the updated color.
View Updated
When a View signals that it's been updated, the renderer
re-renders the View. All the minor updates that have happened
(such as object visibility changes, matrix updates, color updates etc)
are already reflected in GPU memory, so the renderer can just
go ahead and render the current state.
A View signals that it's "updated", meaning that it has a batch of minor updates to render.
WebGLRenderer is notified via ViewerEvents.onViewUpdated.
ViewManager initiates render via RenderManager.render.
RenderManager retrieves visible RendererObjects from MeshManager.
RenderManager sets up render passes and state.
RenderManager issues draw calls using DrawOps for each visible RendererObject.
Frame is rendered to the canvas.
Picking Operation (WIP)
When a user initiates a picking operation (e.g., clicking on the canvas),
the renderer performs GPU-based picking to identify the selected object.
The rationale for implementing picking via the WebGLRenderer API, and not via the Viewer API (which would really be
semantically nicer), is because we need the renderer's GPU resources to perform picking, and we don't want to do it
using the renderer through the Viewer (like a facade), because the Viewer needs to remain agnostic of
the renderer.
User initiates picking on a View canvas.
WebGLRenderer.pick(...) is called.
ViewManager delegates to PickManager.
PickManager sets up picking render targets and state.
PickManager issues draw calls using DrawOps to render to picking buffer.
PickManager reads picking results from GPU.
PickManager identifies picked ViewObject and notifies WebGLRenderer.
WebGLRenderer.pick returns result to caller.
Caller can find picked SceneObject via ViewObject.
WebGLRenderer Internals
Internal documentation for xeokit developers
Overview
This module documents the internal architecture of xeokit’s WebGL2 rendering backend. It is intended for contributors and maintainers of the renderer, not for public API usage.
The WebGLRenderer follows SOLID principles and is structured as a hierarchy of specialized managers, each responsible for a clearly defined aspect of the rendering pipeline.
Internal Structure
The public WebGLRenderer owns a set of high-level facilities and a single internal ViewManager, which coordinates all rendering work.
Architectural Relationships
The following class diagram shows the main internal components and how they interact. Ownership relationships are shown as compositions, while data flow and notifications are shown as directed associations.
Core Components
WebGLRenderer (public)
ViewManager (internal)
MeshManager (internal)
GPUMemoryManager (internal)
RenderManager (internal)
PickManager (internal)
DrawOps (internal)
Low-level WebGL2 draw infrastructure used by both rendering and picking.
DrawTechnique
DrawOp
RenderPassDrawOps
DrawOps
getDrawOps / putDrawOps
Inspection APIs (Diagnostics)
The WebGLRenderer provides read-only diagnostics APIs for inspecting all GPU-resident renderer state. These APIs are intended for debugging, profiling, and validation by xeokit developers, and are not part of the public API surface.
Memory Inspection
MemoryUsage via WebGLRenderer.getMemoryUsage
MemoryInspector via WebGLRenderer.getMemoryInspector
Shader Inspection
The WebGLRenderer exposes read-only APIs for inspecting the generated WebGL shader programs and techniques.
Draw List Inspection
The WebGLRenderer includes a Draw List Inspector for logging and analyzing all draw calls issued during rendering.
Execution Workflows
The following selected workflows help illustrate how the core components interact during key operations.
Viewer Attached to WebGLRenderer
This is when the WebGLRenderer gets initialized, ready for action.
SceneGeometry Creation
Whenever geometries are created, they get pre-loaded into the renderer.
SceneMesh Creation
Whenever meshes are created, they get loaded into the renderer, and are attached to RendererMesh instances.
SceneObject Creation
Whenever SceneObjects are created, they automatically get loaded into the Viewer and the WebGLRenderer.
SceneObject Deletion
Whenever SceneObjects are deleted, they get automatically get unloaded from the Viewer and the WebGLRenderer. The RendererMesh and RendererObject instances are not unloaded immediately, but are instead kept in memory for potential reuse. This is actually a useful way to cache content for any objects that repeatedly get created and destroyed.
ViewObject Visibility Change
Whenever a ViewObject's visibility is changed, the renderer updates the visibility state in GPU memory, so that only visible objects are rendered.
SceneMesh Matrix Update
Whenever a SceneMesh's matrix is updated, the renderer updates the matrix data in GPU memory.
SceneMesh Color Update
Whenever a SceneMesh's color is updated, the renderer updates the color data in GPU memory.
View Updated
When a View signals that it's been updated, the renderer re-renders the View. All the minor updates that have happened (such as object visibility changes, matrix updates, color updates etc) are already reflected in GPU memory, so the renderer can just go ahead and render the current state.
Picking Operation (WIP)
When a user initiates a picking operation (e.g., clicking on the canvas), the renderer performs GPU-based picking to identify the selected object.
The rationale for implementing picking via the WebGLRenderer API, and not via the Viewer API (which would really be semantically nicer), is because we need the renderer's GPU resources to perform picking, and we don't want to do it using the renderer through the Viewer (like a facade), because the Viewer needs to remain agnostic of the renderer.