/*
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 s}from"../../../../webgl/BufferObject.js";import{PrimitiveType as r,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:s,size:r}=e;t(a);const i=await this._params.loadImagery(s,r[0],r[1],this._params.timeExtent,a),{vertexData:o,indexData:n}=await this._params.createFlowMesh("Streamlines",this._params.simulationSettings,i,a);return new _(o,n,{color:this._params.color,opacity:this._params.opacity,size:this._params.size})}render(t,e,s){const{context:o}=t,{program:n}=s;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(s.vertexArray),o.drawElements(r.TRIANGLES,s.indexCount,i.UNSIGNED_INT,0)}}const f=[new p("a_positionAndSide",3,i.FLOAT,0,36),new p("a_timeInfo",3,i.FLOAT,12,36),new p("a_extrude",2,i.FLOAT,24,36),new p("a_speed",1,i.FLOAT,32,36)],h={vsPath:"raster/flow/streamlines",fsPath:"raster/flow/streamlines",locations:n(f)};class _{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),r=s.createIndex(e,35044,this._indexData),i=new o(e,a,r),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 default};
