Repository navigation
Expand file tree
/
Copy pathvtkWasmConfiguration.js
More file actions
48 lines (46 loc) · 1.63 KB
/
Copy pathvtkWasmConfiguration.js
File metadata and controls
48 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ----------------------------------------------------------------------------
// Sets up a base configuration for VTK-wasm with rendering.
const BaseConfig = {
//Pipes std::cout and std::cerr into debug and error in dev console.
'print': (function () {
return function (text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.debug(text);
};
})(),
'printErr': function (text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
}
};
// ----------------------------------------------------------------------------
export function makeWebGPUConfig(webgpuCanvas, webgpuDevice) {
var cfg = BaseConfig;
cfg.canvas = (function () {
return webgpuCanvas;
})()
cfg.preRun = [function (module) {
// select WebGPU backend
module.ENV.VTK_FACTORY_PREFER = 'RenderingBackend=WebGPU';
}];
// Set the device from JS. This can be done in C++ as well.
// See https://github.com/kainino0x/webgpu-cross-platform-demo/blob/main/main.cpp#L51
cfg.preinitializedWebGPUDevice = webgpuDevice;
return cfg;
}
// ----------------------------------------------------------------------------
export function makeWebGLConfig(webglCanvas) {
var cfg = BaseConfig;
cfg.canvas = (function () {
webglCanvas.addEventListener(
"webglcontextlost",
function (e) {
console.error('WebGL context lost. You will need to reload the page.');
e.preventDefault();
},
false
);
return webglCanvas;
})()
return cfg;
}