@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.06 kB
JavaScript
import e from"../../../../core/PooledArray.js";import{isPromiseLike as t,createAbortError as r}from"../../../../core/promiseUtils.js";import{union as n}from"./depthRange.js";import{RenderSlot as s}from"./RenderSlot.js";class i{constructor(t){this._context=t,this._renderPlugins=new e,this._slots=[];for(let e=0;e<s.MAX_SLOTS;++e)this._slots[e]=[]}add(e,n,s){const i=()=>{if(s?.aborted)throw n.uninitializeRenderContext(),r();this._renderPlugins.push(n);for(const t of e)this._slots[t].push(n);this._context.requestRender()},o=n.initializeRenderContext(this._context,s);if(t(o))return o.then(i);i()}remove(e){if(null!=this._renderPlugins.removeUnordered(e)){for(let t=0;t<this._slots.length;++t)this._slots[t]=this._slots[t].filter((t=>t!==e));e.uninitializeRenderContext(),this._context.requestRender()}}prepareRender(){this._renderPlugins.forAll((e=>{e.prepareRender&&e.prepareRender(this._context.renderContext)}))}updateAnimation(e){let t=!1;return this._renderPlugins.forAll((r=>{r.updateAnimation&&(t=r.updateAnimation(e)||t)})),t}render(){const e=this._slots[this._context.renderContext.bindParameters.slot],t=new Array;e.filter((e=>{if(!e.canRender)return!1;if(o(e)){const r=e.prepareTechnique(this._context.renderContext);return!!r&&(t.push(r),!0)}return t.push(null),!0})).forEach(((e,r)=>e.render(this._context.renderContext,t[r])))}queryDepthRange(e){const t=d;return t.near=1/0,t.far=-1/0,this._renderPlugins.forAll((r=>{if(r.queryDepthRange){const s=r.queryDepthRange(e);s&&n(t,s,t)}})),t}get needsTransparentPass(){return this._renderPlugins.some((e=>!!e.needsTransparentPass))}get needsHighlight(){return this._renderPlugins.some((e=>!!e.needsHighlight))}get needsLinearDepth(){return this._renderPlugins.some((e=>!!e.needsLinearDepth))}get needsLaserlineWithContrastControl(){const e=this._slots[s.LASERLINES_CONTRAST_CONTROL];return!!e&&e.length>0}get renderOccludedFlags(){return this._renderPlugins.reduce(((e,t)=>e|t.renderOccludedFlags),0)}}function o(e){return"prepareTechnique"in e}const d={near:0,far:0};export{i as RenderPluginManager};