# How to get GPU texture id(or handle) or texture buffer?

**URL:** <https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760>\
**Category:** Development\
**Tags:** python\
**Created:** [May 24, 2021, 12:27pm UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760 "2021-05-24T12:27:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![liku](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@liku](https://discourse.slicer.org/u/liku)\
**Post date:** [May 24, 2021, 12:27pm UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/1 "2021-05-24T12:27:41Z")

</div>

I loaded sample data and displayed volume in 3D view.  
Now I need to get texture buffer of this volume to do some process.  
Is there a method to get GPU texture buffer or texture id?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 24, 2021, 1:06pm UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/2 "2021-05-24T13:06:58Z")

</div>

When you load a volume into the scene, it is stored into CPU memory only.

Individual reformatted slices are uploaded to GPU (when you display the volume in slice views).

The entire volume is uploaded to the GPU if you display it using GPU volume rendering. You can run custom GLSL shaders on it (see Slicer Prism extension), but I am not sure if you can get access to the buffer (check out VTK and the Volume Rendering module for details).

What is your overall goal?

---

<div class="post-metadata">

**Author:** ![liku](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@liku](https://discourse.slicer.org/u/liku)\
**Post date:** [May 24, 2021, 7:06am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/3 "2021-05-24T07:06:41Z")

</div>

Operating system: Windows 10  
Slicer version: 4.11

I loaded the sample data and displayed the volume in 3D view by choosing “VTK GPU Ray Casting”.

Now I need to get texture id or texture buffer to do other process.  
Is there a way to get it?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 24, 2021, 4:00pm UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/5 "2021-05-24T16:00:47Z")

</div>

Let us know what you want to achieve and then we can give further guidance.

---

<div class="post-metadata">

**Author:** ![liku](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@liku](https://discourse.slicer.org/u/liku)\
**Post date:** [May 25, 2021, 6:05am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/6 "2021-05-25T06:05:11Z")

</div>

Thanks for reply.

We have a c++ library that performs image processing on textures.  
So I need texture buffer (or id or handle) as input parameter.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 25, 2021, 11:29am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/7 "2021-05-25T11:29:55Z")

</div>

This is a challenge because VTK manages the OpenGL state to support a wide range of visualization options so you’ll need to study that code carefully to integrate it. I had some prototypes working with earlier versions of VTK but haven’t tried with vtk 9 that Slicer currently uses. It would be helpful to have a formula for this kind of operation, so if you make progress please share back some documentation or example code. Starting with SlicerPrism as Andras suggested may get you started.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 25, 2021, 11:46am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/8 "2021-05-25T11:46:38Z")

</div>

> [@liku](#):
>
> We have a c++ library that performs image processing on textures.

I don’t think you can implement processing on the GPU in C++.

If it is really C++ then it runs on the CPU and you don’t need to transfer the image to the GPU.

If the library is actually in GLSL then PRISM or the GPU image processing filter in vtkAddon are good examples.

If the library uses OpenCL then you can find examples for how to create a processing filter from it in ITK.

If you have Cuda code then I would recommend to port it to GLSL or OpenCL for compatibility with non-NVidia hardware, but if I remember well there are some Cuda examples in the VASST extension.

---

<div class="post-metadata">

**Author:** ![liku](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@liku](https://discourse.slicer.org/u/liku)\
**Post date:** [May 26, 2021, 1:23am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/9 "2021-05-26T01:23:21Z")

</div>

Thanks for suggestion. I’ll look into Slicer Prism extension.

---

<div class="post-metadata">

**Author:** ![liku](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@liku](https://discourse.slicer.org/u/liku)\
**Post date:** [May 26, 2021, 1:26am UTC](https://discourse.slicer.org/t/how-to-get-gpu-texture-id-or-handle-or-texture-buffer/17760/10 "2021-05-26T01:26:44Z")

</div>

Yes, the library uses OpenCL.  
Thanks for suggestion.
