/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../../../../../../core/Logger.js";import{disposeMaybe as r}from"../../../../../../../core/maybe.js";import{PixelType as t,SizedDepthStencilFormat as a}from"../../../../../../webgl/enums.js";import{FramebufferObject as i}from"../../../../../../webgl/FramebufferObject.js";import{loadHeatmapTextureConfiguration as s}from"../../../../../../webgl/heatmapTextureUtils.js";import{RenderbufferDescriptor as u}from"../../../../../../webgl/RenderbufferDescriptor.js";import l from"../../../../../../webgl/Texture.js";import{TextureDescriptor as o}from"../../../../../../webgl/TextureDescriptor.js";const n=()=>e.getLogger("esri.views.2d.engine.webgl.shaderGraph.techniques.heatmap.HeatmapResources");class m{destroy(){this._accumulateFramebuffer=r(this._accumulateFramebuffer),this._resolveGradientTexture=r(this._resolveGradientTexture),this._prevGradientHash=null,this._qualityProfile=null}get initialized(){return null!=this._accumulateFramebuffer&&null!=this._resolveGradientTexture}get accumulateFramebuffer(){return this._accumulateFramebuffer}get resolveGradientTexture(){return this._resolveGradientTexture}loadQualityProfile(e){if(null==this._qualityProfile){const r=s(e,n());this._qualityProfile={...r,defines:{usesHalfFloatPrecision:r.dataType!==t.FLOAT}}}return this._qualityProfile}ensureAccumulateFBO(e,r,t){if(null==this._accumulateFramebuffer){const{dataType:s,samplingMode:l,pixelFormat:n,internalFormat:m}=this.loadQualityProfile(e),f=new o(r,t);f.pixelFormat=n,f.internalFormat=m,f.dataType=s,f.samplingMode=l,f.wrapMode=33071;const h=new u(a.DEPTH24_STENCIL8,r,t);this._accumulateFramebuffer=new i(e,f,h)}else{const{width:e,height:a}=this._accumulateFramebuffer;e===r&&a===t||this._accumulateFramebuffer.resize(r,t)}return this._accumulateFramebuffer}ensureResolveGradientTexture(e,r,t){if(null==this._resolveGradientTexture){const r=new o;r.wrapMode=33071,this._resolveGradientTexture=new l(e,r),this._prevGradientHash=null}return this._prevGradientHash!==r&&(this._resolveGradientTexture.resize(t.length/4,1),this._resolveGradientTexture.setData(t),this._prevGradientHash=r),this._resolveGradientTexture}}export{m as HeatmapResources};
