/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{reallocGrowthFactor as t}from"../../../../core/arrayUtils.js";import{fromValues as e}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{minExpectedGaussianCount as a}from"./GaussianSplatAtlasPages.js";import{TextureDescriptor as o}from"../../../webgl/TextureDescriptor.js";class u{constructor(t){this.texture=null,this._orderTextureCapacity=0,this._rctx=t}ensureCapacity(e){if(this._orderTextureCapacity>=e)return;const u=Math.max(Math.ceil(e*t),a),[p,c]=this._evalTextureSize(u),h=p*c;this._orderBuffer=new Uint32Array(h),this._orderTextureCapacity=h,this.texture?.dispose();const l=new o;l.width=p,l.height=c,l.pixelFormat=36244,l.dataType=i.UNSIGNED_INT,l.internalFormat=s.R32UI,l.wrapMode=33071,l.samplingMode=9728,l.isImmutable=!0,this.texture=new r(this._rctx,l),this._orderTextureCapacity=h}setData(t,e){this.ensureCapacity(e),this._orderBuffer.set(t);const r=this.texture.descriptor.width,i=Math.ceil(e/r),s=r*i;this.texture.updateData(0,0,0,r,i,this._orderBuffer.subarray(0,s))}clear(){this._orderTextureCapacity=0,this.texture?.dispose(),this.texture=null}destroy(){this.texture?.dispose()}_evalTextureSize(t){const r=Math.ceil(Math.sqrt(t)),i=Math.ceil(t/r);return e(r,i)}}export{u as GaussianSplatOrderTexture};
