import * as macro from 'vtk.js/Sources/macros'; import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';
import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory';
const { vtkDebugMacro } = macro;
function vtkOpenGLPixelSpaceCallbackMapper(publicAPI, model) { model.classHierarchy.push('vtkOpenGLPixelSpaceCallbackMapper');
publicAPI.opaquePass = (prepass, renderPass) => { model._openGLRenderer = publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer'); model._openGLRenderWindow = model._openGLRenderer.getLastAncestorOfType( 'vtkOpenGLRenderWindow' ); const aspectRatio = model._openGLRenderer.getAspectRatio(); const camera = model._openGLRenderer ? model._openGLRenderer.getRenderable().getActiveCamera() : null; const tsize = model._openGLRenderer.getTiledSizeAndOrigin(); let texels = null;
if (model.renderable.getUseZValues()) { const zbt = renderPass.getZBufferTexture(); const width = Math.floor(zbt.getWidth()); const height = Math.floor(zbt.getHeight());
const gl = model._openGLRenderWindow.getContext(); zbt.bind();
const fb = renderPass.getFramebuffer(); if (!fb) { vtkDebugMacro('No framebuffer to save/restore'); } else { fb.saveCurrentBindingsAndBuffers(); }
const framebuffer = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, zbt.getHandle(), 0 );
if ( gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE ) { texels = new Uint8Array(width * height * 4); gl.viewport(0, 0, width, height); gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, texels); }
if (fb) { fb.restorePreviousBindingsAndBuffers(); }
gl.deleteFramebuffer(framebuffer); }
model.renderable.invokeCallback( model.renderable.getInputData(), camera, aspectRatio, tsize, texels ); };
publicAPI.queryPass = (prepass, renderPass) => { if (prepass) { if (model.renderable.getUseZValues()) { renderPass.requestDepth(); } } }; }
const DEFAULT_VALUES = {};
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkViewNode.extend(publicAPI, model, initialValues);
vtkOpenGLPixelSpaceCallbackMapper(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkOpenGLPixelSpaceCallbackMapper' );
export default { newInstance, extend };
registerOverride('vtkPixelSpaceCallbackMapper', newInstance);
|