/*
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/has","../../../../core/maybe","../../../../chunks/mat3","../../../../chunks/mat3f32","../../../../chunks/vec2f32","../../../../layers/support/rasterFunctions/vectorFieldUtils","../DisplayObject","../webgl/Utils","../../../webgl/BufferObject","../../../webgl/enums","../../../webgl/VertexArrayObject"],(function(e,t,a,s,r,i,o,n,l,c,u,h,d){"use strict";let m=function(e){function a(t=null){var a;return(a=e.call(this)||this)._source=null,a._symbolizerParameters=null,a._vaoInvalidated=!0,a.coordScale=[1,1],a.height=null,a.stencilRef=0,a.resolution=null,a.pixelRatio=1,a.x=0,a.y=0,a.rotation=0,a.rawPixelData=null,a.width=null,a.source=t,a}t._inheritsLoose(a,e);var l=a.prototype;return l.destroy=function(){var e,t;s.isSome(this.vaoData)&&(null==(e=this.vaoData.magdir)||e.vao.dispose(),null==(t=this.vaoData.scalar)||t.vao.dispose(),this.vaoData=null)},l.invalidateVAO=function(){var e,t;!this._vaoInvalidated&&s.isSome(this.vaoData)&&(null==(e=this.vaoData.magdir)||e.vao.dispose(),null==(t=this.vaoData.scalar)||t.vao.dispose(),this.vaoData=null,this._vaoInvalidated=!0,this.requestRender())},l.updateVectorFieldVAO=function(e){if(this._vaoInvalidated){if(this._vaoInvalidated=!1,s.isSome(this.source)&&s.isNone(this.vaoData)){const{style:t}=this.symbolizerParameters;switch(t){case"beaufort_ft":case"beaufort_km":case"beaufort_kn":case"beaufort_m":case"beaufort_mi":case"classified_arrow":case"ocean_current_kn":case"ocean_current_m":case"single_arrow":{const t=n.createVFMesh(this.source,this.symbolizerParameters),a=this._createVectorFieldVAO(e.context,t);this.vaoData={magdir:a}}break;case"simple_scalar":{const t=n.createVFMeshScalar(this.source,this.symbolizerParameters),a=this._createVectorFieldVAO(e.context,t);this.vaoData={scalar:a}}break;case"wind_speed":{const t=n.createVFMesh(this.source,this.symbolizerParameters),a=this._createVectorFieldVAO(e.context,t),s=n.createVFMeshScalar(this.source,this.symbolizerParameters),r=this._createVectorFieldVAO(e.context,s);this.vaoData={magdir:a,scalar:r}}}}this.ready(),this.requestRender()}},l._createTransforms=function(){return{dvs:i.create()}},l.setTransform=function(e){const t=r.identity(this.transforms.dvs),[a,s]=e.toScreenNoRotation([0,0],[this.x,this.y]),i=this.resolution/this.pixelRatio/e.resolution,n=i*this.width,l=i*this.height,c=Math.PI*this.rotation/180;r.translate(t,t,o.fromValues(a,s)),r.translate(t,t,o.fromValues(n/2,l/2)),r.rotate(t,t,-c),r.translate(t,t,o.fromValues(-n/2,-l/2)),r.scaleByVec2(t,t,o.fromValues(n,l)),r.multiply(this.transforms.dvs,e.displayViewMat3,t)},l.onAttach=function(){this.invalidateVAO()},l.onDetach=function(){this.invalidateVAO()},l._createVectorFieldVAO=function(e,t){const{vertexData:a,indexData:s}=t,r=u.BufferObject.createVertex(e,h.Usage.STATIC_DRAW,new Float32Array(a)),i=u.BufferObject.createIndex(e,h.Usage.STATIC_DRAW,new Uint32Array(s)),o=c.createProgramDescriptor("vector-field",{geometry:[{location:0,name:"a_pos",count:2,type:h.DataType.FLOAT,normalized:!1},{location:1,name:"a_offset",count:2,type:h.DataType.FLOAT,normalized:!1},{location:2,name:"a_vv",count:2,type:h.DataType.FLOAT,normalized:!1}]});return{vao:new d.VertexArrayObject(e,o.attributes,o.bufferLayouts,{geometry:r},i),elementCount:s.length}},t._createClass(a,[{key:"symbolizerParameters",get:function(){return this._symbolizerParameters},set:function(e){JSON.stringify(this._symbolizerParameters)!==JSON.stringify(e)&&(this._symbolizerParameters=e,this.invalidateVAO())}},{key:"source",get:function(){return this._source},set:function(e){this._source=e,this.invalidateVAO()}}]),a}(l.DisplayObject);e.RasterVFDisplayObject=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
