/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{reallocGrowthFactor as e}from"../../../../core/arrayUtils.js";import{estimateNumberArrayMemory as t}from"../../../../core/memoryEstimations.js";import{fromValues as r}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import"../../../webgl/BufferObject.js";import"../../../webgl/FramebufferObject.js";import"../../../webgl/Program.js";import"../../../../core/has.js";import"../../../webgl/Renderbuffer.js";import s from"../../../webgl/Texture.js";import"../../../../core/Logger.js";import{PixelType as i,SizedPixelFormat as a}from"../../../webgl/enums.js";import"../../../webgl/Util.js";import{initialSplatAtlasTexturePages as o}from"./GaussianSplatAtlasPages.js";import{TextureDescriptor as u}from"../../../webgl/TextureDescriptor.js";class f{constructor(e){this.texture=null,this._fadeTextureCapacity=0,this._rctx=e}get usedMemory(){return(this.texture?.usedMemory??0)+t(this._fadeBuffer)}ensureCapacity(t){const r=this.texture;if(this._fadeTextureCapacity>=t&&r?.hasWebGLTextureObject)return;const f=Math.max(Math.ceil(t*e),o),[h,c]=this._evalTextureSize(f),m=h*c,p=this._fadeBuffer,l=new Uint8Array(m);p&&l.set(p.subarray(0,this._fadeTextureCapacity)),this._fadeBuffer=l,this._fadeTextureCapacity=m,this.texture?.dispose();const d=new u;d.width=h,d.height=c,d.pixelFormat=36244,d.dataType=i.UNSIGNED_BYTE,d.internalFormat=a.R8UI,d.unpackAlignment=1,d.wrapMode=33071,d.samplingMode=9728,d.isImmutable=!0,this.texture=new s(this._rctx,d)}updateTexture(e){this.ensureCapacity(e);const t=this.texture.descriptor.width,r=Math.ceil(e/t),s=t*r;this.texture.updateData(0,0,0,t,r,this._fadeBuffer.subarray(0,s))}updateBuffer(e,t){this.ensureCapacity(t+1),this._fadeBuffer&&(this._fadeBuffer[t]=e)}clear(){this._fadeBuffer=void 0,this._fadeTextureCapacity=0,this.texture?.dispose(),this.texture=null}destroy(){this.clear()}_evalTextureSize(e){const t=Math.ceil(Math.sqrt(e)),s=Math.ceil(e/t);return r(t,s)}}export{f as GaussianSplatFadeTexture};
