Stores per-slot hatch patterns for hatching on triangle- surface meshes.

Ten RGBA32F texels per slot. Each of the four families spans two consecutive texels, followed by the shared ink colour and the shared flags texel:

  • base + 0 — family 0a: (cos(angle), sin(angle), spacing, lineWidth)
  • base + 1 — family 0b: (typeId, phase, param1, param2)
  • base + 2 — family 1a
  • base + 3 — family 1b
  • base + 4 — family 2a
  • base + 5 — family 2b
  • base + 6 — family 3a
  • base + 7 — family 3b
  • base + 8 — hatch ink colour (r, g, b, opacity)
  • base + 9 — flags (space, 0, 0, 0)

typeId is 0=line, 1=dot, 2=wavy, 3=brick. param1 and param2 carry the type-specific extras (amplitude / wavelength for wavy; brickHeight / courseOffset for brick).

The CPU encoder zero-pads unused trailing families so the shader's loop is bounded and branch-free; spacing == 0 still serves as the "this slot is unused" sentinel.

Slot 0 is reserved as the "no hatch" sentinel — meshes whose materials carry no hatch leave their hatchPatternSlot at 0, and the surface technique skips the lookup entirely.

Hierarchy (View Summary)

Constructors

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.

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: 160

Accessors

Methods

  • Writes the four families' parameter pairs, the ink colour, and the flags texel for slotIndex.

    families is expected to be MAX_HATCH_FAMILIES × 8 floats long — two texels per family (see the class doc-comment). color is (r, g, b, opacity); space is 0 for screen-space, 1 for world-space, 2 for tangent-space.

    Slot 0 is the "no hatch" sentinel and should not be written — callers allocate slots starting at index 1.

    Parameters

    • slotIndex: number
    • families: Float32Array
    • color: Float32Array
    • space: number

    Returns void

  • Uploads all dirty items to the GPU as efficiently as possible.

    Internal algorithm:

    • Dirty items are indices of items whose data has changed and needs to be uploaded to the GPU.
    • The method sorts all dirty indices and finds contiguous runs (sequences of adjacent indices).
    • For each run, it uploads the run in chunks, where each chunk fits within a row of the texture.
    • This minimizes the number of WebGL texSubImage2D calls by uploading as large a block as possible per call.
    • After all dirty items are uploaded, the dirty set is cleared, the texture is unbound, and update notifications are sent.

    Returns boolean

    True if any uploads occurred, false otherwise.