UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.13 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{numericHash as t}from"../../../../../core/string.js";import{TypedShaderProgram as e}from"./typed/TypedShaderProgram.js";class o{constructor(){this.computeAttributes={}}get locationsMap(){const t=new Map;for(const e in this.locations)t.set(e,this.locations[e].index);return t}get optionPropertyKeys(){if(!this._optionPropertyKeys){const t=new Set(Object.keys(this.options));this._optionPropertyKeys=t}return this._optionPropertyKeys}get _transformFeedbackBindings(){return[]}get locationInfo(){if(!this._locationInfo){const e=this.locationsMap,o=Array.from(e.entries()).map((([t,e])=>`${t}.${e}`)).join("."),n=t(o);this._locationInfo={hash:n,stringHash:o,locations:e,computeAttributeMap:this.computeAttributes}}return this._locationInfo}get renamedLocationsMap(){const t=new Map;for(const[e,o]of this.locationsMap.entries())t.set("a_"+e,o);return t}getShaderKey(t,e,o){return`${Object.keys(t).map((e=>`${e}.${t[e]}`)).join(".")}.${Object.keys(o).filter((t=>o[t])).map((t=>`${t}_${o[t].toString()}`)).join(".")}.${Object.keys(e).filter((t=>this.optionPropertyKeys.has(t))).join(".")}`}getProgram(t,o,n,r){let i="",s="";for(const e in n)if(n[e]){const t="boolean"==typeof n[e]?`#define ${e}\n`:`#define ${e} ${n[e]}\n`;i+=t,s+=t}return i+=this.vertexShader,s+=this.fragmentShader,new e(i,s,this.renamedLocationsMap,this.locationInfo,this._getUniformBindings(o),this._transformFeedbackBindings)}_getUniformBindings(t){const e=[];for(const o in this.required){const t=this.required[o];e.push({uniformHydrated:null,shaderModulePath:o,uniformName:o,uniformType:t.type,uniformArrayElementType:n(t),uniformArrayLength:r(t)})}for(const o in t){const i=this.options[o];if(t[o])for(const t in i){const s=i[t];e.push({uniformHydrated:null,shaderModulePath:`${o}.${t}`,uniformName:t,uniformType:s.type,uniformArrayElementType:n(s),uniformArrayLength:r(s)})}}return e}}const n=t=>"array"===t.type?t.elementType?.type:void 0,r=t=>"array"===t.type?t.size:void 0;export{o as GLSLShaderModule};