UNPKG

3.56 kBTypeScriptView Raw
1import { GLBuffer } from './GLBuffer';
2import type { BUFFER_TYPE } from '@pixi/constants';
3import type { ExtensionMetadata } from '@pixi/extensions';
4import type { IRenderingContext } from '../IRenderer';
5import type { Renderer } from '../Renderer';
6import type { ISystem } from '../system/ISystem';
7import type { Buffer } from './Buffer';
8/**
9 * System plugin to the renderer to manage buffers.
10 *
11 * WebGL uses Buffers as a way to store objects to the GPU.
12 * This system makes working with them a lot easier.
13 *
14 * Buffers are used in three main places in WebGL
15 * - geometry information
16 * - Uniform information (via uniform buffer objects - a WebGL 2 only feature)
17 * - Transform feedback information. (WebGL 2 only feature)
18 *
19 * This system will handle the binding of buffers to the GPU as well as uploading
20 * them. With this system, you never need to work directly with GPU buffers, but instead work with
21 * the PIXI.Buffer class.
22 * @class
23 * @memberof PIXI
24 */
25export declare class BufferSystem implements ISystem {
26 /** @ignore */
27 static extension: ExtensionMetadata;
28 CONTEXT_UID: number;
29 gl: IRenderingContext;
30 /** Cache for all buffers by id, used in case renderer gets destroyed or for profiling */
31 readonly managedBuffers: {
32 [key: number]: Buffer;
33 };
34 /** Cache keeping track of the base bound buffer bases */
35 readonly boundBufferBases: {
36 [key: number]: Buffer;
37 };
38 private renderer;
39 /**
40 * @param {PIXI.Renderer} renderer - The renderer this System works for.
41 */
42 constructor(renderer: Renderer);
43 /**
44 * @ignore
45 */
46 destroy(): void;
47 /** Sets up the renderer context and necessary buffers. */
48 protected contextChange(): void;
49 /**
50 * This binds specified buffer. On first run, it will create the webGL buffers for the context too
51 * @param buffer - the buffer to bind to the renderer
52 */
53 bind(buffer: Buffer): void;
54 unbind(type: BUFFER_TYPE): void;
55 /**
56 * Binds an uniform buffer to at the given index.
57 *
58 * A cache is used so a buffer will not be bound again if already bound.
59 * @param buffer - the buffer to bind
60 * @param index - the base index to bind it to.
61 */
62 bindBufferBase(buffer: Buffer, index: number): void;
63 /**
64 * Binds a buffer whilst also binding its range.
65 * This will make the buffer start from the offset supplied rather than 0 when it is read.
66 * @param buffer - the buffer to bind
67 * @param index - the base index to bind at, defaults to 0
68 * @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
69 */
70 bindBufferRange(buffer: Buffer, index?: number, offset?: number): void;
71 /**
72 * Will ensure the data in the buffer is uploaded to the GPU.
73 * @param {PIXI.Buffer} buffer - the buffer to update
74 */
75 update(buffer: Buffer): void;
76 /**
77 * Disposes buffer
78 * @param {PIXI.Buffer} buffer - buffer with data
79 * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
80 */
81 dispose(buffer: Buffer, contextLost?: boolean): void;
82 /**
83 * dispose all WebGL resources of all managed buffers
84 * @param {boolean} [contextLost=false] - If context was lost, we suppress `gl.delete` calls
85 */
86 disposeAll(contextLost?: boolean): void;
87 /**
88 * creates and attaches a GLBuffer object tied to the current context.
89 * @param buffer
90 * @protected
91 */
92 protected createGLBuffer(buffer: Buffer): GLBuffer;
93}