/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{releaseMaybe as t}from"../../../../core/maybe.js";import{isPromiseLike as e}from"../../../../core/promiseUtils.js";import s from"./GLMaterial.js";import{NoParameters as i}from"../../../webgl/NoParameters.js";class r extends s{constructor(t){super(t),this._numLoading=0,this._disposed=!1,this._textures=t.textures,this.updateTexture(t.textureId),this._acquire(t.normalTextureId,t=>this._textureNormal=t),this._acquire(t.emissiveTextureId,t=>this._textureEmissive=t),this._acquire(t.occlusionTextureId,t=>this._textureOcclusion=t),this._acquire(t.metallicRoughnessTextureId,t=>this._textureMetallicRoughness=t)}dispose(){super.dispose(),this._texture=t(this._texture),this._textureNormal=t(this._textureNormal),this._textureEmissive=t(this._textureEmissive),this._textureOcclusion=t(this._textureOcclusion),this._textureMetallicRoughness=t(this._textureMetallicRoughness),this._disposed=!0}ensureResources(t){return 0===this._numLoading?2:1}get textureBindParameters(){return new l(this._texture?.texture??null,this._textureNormal?.texture??null,this._textureEmissive?.texture??null,this._textureOcclusion?.texture??null,this._textureMetallicRoughness?.texture??null)}updateTexture(e){null!=this._texture&&e===this._texture.id||(this._texture=t(this._texture),this._acquire(e,t=>this._texture=t))}_acquire(s,i){if(null==s)return void i(null);const r=this._textures.acquire(s);if(e(r))return++this._numLoading,void r.then(e=>{if(this._disposed)return t(e),void i(null);i(e)}).finally(()=>--this._numLoading);i(r)}}class u extends i{constructor(t=null){super(),this.textureEmissive=t}}class l extends u{constructor(t,e,s,i,r,u,l){super(s),this.texture=t,this.textureNormal=e,this.textureOcclusion=i,this.textureMetallicRoughness=r,this.scale=u,this.normalTextureTransformMatrix=l}}export{u as GLEmissiveTexturePassParameters,r as GLTextureMaterial,l as GLTextureMaterialBindParameters};
