Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Documentation/public/gallery/SharedContext.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
405 changes: 405 additions & 0 deletions Examples/Rendering/SharedContext/index.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Sources/Rendering/OpenGL/RenderWindow/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IOpenGLRenderWindowInitialValues {
context?: WebGLRenderingContext | WebGL2RenderingContext;
context2D?: CanvasRenderingContext2D;
canvas?: HTMLCanvasElement;
manageCanvas?: boolean;
cursorVisibility?: boolean;
cursor?: string;
textureUnitManager?: null;
Expand Down Expand Up @@ -93,6 +94,10 @@ export interface vtkOpenGLRenderWindow extends vtkViewNode {
*/
setCanvas(canvas: Nullable<HTMLCanvasElement>): boolean;

getManageCanvas(): boolean;

setManageCanvas(manageCanvas: boolean): boolean;

/**
* Check if a point is in the viewport.
* @param {Number} x The x coordinate.
Expand Down
29 changes: 23 additions & 6 deletions Sources/Rendering/OpenGL/RenderWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
const previousSize = [0, 0];
function updateWindow() {
// Canvas size
if (model.renderable) {
if (model.renderable && model.manageCanvas) {
if (
model.size[0] !== previousSize[0] ||
model.size[1] !== previousSize[1]
Expand All @@ -160,7 +160,9 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
}

// Offscreen ?
model.canvas.style.display = model.useOffScreen ? 'none' : 'block';
if (model.manageCanvas) {
model.canvas.style.display = model.useOffScreen ? 'none' : 'block';
}

// Cursor type
if (model.el) {
Expand Down Expand Up @@ -549,15 +551,28 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
if (model.deleted) {
return null;
}
const requestedSize =
!!size || scale !== 1
? size || model.size.map((val) => val * scale)
: null;
const requiresCanvasResize =
requestedSize !== null &&
(requestedSize[0] !== model.size[0] ||
requestedSize[1] !== model.size[1]);
const screenshotSize = requiresCanvasResize ? requestedSize : null;

if (!model.manageCanvas && requiresCanvasResize) {
throw new Error(
'Resizing screenshot capture requires manageCanvas=true on vtkOpenGLRenderWindow'
);
}

model.imageFormat = format;
const previous = model.notifyStartCaptureImage;
model.notifyStartCaptureImage = true;

model._screenshot = {
size:
!!size || scale !== 1
? size || model.size.map((val) => val * scale)
: null,
size: screenshotSize,
};

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1307,6 +1322,7 @@ const DEFAULT_VALUES = {
context: null,
context2D: null,
canvas: null,
manageCanvas: true,
cursorVisibility: true,
cursor: 'pointer',
textureUnitManager: null,
Expand Down Expand Up @@ -1377,6 +1393,7 @@ export function extend(publicAPI, model, initialValues = {}) {
'context',
'context2D',
'canvas',
'manageCanvas',
'renderPasses',
'notifyStartCaptureImage',
'defaultToWebgl2',
Expand Down
56 changes: 56 additions & 0 deletions Sources/Rendering/OpenGL/SharedRenderWindow/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import vtkOpenGLRenderWindow, {
IOpenGLRenderWindowInitialValues,
} from '../RenderWindow';

export interface ISharedRenderWindowInitialValues
extends IOpenGLRenderWindowInitialValues {
autoClear?: boolean;
autoClearColor?: boolean;
autoClearDepth?: boolean;
}

export type SharedRenderCallback = () => void;

export interface vtkSharedRenderWindow extends vtkOpenGLRenderWindow {
/** Reset vtk.js render state and render into a host-owned WebGL2 context. */
renderShared(options?: Record<string, any>): void;

/** Reset vtk.js GL state and sync size before shared-context rendering. */
prepareSharedRender(options?: Record<string, any>): void;

syncSizeFromCanvas(): boolean;

setRenderCallback(callback?: SharedRenderCallback | null): void;

setAutoClear(autoClear: boolean): boolean;
getAutoClear(): boolean;

setAutoClearColor(autoClearColor: boolean): boolean;
getAutoClearColor(): boolean;

setAutoClearDepth(autoClearDepth: boolean): boolean;
getAutoClearDepth(): boolean;
}

export function extend(
publicAPI: object,
model: object,
initialValues?: ISharedRenderWindowInitialValues
): void;

export function newInstance(
initialValues?: ISharedRenderWindowInitialValues
): vtkSharedRenderWindow;

export function createFromContext(
canvas: HTMLCanvasElement,
gl: WebGL2RenderingContext,
options?: ISharedRenderWindowInitialValues
): vtkSharedRenderWindow;

export declare const vtkSharedRenderWindow: {
newInstance: typeof newInstance;
extend: typeof extend;
createFromContext: typeof createFromContext;
};
export default vtkSharedRenderWindow;
Loading
Loading