@thewtex/vtk.js-esm
Version:
Visualization Toolkit for the Web
72 lines (56 loc) • 2.28 kB
JavaScript
import { obj, get, setGet, newInstance as newInstance$1 } from '../../macro.js';
// vtkWebGPUSwapChain methods
// ----------------------------------------------------------------------------
function vtkWebGPUSwapChain(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkWebGPUSwapChain');
/* eslint-disable no-undef */
/* eslint-disable no-bitwise */
publicAPI.create = function (device, window) {
model.device = device;
model.window = window;
if (window.getContext()) {
model.colorFormat = 'bgra8unorm';
model.handle = window.getContext().configureSwapChain({
device: device.getHandle(),
format: model.colorFormat,
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST
});
model.created = true;
}
};
publicAPI.getCurrentTexture = function () {
return model.handle.getCurrentTexture();
};
publicAPI.releaseGraphicsResources = function () {
if (model.created) {
model.handle = null;
model.created = false;
model.depthTexture = null;
}
};
} // ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
var DEFAULT_VALUES = {
device: null,
created: false,
handle: null,
colorFormat: null
}; // ----------------------------------------------------------------------------
function extend(publicAPI, model) {
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
obj(publicAPI, model);
get(publicAPI, model, ['colorFormat']);
setGet(publicAPI, model, ['created', 'device', 'handle']); // For more macro methods, see "Sources/macro.js"
// Object specific methods
vtkWebGPUSwapChain(publicAPI, model);
} // ----------------------------------------------------------------------------
var newInstance = newInstance$1(extend, 'vtkWebGPUSwapChain'); // ----------------------------------------------------------------------------
var vtkWebGPUSwapChain$1 = {
newInstance: newInstance,
extend: extend
};
export default vtkWebGPUSwapChain$1;
export { extend, newInstance };