[vtkusers] offscreen rendering from gui application in vtk8/opengl2

Andreas Buykx A.Buykx at dianafea.com
Mon Jul 9 09:50:55 EDT 2018


I tried the SetUseOffScreenBuffers approach which does work in the sense that it renders to the hardware buffers without errors (see new version of writetopng.py). Unfortunately when I want to render to a different screen size the behavior is dependent on the actual render window used:

1.       using vtkpython I will briefly see the vtk viewer window resized to that size, and

2.       within our QVTKOpenGLWidget the widget remains as is, which is good, but the image written contains just a fragment of the viewer window in the lower left corner, with the upper and right parts of the image solid black.

Regarding Patric Bergeron’s remark about re-initializing graphics resources: I had expected this to work with my initial approach since vtkRenderWindow::RemoveRenderer calls ReleaseGraphicsResources…

From: Ken Martin <ken.martin at kitware.com>
Sent: maandag 9 juli 2018 2:25
To: Patrick Bergeron <pbergeron at spiria.com>
Cc: Andreas Buykx <A.Buykx at dianafea.com>; vtkusers at public.kitware.com
Subject: Re: [vtkusers] offscreen rendering from gui application in vtk8/opengl2

Another option might be to try switching to offscreen on your main render window then switching it back to onscreen. I think the method is SetUseOffscreenBuffers.  Then you don't have to copy any actors etc. That might do the trick for you.

On Mon, Jul 9, 2018 at 7:38 AM, Patrick Bergeron <pbergeron at spiria.com<mailto:pbergeron at spiria.com>> wrote:
The new OpenGL backend simply works differently than before.

The other thing you can try is to debug vtk to try to detect a context change and to re-initialize the graphics resources.

So when you switch Graphics contexts, they get destroyed and re created.

You may try this with shaders first since it is your immediate problem. But I might expect you’d have to do it with textures too at least.

Another way to get around it is to render into a different render target and read the contents of the image (if you can do with the same rendered size) by using a frame buffer object.


Sent from my iPhone

On Jul 9, 2018, at 07:23, Andreas Buykx <A.Buykx at dianafea.com<mailto:A.Buykx at dianafea.com>> wrote:
I had hoped I would not get this advice as it’s rather painful : we have heaps of actors and mappers with associated properties.
This used to work before, was that a lucky accident?


From: Patrick Bergeron <pbergeron at spiria.com<mailto:pbergeron at spiria.com>>
Sent: maandag 9 juli 2018 1:15
To: Andreas Buykx <A.Buykx at dianafea.com<mailto:A.Buykx at dianafea.com>>; 'vtkusers at public.kitware.com<mailto:vtkusers at public.kitware.com>' <vtkusers at public.kitware.com<mailto:vtkusers at public.kitware.com>>
Subject: Re: offscreen rendering from gui application in vtk8/opengl2

Hi Andreas,

The actors and mappers use OpenGL resources that belong to an OpenGL context, but not all can be shared across multiple OpenGL contexts, especially if one context is software OpenGL (mesaGL?) and the other is not.

Maybe VTK should have a way to clone the renderer and all its contents to do this automatically, or find a way to share shaders across contexts too...


For now here is my recommendation, re-create your scene.

- Create a new render window
- Create a new renderer
- Get all actors in the renderer,  and for each actor:
- Create a new actor
- Create a new mapper
- Set the new mapper to the new actor
- Get the input connection source of the mapper and set it to the new mapper
- Copy the actor's rendering property to the new actor
- Set the user transform of the old actor to the new actor.

Set the active camera from y9our old renderer to new renderer

Copy the lights too if necessary

I think that is it!

________________________________
From: vtkusers <vtkusers-bounces at public.kitware.com<mailto:vtkusers-bounces at public.kitware.com>> on behalf of Andreas Buykx <A.Buykx at dianafea.com<mailto:A.Buykx at dianafea.com>>
Sent: July 9, 2018 3:42:27 AM
To: 'vtkusers at public.kitware.com<mailto:vtkusers at public.kitware.com>'
Subject: [vtkusers] offscreen rendering from gui application in vtk8/opengl2


We recently switched our FEA application from vtk7.1 and the OpenGL backend to using 8.1 and the new OpenGL2 backend.



With 7.1 we could make off-screen images from the gui application using a temporary off-screen render window, temporarily moving renderers from the GUI render window to the off-screen render window, render the image and then move all renderers back to the GUI render window.

With vtk8.1 and OpenGL2 this causes OpenGL errors.



I reproduced this with the attached script which on vtk8.1.1 and the current head leads to an openGL error:



ERROR: In path-to/VTK-master/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx, line 1814

vtkOpenGLPolyDataMapper (0x273dc00): failed after UpdateShader 1 OpenGL errors detected

  0 : (1282) Invalid operation



When the script is run with a global off-screen render window things work out fine.



Is my approach wrong (temporary render window, moving renderers to it temporarily) or is this a bug?



Thanks for your help!



DIANA FEA BV

Software Developers and Analysis Consultants for Civil and Geotechnical Engineering



Delftechpark 19a, 2628XJ, Delft, The Netherlands

Tel: +31 88 34262 15 (Direct) │ Tel: +31 88 34262 00 (Switchboard) │ Fax: +31 88 34262 99

http://dianafea.com<http://dianafea.com/>



_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers



--
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
101 East Weaver Street
Carrboro, North Carolina
27510 USA
This communication, including all attachments, contains confidential and legally privileged information, and it is intended only for the use of the addressee.  Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken in reliance on it is prohibited and may be unlawful. If you received this communication in error please notify us immediately and destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180709/e561583b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: writetopng.py
Type: application/octet-stream
Size: 2380 bytes
Desc: writetopng.py
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180709/e561583b/attachment.obj>


More information about the vtkusers mailing list