UNPKG

playcanvas

Version:

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

41 lines (40 loc) 1.17 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 _validations = /* @__PURE__ */ new Map(); glsl = new ShaderChunkMap(ShaderChunks._validations); wgsl = new ShaderChunkMap(ShaderChunks._validations); 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) { } version = ""; 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; } } export { ShaderChunks };