/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{reallocGrowthFactor as e}from"../../../../core/arrayUtils.js";import{fromValues as t}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 r from"../../../webgl/Texture.js";import"../../../../core/Logger.js";import{PixelType as i,SizedPixelFormat as s}from"../../../webgl/enums.js";import"../../../webgl/Util.js";import{initialSplatAtlasTexturePages as a}from"./GaussianSplatAtlasPages.js";import{TextureDescriptor as o}from"../../../webgl/TextureDescriptor.js";class u{constructor(e){this.texture=null,this._fadeTextureCapacity=0,this._rctx=e}ensureCapacity(t){if(this._fadeTextureCapacity>t)return;const u=Math.max(Math.ceil(t*e),a),[f,p]=this._evalTextureSize(u),c=f*p,h=this._fadeBuffer,m=new Uint8Array(c);h&&m.set(h.subarray(0,this._fadeTextureCapacity)),this._fadeBuffer=m,this._fadeTextureCapacity=c,this.texture?.dispose();const l=new o;l.width=f,l.height=p,l.pixelFormat=36244,l.dataType=i.UNSIGNED_BYTE,l.internalFormat=s.R8UI,l.unpackAlignment=1,l.wrapMode=33071,l.samplingMode=9728,l.isImmutable=!0,this.texture=new r(this._rctx,l)}updateTexture(e){this.ensureCapacity(e);const t=this.texture.descriptor.width,r=Math.ceil(e/t),i=t*r;this.texture.updateData(0,0,0,t,r,this._fadeBuffer.subarray(0,i))}updateBuffer(e,t){this.ensureCapacity(t+1),this._fadeBuffer&&(this._fadeBuffer[t]=e)}destroy(){this.texture?.dispose()}_evalTextureSize(e){const r=Math.ceil(Math.sqrt(e)),i=Math.ceil(e/r);return t(r,i)}}export{u as GaussianSplatFadeTexture};
