@luma.gl/engine
Version:
3D Engine Components for luma.gl
250 lines • 11 kB
TypeScript
import { type TypedArray } from '@math.gl/types';
import { type RenderPipelineProps, type RenderPipelineParameters, type BufferLayout, type VertexArray, type TransformFeedback, type AttributeInfo, type Binding, type BindingsByGroup, type PrimitiveTopology, Device, Buffer, RenderPipeline, RenderPass, PipelineFactory, ShaderFactory, UniformStore } from '@luma.gl/core';
import type { ShaderBindingDebugRow, ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
import { ShaderAssembler } from '@luma.gl/shadertools';
import type { Geometry } from "../geometry/geometry.js";
import { GPUGeometry } from "../geometry/gpu-geometry.js";
import { ShaderInputs } from "../shader-inputs.js";
import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
import { Material } from "../material/material.js";
export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
source?: string;
vs?: string | null;
fs?: string | null;
/** shadertool shader modules (added to shader code) */
modules?: ShaderModule[];
/** Shadertool module defines (configures shader code)*/
defines?: Record<string, boolean>;
/** Shader inputs, used to generated uniform buffers and bindings */
shaderInputs?: ShaderInputs;
/** Material-owned group-3 bindings */
material?: Material;
/** Bindings */
bindings?: Record<string, Binding | DynamicTexture>;
/** WebGL-only uniforms */
uniforms?: Record<string, unknown>;
/** Parameters that are built into the pipeline */
parameters?: RenderPipelineParameters;
/** Geometry */
geometry?: GPUGeometry | Geometry | null;
/** @deprecated Use instanced rendering? Will be auto-detected in 9.1 */
isInstanced?: boolean;
/** instance count */
instanceCount?: number;
/** Vertex count */
vertexCount?: number;
indexBuffer?: Buffer | null;
/** @note this is really a map of buffers, not a map of attributes */
attributes?: Record<string, Buffer>;
/** */
constantAttributes?: Record<string, TypedArray>;
/** Some applications intentionally supply unused attributes and bindings, and want to disable warnings */
disableWarnings?: boolean;
/** @internal For use with {@link TransformFeedback}, WebGL only. */
varyings?: string[];
transformFeedback?: TransformFeedback;
/** Show shader source in browser? */
debugShaders?: 'never' | 'errors' | 'warnings' | 'always';
/** Factory used to create a {@link RenderPipeline}. Defaults to {@link Device} default factory. */
pipelineFactory?: PipelineFactory;
/** Factory used to create a {@link Shader}. Defaults to {@link Device} default factory. */
shaderFactory?: ShaderFactory;
/** Shader assembler. Defaults to the ShaderAssembler.getShaderAssembler() */
shaderAssembler?: ShaderAssembler;
};
/**
* High level draw API for luma.gl.
*
* A `Model` encapsulates shaders, geometry attributes, bindings and render
* pipeline state into a single object. It automatically reuses and rebuilds
* pipelines as render parameters change and exposes convenient hooks for
* updating uniforms and attributes.
*
* Features:
* - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
* - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
* - Manages geometry attributes and buffer bindings.
* - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
* - Provides detailed debug logging and optional shader source inspection.
*/
export declare class Model {
static defaultProps: Required<ModelProps>;
/** Device that created this model */
readonly device: Device;
/** Application provided identifier */
readonly id: string;
/** WGSL shader source when using unified shader */
readonly source: string;
/** GLSL vertex shader source */
readonly vs: string;
/** GLSL fragment shader source */
readonly fs: string;
/** Factory used to create render pipelines */
readonly pipelineFactory: PipelineFactory;
/** Factory used to create shaders */
readonly shaderFactory: ShaderFactory;
/** User-supplied per-model data */
userData: {
[key: string]: any;
};
/** The render pipeline GPU parameters, depth testing etc */
parameters: RenderPipelineParameters;
/** The primitive topology */
topology: PrimitiveTopology;
/** Buffer layout */
bufferLayout: BufferLayout[];
/** Use instanced rendering */
isInstanced: boolean | undefined;
/** instance count. `undefined` means not instanced */
instanceCount: number;
/** Vertex count */
vertexCount: number;
/** Index buffer */
indexBuffer: Buffer | null;
/** Buffer-valued attributes */
bufferAttributes: Record<string, Buffer>;
/** Constant-valued attributes */
constantAttributes: Record<string, TypedArray>;
/** Bindings (textures, samplers, uniform buffers) */
bindings: Record<string, Binding | DynamicTexture>;
/**
* VertexArray
* @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
* @todo - allow application to define multiple vertex arrays?
* */
vertexArray: VertexArray;
/** TransformFeedback, WebGL 2 only. */
transformFeedback: TransformFeedback | null;
/** The underlying GPU "program". @note May be recreated if parameters change */
pipeline: RenderPipeline;
/** ShaderInputs instance */
shaderInputs: ShaderInputs;
material: Material | null;
_uniformStore: UniformStore;
_attributeInfos: Record<string, AttributeInfo>;
_gpuGeometry: GPUGeometry | null;
private props;
_pipelineNeedsUpdate: string | false;
private _needsRedraw;
private _destroyed;
/** "Time" of last draw. Monotonically increasing timestamp */
_lastDrawTimestamp: number;
private _bindingTable;
get [Symbol.toStringTag](): string;
toString(): string;
constructor(device: Device, props: ModelProps);
destroy(): void;
/** Query redraw status. Clears the status. */
needsRedraw(): false | string;
/** Mark the model as needing a redraw */
setNeedsRedraw(reason: string): void;
/** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
getBindingDebugTable(): readonly ShaderBindingDebugRow[];
/** Update uniforms and pipeline state prior to drawing. */
predraw(): void;
/**
* Issue one draw call.
* @param renderPass - render pass to draw into
* @returns `true` if the draw call was executed, `false` if resources were not ready.
*/
draw(renderPass: RenderPass): boolean;
/**
* Updates the optional geometry
* Geometry, set topology and bufferLayout
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
*/
setGeometry(geometry: GPUGeometry | Geometry | null): void;
/**
* Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
* @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
*/
setTopology(topology: PrimitiveTopology): void;
/**
* Updates the buffer layout.
* @note Triggers a pipeline rebuild / pipeline cache fetch
*/
setBufferLayout(bufferLayout: BufferLayout[]): void;
/**
* Set GPU parameters.
* @note Can trigger a pipeline rebuild / pipeline cache fetch.
* @param parameters
*/
setParameters(parameters: RenderPipelineParameters): void;
/**
* Updates the instance count (used in draw calls)
* @note Any attributes with stepMode=instance need to be at least this big
*/
setInstanceCount(instanceCount: number): void;
/**
* Updates the vertex count (used in draw calls)
* @note Any attributes with stepMode=vertex need to be at least this big
*/
setVertexCount(vertexCount: number): void;
/** Set the shader inputs */
setShaderInputs(shaderInputs: ShaderInputs): void;
setMaterial(material: Material | null): void;
/** Update uniform buffers from the model's shader inputs */
updateShaderInputs(): void;
/**
* Sets bindings (textures, samplers, uniform buffers)
*/
setBindings(bindings: Record<string, Binding | DynamicTexture>): void;
/**
* Updates optional transform feedback. WebGL only.
*/
setTransformFeedback(transformFeedback: TransformFeedback | null): void;
/**
* Sets the index buffer
* @todo - how to unset it if we change geometry?
*/
setIndexBuffer(indexBuffer: Buffer | null): void;
/**
* Sets attributes (buffers)
* @note Overrides any attributes previously set with the same name
*/
setAttributes(buffers: Record<string, Buffer>, options?: {
disableWarnings?: boolean;
}): void;
/**
* Sets constant attributes
* @note Overrides any attributes previously set with the same name
* Constant attributes are only supported in WebGL, not in WebGPU
* Any attribute that is disabled in the current vertex array object
* is read from the context's global constant value for that attribute location.
* @param constantAttributes
*/
setConstantAttributes(attributes: Record<string, TypedArray>, options?: {
disableWarnings?: boolean;
}): void;
/** Check that bindings are loaded. Returns id of first binding that is still loading. */
_areBindingsLoading(): string | false;
/** Extracts texture view from loaded async textures. Returns null if any textures have not yet been loaded. */
_getBindings(): Record<string, Binding>;
_getBindGroups(): BindingsByGroup;
_getBindGroupCacheKeys(): Partial<Record<number, object>>;
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
_getBindingsUpdateTimestamp(): number;
/**
* Updates the optional geometry attributes
* Geometry, sets several attributes, indexBuffer, and also vertex count
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
*/
_setGeometryAttributes(gpuGeometry: GPUGeometry): void;
/** Mark pipeline as needing update */
_setPipelineNeedsUpdate(reason: string): void;
/** Update pipeline if needed */
_updatePipeline(): RenderPipeline;
/** Throttle draw call logging */
_lastLogTime: number;
_logOpen: boolean;
_logDrawCallStart(): void;
_logDrawCallEnd(): void;
protected _drawCount: number;
_logFramebuffer(renderPass: RenderPass): void;
_getAttributeDebugTable(): Record<string, Record<string, unknown>>;
_getBufferOrConstantValues(attribute: Buffer | TypedArray, dataType: any): string;
private _getNonMaterialBindings;
}
/** Create a shadertools platform info from the Device */
export declare function getPlatformInfo(device: Device): PlatformInfo;
//# sourceMappingURL=model.d.ts.map