/** * A bind group represents a collection of {@link UniformBuffer}, {@link Texture} and * {@link StorageBuffer} instanced, which can be bind on a GPU for rendering. * * @ignore */ export class BindGroup { /** * Create a new Bind Group. * * @param {GraphicsDevice} graphicsDevice - The graphics device used to manage this uniform buffer. * @param {BindGroupFormat} format - Format of the bind group. * @param {UniformBuffer} [defaultUniformBuffer] - The default uniform buffer. Typically a bind * group only has a single uniform buffer, and this allows easier access. */ constructor(graphicsDevice: GraphicsDevice, format: BindGroupFormat, defaultUniformBuffer?: UniformBuffer); /** * A render version the bind group was last updated on. * * @private */ private renderVersionUpdated; /** @type {UniformBuffer[]} */ uniformBuffers: UniformBuffer[]; /** * An array of offsets for each uniform buffer in the bind group. This is the offset in the * buffer where the uniform buffer data starts. * * @type {number[]} */ uniformBufferOffsets: number[]; /** * For each uniform buffer slot, the dynamic GPU buffer a non-persistent uniform buffer was * last built against. Used to detect when such a buffer is re-allocated into a different * dynamic buffer (which requires the bind group to be rebuilt). * * @type {DynamicBuffer[]} * @private */ private _uniformBufferContainers; /** * For each texture / storage-texture slot, the GPU implementation object the slot was last * built against. A texture's `impl` is replaced when its GPU resource is recreated (e.g. * {@link Texture#resize}), which can happen mid-render in the same render version the bind * group was last built — so the {@link renderVersionDirty} check alone misses it and the bind * group keeps a view of the (now destroyed) old GPU texture. Tracking impl identity forces a * rebuild whenever the underlying GPU resource is recreated. * * @type {object[]} * @private */ private _textureImpls; /** * @type {object[]} * @private */ private _storageTextureImpls; id: number; device: GraphicsDevice; format: BindGroupFormat; dirty: boolean; impl: any; /** @type {(Texture|TextureView)[]} */ textures: (Texture | TextureView)[]; /** @type {(Texture|TextureView)[]} */ storageTextures: (Texture | TextureView)[]; storageBuffers: any[]; /** @type {UniformBuffer} */ defaultUniformBuffer: UniformBuffer; /** * Frees resources associated with this bind group. */ destroy(): void; /** * Assign a uniform buffer to a slot. * * @param {string} name - The name of the uniform buffer slot * @param {UniformBuffer} uniformBuffer - The Uniform buffer to assign to the slot. */ setUniformBuffer(name: string, uniformBuffer: UniformBuffer): void; /** * Assign a storage buffer to a slot. * * @param {string} name - The name of the storage buffer slot. * @param {StorageBuffer} storageBuffer - The storage buffer to assign to the slot. */ setStorageBuffer(name: string, storageBuffer: StorageBuffer): void; /** * Assign a texture to a named slot. * * @param {string} name - The name of the texture slot. * @param {Texture|TextureView} value - Texture or TextureView to assign to the slot. */ setTexture(name: string, value: Texture | TextureView): void; /** * Assign a storage texture to a named slot. * * @param {string} name - The name of the texture slot. * @param {Texture|TextureView} value - Texture or TextureView to assign to the slot. */ setStorageTexture(name: string, value: Texture | TextureView): void; /** * Updates the uniform buffers in this bind group. */ updateUniformBuffers(): void; /** * Applies any changes made to the bind group's properties. Note that the content of used * uniform buffers needs to be updated before calling this method. */ update(): void; } /** * Data structure to hold a bind group and its offsets. This is used by {@link UniformBuffer#update} * to return a dynamic bind group and offset for the uniform buffer. * * @ignore */ export class DynamicBindGroup { bindGroup: any; offsets: any[]; } import type { UniformBuffer } from './uniform-buffer.js'; import type { GraphicsDevice } from './graphics-device.js'; import type { BindGroupFormat } from './bind-group-format.js'; import type { Texture } from './texture.js'; import { TextureView } from './texture-view.js'; import type { StorageBuffer } from './storage-buffer.js';