/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/promiseUtils","../utils","../../../../webgl/BufferObject","../../../../webgl/enums","../../../../webgl/VertexArrayObject","../../../../webgl/VertexElementDescriptor"],(function(e,t,a,r,i,s,n){"use strict";let o=function(){function r(e){this._params=e}var s=r.prototype;return s.isCompatible=function(e){return e instanceof r&&a.areStreamlinesCompatible(this._params,e._params)},s.load=function(){var a=e._asyncToGenerator((function*(e,a){const{extent:r,size:i}=e;t.throwIfAborted(a);const s=yield this._params.loadImagery(r,i[0],i[1],this._params.timeExtent,a),{vertexData:n,indexData:o}=yield this._params.createFlowMesh("Streamlines",this._params.simulationSettings,s,a);return new f(n,o,{color:this._params.color,opacity:this._params.opacity,size:this._params.size})}));function r(e,t){return a.apply(this,arguments)}return r}(),s.render=function(e,t,r){const{context:s}=e,{program:n}=r;s.setFaceCullingEnabled(!1),s.setBlendingEnabled(!0),s.setBlendFunction(i.BlendFactor.ONE,i.BlendFactor.ONE_MINUS_SRC_ALPHA),s.useProgram(n),n.setUniform1f("u_time",t.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",t.dvsMat3),n.setUniformMatrix3fv("u_displayViewMat3",t.displayViewMat3),a.setUniforms(n,"color","vec4",this._params.color),a.setUniforms(n,"opacity","float",this._params.opacity),a.setUniforms(n,"size","float",this._params.size),s.bindVAO(r.vertexArray),s.drawElements(i.PrimitiveType.TRIANGLES,r.indexCount,i.DataType.UNSIGNED_INT,0)},e._createClass(r,[{key:"animated",get:function(){return this._params.flowSpeed>0}}]),r}();const p=new Map;p.set("a_positionAndSide",0),p.set("a_timeInfo",1),p.set("a_extrude",2),p.set("a_speed",3);const l={geometry:[new n.VertexElementDescriptor("a_positionAndSide",3,i.DataType.FLOAT,0,36),new n.VertexElementDescriptor("a_timeInfo",3,i.DataType.FLOAT,12,36),new n.VertexElementDescriptor("a_extrude",2,i.DataType.FLOAT,24,36),new n.VertexElementDescriptor("a_speed",1,i.DataType.FLOAT,32,36)]},m={vsPath:"raster/flow/streamlines",fsPath:"raster/flow/streamlines",attributes:p};let f=function(){function t(e,t,a){this._vertexData=e,this._indexData=t,this._values=a}var a=t.prototype;return a.attach=function(e){const{context:t}=e,a=r.BufferObject.createVertex(t,i.Usage.STATIC_DRAW,this._vertexData),n=r.BufferObject.createIndex(t,i.Usage.STATIC_DRAW,this._indexData),o={geometry:a},f=new s.VertexArrayObject(t,p,l,o,n),c=[];"ramp"===this._values.color.kind&&c.push("vvColor"),"ramp"===this._values.opacity.kind&&c.push("vvOpacity"),"ramp"===this._values.size.kind&&c.push("vvSize");const u=e.painter.materialManager.getProgram(m,c);this.vertexArray=f,this.program=u,this.indexCount=this._indexData.length,this._vertexData=null,this._indexData=null},a.detach=function(){this.vertexArray.dispose()},e._createClass(t,[{key:"ready",get:function(){return this.program.isCompiled}}]),t}();return o}));
