/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../../../../core/Error.js";import"../../../../../core/has.js";import{NestedMap as t}from"../../../../../core/NestedMap.js";import{ShaderTechniqueConfiguration as i}from"./ShaderTechniqueConfiguration.js";class o{constructor(e){this._context=e,this._debug=!1,this._precompiling=this._debug?0:1,this._cache=new t}get context(){return this._context}get precompiling(){return this._precompiling}set precompiling(e){this._precompiling=e,0===e&&this.context.rctx.gl.flush()}get viewingMode(){return this.context.viewingMode}destroy(){this._cache.forAll(e=>e.destroy()),this._cache.clear(),this._context=null}precompile(e,t=r){++this.precompiling,this.get(e,t),--this.precompiling}get(t,i=r,o){const c=i.key.code;let n=this._cache.get(t,c);if(null==n){if(0===this._precompiling){let o=`Uncached shader compile in ${(new Error).stack}\n  for configuration\n${i.decode()}`;const c=this._cache.getInner(t);throw c?.size&&(o+="\n\n  cached configurations:\n",o+=Array.from(c.values()).map(e=>i.decode(e.key)).sort().join("\n\n")),console.log(o),new e("shader:uncached-compile",o)}n=new t(this.context,i,o),this._cache.set(t,c,n)}return n}async reloadAll(){const e=new Array;this._cache.forEach(t=>e.push(c(t))),await Promise.all(e)}}async function c(e){let t=!0;e.forEach(async e=>{await e.reload(t),t=!1})}const r=new i;export{r as NoConfiguration,o as ShaderTechniqueRepository};
