UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.84 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{isArrayLike as e}from"../../../../../core/arrayUtils.js";import{WGLDrawPhase as r}from"../enums.js";class t{constructor(e,t){this.brushes=e,this.name=t.name,this.drawPhase=t.drawPhase||r.MAP,this._targetFn=t.target,this.effects=t.effects||[],this.enableDefaultDraw=t.enableDefaultDraw??(()=>!0),this.forceDrawByDisplayOrder=!!t.forceDrawByDisplayOrder}render(e){const{context:r,profiler:t}=e,s=this._targetFn(),a=this.drawPhase&e.drawPhase;if(t.recordPassStart(this.name),a){this.enableDefaultDraw()&&this._doRender(e,s),t.recordPassEnd();for(const t of this.effects){if(!t.enable())continue;const a=t.apply,n=t.args?.(),i=r.getViewport(),o=r.getBoundFramebufferObject(),d=e.passOptions;this._bindEffect(e,a,n),this._doRender(e,s,a.defines),this._drawAndUnbindEffect(e,a,i,o,d,n)}}}_doRender(e,r,t){if(null==r)return;const{profiler:s,context:a}=e;for(const n of this.brushes){if(s.recordBrushStart(n.name),null!=n.brushEffect){const s=a.getViewport(),i=a.getBoundFramebufferObject(),o=e.passOptions;this._bindEffect(e,n.brushEffect),this._drawWithBrush(n,e,r,t),this._drawAndUnbindEffect(e,n.brushEffect,s,i,o)}else this._drawWithBrush(n,e,r,t);s.recordBrushEnd()}}_drawWithBrush(r,t,s,a){e(s)?(r.prepareState(t,a),r.drawMany(t,s,a)):s.visible&&(r.prepareState(t,a),r.draw(t,s,a))}_bindEffect(e,r,t){const{profiler:s}=e;s.recordPassStart(this.name+"."+r.name),r.bind(e,t);const a=r.createOptions(e,t);e.passOptions=a}_drawAndUnbindEffect(e,r,t,s,a,n){const{profiler:i,context:o}=e;e.passOptions=a,i.recordBrushStart(r.name),r.draw(e,n),r.unbind(e,n),o.bindFramebuffer(s);const{x:d,y:f,width:h,height:c}=t;o.setViewport(d,f,h,c),i.recordBrushEnd(),i.recordPassEnd()}}export{t as default};