// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/views/vectorTiles/renderers/SDFRenderer","require exports dojo/has ../../../core/libs/gl-matrix/mat4 ../../../core/libs/gl-matrix/vec4 ../../../core/libs/gl-matrix/vec3 ../../webgl/VertexArrayObject ../GeometryUtils ./rendererUtils ../../webgl/ShaderVariations ./vtShaderSnippets".split(" "),function(K,L,F,p,x,y,u,D,G,H,I){var J=1/65536;return function(){function g(){this._attributeLocations={a_pos:0,a_vertexOffset:1,a_tex:2,a_levelInfo:3};this._attributeLocationsDD=
{a_pos:0,a_vertexOffset:1,a_tex:2,a_levelInfo:3,a_color:4,a_size:5};this._initialized=!1;this._viewProjMat=p.create();this._offsetVector=y.create();this._extrudeMat=p.create();this._haloColor=x.create();this._sdfColor=x.create();this._scaleVec=y.create()}g.prototype.dispose=function(){};g.prototype.render=function(e,c,b,d,g,f,r,h,z,v,A,B,m){var l=this;if(!F("esri-vector-tiles-avoid-text")){this._initialized||this._initialize(e);var x=h.getLayoutValue("text-size",b),y=D.degToByte(g),w=h.getLayoutValue("text-rotation-alignment",
b);2===w&&(w=1===h.getLayoutValue("symbol-placement",b)?0:1);var u=0===w,w=h.getLayoutValue("text-keep-upright",b)&&u;d=3===d;B=.8*3/B;var C=m*h.getPaintValue("text-opacity",b);this._glyphTextureSize||(this._glyphTextureSize=new Float32Array([z.width/4,z.height/4]));m=r.tileTransform.transform;var n=h.getPaintValue("text-translate",b);if(0!==n[0]||0!==n[1]){p.copy(this._viewProjMat,r.tileTransform.transform);m=n[0];var n=n[1],t=0,q=0,q=(1<<r.key.level)/Math.pow(2,b)*(r.coordRange/512);if(1===h.getPaintValue("text-translate-anchor",
b)){t=-D.C_DEG_TO_RAD*g;g=Math.sin(t);var E=Math.cos(t),t=q*(m*E-n*g),q=q*(m*g+n*E)}else t=q*m,q*=n;this._offsetVector[0]=t;this._offsetVector[1]=q;this._offsetVector[2]=0;p.translate(this._viewProjMat,this._viewProjMat,this._offsetVector);m=this._viewProjMat}u?p.copy(this._extrudeMat,v):p.copy(this._extrudeMat,A);this._scaleVec[0]=1/24;this._scaleVec[1]=1/24;this._scaleVec[2]=1;p.scale(this._extrudeMat,this._extrudeMat,this._scaleVec);v=h.hasDataDrivenText;if(A=this._getSDFVAO(e,r,v)){e.bindVAO(A);
var a=this._shaderVariations.getProgram([v,d],void 0,void 0,v?this._attributeLocationsDD:this._attributeLocations);e.bindProgram(a);a.setUniformMatrix4fv("u_transformMatrix",m);a.setUniformMatrix4fv("u_extrudeMatrix",this._extrudeMat);a.setUniform2fv("u_normalized_origin",r.tileTransform.displayCoord);a.setUniform1f("u_depth",h.z+J);a.setUniform2fv("u_mosaicSize",this._glyphTextureSize);a.setUniform1f("u_mapRotation",y);a.setUniform1f("u_keepUpright",w?1:0);a.setUniform1f("u_level",10*b);a.setUniform1f("u_fadeSpeed",
10*f.fadeSpeed);a.setUniform1f("u_minfadeLevel",10*f.minfadeLevel);a.setUniform1f("u_maxfadeLevel",10*f.maxfadeLevel);a.setUniform1f("u_fadeChange",10*(b+f.fadeChange));a.setUniform1f("u_opacity",C);a.setUniform1i("u_texture",0);a.setUniform1f("u_size",x);a.setUniform1f("u_antialiasingWidth",B);d&&(f=G.int32To4Bytes(c.layerID),a.setUniform4f("u_id",f[0],f[1],f[2],f[3]));c.glyphPerPageElementsMap.forEach(function(c,g){z.bind(e,9729,g,0);var k=h.getPaintValue("text-halo-color",b),d=h.getPaintValue("text-halo-width",
b);if(0<k[3]&&0<d){var f=k[3]*C;l._haloColor[0]=f*k[0];l._haloColor[1]=f*k[1];l._haloColor[2]=f*k[2];l._haloColor[3]=f;k=3*h.getPaintValue("text-halo-blur",b);d*=3;a.setUniform4fv("u_color",l._haloColor);a.setUniform1f("u_halo",1);a.setUniform1f("u_edgeDistance",d);a.setUniform1f("u_edgeBlur",k);e.drawElements(4,c[1],5125,12*c[0])}d=h.getPaintValue("text-color",b);0<d[3]&&(k=d[3]*C,l._sdfColor[0]=k*d[0],l._sdfColor[1]=k*d[1],l._sdfColor[2]=k*d[2],l._sdfColor[3]=k,a.setUniform4fv("u_color",l._sdfColor),
a.setUniform1f("u_halo",0),a.setUniform1f("u_edgeDistance",0),a.setUniform1f("u_edgeBlur",0),e.drawElements(4,c[1],5125,12*c[0]))});e.bindVAO()}}};g.prototype._initialize=function(e){if(this._initialized)return!0;e=new H("text",["textVS","textFS"],[],I,e);e.addDefine("DD","DD",[!0,!1],"DD");e.addDefine("ID","ID",[!0,!0],"ID");this._shaderVariations=e;this._vertexAttributes={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:16,normalized:!1,divisor:0},{name:"a_vertexOffset",count:2,type:5122,
offset:4,stride:16,normalized:!1,divisor:0},{name:"a_tex",count:4,type:5121,offset:8,stride:16,normalized:!1,divisor:0},{name:"a_levelInfo",count:4,type:5121,offset:12,stride:16,normalized:!1,divisor:0}]};this._vertexAttributesDD={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:24,normalized:!1,divisor:0},{name:"a_vertexOffset",count:2,type:5122,offset:4,stride:24,normalized:!1,divisor:0},{name:"a_tex",count:4,type:5121,offset:8,stride:24,normalized:!1,divisor:0},{name:"a_levelInfo",count:4,
type:5121,offset:12,stride:24,normalized:!1,divisor:0},{name:"a_color",count:4,type:5121,offset:16,stride:24,normalized:!0,divisor:0},{name:"a_size",count:1,type:5126,offset:20,stride:24,normalized:!1,divisor:0}]};return this._initialized=!0};g.prototype._getSDFVAO=function(e,c,b){if(b){if(c.textDDVertexArrayObject)return c.textDDVertexArrayObject;b=c.textDDVertexBuffer;var d=c.textIndexBuffer;if(!b||!d)return null;c.textDDVertexArrayObject=new u(e,this._attributeLocationsDD,this._vertexAttributesDD,
{geometry:b},d);return c.textDDVertexArrayObject}if(c.textVertexArrayObject)return c.textVertexArrayObject;b=c.textVertexBuffer;d=c.textIndexBuffer;if(!b||!d)return null;c.textVertexArrayObject=new u(e,this._attributeLocations,this._vertexAttributes,{geometry:b},d);return c.textVertexArrayObject};return g}()});