/*
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{property as t,subclass as s}from"../../../../../core/accessorSupport/decorators.js";import{RenderCategory as r,InternalRenderCategory as i}from"../../../webgl.js";import o from"../../../webgl/RenderNode.js";import{F as n}from"../../../../../chunks/FocusAreaMask.glsl.js";import{FocusAreaMaskTechnique as a}from"./FocusAreaMaskTechnique.js";import{Pos3 as h}from"../../lib/DefaultVertexBufferLayouts.js";import{VertexArrayObject as c}from"../../lib/VertexArrayObject.js";import{DepthStencilAttachment as l,PrimitiveType as u}from"../../../../webgl/enums.js";import{noParameters as p}from"../../../../webgl/NoParameters.js";import{VertexBuffer as m}from"../../../../webgl/VertexBuffer.js";let d=class extends o{constructor(e){super({...e,view:e.focusAreasView.view}),this.consumes={required:[r.TRANSPARENT]},this.produces=i.FOCUSAREA,this._vaos=new Array,this._counts=new Array,this._origins=new Array,this._maskParameters=new n}initialize(){this.updateGeometries()}destroy(){this._vaos.forEach(e=>e.dispose()),this._vaos.length=this._counts.length=this._origins.length=0}precompile(){this.techniques.precompile(a)}render(e){const t=this.techniques.get(a),s=this.bindParameters,o=s.camera,n=o.fullViewport[2],h=o.fullViewport[3];if(!t.compiled||!this._vaos)return void this.requestRender(1);const c=e.find(({name:e})=>e===r.TRANSPARENT),m=this.renderingContext,d=this.fboCache.acquire(n,h,i.FOCUSAREA,2);this.view.stage.renderer.occludedRequiresStencil?(d.acquireDepth(14),m.blitFramebuffer(c.fbo,d.fbo,256)):d.attachDepth(c.getAttachment(l)),m.bindFramebuffer(d.fbo),m.setClearColor(0,0,0,1),m.clear(17408),m.setViewport(0,0,n,h);const f=m.bindTechnique(t,s);m.setFaceCullingEnabled(!1),m.setStencilTestEnabled(!0),m.setStencilOpSeparate(1028,7680,34055,7680),m.setStencilOpSeparate(1029,7680,34056,7680),m.setDepthWriteEnabled(!1);for(let r=0;r<this._vaos.length;r++){const e=this._vaos[r],t=this._counts[r];this._maskParameters.origin=this._origins[r],f.bindDraw(s,p,this._maskParameters),m.bindVAO(e),m.setDepthTestEnabled(!0),m.setStencilWriteMask(255),m.setStencilFunction(519,0,255),m.setColorMask(!1,!1,!1,!1),m.drawArrays(u.TRIANGLES,0,t),m.setDepthTestEnabled(!1),m.setStencilWriteMask(0),m.setStencilFunction(517,0,255),m.setColorMask(!0,!0,!0,!0),m.drawArrays(u.TRIANGLES,0,t)}return d}updateGeometries(){if(!this.view.stage)return;this._vaos.forEach(e=>e.dispose()),this._vaos.length=this._counts.length=this._origins.length=0;this.focusAreasView.volumes.forEach(e=>{const t=new Array;let s=0,r=0;e.geometryVolumes.forEach(e=>{const i=e.indicesBottom;s+=i.length;for(let s=0;s<i.length;s++)t.push(e.positions[3*(i[s]-1)]),t.push(e.positions[3*(i[s]-1)+1]),t.push(e.positions[3*(i[s]-1)+2]);const o=e.indicesExtruded;r+=o.length;for(let s=0;s<o.length;s++)t.push(e.positions[3*o[s]]),t.push(e.positions[3*o[s]+1]),t.push(e.positions[3*o[s]+2])});const i=new c(this.renderingContext,new m(this.renderingContext,h,new Float32Array(t)));this._vaos.push(i),this._counts.push(s+r),this._origins.push(e.origin)}),this.requestRender(1)}};e([t()],d.prototype,"consumes",void 0),e([t()],d.prototype,"produces",void 0),e([t({constructOnly:!0})],d.prototype,"focusAreasView",void 0),d=e([s("esri.views.3d.webgl-engine.effects.focusArea.FocusAreaMaskNode")],d);export{d as FocusAreaMaskNode};
