/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{set as e,equals as t,transformMat4 as r}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{makeFloat16Array as s}from"../../../../geometry/support/float16.js";import{isColor as a,isDepth as o,isColorHighlightOLIDOrDepth as h}from"../core/shaderLibrary/ShaderOutput.js";import n from"../lib/GLMaterial.js";import{Material as c}from"../lib/Material.js";import{VisualVariablePassParameters as p}from"./VisualVariablePassParameters.js";import{writeDeltaF16Vector as m}from"./internal/bufferWriterUtils.js";import{getLayout as l,LineMarkerTechnique as u}from"../shaders/LineMarkerTechnique.js";import{LineMarkerTechniqueConfiguration as d}from"../shaders/LineMarkerTechniqueConfiguration.js";import{alphaCutoff as f}from"../../../../webscene/support/AlphaCutoff.js";class g extends c{constructor(e,t){super(e,v),this.produces=new Map([[2,e=>10===e||a(e)&&8===this.parameters.renderOccluded],[3,e=>o(e)],[10,e=>h(e)&&8===this.parameters.renderOccluded],[11,e=>h(e)&&8===this.parameters.renderOccluded],[4,e=>a(e)&&this.parameters.writeDepth],[8,e=>a(e)&&!this.parameters.writeDepth],[18,e=>a(e)||10===e]]),this.intersectDraped=void 0,this._configuration=new d(t)}updateConfiguration(e){super.updateConfiguration(e),this._configuration.space=18===e.slot?0:this.parameters.worldSpace?2:1,this._configuration.hideOnShortSegments=this.parameters.hideOnShortSegments,this._configuration.hasCap=0!==this.parameters.cap,this._configuration.anchor=this.parameters.anchor,this._configuration.hasTip=this.parameters.hasTip,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.hasOccludees=e.hasOccludees,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.hasVVSize=this.parameters.hasVVSize,this._configuration.hasVVColor=this.parameters.hasVVColor,this._configuration.hasVVOpacity=this.parameters.hasVVOpacity,this._configuration.occluder=8===this.parameters.renderOccluded,this._configuration.hasScreenSizePerspective=null!=this.parameters.screenSizePerspective}get visible(){return this.parameters.color[3]>=f}intersect(){}createBufferWriter(){return new S(l(this.parameters),this.parameters)}createGLMaterial(e){return new _(e)}}class _ extends n{dispose(){super.dispose(),this._markerTextures?.release(this._markerPrimitive),this._markerPrimitive=null}beginSlot(e){const t=this._material.parameters.markerPrimitive;return t!==this._markerPrimitive&&(this._material.setParameters({markerTexture:this._markerTextures.swap(t,this._markerPrimitive)}),this._markerPrimitive=t),this.getTechnique(u,e)}}class v extends p{constructor(){super(...arguments),this.width=0,this.color=[1,1,1,1],this.markerPrimitive="arrow",this.placement="end",this.cap=0,this.anchor=0,this.hasTip=!1,this.worldSpace=!1,this.hideOnShortSegments=!1,this.writeDepth=!0,this.hasSlicePlane=!1,this.vvFastUpdate=!1,this.stipplePattern=null,this.markerTexture=null}}class S{constructor(e,t){this.layout=e,this._parameters=t}elementCount(){return"begin-end"===this._parameters.placement?12:6}write(i,a,o,h,n){const{buffer:c,offset:p}=n,l=o.get("position").data,u=l.length/3;let d=[1,0,0];const f=o.get("normal");this._parameters.worldSpace&&null!=f&&(d=f.data);let g=1,_=0;this._parameters.vvSize?_=o.get("sizeFeatureAttribute").data[0]:o.has("size")&&(g=o.get("size").data[0]);let v=[1,1,1,1],S=0;this._parameters.vvColor?S=o.get("colorFeatureAttribute").data[0]:o.has("color")&&(v=o.get("color").data);let P=0;this._parameters.vvOpacity&&(P=o.get("opacityFeatureAttribute").data[0]);const O=new Float32Array(c.buffer),T=s(c.buffer),V=new Uint8Array(c.buffer);let k=p*(this.layout.stride/4);const j=O.BYTES_PER_ELEMENT/T.BYTES_PER_ELEMENT,y=4/j,M=(e,t,r,i)=>{O[k++]=e[0],O[k++]=e[1],O[k++]=e[2],m(t,e,T,k*j),k+=y;let s=k*j;if(T[s++]=r[0],T[s++]=r[1],k=Math.ceil(s/j),this._parameters.vvColor)O[k++]=S;else{const e=Math.min(4*i,v.length-4),t=4*k++;V[t]=255*v[e],V[t+1]=255*v[e+1],V[t+2]=255*v[e+2],V[t+3]=255*v[e+3]}this._parameters.vvOpacity&&(O[k++]=P),s=k*j,this._parameters.vvSize?(O[k++]=_,s+=2):T[s++]=g,this._parameters.worldSpace&&(T[s++]=d[0],T[s++]=d[1],T[s++]=d[2]),k=Math.ceil(s/j)},x=(s,a)=>{const o=e(b,l[3*s],l[3*s+1],l[3*s+2]),h=w;let n=s+a;do{e(h,l[3*n],l[3*n+1],l[3*n+2]),n+=a}while(t(o,h)&&n>=0&&n<u);i&&(r(o,o,i),r(h,h,i)),M(o,h,[-1,-1],s),M(o,h,[1,-1],s),M(o,h,[1,1],s),M(o,h,[-1,-1],s),M(o,h,[1,1],s),M(o,h,[-1,1],s)},C=this._parameters.placement;"begin"!==C&&"begin-end"!==C||x(0,1),"end"!==C&&"begin-end"!==C||x(u-1,-1)}}const b=i(),w=i();export{g as LineMarkerMaterial,v as Parameters};
