/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{throwIfAborted as t}from"../../../../../core/promiseUtils.js";import{areStreamlinesCompatible as e,setUniforms as a}from"../utils.js";import{BufferObject as r}from"../../../../webgl/BufferObject.js";import{PrimitiveType as s,DataType as i}from"../../../../webgl/enums.js";import{VertexArrayObject as o}from"../../../../webgl/VertexArrayObject.js";import{fromLayout as n}from"../../../../webgl/VertexAttributeLocations.js";import{VertexBuffer as m}from"../../../../webgl/VertexBuffer.js";import{VertexElementDescriptor as p}from"../../../../webgl/VertexElementDescriptor.js";class l{constructor(t){this._params=t}get animated(){return this._params.flowSpeed>0}isCompatible(t){return t instanceof l&&e(this._params,t._params)}async load(e,a){const{extent:r,size:s}=e;t(a);const i=await this._params.loadImagery(r,s[0],s[1],this._params.timeExtent,a),{vertexData:o,indexData:n}=await this._params.createFlowMesh("Particles",this._params.simulationSettings,i,a);return new c(o,n,{color:this._params.color,opacity:this._params.opacity,size:this._params.size})}render(t,e,r){const{context:o}=t,{program:n}=r;o.setFaceCullingEnabled(!1),o.setBlendingEnabled(!0),o.setBlendFunction(1,771),o.useProgram(n),n.setUniform1f("u_time",e.time),n.setUniform1f("u_trailLength",this._params.trailLength),n.setUniform1f("u_flowSpeed",this._params.flowSpeed),n.setUniform1f("u_featheringSize",this._params.featheringSize),n.setUniform1f("u_featheringOffset",this._params.featheringOffset),n.setUniform1f("u_introFade",this._params.introFade?1:0),n.setUniform1f("u_fadeToZero",this._params.fadeToZero?1:0),n.setUniform1f("u_decayRate",this._params.decayRate),n.setUniformMatrix3fv("u_dvsMat3",e.dvsMat3),n.setUniformMatrix3fv("u_displayViewMat3",e.displayViewMat3),a(n,"color","vec4",this._params.color),a(n,"opacity","float",this._params.opacity),a(n,"size","float",this._params.size),o.bindVAO(r.vertexArray),o.drawElements(s.TRIANGLES,r.indexCount,i.UNSIGNED_INT,0)}}const f=[new p("a_xyts0",4,i.FLOAT,0,64),new p("a_xyts1",4,i.FLOAT,16,64),new p("a_typeIdDurationSeed",4,i.FLOAT,32,64),new p("a_extrudeInfo",4,i.FLOAT,48,64)],h={vsPath:"raster/flow/particles",fsPath:"raster/flow/particles",locations:n(f)};class c{constructor(t,e,a){this._vertexData=t,this._indexData=e,this._values=a}attach(t){const{context:e}=t,a=new m(e,f,this._vertexData),s=r.createIndex(e,35044,this._indexData),i=new o(e,a,s),n=[];"ramp"===this._values.color.kind&&n.push("vvColor"),"ramp"===this._values.opacity.kind&&n.push("vvOpacity"),"ramp"===this._values.size.kind&&n.push("vvSize");const p=t.getProgram(h,n);this.vertexArray=i,this.program=p,this.indexCount=this._indexData.length,this._vertexData=null,this._indexData=null}detach(){this.vertexArray.dispose()}get ready(){return this.program.compiled}}export{l as Particles,c as ParticlesResources};
