GPU data texture mapping each primitive to its owning mesh for a given render pass.

PrimitiveMeshIndexTexture is a GPU-resident table used by the renderer to efficiently determine, for each primitive (triangle, line, or point), which mesh it belongs to and its offset within that mesh.

  • Each item stores two uint32 values:
    • meshIndex: index of the owning mesh
    • offset: primitive index within that mesh
  • Items are grouped into "portions", each associated with:
    • a mesh (meshIndex)
    • a render pass (renderPass)
  • Portions are dynamically packed into contiguous runs per render pass during uploadChanges.
  • Render passes are registered at runtime using registerRenderPass.
  • Each registered pass gets a contiguous primitive range stored in passRanges.
  • Pass registration order defines packing order, which also defines draw order for users that consume the ranges sequentially.

A portion is included in packing only when both:

  • objectVisible === true
  • meshVisible === true

Invisible portions remain allocated, but do not contribute to packed primitive ranges.

Typical flow:

  1. Register render passes
  2. Create portions
  3. Modify visibility and/or render passes
  4. Call uploadChanges
  5. Use getPassRange to drive draw calls

Hierarchy (View Summary)

Properties

buffer: any

CPU-side backing buffer used to populate this texture.

The concrete type depends on the implementation (e.g., Uint32Array, Float32Array, or a view over an ArrayBuffer). This buffer is uploaded to the GPU when updated.

bufferClass: any

The ArrayBufferView class used for the CPU-side buffer.

bytesPerTexel: number

Size in bytes of a single texel in the data texture.

debugging: boolean = true

Enables internal event emission for this data texture.

description: string = ""

Human-readable description of the data stored in this texture.

Intended for debugging UIs and diagnostics (e.g., displayed above inspectors). Subclasses or owners should populate this with a concise explanation of the layout and semantic meaning (e.g., “mesh matrices (Mat4, row-major), indexed by meshId”).

elementsPerItem: number

Number of individual elements (e.g., floats, uint32s) stored per logical item in this data texture.

elementsPerTexel: number

Number of individual elements (e.g., floats, uint32s) stored per texel in the data texture.

format: number

Texture format (e.g., gl.RGBA, gl.RGBA_INTEGER).

gl: WebGL2RenderingContext

The WebGL2 rendering context.

height: number

Texture height in texels.

internalFormat: number

Texture internal format (e.g., gl.RGBA8, gl.RGBA32UI, gl.RGBA32F).

itemSizeInBytes: number

Size in bytes of a single logical item stored in the data texture.

lastUploadTimeMS: number = 0

Duration (in milliseconds) of the last upload to GPU.

This value is 0 until the first upload occurs.

maxItems: number

Maximum number of logical items that can be stored in this texture.

The value of numItems never exceeds this limit.

onUpdated: EventEmitter<DataTexture, undefined> = ...

Emitted when the CPU-side buffer for this texture has changed and been uploaded to the GPU.

This event is intended for debugging tools and monitoring UIs; it is only emitted when debugging is enabled.

passRanges: Map<number, PrimRange> = ...

Per-pass primitive ranges.

Each entry defines a contiguous segment within the packed primitive buffer.

primRange: PrimRange = ...

Full range of drawable primitives across all visible portions and all registered passes.

This is useful for passes such as picking that want to consider all visible primitives regardless of render pass.

texelsPerItem: number

Number of texels occupied by a single logical item in the data texture.

texture: WebGLTexture

The underlying WebGL texture object.

This is the GPU resource that is bound and sampled/loaded by shaders.

type: number

Texture data type (e.g., gl.UNSIGNED_BYTE, gl.UNSIGNED_INT, gl.FLOAT).

useBuffer: boolean

Whether to use a CPU-side buffer for staging data before uploading to the GPU.

width: number

Texture width in texels.

itemSizeInBytes: 8

Size of a single item in bytes.

Each item stores:

  • meshIndex (uint32)
  • offset (uint32)

Accessors

Methods