Skip to content

Commit ca07f48

Browse files
authored
Merge branch 'master' into volumeShadowExample
2 parents 26ab3b5 + 8490c07 commit ca07f48

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

Sources/Proxy/Core/ViewProxy/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ function vtkViewProxy(publicAPI, model) {
166166
// --------------------------------------------------------------------------
167167

168168
publicAPI.setContainer = (container) => {
169+
const orientationWidgetEnabled = model.orientationWidget.getEnabled();
170+
169171
if (model.container) {
172+
model.orientationWidget.setEnabled(false);
170173
model.interactor.unbindEvents(model.container);
171174
model.openglRenderWindow.setContainer(null);
172175
model.cornerAnnotation.setContainer(null);
@@ -179,6 +182,7 @@ function vtkViewProxy(publicAPI, model) {
179182
model.cornerAnnotation.setContainer(container);
180183
model.interactor.initialize();
181184
model.interactor.bindEvents(container);
185+
model.orientationWidget.setEnabled(orientationWidgetEnabled);
182186
}
183187
};
184188

@@ -577,11 +581,21 @@ function vtkViewProxy(publicAPI, model) {
577581

578582
// --------------------------------------------------------------------------
579583

580-
publicAPI.delete = macro.chain(
581-
publicAPI.setContainer,
582-
model.openglRenderWindow.delete,
583-
publicAPI.delete
584-
);
584+
publicAPI.delete = macro.chain(() => {
585+
publicAPI.setContainer(null);
586+
model.orientationWidget.setEnabled(false);
587+
model.orientationWidget.delete();
588+
model.orientationAxesArrow.delete();
589+
model.orientationAxesCube.delete();
590+
model.interactorStyle2D.delete();
591+
model.interactorStyle3D.delete();
592+
model.cornerAnnotation.delete();
593+
// in reverse order
594+
model.interactor.delete();
595+
model.renderer.delete();
596+
model.openglRenderWindow.delete();
597+
model.renderWindow.delete();
598+
}, publicAPI.delete);
585599

586600
// --------------------------------------------------------------------------
587601
// Initialization from state or input

Sources/Rendering/OpenGL/RenderWindow/index.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
9292

9393
publicAPI.getViewNodeFactory = () => model.myFactory;
9494

95+
// prevent default context lost handler
96+
model.canvas.addEventListener(
97+
'webglcontextlost',
98+
(event) => {
99+
event.preventDefault();
100+
},
101+
false
102+
);
103+
104+
model.canvas.addEventListener(
105+
'webglcontextrestored',
106+
publicAPI.restoreContext,
107+
false
108+
);
109+
110+
// Cache the value here as calling it on each frame is expensive
111+
const isImmersiveVrSupported =
112+
navigator.xr !== undefined &&
113+
navigator.xr.isSessionSupported('immersive-vr');
114+
95115
// Auto update style
96116
const previousSize = [0, 0];
97117
function updateWindow() {
@@ -244,10 +264,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
244264
let result = null;
245265

246266
// Do we have webxr support
247-
if (
248-
navigator.xr !== undefined &&
249-
navigator.xr.isSessionSupported('immersive-vr')
250-
) {
267+
if (isImmersiveVrSupported) {
251268
publicAPI.invokeHaveVRDisplay();
252269
}
253270

@@ -267,21 +284,6 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
267284
model.canvas.getContext('experimental-webgl', options);
268285
}
269286

270-
// prevent default context lost handler
271-
model.canvas.addEventListener(
272-
'webglcontextlost',
273-
(event) => {
274-
event.preventDefault();
275-
},
276-
false
277-
);
278-
279-
model.canvas.addEventListener(
280-
'webglcontextrestored',
281-
publicAPI.restoreContext,
282-
false
283-
);
284-
285287
return result;
286288
};
287289

0 commit comments

Comments
 (0)