/*
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","../../../core/Logger","../../../core/maybe","../../../core/promiseUtils","../../../chunks/mat4","../../../chunks/mat4f64","../../../support/requestImageUtils","../../../chunks/SimpleAtmosphere.glsl","./SimpleAtmosphereTechnique","./SimpleAtmosphereTechniqueConfiguration","./resources/SimpleAtmosphereTexture","../support/buffer/glUtil","../support/buffer/InterleavedLayout","../webgl-engine/lib/DefaultVertexAttributeLocations","../webgl-engine/lib/GeometryUtil","../webgl-engine/lib/VertexAttribute","../../webgl/BufferObject","../../webgl/enums","../../webgl/Texture","../../webgl/Util","../../webgl/VertexArrayObject"],(function(e,t,r,i,s,o,n,a,l,u,c,h,p,m,g,b,d,y,f,_,x,A){"use strict";const v=r.getLogger("esri.views.3d.environment.PanoramicAtmosphere");let T=function(){function e(){this.type="panoramic",this._techniqueConfig=new c.SimpleAtmosphereTechniqueConfiguration,this._passParameters=new l.SimpleAtmospherePassParameters,this._readyResolver=s.createResolver(),this._readyController=new AbortController}var r=e.prototype;return r.destroy=function(){this._readyResolver.reject(),this._passParameters.texture=i.disposeMaybe(this._passParameters.texture),this._vao=i.disposeMaybe(this._vao),this._readyController=i.abortMaybe(this._readyController)},r.when=function(){return this._readyResolver.promise},r.initializeRenderContext=function(e){this._techniqueConfig.geometry=c.SimpleAtmosphereGeometry.Cylinder,this._technique=e.shaderTechniqueRepository.acquire(u.SimpleAtmosphereTechnique,this._techniqueConfig);const t=e.renderContext.rctx;this._vao=this._createVertexArrayObject(t),this._vaoCount=x.vertexCount(this._vao,"geometry"),a.requestImage(h,{signal:this._readyController.signal}).then((r=>{this._passParameters.texture=new _.Texture(t,{pixelFormat:f.PixelFormat.RGBA,dataType:f.PixelType.UNSIGNED_BYTE,wrapMode:f.TextureWrapMode.CLAMP_TO_EDGE,samplingMode:f.TextureSamplingMode.LINEAR,flipped:!0},r),e.requestRender(),this._readyController=null,this._readyResolver.resolve()})).catch((e=>{s.isAbortError(e)||v.error("Unable to initialize atmosphere: image request failed",e),this._readyResolver.reject()}))},r.render=function(e){const t=e.rctx,r=t.bindTechnique(this._technique,this._passParameters,e.bindParameters);P(C,e.bindParameters.camera.viewMatrix),r.setUniformMatrix4fv("view",C),t.bindVAO(this._vao),r.assertCompatibleVertexAttributeLocations(this._vao),t.drawArrays(f.PrimitiveType.TRIANGLES,0,this._vaoCount)},r.renderHaze=function(){return!1},r._createVertexArrayObject=function(e){const t=b.createPolySphereGeometry(1,2,!1),r=t.indices.get(d.VertexAttribute.POSITION);for(let n=0;n<r.length;n+=3){const e=r[n];r[n]=r[n+2],r[n+2]=e}const i=t.vertexAttributes.get(d.VertexAttribute.POSITION).data,s=w.createBuffer(r.length),o=s.position;for(let n=0;n<r.length;++n){const e=3*r[n];o.set(n,0,i[e]),o.set(n,1,i[e+1]),o.set(n,2,i[e+2])}return new A.VertexArrayObject(e,g.Default3D,{geometry:p.glLayout(w)},{geometry:y.BufferObject.createVertex(e,f.Usage.STATIC_DRAW,s.buffer)})},t._createClass(e,[{key:"canRender",get:function(){return null!=this._passParameters.texture}}]),e}();function P(e,t){o.copy(e,t),e[12]=0,e[13]=0,e[14]=0,e[15]=1}const C=n.create(),w=m.newLayout().vec3f(d.VertexAttribute.POSITION);e.PanoramicAtmosphere=T,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
