UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

42 lines (39 loc) 1.24 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; } static registerValidation(name, options) {} 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(ShaderChunks._validations); this.wgsl = new ShaderChunkMap(ShaderChunks._validations); this.version = ''; } } ShaderChunks._validations = new Map(); export { ShaderChunks };