UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

42 lines (39 loc) 1.22 kB
import { BINDGROUP_VIEW } from './constants.js'; class ShaderProcessorOptions { constructor(viewUniformFormat, viewBindGroupFormat, vertexFormat){ this.uniformFormats = []; this.bindGroupFormats = []; 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 };