Home > Articles > Programming > Graphic Programming

  • Print
  • + Share This
From the author of Writing an OpenCL Kernel

OpenCL and OpenGL

The OpenGL 4 specification includes support for combining OpenGL and OpenCL. For example, you could easily extend this example to output a copy of the board into a texture, and then composite that texture into an OpenGL scene. You can also use OpenCL to generate geometry or texture data algorithmically and then send this data directly into the OpenGL stack, without ever copying to the CPU or main memory.

The code in the example just dumps the output to the terminal. If you're familiar with OpenGL, you could try modifying the example to create an OpenGL texture. With that approach, you can eliminate the read altogether; the board never needs to be stored in main memory after the first initialization.

OpenCL provides a very simple model to programmers. If you know C already, you should need only a few minutes to get your first OpenCL program working, and a couple of hours to become really comfortable with the system. Writing efficient, well-optimized code may take a bit longer, because you have to become familiar with a target architecture that's quite unlike anything you're likely to have programmed with C.

The example for this article was written and tested on OS X 10.6, but it should work on other platforms with minimal changes. nVidia and ATi both support OpenCL with their latest drivers, and Gallium3D provides preliminary support, so OpenCL is likely to become a lot closer to ubiquitous over the next few years.

In this article, I've glossed over a lot of the details of OpenCL. The specification is over 300 pages long and contains a lot of detail. But I hope that I've motivated you to read some of the specification—which is a lot more readable than most specs I've come across—and play with the language.

  • + Share This
  • 🔖 Save To Your Account