/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{releaseMaybe as e}from"../../../../core/maybe.js";import{f as i}from"../../../../chunks/vec42.js";import{ZEROS as t}from"../../../../core/libs/gl-matrix-2/factories/vec4f32.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{ViewportSize as r}from"./BindParameters.js";import{ColorAttachment1 as o}from"../../../webgl/enums.js";import{ensureAttachmentMaxSize as h}from"../../../webgl/FramebufferObject.js";class l{constructor(e){this._fbos=e,this._requiresEmission=!1,this._size=new r(0,0),this._clearColor=s()}dispose(){this._color=e(this._color),this.releaseDepth()}initialize(e,t,s,r){this._size.width=e,this._size.height=t,h(this._size,this._fbos.rctx.parameters.maxTextureSize);const o=this._color;return this._color=null,this.releaseDepth(),this._requiresEmission=r,i(this._clearColor,s),o}releaseDepth(){this._color?.detachDepth(),this._depth=e(this._depth)}update(e){const i=this._ensureColor();i.attachDepth(this.depth),this._color=e(i)}bind(){const{rctx:e}=this._fbos,i=null==this._color;this.color.attachDepth(this.depth),e.bindFramebuffer(this.color.fbo),i&&(e.setClearStencil(0),e.setClearColor(this._clearColor[0],this._clearColor[1],this._clearColor[2],this._clearColor[3]),e.clear(17664),this._requiresEmission&&e.clearBuffer(1,t))}_acquireColor(){return this._requiresEmission?this._fbos.acquire(this._size.width,this._size.height,"main color").acquireColor(o,8,"emissive"):this._fbos.acquire(this._size.width,this._size.height,"main color")}_acquireDepth(){return this._fbos.acquireDepth(14,this._size.width,this._size.height,"main depth")}get size(){return this._size}get color(){return this._ensureColor()}get depth(){return this._depth??=this._acquireDepth(),this._depth}_ensureColor(){return this._color??=this._acquireColor(),this._color}}export{l as MainFramebuffer};
