/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import t from"../../../../../core/PooledArray.js";import{property as r,subclass as s}from"../../../../../core/accessorSupport/decorators.js";import{ZEROS as o}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{InternalRenderCategory as n}from"../../../webgl.js";import i from"../../../webgl/RenderNode.js";import{Blit as c}from"../blit/Blit.js";import{DepthStencilAttachment as d}from"../../../../webgl/enums.js";let l=class extends i{constructor(e){super(e),this.consumes={required:[n.OCCLUDED]},this.produces=n.OCCLUDED,this._blit=new c(e.view.stage.renderView.techniques,2)}precompile(){const e=this.view.stage.renderer;e.plugins.plugins.forEach(t=>{e.precompileSlots(t,10,12),t.material&&e.precompileOccludedSlots(t,h)})}render(e){const t=e.find(({name:e})=>e===this.produces);return this._renderOccludedAndTransparentStencil(t),this._renderOccludedComposite(t),t}_renderOccludedAndTransparentStencil(e){const t=this.view.stage.renderer,r=a;r.clear();for(const s of t.plugins.plugins)8&s.renderOccludedFlags&&r.push(s);0!==r.length&&(t.renderSlots(r,11),this._renderAndComposite(e,e.getAttachment(d),.5,()=>t.renderSlots(r,12),!1,!1),r.clear())}_renderOccludedComposite(e){const t=this.view.stage.renderer,r=a;r.clear();let s=0;for(const i of t.plugins.plugins){const e=i.renderOccludedFlags&u;s|=e,e&&r.push(i)}if(!s)return void r.clear();const o=this._getDepthStencilAttachment(e);let n=o.clearStencil;for(const i of h)s&i&&(this._renderAndComposite(e,o.depth,16===i?1:.5,()=>t.renderOccludedSlots(r,i),!0,n),n=!1);o.release(),r.clear()}_renderAndComposite(e,t,r,s,n,i){const c=this.renderingContext,{width:d,height:l}=e.fbo,a=this.fboCache.acquire(d,l,"tmp color");a.attachDepth(t),c.bindFramebuffer(a.fbo),c.clearFramebuffer(o,n,i),s(),a.detachDepth(),this._blit.blend(c,a,e,this.bindParameters,r),a.release()}_getDepthStencilAttachment(e){const{width:t,height:r}=e.fbo;if(!this.view.stage.renderer.occludedRequiresIntegratedMeshStencil){const e=this.fboCache.acquireDepth(14,t,r,"retained stencil");return{depth:e,release:()=>e.release(),clearStencil:!0}}const s=this.fboCache.acquire(t,r,"retained stencil",14);return this.renderingContext.blitFramebuffer(e.fbo,s.fbo,1024),{depth:s.getAttachment(d),release:()=>s.release(),clearStencil:!1}}};e([r()],l.prototype,"consumes",void 0),e([r()],l.prototype,"produces",void 0),l=e([s("esri.views.3d.webgl-engine.effects.geometry.RenderOccludedRenderNode")],l);const a=new t;function p(){a.prune()}const h=[4,2,16],u=h.reduce((e,t)=>e|t,0);export{l as RenderOccludedRenderNode,p as cleanupRenderOccluded};
