# Can I use OpenGL compute shaders in VTK program?

**URL:** https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055
**Category:** Support
**Created:** [August 24, 2020, 10:18am UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055 "2020-08-24T10:18:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![yuxing55555](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuxing55555/32/2234_2.png) [@yuxing55555](https://discourse.vtk.org/u/yuxing55555)
#### Post date: [August 24, 2020, 10:18am UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/1 "2020-08-24T10:18:41Z")

</div>

VTK9.0 use OpenGL2 at backend, and use GetOpenGLVersion result is 4.4.

i found vtkShader not contain compute shader.

Does anyone has any example to use compute shader?

thank you!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 24, 2020, 3:28pm UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/2 "2020-08-24T15:28:55Z")

</div>

Hi, friend,

Since your post was not much specific, I can only suggest this example here: [https://gitlab.kitware.com/vtk/vtk/blob/v7.0.0.rc2/Rendering/OpenGL2/Testing/Cxx/TestUserShader2.cxx](https://gitlab.kitware.com/vtk/vtk/blob/v7.0.0.rc2/Rendering/OpenGL2/Testing/Cxx/TestUserShader2.cxx) . It includes a basic example in glsl language.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![Lfx\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lfx_paul/32/2097_2.png) [@Lfx\_Paul](https://discourse.vtk.org/u/Lfx_Paul)
#### Post date: [August 24, 2020, 3:31pm UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/3 "2020-08-24T15:31:14Z")

</div>

Indeed, there is no GL\_COMPUTE\_SHADER in the Compile function of vtkShader. If I remember well VTK use openGL version 3.2. If you want to create a compute shader, you must compile it yourself, as well as call glComputeDispatch by hand

---

<div class="post-metadata">

### Author: ![Lfx\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lfx_paul/32/2097_2.png) [@Lfx\_Paul](https://discourse.vtk.org/u/Lfx_Paul)
#### Post date: [August 24, 2020, 3:34pm UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/4 "2020-08-24T15:34:58Z")

</div>

This is the method to use a user custom shader, but this won’t work in case of a GL\_COMPUTE\_SHADER (introduced in OpenGL version 4.3). This seems to work only for vertex and fragment shader

---

<div class="post-metadata">

### Author: ![yuxing55555](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuxing55555/32/2234_2.png) [@yuxing55555](https://discourse.vtk.org/u/yuxing55555)
#### Post date: [August 25, 2020, 1:07am UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/5 "2020-08-25T01:07:53Z")

</div>

thanks for the reply, I know this. You can also find some shader-related examples here, but there are no compute shader-related examples.  
[https://lorensen.github.io/VTKExamples/site/Cxx/#shaders](https://lorensen.github.io/VTKExamples/site/Cxx/#shaders)

---

<div class="post-metadata">

### Author: ![yuxing55555](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuxing55555/32/2234_2.png) [@yuxing55555](https://discourse.vtk.org/u/yuxing55555)
#### Post date: [August 25, 2020, 1:08am UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/6 "2020-08-25T01:08:40Z")

</div>

thanks for the reply.Yes, vtkShader does not include GL\_COMPUTE\_SHADER. I myself use vtk9.0.0 compiled by mingw4.8.2, and then I use the GetOpenGLVersion method of vtkWin32OpenGLRenderWindow to get the opengl version 4.4. When I compiled vtk9.0.0, I didn’t find a way to set the opengl version. . I will try the way you said,thank you.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 14, 2023, 7:21pm UTC](https://discourse.vtk.org/t/can-i-use-opengl-compute-shaders-in-vtk-program/4055/7 "2023-11-14T19:21:44Z")

</div>

I know this is an old thread, but in the latest master, compute shaders are now supported and in `vtk/Rendering/OpenGL2/Testing/Cxx/TestComputeShader.cxx` a test is included.
