UniformStore
UniformStore packs typed uniform values into named blocks and optionally owns a GPU buffer
for each block. The device determines the default layout: WGSL uniform layout on WebGPU,
std140 on WebGL. ShaderInputs uses this lower-level
machinery for shader-module props.
Usage
import {UniformStore} from '@luma.gl/core';
const store = new UniformStore<{frame: {time: number}}>(device, {
frame: {uniformTypes: {time: 'f32'}, defaultUniforms: {time: 0}}
});
const frameUniforms = store.getManagedUniformBuffer('frame');
store.setUniforms({frame: {time: 1}});
// Bind frameUniforms to a compatible shader block, then destroy the store when finished.
store.destroy();
Block definitions
The constructor accepts (device, blocks), keyed by uniform-block name.
| Field | Type | Meaning |
|---|---|---|
uniformTypes? | Record<string, CompositeShaderType> | Types used to pack each uniform. |
defaultUniforms? | Record<string, CompositeUniformValue> | Initial values. |
layout? | 'std140' | 'wgsl-uniform' | 'wgsl-storage' | Explicit layout override. |
defaultProps? | Record<string, unknown> | Reserved; not applied as uniform defaults. |
Methods
setUniforms(values, commandEncoder?): voidmerges partial block values and updates existing managed buffers. An encoder orders uploads with later GPU work in the same submission.getUniformBufferByteLength(name): numberreturns the allocation size, including the store's minimum buffer-size policy.getUniformBufferData(name): Uint8Arrayreturns packed bytes; its length can be smaller than the allocation size.getManagedUniformBuffer(name): Bufferlazily creates a store-owned buffer. CallsetUniforms()orupdateUniformBuffer()before consuming it.createUniformBuffer(name, values?): Buffercreates an initialized, caller-owned buffer.updateUniformBuffer(name, commandEncoder?): false | stringupdates a dirty managed block and returns its redraw reason, orfalse.updateUniformBuffers(commandEncoder?): false | stringupdates all dirty managed blocks.destroy(): voiddestroys managed buffers. Caller-owned buffers remain the caller's responsibility.