UNPKG

playcanvas

Version:

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

43 lines (42 loc) 1.16 kB
import { BINDGROUP_VIEW } from "./constants.js"; class ShaderProcessorOptions { uniformFormats = []; bindGroupFormats = []; vertexFormat; constructor(viewUniformFormat, viewBindGroupFormat, vertexFormat) { this.uniformFormats[BINDGROUP_VIEW] = viewUniformFormat; this.bindGroupFormats[BINDGROUP_VIEW] = viewBindGroupFormat; this.vertexFormat = vertexFormat; } hasUniform(name) { for (let i = 0; i < this.uniformFormats.length; i++) { const uniformFormat = this.uniformFormats[i]; if (uniformFormat?.get(name)) { return true; } } return false; } hasTexture(name) { for (let i = 0; i < this.bindGroupFormats.length; i++) { const groupFormat = this.bindGroupFormats[i]; if (groupFormat?.getTexture(name)) { return true; } } return false; } getVertexElement(semantic) { return this.vertexFormat?.elements.find((element) => element.name === semantic); } generateKey(device) { let key = JSON.stringify(this.uniformFormats) + JSON.stringify(this.bindGroupFormats); if (device.isWebGPU) { key += this.vertexFormat?.shaderProcessingHashString; } return key; } } export { ShaderProcessorOptions };