/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{releaseMaybe as t}from"../../../../core/maybe.js";import{copy as i}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as e,ZEROS 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(t){this._fbos=t,this._hasEmission=!1,this._size=new r(0,0),this._clearColor=e()}dispose(){this._color=t(this._color),this.releaseDepth()}initialize(t,e,s,r){this._size.width=t,this._size.height=e,h(this._size,this._fbos.rctx.parameters.maxTextureSize);const o=this._color;return this._color=null,this.releaseDepth(),this._hasEmission=r,i(this._clearColor,s),o}releaseDepth(){this._color?.detachDepth(),this._depth=t(this._depth)}update(t){const i=this._ensureColor();i.attachDepth(this.depth),this._color=t(i)}bind(){const{rctx:t}=this._fbos,i=null==this._color;this.color.attachDepth(this.depth),t.bindFramebuffer(this.color.fbo),i&&(t.setClearStencil(0),t.setClearColor(this._clearColor[0],this._clearColor[1],this._clearColor[2],this._clearColor[3]),t.clear(17664),this._hasEmission&&t.clearBuffer(1,s))}_acquireColor(){return this._hasEmission?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};
