UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

40 lines (37 loc) 1.11 kB
import { SHADERLANGUAGE_GLSL } from '../../platform/graphics/constants.js'; import { DeviceCache } from '../../platform/graphics/device-cache.js'; import { ShaderChunkMap } from './shader-chunk-map.js'; const _chunksCache = new DeviceCache(); class ShaderChunks { static get(device, shaderLanguage = SHADERLANGUAGE_GLSL) { const cache = _chunksCache.get(device, ()=>{ return new ShaderChunks(); }); return shaderLanguage === SHADERLANGUAGE_GLSL ? cache.glsl : cache.wgsl; } get useWGSL() { return this.glsl.size === 0 || this.wgsl.size > 0; } get key() { return `GLSL:${this.glsl.key}|WGSL:${this.wgsl.key}|API:${this.version}`; } isDirty() { return this.glsl.isDirty() || this.wgsl.isDirty(); } resetDirty() { this.glsl.resetDirty(); this.wgsl.resetDirty(); } copy(source) { this.version = source.version; this.glsl.copy(source.glsl); this.wgsl.copy(source.wgsl); return this; } constructor(){ this.glsl = new ShaderChunkMap(); this.wgsl = new ShaderChunkMap(); this.version = ''; } } export { ShaderChunks };