// luma.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors /** * Shader selection * @param device * @param props * @returns */ export function selectShaders(props) { // If we have a source field, we have a single unified shader source if (props.source && props.platformInfo.type === 'webgpu') { const propsCopy = { ...props, vs: undefined, fs: undefined }; return propsCopy; } if (!props.vs) { throw new Error('no vertex shader'); } // Resolve WGSL vs GLSL const vs = getShaderSource(props.platformInfo, props.vs); let fs; if (props.fs) { fs = getShaderSource(props.platformInfo, props.fs); } return { ...props, vs, fs }; } /** Create a shader from the different overloads */ function getShaderSource(platformInfo, shader) { // TODO - detect WGSL/GLSL and throw an error if not supported if (typeof shader === 'string') { return shader; } switch (platformInfo.type) { case 'webgpu': if (shader?.wgsl) { return shader.wgsl; } throw new Error('WebGPU does not support GLSL shaders'); default: if (shader?.glsl) { return shader.glsl; } throw new Error('WebGL does not support WGSL shaders'); } }