playcanvas
Version:
PlayCanvas WebGL game engine
70 lines (69 loc) • 2.93 kB
TypeScript
/**
* @import { GraphicsDevice } from './graphics-device.js'
* @import { StorageBuffer } from './storage-buffer.js'
* @import { Texture } from './texture.js'
* @import { EventHandle } from '../../core/event-handle.js'
*/
/**
* Manages non-blocking uploads of data to GPU resources (textures or storage buffers).
* Internally pools staging resources (PBOs on WebGL, staging buffers on WebGPU) to avoid blocking
* when the GPU is busy with previous uploads.
*
* Important: Create one UploadStream per target resource.
*
* @category Graphics
* @ignore
*/
export class UploadStream {
/**
* Create a new UploadStream instance.
*
* @param {GraphicsDevice} device - The graphics device.
* @param {boolean} [useSingleBuffer] - If true, uses simple direct uploads (single texture on
* WebGL, direct write on WebGPU). If false (default), uses optimized multi-buffer strategy (PBOs
* with orphaning on WebGL, staging buffers on WebGPU) for potentially non-blocking uploads.
*/
constructor(device: GraphicsDevice, useSingleBuffer?: boolean);
/**
* Event handle for device lost event.
*
* @type {EventHandle|null}
* @protected
*/
protected _deviceLostEvent: EventHandle | null;
device: GraphicsDevice;
useSingleBuffer: boolean;
impl: any;
/**
* Destroy the upload stream and clean up all pooled resources.
*/
destroy(): void;
/**
* Upload data to a texture (WebGL path) or storage buffer (WebGPU path).
* For WebGL textures, both offset and size must be multiples of the texture width (aligned to
* full rows).
* For WebGPU storage buffers, both offset and size byte values must be multiples of 4.
*
* @param {Uint8Array|Uint32Array|Float32Array} data - The data to upload. Must contain at least
* `size` elements.
* @param {Texture|StorageBuffer} target - The target resource (texture for WebGL, storage
* buffer for WebGPU).
* @param {number} [offset] - The element offset in the target where upload starts. Defaults to 0.
* For WebGL textures, must be a multiple of texture width. For WebGPU, the byte offset must be
* a multiple of 4.
* @param {number} [size] - The number of elements to upload. Defaults to data.length.
* For WebGL textures, must be a multiple of texture width. For WebGPU, the byte size must be
* a multiple of 4.
*/
upload(data: Uint8Array | Uint32Array | Float32Array, target: Texture | StorageBuffer, offset?: number, size?: number): void;
/**
* Handles device lost event. Override in platform implementations.
*
* @private
*/
private _onDeviceLost;
}
import type { EventHandle } from '../../core/event-handle.js';
import type { GraphicsDevice } from './graphics-device.js';
import type { Texture } from './texture.js';
import type { StorageBuffer } from './storage-buffer.js';