/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../../../../../../core/RandomLCG.js";import{tileSize as e}from"../../../definitions.js";import{SimpleMesh as s}from"../../../meshing/SimpleMesh.js";import{SizedDepthStencilFormat as o,DataType as r,PrimitiveType as i,PixelType as n}from"../../../../../../webgl/enums.js";import{DisposableFramebufferObject as u}from"../../../../../../webgl/FramebufferObject.js";import{Renderbuffer as d}from"../../../../../../webgl/Renderbuffer.js";import{RenderbufferDescriptor as l}from"../../../../../../webgl/RenderbufferDescriptor.js";import h from"../../../../../../webgl/Texture.js";import{TextureDescriptor as _}from"../../../../../../webgl/TextureDescriptor.js";const m={pos:{count:2,type:r.UNSIGNED_SHORT}};class T{constructor(){this._dotTextureSize=0,this._dotTextures=null,this._dotMesh=null}destroy(){this._disposeTextures(),this._dotFBO?.dispose(),this._dotMesh?.destroy()}getFBO(t){if(null==this._dotFBO){const s=e,r=e,i=new _(s,r);i.samplingMode=9728,i.wrapMode=33071;const n=new d(t,new l(o.DEPTH24_STENCIL8,s,r));this._dotFBO=new u(t,i,n)}return this._dotFBO}getDotDensityMesh(t){if(null==this._dotMesh){const o=e,r=o*o,n=2,u=new Int16Array(r*n);for(let t=0;t<o;t++)for(let e=0;e<o;e++)u[n*(e+t*o)]=e,u[n*(e+t*o)+1]=t;this._dotMesh=s.create(t,{primitive:i.POINTS,vertex:u,count:r,layout:m})}return this._dotMesh}getDotDensityTextures(e,s,o){if(this._dotTextureSize===s&&this._seed===o||(this._disposeTextures(),this._dotTextureSize=s,this._seed=o),null===this._dotTextures){const r=new t(o);this._dotTextures=[this._allocDotDensityTexture(e,s,r),this._allocDotDensityTexture(e,s,r)]}return this._dotTextures}_disposeTextures(){if(this._dotTextures){for(let t=0;t<this._dotTextures.length;t++)this._dotTextures[t].dispose();this._dotTextures=null}}_allocDotDensityTexture(t,e,s){const o=new Float32Array(e*e*4);for(let i=0;i<o.length;i++)o[i]=s.getFloat();const r=new _(e);return r.dataType=n.FLOAT,r.samplingMode=9728,new h(t,r,o)}}export{T as DotDensityResources};
