UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

48 lines (47 loc) 1.76 kB
/** * @import { WebglGraphicsDevice } from './webgl-graphics-device.js' */ /** * A WebGL implementation of a dynamic buffer - a single whole uniform buffer that is handed out * from a pool for one frame at a time. The data is written into a CPU-side backing array and * uploaded with `bufferData` (a full respecify), which orphans the previous storage and lets the * driver hand back fresh storage - so reusing a buffer never stalls on in-flight draws. As each use * gets its own buffer, the offset into it is always zero. * * @ignore */ export class WebglDynamicBuffer extends DynamicBuffer { /** * @param {WebglGraphicsDevice} device - The graphics device. * @param {number} size - The byte size of the buffer. */ constructor(device: WebglGraphicsDevice, size: number); /** * The GL buffer object (mirrors WebgpuDynamicBuffer.buffer). Created lazily on the first * upload, so it is also recreated automatically after a context loss nulls it. * * @type {WebGLBuffer|null} */ bufferId: WebGLBuffer | null; /** * CPU-side backing for the whole buffer, written to during the uniform buffer update and * uploaded by {@link upload}. * * @type {Int32Array} */ storage: Int32Array; /** * Byte size of the buffer. * * @type {number} */ size: number; destroy(device: any): void; /** * Called when the rendering context is lost. The GL buffer is gone with the context, so drop * the handle; the next upload recreates it. The CPU storage and pooling are preserved. */ loseContext(): void; } import { DynamicBuffer } from '../dynamic-buffer.js'; import type { WebglGraphicsDevice } from './webgl-graphics-device.js';