1 | import { Buffer } from '../geometry/Buffer';
|
2 | import type { Dict } from '@pixi/utils';
|
3 | import type { UniformsSyncCallback } from './utils';
|
4 | /**
|
5 | * Uniform group holds uniform map and some ID's for work
|
6 | *
|
7 | * `UniformGroup` has two modes:
|
8 | *
|
9 | * 1: Normal mode
|
10 | * Normal mode will upload the uniforms with individual function calls as required
|
11 | *
|
12 | * 2: Uniform buffer mode
|
13 | * This mode will treat the uniforms as a uniform buffer. You can pass in either a buffer that you manually handle, or
|
14 | * or a generic object that PixiJS will automatically map to a buffer for you.
|
15 | * For maximum benefits, make Ubo UniformGroups static, and only update them each frame.
|
16 | *
|
17 | * Rules of UBOs:
|
18 | * - UBOs only work with WebGL2, so make sure you have a fallback!
|
19 | * - Only floats are supported (including vec[2,3,4], mat[2,3,4])
|
20 | * - Samplers cannot be used in ubo's (a GPU limitation)
|
21 | * - You must ensure that the object you pass in exactly matches in the shader ubo structure.
|
22 | * Otherwise, weirdness will ensue!
|
23 | * - The name of the ubo object added to the group must match exactly the name of the ubo in the shader.
|
24 | *
|
25 | * ```glsl
|
26 | * // UBO in shader:
|
27 | * uniform myCoolData { // Declaring a UBO...
|
28 | * mat4 uCoolMatrix;
|
29 | * float uFloatyMcFloatFace;
|
30 | * };
|
31 | * ```
|
32 | *
|
33 | * ```js
|
34 | * // A new Uniform Buffer Object...
|
35 | * const myCoolData = new UniformBufferGroup({
|
36 | * uCoolMatrix: new Matrix(),
|
37 | * uFloatyMcFloatFace: 23,
|
38 | * }}
|
39 | *
|
40 | * // Build a shader...
|
41 | * const shader = Shader.from(srcVert, srcFrag, {
|
42 | * myCoolData // Name matches the UBO name in the shader. Will be processed accordingly.
|
43 | * })
|
44 | *
|
45 | * ```
|
46 | * @memberof PIXI
|
47 | */
|
48 | export declare class UniformGroup<LAYOUT = Dict<any>> {
|
49 | /**
|
50 | * Uniform values
|
51 | * @member {object}
|
52 | */
|
53 | readonly uniforms: LAYOUT;
|
54 | /**
|
55 | * Its a group and not a single uniforms.
|
56 | * @default true
|
57 | */
|
58 | readonly group: boolean;
|
59 | /**
|
60 | * unique id
|
61 | * @protected
|
62 | */
|
63 | id: number;
|
64 | syncUniforms: Dict<UniformsSyncCallback>;
|
65 | /**
|
66 | * Dirty version
|
67 | * @protected
|
68 | */
|
69 | dirtyId: number;
|
70 | /** Flag for if uniforms wont be changed after creation. */
|
71 | static: boolean;
|
72 | /** Flags whether this group is treated like a uniform buffer object. */
|
73 | ubo: boolean;
|
74 | buffer?: Buffer;
|
75 | autoManage: boolean;
|
76 | /**
|
77 | * @param {object | Buffer} [uniforms] - Custom uniforms to use to augment the built-in ones. Or a pixi buffer.
|
78 | * @param isStatic - Uniforms wont be changed after creation.
|
79 | * @param isUbo - If true, will treat this uniform group as a uniform buffer object.
|
80 | */
|
81 | constructor(uniforms: LAYOUT | Buffer, isStatic?: boolean, isUbo?: boolean);
|
82 | update(): void;
|
83 | add(name: string, uniforms: Dict<any>, _static?: boolean): void;
|
84 | static from(uniforms: Dict<any> | Buffer, _static?: boolean, _ubo?: boolean): UniformGroup;
|
85 | /**
|
86 | * A short hand function for creating a static UBO UniformGroup.
|
87 | * @param uniforms - the ubo item
|
88 | * @param _static - should this be updated each time it is used? defaults to true here!
|
89 | */
|
90 | static uboFrom(uniforms: Dict<any> | Buffer, _static?: boolean): UniformGroup;
|
91 | }
|