/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{disposeMaybe as t}from"../../../core/maybe.js";import{watch as r,initial as i}from"../../../core/reactiveUtils.js";import{subclass as s}from"../../../core/accessorSupport/decorators.js";import{copy as o}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{InternalRenderCategory as m}from"../webgl.js";import{S as a}from"../../../chunks/SimpleAtmosphere.glsl.js";import{SimpleAtmosphereTechnique as p,layout as h}from"./SimpleAtmosphereTechnique.js";import{SimpleAtmosphereTechniqueConfiguration as f}from"./SimpleAtmosphereTechniqueConfiguration.js";import{earthAtmosphereTextureSimple as c}from"./resources/SimpleAtmosphereTexture.js";import{glLayout as l}from"../support/buffer/glUtil.js";import{OpaqueEnvironment as u}from"../webgl-engine/effects/OpaqueEnvironment.js";import{createPolySphereData as b}from"../webgl-engine/lib/GeometryUtil.js";import{VertexArrayObject as g}from"../webgl-engine/lib/VertexArrayObject.js";import{PrimitiveType as _}from"../../webgl/enums.js";import d from"../../webgl/Texture.js";import{TextureDescriptor as v}from"../../webgl/TextureDescriptor.js";import{VertexBuffer as w}from"../../webgl/VertexBuffer.js";let j=class extends u{constructor(){super(...arguments),this._configuration=new f,this._passParameters=new a,this._vao=null,this._vaoCount=0}initialize(){this._configuration.geometry=1,this.addHandles([r(()=>this.view.environment.atmosphereEnabled,e=>e?this._enable():this._disable(),i)])}destroy(){this._passParameters.texture=t(this._passParameters.texture),this._vao=t(this._vao)}precompile(){this.techniques.precompile(p,this._configuration)}render(e){const t=e.find(({name:e})=>e===m.OPAQUE_ENVIRONMENT),r=this.techniques.get(p,this._configuration);if(!r.compiled)return this.requestRender(1),t;const i=this.renderingContext;if(this._vao||(this._vao=x(i),this._vaoCount=this._vao.vertexCount("geometry")),!this._passParameters.texture){const e=new v(1,512);e.wrapMode=33071,e.flipped=!0,this._passParameters.texture=new d(i,e,c)}const s=i.bindTechnique(r,this.bindParameters,this._passParameters);return A(P,this.bindParameters.camera.viewMatrix),s.setUniformMatrix4fv("view",P),i.bindVAO(this._vao),s.assertCompatibleVertexAttributeLocations(this._vao),i.drawArrays(_.TRIANGLES,0,this._vaoCount),t}};function x(e){const t=b(1,2,!1),{data:r,indices:i}=t[0][1],s=h.createBuffer(i.length),o=s.position;for(let n=0;n<i.length;++n){const e=3*i[n%3==0?n+2:n%3==2?n-2:n];o.set(n,0,r[e]),o.set(n,1,r[e+1]),o.set(n,2,r[e+2])}return new g(e,new w(e,l(h),s.buffer))}function A(e,t){o(e,t),e[12]=0,e[13]=0,e[14]=0,e[15]=1}j=e([s("esri.views.3d.environment.LocalAtmosphere")],j);const P=n();export{j as LocalAtmosphere};
