UNPKG

1.38 kBJavaScriptView Raw
1import { BUFFER_TYPE } from '@pixi/constants';
2import { Buffer } from '../geometry/Buffer.mjs';
3
4let UID = 0;
5class UniformGroup {
6 constructor(uniforms, isStatic, isUbo) {
7 this.group = true;
8 this.syncUniforms = {};
9 this.dirtyId = 0;
10 this.id = UID++;
11 this.static = !!isStatic;
12 this.ubo = !!isUbo;
13 if (uniforms instanceof Buffer) {
14 this.buffer = uniforms;
15 this.buffer.type = BUFFER_TYPE.UNIFORM_BUFFER;
16 this.autoManage = false;
17 this.ubo = true;
18 } else {
19 this.uniforms = uniforms;
20 if (this.ubo) {
21 this.buffer = new Buffer(new Float32Array(1));
22 this.buffer.type = BUFFER_TYPE.UNIFORM_BUFFER;
23 this.autoManage = true;
24 }
25 }
26 }
27 update() {
28 this.dirtyId++;
29 if (!this.autoManage && this.buffer) {
30 this.buffer.update();
31 }
32 }
33 add(name, uniforms, _static) {
34 if (!this.ubo) {
35 this.uniforms[name] = new UniformGroup(uniforms, _static);
36 } else {
37 throw new Error("[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them");
38 }
39 }
40 static from(uniforms, _static, _ubo) {
41 return new UniformGroup(uniforms, _static, _ubo);
42 }
43 static uboFrom(uniforms, _static) {
44 return new UniformGroup(uniforms, _static ?? true, true);
45 }
46}
47
48export { UniformGroup };
49//# sourceMappingURL=UniformGroup.mjs.map