import macro from 'vtk.js/Sources/macros'; import vtkWebGPUShaderModule from 'vtk.js/Sources/Rendering/WebGPU/ShaderModule';
function substitute(source, search, replace, all = true) { const replaceStr = Array.isArray(replace) ? replace.join('\n') : replace; let replaced = false; if (source.search(search) !== -1) { replaced = true; } let gflag = ''; if (all) { gflag = 'g'; } const regex = new RegExp(search, gflag); const resultstr = source.replace(regex, replaceStr); return { replace: replaced, result: resultstr }; }
function vtkWebGPUShaderCache(publicAPI, model) { model.classHierarchy.push('vtkWebGPUShaderCache');
publicAPI.getShaderModule = (shaderDesc) => { const sType = shaderDesc.getType(); const sHash = shaderDesc.getHash(); const keys = model._shaderModules.keys(); for (let i = 0; i < keys.length; i++) { const key = keys[i]; if (key.getHash() === sHash && key.getType() === sType) { return model._shaderModules.get(key); } }
const sm = vtkWebGPUShaderModule.newInstance(); sm.initialize(model.device, shaderDesc); model._shaderModules.set(shaderDesc, sm); return sm; }; }
const DEFAULT_VALUES = { shaderModules: null, device: null, window: null, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
model._shaderModules = new Map();
macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['device', 'window']);
vtkWebGPUShaderCache(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkWebGPUShaderCache');
export default { newInstance, extend, substitute };
|