@thewtex/vtk.js-esm
Version:
Visualization Toolkit for the Web
104 lines (82 loc) • 3.86 kB
JavaScript
import macro from '../../macro.js';
import vtkWebGPURenderEncoder from './RenderEncoder.js';
import vtkWebGPUTexture from './Texture.js';
import vtkRenderPass from '../SceneGraph/RenderPass.js';
function vtkWebGPUOpaquePass(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkWebGPUOpaquePass'); // this pass implements a forward rendering pipeline
// if both volumes and opaque geometry are present
// it will mix the two together by capturing a zbuffer
// first
publicAPI.traverse = function (renNode, viewNode) {
if (model.deleted) {
return;
} // we just render our delegates in order
model.currentParent = viewNode;
var device = viewNode.getDevice();
if (!model.renderEncoder) {
publicAPI.createRenderEncoder();
model.colorTexture = vtkWebGPUTexture.newInstance();
model.colorTexture.create(device, {
width: viewNode.getCanvas().width,
height: viewNode.getCanvas().height,
format: 'bgra8unorm',
/* eslint-disable no-undef */
/* eslint-disable no-bitwise */
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.SAMPLED | GPUTextureUsage.COPY_SRC
});
var ctView = model.colorTexture.createView();
ctView.setName('opaquePassColorTexture');
model.renderEncoder.setColorTextureView(0, ctView); // model.depthFormat = 'depth24plus-stencil8';
model.depthFormat = 'depth32float';
model.depthTexture = vtkWebGPUTexture.newInstance();
model.depthTexture.create(device, {
width: viewNode.getCanvas().width,
height: viewNode.getCanvas().height,
format: model.depthFormat,
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.SAMPLED | GPUTextureUsage.COPY_SRC
});
var dView = model.depthTexture.createView();
dView.setName('opaquePassDepthTexture');
model.renderEncoder.setDepthTextureView(dView);
} else {
model.colorTexture.resize(viewNode.getCanvas().width, viewNode.getCanvas().height);
model.depthTexture.resize(viewNode.getCanvas().width, viewNode.getCanvas().height);
}
model.renderEncoder.attachTextureViews();
publicAPI.setCurrentOperation('opaquePass');
renNode.setRenderEncoder(model.renderEncoder);
renNode.traverse(publicAPI);
};
publicAPI.getColorTextureView = function () {
return model.renderEncoder.getColorTextureViews()[0];
};
publicAPI.getDepthTextureView = function () {
return model.renderEncoder.getDepthTextureView();
};
publicAPI.createRenderEncoder = function () {
model.renderEncoder = vtkWebGPURenderEncoder.newInstance(); // default settings are fine for this
model.renderEncoder.setPipelineHash('op');
};
} // ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
var DEFAULT_VALUES = {
renderEncoder: null,
colorTexture: null,
depthTexture: null
}; // ----------------------------------------------------------------------------
function extend(publicAPI, model) {
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
vtkRenderPass.extend(publicAPI, model, initialValues);
macro.get(publicAPI, model, ['colorTexture', 'depthTexture']); // Object methods
vtkWebGPUOpaquePass(publicAPI, model);
} // ----------------------------------------------------------------------------
var newInstance = macro.newInstance(extend, 'vtkWebGPUOpaquePass'); // ----------------------------------------------------------------------------
var vtkWebGPUOpaquePass$1 = {
newInstance: newInstance,
extend: extend
};
export default vtkWebGPUOpaquePass$1;
export { extend, newInstance };