/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import has from"../../core/has.js";import{ResourceType as e}from"./enums.js";import{estimateMemory as t}from"./RenderbufferDescriptor.js";const r=!!has("esri-tests-disable-gpu-memory-measurements");class s{constructor(t,r){this._context=t,this._descriptor=r,this.type=2,this._context.instanceCounter.increment(e.Renderbuffer,this);const s=this._context.gl;this.glName=s.createRenderbuffer(),this._context.bindRenderbuffer(this);const{width:i,height:n,internalFormat:o,multisampled:h}=r;h?s.renderbufferStorageMultisample(s.RENDERBUFFER,this.samples,o,i,n):s.renderbufferStorage(s.RENDERBUFFER,o,i,n),this._context.bindRenderbuffer(null)}get descriptor(){return this._descriptor}get samples(){const e=this._descriptor.samples,t=this._context.parameters.maxSamples;return e?Math.min(e,t):t}get usedMemory(){return r?0:t(this._descriptor)}resize(e,t){const r=this._descriptor;if(r.width===e&&r.height===t)return;r.width=e,r.height=t;const s=this._context.gl;this._context.bindRenderbuffer(this),r.multisampled?s.renderbufferStorageMultisample(s.RENDERBUFFER,this.samples,r.internalFormat,r.width,r.height):s.renderbufferStorage(s.RENDERBUFFER,r.internalFormat,r.width,r.height),this._context.bindRenderbuffer(null)}dispose(){this._context&&(this._context.gl.deleteRenderbuffer(this.glName),this._context.instanceCounter.decrement(e.Renderbuffer,this),this._context=null)}}export{s as Renderbuffer};
