// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.25/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/views/vectorTiles/renderers/FillRenderer","require exports ../../../core/libs/gl-matrix/mat3 ../../../core/libs/gl-matrix/mat4 ../../../core/libs/gl-matrix/vec3 ../../../core/libs/gl-matrix/vec4 ../GeometryUtils ./rendererUtils ./vtShaderSnippets ../../webgl/ShaderVariations ../../webgl/VertexArrayObject".split(" "),function(I,J,A,z,F,B,G,H,C,D,y){var E=1/65536;return function(){function p(){this._fillAttributeLocations={a_pos:0};this._fillAttributeLocationsDD={a_pos:0,
a_color:1};this._outlineAttributeLocations={a_pos:0,a_offset:1,a_xnormal:2};this._outlineAttributeLocationsDD={a_pos:0,a_offset:1,a_xnormal:2,a_color:3};this._initialized=!1;this._viewProjMat=z.create();this._offsetVector=F.create();this._patternMatrix=A.create();this._color=B.create();this._outlineColor=B.create()}p.prototype.dispose=function(){};p.prototype.render=function(d,a,b,c,m,l,h,p,x,n,e){if(0!==a.triangleElementCount){this._initialized||this._initialize(d);var t=void 0!==h.getPaintValue("fill-pattern",
b),f=h.hasDataDrivenColor?[1,1,1,1]:h.getPaintValue("fill-color",b),q=h.hasDataDrivenOpacity?1:h.getPaintValue("fill-opacity",b),g=q*f[3]*e;this._color[0]=g*f[0];this._color[1]=g*f[1];this._color[2]=g*f[2];this._color[3]=g;var f=3===m,k;f&&(k=H.int32To4Bytes(a.layerID));var g=l.tileTransform.transform,u=l.coordRange/512,r=h.getPaintValue("fill-translate",b);if(0!==r[0]||0!==r[1]){z.copy(this._viewProjMat,l.tileTransform.transform);var g=r[0],r=r[1],v=0,w=0,u=(1<<l.key.level)/Math.pow(2,b)*u;1===h.getPaintValue("fill-translate-anchor",
b)?(v=-G.C_DEG_TO_RAD*c,c=Math.sin(v),w=Math.cos(v),v=u*(g*w-r*c),w=u*(g*c+r*w)):(v=u*g,w=u*r);this._offsetVector[0]=v;this._offsetVector[1]=w;this._offsetVector[2]=0;z.translate(this._viewProjMat,this._viewProjMat,this._offsetVector);g=this._viewProjMat}this._drawFill(d,a,b,m,l,h,p,g,n,e,f,k);if(h.getPaintValue("fill-antialias",b)&&!t&&0<a.outlineElementCount&&(1===m||3===m)){m=h.hasDataDrivenOutline;if(h.outlineUsesFillColor){if(1!==this._color[3])return;this._outlineColor[0]=this._color[0];this._outlineColor[1]=
this._color[1];this._outlineColor[2]=this._color[2];this._outlineColor[3]=this._color[3]}else b=h.hasDataDrivenOutlineColor?[1,1,1,1]:h.getPaintValue("fill-outline-color",b),e*=q*b[3],this._outlineColor[0]=e*b[0],this._outlineColor[1]=e*b[1],this._outlineColor[2]=e*b[2],this._outlineColor[3]=e;n=.75/n;if(e=this._getOutlineVAO(d,l,m))d.bindVAO(e),e=this._outlineShaderVariations.getProgram([m,f],void 0,void 0,m?this._outlineAttributeLocationsDD:this._outlineAttributeLocations),d.bindProgram(e),e.setUniformMatrix4fv("u_transformMatrix",
g),e.setUniformMatrix4fv("u_extrudeMatrix",x),e.setUniform2fv("u_normalized_origin",l.tileTransform.displayCoord),e.setUniform1f("u_depth",h.z+E),e.setUniform1f("u_outline_width",n),e.setUniform4fv("u_color",this._outlineColor),f&&e.setUniform4f("u_id",k[0],k[1],k[2],k[3]),d.drawElements(4,a.outlineElementCount,5125,12*a.outlineElementStart),d.bindVAO()}}};p.prototype._initialize=function(d){if(this._initialized)return!0;var a=new D("fill",["fillVS","fillFS"],[],C,d);a.addDefine("PATTERN","PATTERN",
[!0,!0],"PATTERN");a.addDefine("DD","DD",[!0,!1],"DD");a.addDefine("ID","ID",[!0,!0],"ID");this._fillShaderVariations=a;this._fillVertexAttributes={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:4,normalized:!1,divisor:0}]};this._fillVertexAttributesDD={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:8,normalized:!1,divisor:0},{name:"a_color",count:4,type:5121,offset:4,stride:8,normalized:!0,divisor:0}]};d=new D("outline",["outlineVS","outlineFS"],[],C,d);d.addDefine("DD","DD",
[!0,!1],"DD");d.addDefine("ID","ID",[!0,!0],"ID");this._outlineShaderVariations=d;this._outlineVertexAttributes={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:8,normalized:!1,divisor:0},{name:"a_offset",count:2,type:5120,offset:4,stride:8,normalized:!1,divisor:0},{name:"a_xnormal",count:2,type:5120,offset:6,stride:8,normalized:!1,divisor:0}]};this._outlineVertexAttributesDD={geometry:[{name:"a_pos",count:2,type:5122,offset:0,stride:12,normalized:!1,divisor:0},{name:"a_offset",count:2,
type:5120,offset:4,stride:12,normalized:!1,divisor:0},{name:"a_xnormal",count:2,type:5120,offset:6,stride:12,normalized:!1,divisor:0},{name:"a_color",count:4,type:5121,offset:8,stride:12,normalized:!0,divisor:0}]};return this._initialized=!0};p.prototype._drawFill=function(d,a,b,c,m,l,h,p,x,n,e,t){var f=l.getPaintValue("fill-pattern",b),q=void 0!==f,g=l.hasDataDrivenOpacity?1:n*l.getPaintValue("fill-opacity",b),k=l.hasDataDrivenColor?[1,1,1,1]:l.getPaintValue("fill-color",b);n*=g*k[3];this._color[0]=
n*k[0];this._color[1]=n*k[1];this._color[2]=n*k[2];this._color[3]=n;k=l.hasDataDrivenFill;g=!1;!q&&(k?0:1===n)&&(g=!0);if(!q||0!==c)if(!g||1!==c)if(q||g||0!==c)if(c=this._getFillVAO(d,m,k))d.bindVAO(c),c=this._fillShaderVariations.getProgram([q,k,e],void 0,void 0,k?this._fillAttributeLocationsDD:this._fillAttributeLocations),d.bindProgram(c),q&&(f=h.getMosaicItemPosition(f,!0))&&(b=m.coordRange/512/Math.pow(2,Math.round(b)-m.key.level)/x,A.identity(this._patternMatrix),x=1/(f.size[1]*b),this._patternMatrix[0]=
1/(f.size[0]*b),this._patternMatrix[4]=x,h.bind(d,9729,f.page,1),c.setUniformMatrix3fv("u_pattern_matrix",this._patternMatrix),c.setUniform2f("u_pattern_tl",f.tl[0],f.tl[1]),c.setUniform2f("u_pattern_br",f.br[0],f.br[1]),c.setUniform1i("u_texture",1)),c.setUniformMatrix4fv("u_transformMatrix",p),c.setUniform2fv("u_normalized_origin",m.tileTransform.displayCoord),c.setUniform1f("u_depth",l.z+E),c.setUniform4fv("u_color",this._color),e&&c.setUniform4f("u_id",t[0],t[1],t[2],t[3]),d.drawElements(4,a.triangleElementCount,
5125,12*a.triangleElementStart),d.bindVAO()};p.prototype._getFillVAO=function(d,a,b){if(b){if(a.fillDDVertexArrayObject)return a.fillDDVertexArrayObject;b=a.fillDDVertexBuffer;var c=a.fillIndexBuffer;if(!b||!c)return null;a.fillDDVertexArrayObject=new y(d,this._fillAttributeLocationsDD,this._fillVertexAttributesDD,{geometry:b},c);return a.fillDDVertexArrayObject}if(a.fillVertexArrayObject)return a.fillVertexArrayObject;b=a.fillVertexBuffer;c=a.fillIndexBuffer;if(!b||!c)return null;a.fillVertexArrayObject=
new y(d,this._fillAttributeLocations,this._fillVertexAttributes,{geometry:b},c);return a.fillVertexArrayObject};p.prototype._getOutlineVAO=function(d,a,b){if(b){if(a.outlineDDVertexArrayObject)return a.outlineDDVertexArrayObject;b=a.outlineDDVertexBuffer;var c=a.outlineIndexBuffer;if(!b||!c)return null;a.outlineDDVertexArrayObject=new y(d,this._outlineAttributeLocationsDD,this._outlineVertexAttributesDD,{geometry:b},c);return a.outlineDDVertexArrayObject}if(a.outlineVertexArrayObject)return a.outlineVertexArrayObject;
b=a.outlineVertexBuffer;c=a.outlineIndexBuffer;if(!b||!c)return null;a.outlineVertexArrayObject=new y(d,this._outlineAttributeLocations,this._outlineVertexAttributes,{geometry:b},c);return a.outlineVertexArrayObject};return p}()});