/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{disposeMaybe as t}from"../../core/maybe.js";import{BufferObject as i}from"./BufferObject.js";import{UniformBufferLayout as e}from"./UniformBufferLayout.js";class s{constructor(t,i,s=35048){this._context=t,this._usage=s,this._dirtyRange={from:1/0,to:-1},this._initialized=!1,this._data=new e(i)}get byteLength(){return this._data.byteLength}initialize(){this._initialized||(this.buffer=i.createUniform(this._context,this._usage,this._data.array),this._resetDirtyRange(),this._initialized=!0)}dispose(){this._context.unbindUBO(this),this.buffer=t(this.buffer)}set(t){this._data.setValues(t,this._dirtyRange)}setUniform(t,i){this._data.setValue(t,i,this._dirtyRange)}upload(){this.initialize();const{from:t,to:i}=this._dirtyRange;i>-1&&t<i&&(this.buffer.setSubData(this._data.arrayView32,t,t,i),this._resetDirtyRange())}_resetDirtyRange(){this._dirtyRange.from=1/0,this._dirtyRange.to=-1}}export{s as UniformBufferObject};
