I rendered a scene with opengl (I can also render it to a texture)
I want to use CUDA / Thrust to sort this rendered image
How do I link the texture I made from : cudaGraphicsGLRegisterImage to be used via thrust?
maybe something like this ? how to calculate an average from a int2 array using Thrust
I'm not sure it makes sense to try and use textures directly with thrust. However using an ordinary GL pixel buffer can be made to work directly with thrust.
The following example creates an openGL pixel buffer with a particular green/black pattern, and then displays it. When you press the space bar, the pixel buffer will be made available to CUDA via CUDA/OpenGL interop, and then a thrust sort (in-place) function is called. After the sort, the sorted pixel data is displayed again. The pixel data never leaves the GPU.
Here's the sample code:
compile like this:
Here's what the display window looks like before sorting:
Here's what the display window looks like after sorting (after you press the space bar):
Note that we are sorting pixels based on the green component in this example.
You can press the ESC key to exit the app.
There are some updated versions of this sample code here.