/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/Logger","../../../../core/maybe","../../../../core/NestedMap","./Util"],(function(e,t,i,r,o,s){"use strict";const n=i.getLogger("esri.views.3d.webgl-engine.lib.GLMaterialRepository");let a=function(){function e(e,t,i,r){this._textureRepository=e,this._techniqueRepository=t,this.materialChanged=i,this.requestRender=r,this._id2glMaterialRef=new o.NestedMap}var t=e.prototype;return t.dispose=function(){this._textureRepository.dispose()},t.acquire=function(e,t){this._ownMaterial(e);let i=this._id2glMaterialRef.get(t,e.id);if(r.isNone(i)){const r=e.createGLMaterial({material:e,techniqueRep:this._techniqueRepository,textureRep:this._textureRepository,output:t});i=new l(r),this._id2glMaterialRef.set(t,e.id,i)}return i.ref(),i.glMaterial},t.release=function(e,t){const i=this._id2glMaterialRef.get(t,e.id);r.isSome(i)&&(i.unref(),i.referenced||(r.disposeMaybe(i.glMaterial),this._id2glMaterialRef.delete(t,e.id)))},t._ownMaterial=function(e){r.isSome(e.repository)&&e.repository!==this&&n.error("Material is already owned by a different material repository"),e.repository=this},e}(),l=function(){function e(e){this.glMaterial=e,this.refCnt=0}var i=e.prototype;return i.ref=function(){++this.refCnt},i.unref=function(){--this.refCnt,s.assert(this.refCnt>=0)},t._createClass(e,[{key:"referenced",get:function(){return this.refCnt>0}}]),e}();e.GLMaterialRepository=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
