/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Accessor","../../../core/maybe","../../../core/accessorSupport/decorators/property","../../../chunks/vec2f32","./NoiseTextureAtlasConfiguration","./NoiseTextureAtlasDimensions","./NoiseTextureAtlasTechnique","../webgl-engine/lib/glUtil3D","../../webgl/enums","../../webgl/FramebufferObject"],(function(e,t,r,i,n,s,o,u,a,h,c,l,T){"use strict";let d=function(e){function r(t){var r;let i;return(r=e.call(this,t)||this)._weatherTile=o.fromValues(0,0),r._needsRender=!0,r._frameBuffer=new T.FramebufferObject(t.context.renderContext.rctx,{colorTarget:l.TargetType.TEXTURE,width:a.ATLAS_SIZE,height:a.ATLAS_SIZE},{target:l.TextureType.TEXTURE_2D,pixelFormat:l.PixelFormat.RGBA,dataType:l.PixelType.UNSIGNED_BYTE,wrapMode:l.TextureWrapMode.CLAMP_TO_EDGE,samplingMode:l.TextureSamplingMode.LINEAR,hasMipmap:!1,width:a.ATLAS_SIZE,height:a.ATLAS_SIZE}),r._vao=c.createQuadVAO(t.context.renderContext.rctx),r._shaderTechniqueRepository=t.context.shaderTechniqueRepository,r._ensureRendered=()=>(n.isSome(i)?n.isSome(r.weatherMapTechnique)&&r.weatherMapTechnique.compiled&&r._needsRender&&(i=r._render(t.context.renderContext.rctx,u.NoiseTextureRenderMode.WeatherMap)):n.isSome(r.fullTechnique)&&r.fullTechnique.compiled&&(i=r._render(t.context.renderContext.rctx,u.NoiseTextureRenderMode.Full)),i),r}t._inheritsLoose(r,e);var i=r.prototype;return i._setDirty=function(){this._needsRender=!0},i.updateWeatherMap=function(e){this._weatherTile[0]===e[0]&&this._weatherTile[1]===e[1]||(this._weatherTile=e,this._setDirty())},i.destroy=function(){this._fullTechnique=n.releaseMaybe(this._fullTechnique),this._weatherMapTechnique=n.releaseMaybe(this._weatherMapTechnique),this._frameBuffer=n.disposeMaybe(this._frameBuffer),this._vao=n.disposeMaybe(this._vao)},i._render=function(e,t){if(n.isNone(this._vao)||n.isNone(this._frameBuffer))return null;const r=t===u.NoiseTextureRenderMode.Full?this.fullTechnique:this.weatherMapTechnique;if(n.isNone(r))return null;const i=e.getViewport();e.setViewport(0,0,a.ATLAS_SIZE,a.ATLAS_SIZE),e.bindFramebuffer(this._frameBuffer);const s=e.bindTechnique(r);return s.setUniform2f("weatherTile",this._weatherTile[0],this._weatherTile[1]),e.bindVAO(this._vao),s.assertCompatibleVertexAttributeLocations(this._vao),e.gl.drawArrays(e.gl.TRIANGLE_STRIP,0,4),e.setViewport(i.x,i.y,i.width,i.height),this._needsRender=!1,this._frameBuffer.colorTexture},t._createClass(r,[{key:"textureAtlas",get:function(){return this._ensureRendered()}},{key:"fullTechnique",get:function(){if(n.isNone(this._fullTechnique)){const e=new u.NoiseTextureAtlasTechniqueConfiguration;e.mode=u.NoiseTextureRenderMode.Full,this._fullTechnique=this._shaderTechniqueRepository.acquire(h.NoiseTextureAtlasTechnique,e)}return this._fullTechnique}},{key:"weatherMapTechnique",get:function(){if(n.isNone(this._weatherMapTechnique)){const e=new u.NoiseTextureAtlasTechniqueConfiguration;e.mode=u.NoiseTextureRenderMode.WeatherMap,this._weatherMapTechnique=this._shaderTechniqueRepository.acquire(h.NoiseTextureAtlasTechnique,e)}return this._weatherMapTechnique}}]),r}(i);r.__decorate([s.property({constructOnly:!0})],d.prototype,"context",void 0),e.NoiseTextureAtlas=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
