/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import"../../../../core/has.js";import t from"../../../../core/Logger.js";import{webglDebugEnabled as r}from"../../../webgl/checkWebGLError.js";class e{constructor(e,i,s){this._context=e,this.locations=s,this._textures=new Map,this.source=r()?i:null,i.attributeNames.forEach(r=>{s.has(r)||t.getLogger("esri.views.3d.webgl-engine.lib.Program").error(`Missing VertexAttributeLocation for ${r} used in shader`)}),this._glProgram=e.programCache.acquire(i.generate("vertex",!0),i.generate("fragment",!0),s),this._glProgram.stop=()=>{throw new Error("Wrapped _glProgram used directly")},this.bind=i.generateBind(this),this.bindPass=i.generateBindPass(this),this.bindDraw=i.generateBindDraw(this)}dispose(){this._glProgram.dispose()}get glName(){return this._glProgram.glName}get hasTransformFeedbackVaryings(){return this._glProgram.hasTransformFeedbackVaryings}get compiled(){return this._glProgram.compiled}setUniform1b(t,r){this._glProgram.setUniform1i(t,r?1:0)}setUniform1i(t,r){this._glProgram.setUniform1i(t,r)}setUniform1f(t,r,e){this._glProgram.setUniform1f(t,r,e)}setUniform2fv(t,r,e){this._glProgram.setUniform2fv(t,r,e)}setUniform3fv(t,r,e){this._glProgram.setUniform3fv(t,r,e)}setUniform4fv(t,r,e){this._glProgram.setUniform4fv(t,r,e)}setUniformMatrix3fv(t,r,e){this._glProgram.setUniformMatrix3fv(t,r,!1,e)}setUniformMatrix4fv(t,r,e){this._glProgram.setUniformMatrix4fv(t,r,!1,e)}setUniformMatrices4fv(t,r,e){this._glProgram.setUniformMatrices4fv(t,r,!1,e)}setUniform1fv(t,r,e){this._glProgram.setUniform1fv(t,r,e)}setUniform1iv(t,r){this._glProgram.setUniform1iv(t,r)}setUniform2iv(t,r){this._glProgram.setUniform2iv(t,r)}setUniform3iv(t,r){this._glProgram.setUniform3iv(t,r)}setUniform4iv(t,r){this._glProgram.setUniform4iv(t,r)}assertCompatibleVertexAttributeLocations(t,r){let e=t.locations;if(r){const t=new Map(e);r.forEach((r,i)=>t.set(i,e.size+r)),e=t}e.size!==this.locations.size&&console.error(`VertexAttributeLocations are incompatible: ${e}, ${this.locations}`),this.locations.forEach((t,r)=>{e.get(r)!==t&&console.error(`VertexAttributeLocations are incompatible: Program has ${r} at position ${t}, VAO has it at position ${e.get(r)}.`)})}stop(){this._textures.clear()}bindTexture(t,e){if(!e?.glName){const i=`Texture sampler ${t} in ${this._context.debugBoundTechnique} has no given Texture in ${(new Error).stack}`;r()&&console.error(i),e=this._context.emptyTexture}const i=this._ensureTextureUnit(t,e);this._context.useProgram(this),this.setUniform1i(t,i.unit),this._context.bindTexture(e,i.unit)}_ensureTextureUnit(t,r){let e=this._textures.get(t);return null==e?(e={texture:r,unit:this._textures.size},this._textures.set(t,e)):e.texture=r,e}}export{e as Program};
