UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2var constants = require("@pixi/constants"), Buffer = require("../geometry/Buffer.js");
3let UID = 0;
4class UniformGroup {
5 /**
6 * @param {object | Buffer} [uniforms] - Custom uniforms to use to augment the built-in ones. Or a pixi buffer.
7 * @param isStatic - Uniforms wont be changed after creation.
8 * @param isUbo - If true, will treat this uniform group as a uniform buffer object.
9 */
10 constructor(uniforms, isStatic, isUbo) {
11 this.group = !0, this.syncUniforms = {}, this.dirtyId = 0, this.id = UID++, this.static = !!isStatic, this.ubo = !!isUbo, uniforms instanceof Buffer.Buffer ? (this.buffer = uniforms, this.buffer.type = constants.BUFFER_TYPE.UNIFORM_BUFFER, this.autoManage = !1, this.ubo = !0) : (this.uniforms = uniforms, this.ubo && (this.buffer = new Buffer.Buffer(new Float32Array(1)), this.buffer.type = constants.BUFFER_TYPE.UNIFORM_BUFFER, this.autoManage = !0));
12 }
13 update() {
14 this.dirtyId++, !this.autoManage && this.buffer && this.buffer.update();
15 }
16 add(name, uniforms, _static) {
17 if (!this.ubo)
18 this.uniforms[name] = new UniformGroup(uniforms, _static);
19 else
20 throw new Error("[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them");
21 }
22 static from(uniforms, _static, _ubo) {
23 return new UniformGroup(uniforms, _static, _ubo);
24 }
25 /**
26 * A short hand function for creating a static UBO UniformGroup.
27 * @param uniforms - the ubo item
28 * @param _static - should this be updated each time it is used? defaults to true here!
29 */
30 static uboFrom(uniforms, _static) {
31 return new UniformGroup(uniforms, _static ?? !0, !0);
32 }
33}
34exports.UniformGroup = UniformGroup;
35//# sourceMappingURL=UniformGroup.js.map