14

I wan't to do some calculated pixelart with OpenCL and display this directly on the display without CPU roundtripping. I could use interoperability of OpenCL with OpenGL and write to the texture-banks of the GPU and display the texture with OpenGL. I was wondering what would be the best way to do this, since I do not need any 3d stuff, just 2d pixelart.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
RobotRock
  • 4,211
  • 6
  • 46
  • 86

1 Answers1

15

The best way would be to use OpenCL/OpenGL interop, if your OpenCL implementation supports it. This allows OpenCL to access certain OpenGL objects (buffer objects and textures/renderbuffers). You won't be able to directly access the default OpenGL framebuffer (ie: the display), but you will be able to access an image bound to a framebuffer object. From there, you can, in OpenGL, do a framebuffer blit to the default framebuffer. Nothing will touch CPU memory.

You'll have to look up the specifics on CL/GL interop to learn the details however. The basic idea is that you create a renderbuffer in OpenGL (which you bind to an FBO). Then you hand that renderbuffer off to OpenCL, and do your computations into the renderbuffer. Once that's complete, you perform a glBlitFramebuffer to copy the data from the renderbuffer to the default framebuffer, then swap buffers to display it.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 1
    Good one. I know this method, but I have some problems with realization CL&GL interop. Can you please see my issue here: http://stackoverflow.com/questions/8789662/interoperability-texture-access-block? – itun Jan 10 '12 at 12:18
  • I've written full demos of OpenCL/OpenGL/VAAPI interop that do exactly that: https://github.com/kallaballa/GCV – kallaballa Oct 28 '22 at 08:37