UNPKG

@pixi/core

Version:
50 lines (47 loc) 1.38 kB
import { BUFFER_TYPE } from '@pixi/constants'; import { Buffer } from '../geometry/Buffer.mjs'; let UID = 0; class UniformGroup { constructor(uniforms, isStatic, isUbo) { this.group = true; this.syncUniforms = {}; this.dirtyId = 0; this.id = UID++; this.static = !!isStatic; this.ubo = !!isUbo; if (uniforms instanceof Buffer) { this.buffer = uniforms; this.buffer.type = BUFFER_TYPE.UNIFORM_BUFFER; this.autoManage = false; this.ubo = true; } else { this.uniforms = uniforms; if (this.ubo) { this.buffer = new Buffer(new Float32Array(1)); this.buffer.type = BUFFER_TYPE.UNIFORM_BUFFER; this.autoManage = true; } } } update() { this.dirtyId++; if (!this.autoManage && this.buffer) { this.buffer.update(); } } add(name, uniforms, _static) { if (!this.ubo) { this.uniforms[name] = new UniformGroup(uniforms, _static); } else { throw new Error("[UniformGroup] uniform groups in ubo mode cannot be modified, or have uniform groups nested in them"); } } static from(uniforms, _static, _ubo) { return new UniformGroup(uniforms, _static, _ubo); } static uboFrom(uniforms, _static) { return new UniformGroup(uniforms, _static ?? true, true); } } export { UniformGroup }; //# sourceMappingURL=UniformGroup.mjs.map