@@ -141,7 +141,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
141141 const previousSize = [ 0 , 0 ] ;
142142 function updateWindow ( ) {
143143 // Canvas size
144- if ( model . renderable ) {
144+ if ( model . renderable && model . manageCanvas ) {
145145 if (
146146 model . size [ 0 ] !== previousSize [ 0 ] ||
147147 model . size [ 1 ] !== previousSize [ 1 ]
@@ -160,7 +160,9 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
160160 }
161161
162162 // Offscreen ?
163- model . canvas . style . display = model . useOffScreen ? 'none' : 'block' ;
163+ if ( model . manageCanvas ) {
164+ model . canvas . style . display = model . useOffScreen ? 'none' : 'block' ;
165+ }
164166
165167 // Cursor type
166168 if ( model . el ) {
@@ -549,15 +551,28 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
549551 if ( model . deleted ) {
550552 return null ;
551553 }
554+ const requestedSize =
555+ ! ! size || scale !== 1
556+ ? size || model . size . map ( ( val ) => val * scale )
557+ : null ;
558+ const requiresCanvasResize =
559+ requestedSize !== null &&
560+ ( requestedSize [ 0 ] !== model . size [ 0 ] ||
561+ requestedSize [ 1 ] !== model . size [ 1 ] ) ;
562+ const screenshotSize = requiresCanvasResize ? requestedSize : null ;
563+
564+ if ( ! model . manageCanvas && requiresCanvasResize ) {
565+ throw new Error (
566+ 'Resizing screenshot capture requires manageCanvas=true on vtkOpenGLRenderWindow'
567+ ) ;
568+ }
569+
552570 model . imageFormat = format ;
553571 const previous = model . notifyStartCaptureImage ;
554572 model . notifyStartCaptureImage = true ;
555573
556574 model . _screenshot = {
557- size :
558- ! ! size || scale !== 1
559- ? size || model . size . map ( ( val ) => val * scale )
560- : null ,
575+ size : screenshotSize ,
561576 } ;
562577
563578 return new Promise ( ( resolve , reject ) => {
@@ -1307,6 +1322,7 @@ const DEFAULT_VALUES = {
13071322 context : null ,
13081323 context2D : null ,
13091324 canvas : null ,
1325+ manageCanvas : true ,
13101326 cursorVisibility : true ,
13111327 cursor : 'pointer' ,
13121328 textureUnitManager : null ,
@@ -1377,6 +1393,7 @@ export function extend(publicAPI, model, initialValues = {}) {
13771393 'context' ,
13781394 'context2D' ,
13791395 'canvas' ,
1396+ 'manageCanvas' ,
13801397 'renderPasses' ,
13811398 'notifyStartCaptureImage' ,
13821399 'defaultToWebgl2' ,
0 commit comments