@luma.gl/core
Version:
The luma.gl core Device API
89 lines • 4.4 kB
TypeScript
import type { CompositeShaderType } from "../shadertypes/shader-types/shader-types.js";
import type { CompositeUniformValue } from "../adapter/types/uniforms.js";
import type { Device } from "../adapter/device.js";
import { Buffer } from "../adapter/resources/buffer.js";
import { type ShaderBlockLayout } from "../shadertypes/shader-types/shader-block-layout.js";
import { UniformBlock } from "./uniform-block.js";
import { ShaderBlockWriter } from "./shader-block-writer.js";
/** Definition of a single managed uniform block. */
export type UniformStoreBlockDefinition = {
/** Declared shader types for the block's uniforms. */
uniformTypes?: Record<string, CompositeShaderType>;
/** Reserved for future prop-level defaults. */
defaultProps?: Record<string, unknown>;
/** Initial uniform values written into the backing block. */
defaultUniforms?: Record<string, CompositeUniformValue>;
/** Explicit shader-block layout override. */
layout?: 'std140' | 'wgsl-uniform' | 'wgsl-storage';
};
/** Uniform block definitions keyed by block name. */
export type UniformStoreBlocks<TPropGroups extends Record<string, Record<string, unknown>>> = Record<keyof TPropGroups, UniformStoreBlockDefinition>;
/**
* A uniform store holds a uniform values for one or more uniform blocks,
* - It can generate binary data for any uniform buffer
* - It can manage a uniform buffer for each block
* - It can update managed uniform buffers with a single call
* - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
*/
export declare class UniformStore<TPropGroups extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> {
/** Device used to infer layout and allocate buffers. */
readonly device: Device;
/** Stores the uniform values for each uniform block */
uniformBlocks: Map<keyof TPropGroups, UniformBlock<Record<string, import("../adapter/types/uniforms").UniformValue>>>;
/** Flattened layout metadata for each block. */
shaderBlockLayouts: Map<keyof TPropGroups, ShaderBlockLayout>;
/** Serializers for block-backed uniform data. */
shaderBlockWriters: Map<keyof TPropGroups, ShaderBlockWriter>;
/** Actual buffer for the blocks */
uniformBuffers: Map<keyof TPropGroups, Buffer>;
/**
* Creates a new {@link UniformStore} for the supplied device and block definitions.
*/
constructor(device: Device, blocks: UniformStoreBlocks<TPropGroups>);
/** Destroy any managed uniform buffers */
destroy(): void;
/**
* Set uniforms
*
* Makes all group properties partial and eagerly propagates changes to any
* managed GPU buffers.
*/
setUniforms(uniforms: Partial<{
[group in keyof TPropGroups]: Partial<TPropGroups[group]>;
}>): void;
/**
* Returns the allocation size for the named uniform buffer.
*
* This may exceed the packed layout size because minimum buffer-size policy is
* applied at the store layer.
*/
getUniformBufferByteLength(uniformBufferName: keyof TPropGroups): number;
/**
* Returns packed binary data that can be uploaded to the named uniform buffer.
*
* The returned view length matches the packed block size and is not padded to
* the store's minimum allocation size.
*/
getUniformBufferData(uniformBufferName: keyof TPropGroups): Uint8Array;
/**
* Creates an unmanaged uniform buffer initialized with the current or supplied values.
*/
createUniformBuffer(uniformBufferName: keyof TPropGroups, uniforms?: Partial<{
[group in keyof TPropGroups]: Partial<TPropGroups[group]>;
}>): Buffer;
/** Returns the managed uniform buffer for the named block. */
getManagedUniformBuffer(uniformBufferName: keyof TPropGroups): Buffer;
/**
* Updates every managed uniform buffer whose source uniforms have changed.
*
* @returns The first redraw reason encountered, or `false` if nothing changed.
*/
updateUniformBuffers(): false | string;
/**
* Updates one managed uniform buffer if its corresponding block is dirty.
*
* @returns The redraw reason for the update, or `false` if no write occurred.
*/
updateUniformBuffer(uniformBufferName: keyof TPropGroups): false | string;
}
//# sourceMappingURL=uniform-store.d.ts.map