// 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/VectorTileDisplayObject","require exports ../../core/tsSupport/extendsHelper ../../core/libs/gl-matrix/vec2 ../../core/libs/gl-matrix/mat4 ../../core/ObjectPool ../../geometry/support/spatialReferenceUtils ../webgl/BufferObject ../2d/engine/DisplayObject ../2d/tiling/TileKey ./RenderBucket".split(" "),function(z,A,r,t,u,v,w,f,x,y,q){return function(p){function k(){for(var c=[],b=0;b<arguments.length;b++)c[b]=arguments[b];b=p.call(this)||this;b._renderBuckets=
[];b._vectorTileData=null;b._symbolUpdateData=null;b.status=5;b.coords=[0,0];b.bounds=[0,0,0,0];b.tileTransform={transform:Float32Array[16],displayCoord:Float32Array[2]};b.stencilData={mask:0,reference:0};b.status=0;b.tileTransform.transform=u.create();b.tileTransform.displayCoord=t.create();0<c.length&&(f=b.acquire).call.apply(f,[b].concat(c));return b;var f}r(k,p);k.prototype.reset=function(){y.pool.release(this.key);this.refKey=this.key=null;this.coords[0]=0;this.coords[1]=0;this.bounds[0]=0;this.bounds[1]=
0;this.bounds[2]=0;this.height=this.width=this.bounds[3]=0;this.resolution=null;this.rotation=0;this.id=this._connection=this.workerID=this.styleLayers=this._vectorTileData=null;this.tileTransform.transform.fill(0);this.tileTransform.displayCoord.fill(0);this.stencilData.mask=0;this.stencilData.reference=0;this._renderBuckets.length=0;this._symbolUpdateData=null;this.status=0};k.prototype.acquire=function(c,b,f,a,h){this.key=c;this.refKey=b;b=f.lodAt(c.level).resolution;var d=f.size[0]*b,e=f.origin,
g=c.col*d,l=c.row*d,m=f.spatialReference,k=0;m&&(m._isWrappable?m._isWrappable():m.isWrappable)&&(m=w.getInfo(m),k=m.valid[1]-m.valid[0]);g=e.x+g+c.world*k;e=e.y-l;this.coords[0]=g;this.coords[1]=e;this.bounds[0]=g;this.bounds[1]=e;this.bounds[2]=g+d;this.bounds[3]=e-d;this.widthInPixels=f.size[1];this.coordRange=4096;this.resolution=b;this.rotation=h;this.styleLayers=a;this.id=c.id;this.status=1};k.prototype.setData=function(c,b,f){this._vectorTileData=c;this.workerID=b;this._connection=f;this.status=
3};k.prototype.updateSymbolData=function(c){c&&(this._symbolUpdateData=c,this.requestRender())};k.prototype.dispose=function(){this.fillVertexArrayObject&&(this.fillVertexArrayObject.dispose(),this.fillVertexArrayObject=null);this.fillDDVertexArrayObject&&(this.fillDDVertexArrayObject.dispose(),this.fillDDVertexArrayObject=null);this.outlineVertexArrayObject&&(this.outlineVertexArrayObject.dispose(),this.outlineVertexArrayObject=null);this.outlineDDVertexArrayObject&&(this.outlineDDVertexArrayObject.dispose(),
this.outlineDDVertexArrayObject=null);this.lineVertexArrayObject&&(this.lineVertexArrayObject.dispose(),this.lineVertexArrayObject=null);this.lineDDVertexArrayObject&&(this.lineDDVertexArrayObject.dispose(),this.lineDDVertexArrayObject=null);this.iconVertexArrayObject&&(this.iconVertexArrayObject.dispose(),this.iconVertexArrayObject=null);this.iconDDVertexArrayObject&&(this.iconDDVertexArrayObject.dispose(),this.iconDDVertexArrayObject=null);this.textVertexArrayObject&&(this.textVertexArrayObject.dispose(),
this.textVertexArrayObject=null);this.textDDVertexArrayObject&&(this.textDDVertexArrayObject.dispose(),this.textDDVertexArrayObject=null);this.fillVertexBuffer&&(this.fillVertexBuffer.dispose(),this.fillVertexBuffer=null);this.fillDDVertexBuffer&&(this.fillDDVertexBuffer.dispose(),this.fillDDVertexBuffer=null);this.fillIndexBuffer&&(this.fillIndexBuffer.dispose(),this.fillIndexBuffer=null);this.outlineVertexBuffer&&(this.outlineVertexBuffer.dispose(),this.outlineVertexBuffer=null);this.outlineDDVertexBuffer&&
(this.outlineDDVertexBuffer.dispose(),this.outlineDDVertexBuffer=null);this.outlineIndexBuffer&&(this.outlineIndexBuffer.dispose(),this.outlineIndexBuffer=null);this.lineVertexBuffer&&(this.lineVertexBuffer.dispose(),this.lineVertexBuffer=null);this.lineDDVertexBuffer&&(this.lineDDVertexBuffer.dispose(),this.lineDDVertexBuffer=null);this.lineIndexBuffer&&(this.lineIndexBuffer.dispose(),this.lineIndexBuffer=null);this.iconVertexBuffer&&(this.iconVertexBuffer.dispose(),this.iconVertexBuffer=null);this.iconDDVertexBuffer&&
(this.iconDDVertexBuffer.dispose(),this.iconDDVertexBuffer=null);this.iconIndexBuffer&&(this.iconIndexBuffer.dispose(),this.iconIndexBuffer=null);this.textVertexBuffer&&(this.textVertexBuffer.dispose(),this.textVertexBuffer=null);this.textDDVertexBuffer&&(this.textDDVertexBuffer.dispose(),this.textDDVertexBuffer=null);this.textIndexBuffer&&(this.textIndexBuffer.dispose(),this.textIndexBuffer=null);this.texture&&(this.texture.dispose(),this.texture=null);this._renderBuckets.length=0;this.status=7};
k.prototype.attach=function(c){if(4===this.status)return!0;this.status=3;if(!this._vectorTileData)return!1;if(!this._vectorTileData.bufferDataInfo)return this.status=4,!0;if(0===this._renderBuckets.length)for(var b=new Uint32Array(this._vectorTileData.bucketDataInfo),k=b.length,a=0;a<k;){var h=b[a],d=b[a+1];if(0===d)d=new q.BackgroundRenderBucket,d.layerID=h,this._renderBuckets.push(d),a+=2;else if(1===d)d=new q.FillRenderBucket,d.layerID=h,d.triangleElementStart=b[a+2],d.triangleElementCount=b[a+
3],d.outlineElementStart=b[a+4],d.outlineElementCount=b[a+5],this._renderBuckets.push(d),a+=6;else if(2===d)d=new q.LineRenderBucket,d.layerID=h,d.triangleElementStart=b[a+2],d.triangleElementCount=b[a+3],this._renderBuckets.push(d),a+=6;else if(3===d){d=new q.SymbolRenderBucket;d.layerID=h;d.isSDF=0!==b[a+2];var e=a+3,h=b[e];e++;if(0<h)for(var g=void 0,l=void 0,m=void 0,n=0;n<h;n++)g=b[e],l=b[e+1],m=b[e+2],d.markerPerPageElementsMap.set(g,[l,m]),e+=3;var p=b[e];e++;if(0<p)for(m=l=g=void 0,n=0;n<
p;n++)g=b[e],l=b[e+1],m=b[e+2],d.glyphPerPageElementsMap.set(g,[l,m]),e+=3;this._renderBuckets.push(d);a+=5+3*h+3*p}else console.error("Bad bucket type!")}c=c.context;b=new Uint32Array(this._vectorTileData.bufferDataInfo);k=b.length;for(d=a=0;d<k;d+=2,a++)if(!(0>=b[d+1]||0===this._vectorTileData.bufferData[a].byteLength))switch(b[d]){case 1:this.fillVertexBuffer?this.fillVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.fillVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);
break;case 2:this.fillDDVertexBuffer?this.fillDDVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.fillDDVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 3:this.fillIndexBuffer?this.fillIndexBuffer.setData(this._vectorTileData.bufferData[a]):this.fillIndexBuffer=f.createIndex(c,35044,this._vectorTileData.bufferData[a]);break;case 4:this.outlineVertexBuffer?this.outlineVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.outlineVertexBuffer=f.createVertex(c,
35044,this._vectorTileData.bufferData[a]);break;case 5:this.outlineDDVertexBuffer?this.outlineDDVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.outlineDDVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 6:this.outlineIndexBuffer?this.outlineIndexBuffer.setData(this._vectorTileData.bufferData[a]):this.outlineIndexBuffer=f.createIndex(c,35044,this._vectorTileData.bufferData[a]);break;case 7:this.lineVertexBuffer?this.lineVertexBuffer.setData(this._vectorTileData.bufferData[a]):
this.lineVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 8:this.lineDDVertexBuffer?this.lineDDVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.lineDDVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 9:this.lineIndexBuffer?this.lineIndexBuffer.setData(this._vectorTileData.bufferData[a]):this.lineIndexBuffer=f.createIndex(c,35044,this._vectorTileData.bufferData[a]);break;case 10:this.iconVertexBuffer?this.iconVertexBuffer.setData(this._vectorTileData.bufferData[a]):
this.iconVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 11:this.iconDDVertexBuffer?this.iconDDVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.iconDDVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 12:this.iconIndexBuffer?this.iconIndexBuffer.setData(this._vectorTileData.bufferData[a]):this.iconIndexBuffer=f.createIndex(c,35044,this._vectorTileData.bufferData[a]);break;case 13:this.textVertexBuffer?this.textVertexBuffer.setData(this._vectorTileData.bufferData[a]):
this.textVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 14:this.textDDVertexBuffer?this.textDDVertexBuffer.setData(this._vectorTileData.bufferData[a]):this.textDDVertexBuffer=f.createVertex(c,35044,this._vectorTileData.bufferData[a]);break;case 15:this.textIndexBuffer?this.textIndexBuffer.setData(this._vectorTileData.bufferData[a]):this.textIndexBuffer=f.createIndex(c,35044,this._vectorTileData.bufferData[a])}this.status=4;return!0};k.prototype.detach=function(c){-1!==
this.workerID&&this._connection&&6!==this.status&&7!==this.status&&this._connection.broadcast("destructTileData",{key:this.id,worker:this.workerID},[]);this.dispose();p.prototype.detach.call(this,c)};k.prototype.doRender=function(c){if(this.visible&&4===this.status){var b=c.context,f=c.renderer;if(b&&f){var a=c.drawphase;this._symbolUpdateData&&this._updateSymbolData(c);b.setStencilFunction(514,this.stencilData.reference,this.stencilData.mask);var h=this.styleLayers,d=void 0!==c.layerOpacity?c.layerOpacity:
1;if(0!==d){var e,g=this._renderBuckets.length,l=0;if(0===a)for(l=g-1;0<=l;l--)e=this._renderBuckets[l],3!==e.type&&e.hasData()&&f.renderBucket(b,e,c.displayLevel,c.requiredLevel,a,this,h.layers[e.layerID],d);else for(l=0;l<g;l++)e=this._renderBuckets[l],e.hasData()&&f.renderBucket(b,e,c.displayLevel,c.requiredLevel,a,this,h.layers[e.layerID],d)}}}};k.prototype._updateSymbolData=function(c){if(!this._symbolUpdateData.bucketDataInfo)return!0;var b=new Uint32Array(this._symbolUpdateData.bucketDataInfo),
k=b.length;if(0===k)return this._symbolUpdateData=null,!0;if(1>c.budget.remaining||4!==this.status)return this.requestRender(),!1;c=c.context;for(var a=new Uint32Array(this._symbolUpdateData.bufferDataInfo),h=a.length,d=0,e=0;e<h;e+=2,d++)switch(a[e]){case 10:this.iconVertexBuffer&&(this.iconVertexBuffer.dispose(),this.iconVertexBuffer=null);this.iconVertexBuffer=f.createVertex(c,35044,this._symbolUpdateData.bufferData[d]);break;case 11:this.iconDDVertexBuffer&&(this.iconDDVertexBuffer.dispose(),
this.iconDDVertexBuffer=null);this.iconDDVertexBuffer=f.createVertex(c,35044,this._symbolUpdateData.bufferData[d]);break;case 12:this.iconIndexBuffer&&(this.iconIndexBuffer.dispose(),this.iconIndexBuffer=null);this.iconIndexBuffer=f.createIndex(c,35044,this._symbolUpdateData.bufferData[d]);break;case 13:this.textVertexBuffer&&(this.textVertexBuffer.dispose(),this.textVertexBuffer=null);this.textVertexBuffer=f.createVertex(c,35044,this._symbolUpdateData.bufferData[d]);break;case 14:this.textDDVertexBuffer&&
(this.textDDVertexBuffer.dispose(),this.textDDVertexBuffer=null);this.textDDVertexBuffer=f.createVertex(c,35044,this._symbolUpdateData.bufferData[d]);break;case 15:this.textIndexBuffer&&(this.textIndexBuffer.dispose(),this.textIndexBuffer=null),this.textIndexBuffer=f.createIndex(c,35044,this._symbolUpdateData.bufferData[d])}c=this._renderBuckets.length;for(a=0;a<c;a++)this._renderBuckets[a]instanceof q.SymbolRenderBucket&&(h=this._renderBuckets[a],h.markerPerPageElementsMap.clear(),h.glyphPerPageElementsMap.clear());
for(c=0;c<k;){h=b[c];d=-1;e=this._renderBuckets.length;for(a=0;a<e;a++)if(this._renderBuckets[a].layerID===h){d=a;break}a=this._renderBuckets[d];a||(a=new q.SymbolRenderBucket,a.layerID=h,a.isSDF=0!==b[c+2],this._renderBuckets.push(a));var g=c+3,h=b[g];g++;if(0<h)for(var l=e=d=void 0,m=0;m<h;m++)d=b[g],e=b[g+1],l=b[g+2],a.markerPerPageElementsMap.set(d,[e,l]),g+=3;var n=b[g];g++;if(0<n)for(l=e=d=void 0,m=0;m<n;m++)d=b[g],e=b[g+1],l=b[g+2],a.glyphPerPageElementsMap.set(d,[e,l]),g+=3;c+=5+3*h+3*n}this.iconVertexArrayObject&&
(this.iconVertexArrayObject.dispose(),this.iconVertexArrayObject=null);this.iconDDVertexArrayObject&&(this.iconDDVertexArrayObject.dispose(),this.iconDDVertexArrayObject=null);this.textVertexArrayObject&&(this.textVertexArrayObject.dispose(),this.textVertexArrayObject=null);this.textDDVertexArrayObject&&(this.textDDVertexArrayObject.dispose(),this.textDDVertexArrayObject=null);this._symbolUpdateData=null;return!0};k.pool=new v(k);return k}(x)});