/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","../brushes","./shaders/VTLMaterialManager","./style/StyleDefinition","../../../webgl/enums"],(function(e,t,r,a,s,n){"use strict";const i=1e-6;return function(){function l(e,t){this.spriteMosaic=e,this.glyphMosaic=t,this._brushCache=new Map,this._vtlMaterialManager=new a}var o=l.prototype;return o.dispose=function(){this._brushCache&&(this._brushCache.forEach((e=>e.dispose())),this._brushCache=null),this._vtlMaterialManager=t.disposeMaybe(this._vtlMaterialManager),this.spriteMosaic.dispose(),this.glyphMosaic.dispose()},o.drawTile=function(e,t,r){const{context:a}=e,s=r.layers;r.backgroundBucketIds.length>0&&(e.renderPass="background",r.backgroundBucketIds.forEach((a=>this._renderStyleLayer(r.getLayerById(a),e,t,!0)))),a.setBlendingEnabled(!1),a.setDepthTestEnabled(!0),a.setDepthWriteEnabled(!0),a.setDepthFunction(n.CompareFunction.LEQUAL),e.renderPass="opaque";for(let n=s.length-1;n>=0;n--)this._renderStyleLayer(s[n],e,t,!1);a.setDepthWriteEnabled(!1),a.setBlendingEnabled(!0),a.setBlendFunctionSeparate(n.BlendFactor.ONE,n.BlendFactor.ONE_MINUS_SRC_ALPHA,n.BlendFactor.ONE,n.BlendFactor.ONE_MINUS_SRC_ALPHA),e.renderPass="translucent";for(let n=0;n<s.length;n++)this._renderStyleLayer(s[n],e,t,!1);a.setDepthTestEnabled(!1),e.renderPass="symbol";for(let n=0;n<s.length;n++)this._renderStyleLayer(s[n],e,t,!1);a.bindVAO()},o._renderStyleLayer=function(e,t,r,a=!1){if(!(a||e&&r.layerData.has(e.uid)))return;const n=e.getLayoutProperty("visibility");if(n&&n.getValue()===s.Visibility.NONE)return;const{renderPass:l}=t;let o;switch(e.type){case s.StyleLayerType.BACKGROUND:if("background"!==l)return;o="vtlBackground";break;case s.StyleLayerType.FILL:if("opaque"!==l&&"translucent"!==t.renderPass)return;o="vtlFill";break;case s.StyleLayerType.LINE:if("translucent"!==l)return;o="vtlLine";break;case s.StyleLayerType.CIRCLE:if("symbol"!==l)return;o="vtlCircle";break;case s.StyleLayerType.SYMBOL:if("symbol"!==l)return;o="vtlSymbol"}const h=t.displayLevel;void 0!==e.minzoom&&e.minzoom>h+i||void 0!==e.maxzoom&&e.maxzoom<=h-i||(t.styleLayerUID=e.uid,t.styleLayer=e,this._drawWithBrush(t,r,o))},o._drawWithBrush=function(e,t,a){if(!this._brushCache.has(a)){const e=r.vtlBrushes[a];this._brushCache.set(a,new e)}this._brushCache.get(a).drawMany(e,[t])},e._createClass(l,[{key:"vectorTilesMaterialManager",get:function(){return this._vtlMaterialManager}}]),l}()}));
