UNPKG

2.91 kBTypeScriptView Raw
1import { BUFFER_TYPE } from '@pixi/constants';
2import { Runner } from '@pixi/runner';
3import type { GLBuffer } from './GLBuffer';
4/**
5 * Marks places in PixiJS where you can pass Float32Array, UInt32Array, any typed arrays, and ArrayBuffer
6 *
7 * Same as ArrayBuffer in typescript lib, defined here just for documentation
8 */
9export interface IArrayBuffer extends ArrayBuffer {
10}
11/**
12 * PixiJS classes use this type instead of ArrayBuffer and typed arrays
13 * to support expressions like `geometry.buffers[0].data[0] = position.x`.
14 *
15 * Gives access to indexing and `length` field
16 * - @popelyshev: If data is actually ArrayBuffer and throws Exception on indexing - its user problem :)
17 */
18export interface ITypedArray extends IArrayBuffer {
19 readonly length: number;
20 [index: number]: number;
21 readonly BYTES_PER_ELEMENT: number;
22}
23/**
24 * A wrapper for data so that it can be used and uploaded by WebGL
25 * @memberof PIXI
26 */
27export declare class Buffer {
28 /**
29 * The data in the buffer, as a typed array
30 * @type {PIXI.IArrayBuffer}
31 */
32 data: ITypedArray;
33 /**
34 * The type of buffer this is, one of:
35 * + ELEMENT_ARRAY_BUFFER - used as an index buffer
36 * + ARRAY_BUFFER - used as an attribute buffer
37 * + UNIFORM_BUFFER - used as a uniform buffer (if available)
38 */
39 type: BUFFER_TYPE;
40 static: boolean;
41 id: number;
42 disposeRunner: Runner;
43 /**
44 * A map of renderer IDs to webgl buffer
45 * @private
46 * @type {Object<number, GLBuffer>}
47 */
48 _glBuffers: {
49 [key: number]: GLBuffer;
50 };
51 _updateID: number;
52 /**
53 * @param {PIXI.IArrayBuffer} data - the data to store in the buffer.
54 * @param _static - `true` for static buffer
55 * @param index - `true` for index buffer
56 */
57 constructor(data?: IArrayBuffer, _static?: boolean, index?: boolean);
58 /**
59 * Flags this buffer as requiring an upload to the GPU.
60 * @param {PIXI.IArrayBuffer|number[]} [data] - the data to update in the buffer.
61 */
62 update(data?: IArrayBuffer | Array<number>): void;
63 /** Disposes WebGL resources that are connected to this geometry. */
64 dispose(): void;
65 /** Destroys the buffer. */
66 destroy(): void;
67 /**
68 * Flags whether this is an index buffer.
69 *
70 * Index buffers are of type `ELEMENT_ARRAY_BUFFER`. Note that setting this property to false will make
71 * the buffer of type `ARRAY_BUFFER`.
72 *
73 * For backwards compatibility.
74 */
75 set index(value: boolean);
76 get index(): boolean;
77 /**
78 * Helper function that creates a buffer based on an array or TypedArray
79 * @param {ArrayBufferView | number[]} data - the TypedArray that the buffer will store. If this is a regular Array it will be converted to a Float32Array.
80 * @returns - A new Buffer based on the data provided.
81 */
82 static from(data: IArrayBuffer | number[]): Buffer;
83}