# Sharing Polydata or VBO etc between mappers

**URL:** https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775
**Category:** Support
**Created:** [October 28, 2024, 4:38am UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775 "2024-10-28T04:38:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [October 28, 2024, 4:38am UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/1 "2024-10-28T04:38:41Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [October 28, 2024, 12:55pm UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/2 "2024-10-28T12:55:19Z")

</div>

Hi @geoffw

> [@geoffw](#):
>
> 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…

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

---

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [October 29, 2024, 2:12am UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/3 "2024-10-29T02:12:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [October 29, 2024, 12:18pm UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/4 "2024-10-29T12:18:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [October 30, 2024, 5:30pm UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/5 "2024-10-30T17:30:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [October 30, 2024, 7:49pm UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/6 "2024-10-30T19:49:27Z")

</div>

> [@jaswantp](#):
>
> 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 lim

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

---

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [June 23, 2025, 4:10pm UTC](https://discourse.vtk.org/t/sharing-polydata-or-vbo-etc-between-mappers/14775/7 "2025-06-23T16:10:14Z")

</div>

@jaswantp , I want to port shader to glyphmapper. Can you point me in the right direction? Can I start by copying the shader stuff from the standard polydatamapper? then I just need to get the index and other glyph info available to shader?
