Sharing Polydata or VBO etc between mappers

I’m a little confused about the right way to do instancing in vtk. In some places in our code, we use the vtkGlyphMapper which works great but can be tricky to set up. In other places, we just share a mapper between multiple actors. This also seems to work well in avoiding having multiple copies of data on the gpu ( we routinely have geometries with 10s of millions of triangles and so it can be problematic if you screw up instancing)

However sharing the mapper between actors breaks down if you want to have different mapper configurations for different actors (for example, different section planes).

What is the most straightforward way to share a polydata between mappers in such a way that only one copy of the polydata ends up on the gpu? Or is there a way to share the polydata as some other level, such as VBOs etc? Some have suggested to me that it is as easy as assigning the same polydata to 2 different mappers but I’m not seeing that…

Hi @geoffw

This is the easiset way to do it. The vtkOpenGLPolyDataMapper is designed to reuse VBOs for identical vtkDataArrays.

Jaswant, thanks for the quick reply. Does it do this via checking the pointer or does it actually go and interrogate the data? How can I know that it isn’t writing the VBO twice, is that in the OpenGLPolyDataMapper? maybe monitor UpdateBufferObjects? (wish I was better with nsight…)

Just curious where this caching is occurring. I know it’s in there somewhere

also these polydatas are being assigned to a multipiecedataset. I think that’s where it’s going wrong. It’s definitely getting written to the gpu more than once.

In my experience, there are two important facts about the opengl VBO cache:

  1. It is guaranteed that VTK will always use one VBO for a given vtkDataArray, this is essentially a map of vtkDataArray* to VBO.
  2. Values are uploaded to a VBO only when the MTime of it’s vtkDataArray is greater than the last time that VBO was updated. IIUC, the MTime of a vtkDataArray doesn’t change when the values of the array are modified.

Both of those facts are not strictly true for composite datasets because the composite opengl polydata mapper appends data arrays into a single VBO. While it sounds efficient on paper, a practical limitiation is tha if one of the data arrays change size, all others will have to be re-uploaded.

vtkGlyphMapper might be tricky to setup, but it is more effective. I would suggest designing your app around the glyph mapper.

I agree, we use glyphing in other places and it’s worked well.