Read-only view of GPU-related memory owned by a WebGLRenderer.
Provides structured, immutable access to the renderer’s GPU-resident data for inspection and debugging.
Mental model
The renderer’s data is organized roughly as:
DataTextures → a top-level container for GPU tables.
Batches → groups of meshes by compatible draw state / primitive type.
Views → per-view/per-pass state (eg. camera view, picking, etc.).
Render passes → opaque/translucent/selected/highlighted/xrayed, etc., each with its own draw range.
walk batches → views → render passes → primitive ranges,
map GPU indices back to SceneMesh and geometry instances for correlation,
sanity-check vertex data and simulate parts of the vertex transform path.
Note: This example is intentionally verbose and “inspection oriented”. It is not a recommended
render loop pattern, and it elides some details (eg. certain offsets) that may differ depending
on renderer configuration.
// Get GPU memory usage summary constmemoryUsage: MemoryUsage = webglRenderer.getMemoryUsage(); console.log(`GPU Memory Usage: ${memoryUsage.usedMB} MB used of ${memoryUsage.totalMB} MB total`);
// Get read-only internal view of GPU-resident data constmemoryInspector: MemoryInspector = webglRenderer.getMemoryInspector();
// Example: select a render pass (e.g. OPAQUE) constrenderPass: number = 0;
// Access the top-level data textures collection from the renderer constdataTextures = memoryInspector.dataTextures;
// Iterate over all views (e.g. camera, picking, etc.) for (letviewIndex = 0; viewIndex < 4; viewIndex++) {
// Iterate over all render batches (each batch groups meshes by primitive type) for (letbatchIndex = 0; batchIndex < dataTextures.batches.length; batchIndex++) {
// Get the batch's data textures (per-batch, per-view) constbatchDataTextures = dataTextures.batches[batchIndex];
// Get the view-dependent textures for this batch and view constbatchViewDataTextures = batchDataTextures.views[viewIndex];
// Get the primitive range for the current render pass // This defines which primitives to draw for this pass constprimRange = batchViewDataTextures.renderPassPrimitiveRanges[renderPass];
// Iterate over all primitives in the current pass's range // i.e. gl.drawArrays(gl.TRIANGLES, primRange.start * 3, primRange.numPrims * 3); for (letprimIndex = primRange.start; primIndex < primRange.end; primIndex++) { // Each primitive is a triangle for (letvertexOffset = 0; vertexOffset < 3; vertexOffset++) { // A, B, C vertices of the triangle
constvertexIndex = primIndex * 3 + vertexOffset;
// Lookup the mesh index for this primitive using the primitiveMeshIndexTexture // This table maps each primitive to its owning mesh const { meshIndex, offset } = batchViewDataTextures.primitiveMeshIndexTexture.getItem(primIndex);
// Lookup the SceneMesh using batchIndex and meshIndex constsceneMesh = memoryInspector.getMeshAtIndex(batchIndex, meshIndex);
if (!sceneMesh) { console.error("Error: scene mesh not found for mesh index:", meshIndex); continue; }
// Lookup mesh attributes (view-invariant) using meshAttributeTexture // This includes geometry index, material info, etc. constmeshAttribs = batchDataTextures.meshAttributeTexture.getItem(meshIndex);
// Lookup geometry index for the mesh constgeometryIndex = meshAttribs.geometryIndex; consttileIndex = meshAttribs.tileIndex;
// Lookup geometry attributes using geometryAttributeTexture // This includes base offsets for vertices and indices constgeometryAttributeTexture = batchDataTextures.geometryAttributeTexture.getItem(geometryIndex);
if (vertexPosition[0] !== geometryPosition[0] || vertexPosition[1] !== geometryPosition[1] || vertexPosition[2] !== geometryPosition[2]) { console.error("Error: vertex position mismatch between data textures and scene geometry"); }
Read-only view of GPU-related memory owned by a WebGLRenderer. Provides structured, immutable access to the renderer’s GPU-resident data for inspection and debugging.
Mental model
The renderer’s data is organized roughly as:
Example
The example below demonstrates how to: