/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import"../../../../../../core/has.js";import"../../../../../../core/Logger.js";import{ComponentMaterial as e,computeMaterialPass as r,calculateHasEmissions as t,calculateEmissionSource as a}from"./ComponentMaterial.js";class o{constructor(e,r){this._materialRepository=new Map,this._globalMaterialParameters={floatBufferBlendSupported:e.driverTest.floatBufferBlend.result,sphericalSR:r}}acquireMaterial(r,t,a){const o=l(r,t,a,this._globalMaterialParameters),s=this._materialRepository.get(o);if(s)return s.count++,s.material.key,s.material;const i=new e(r,t,a,this._globalMaterialParameters,o);return this._materialRepository.set(o,{material:i,count:1}),i}releaseMaterial(e){const{key:r}=e,t=this._materialRepository.get(r);if(!t||t.count<1)throw new Error("Internal error in material repository");1===t.count?this._materialRepository.delete(r):t.count--}}function l(e,o,l,s){const i=r(e,l),n=t(e,l,s),u=a(e,l,s);return`|${+e.usePBR}|${+e.hasParametersFromSource}|${+e.isGround}|${+e.slicePlaneEnabled}|${+e.isIntegratedMesh}|${+e.applySSAO}|${+i}|${+l.componentDataType}|${+n}|${+u}|${+e.sphereDepthInterpolate}|${+e.ellipsoidMode}|${+e.doubleSided}|${+e.cullFace}|${+e.alphaDiscardMode}|${+o.hasVertexColors}|${+o.textureCoordinateType}|${+o.shadeNormals}|${+o.hasNormals}|${+e.polygonOffsetEnabled}|${+o.hasModelRotationScale}|`+ +(null!=e.baseColorTexture)+"|"+ +(null!=e.emissionTexture)+"|"+ +(null!=e.metallicRoughnessTexture)+"|"+ +(null!=e.occlusionTexture)+"|"+ +(null!=e.normalTexture)+"|"+ +l.emissiveOverride}export{o as ComponentMaterialRepository,l as makeMaterialKey};
