Optix7.0 opengl interoperation

Can I sample opengl texture directly in Optix shader?
There are some samples showing that we can upload texture to a pbo(pixel buffer object) and then bind it to optix,
however this is not a zero-copy solution.
Is there a direct way to handle opengl texture?

Can I sample opengl texture directly in Optix shader?

Not at this time.

All interoperability between OptiX 7 and other graphics APIs is actually outside of OptiX 7 and happens completely via native CUDA mechanisms.

Also OptiX 7 itself has no knowledge of textures. That all happens via CUDA texture objects and the respective texture functions in CUDA’s texture_fetch_functions.h.

  • An OpenGL PixelBufferObject is just a linear memory area. You can do CUDA-OpenGL interop with that and render directly into the PBO from OptiX.
    You still need to do the glTex(Sub)Image2D call to upload the PBO contents to the OpenGL texture.
    That is actually used in most OptiX SDK examples to display the final image on the screen.
  • CUDA also allows to directly copy device-to-device into a registered OpenGL texture image but this is also not happening inside the shader code.
  • The third method would be to directly read from/write to CUDA surfaces, but this is currently not working in OptiX 7 and should be fixed in the next release.
    Searching the CUDA forums for CUDA reading from OpenGL texture image turns up some threads using CUDA surfaces for that.

Examples using no interop, OpenGL PBO interop and registered OpenGL texture images can be found here:

Search the source code for m_interop and you’ll find the different methods, easiest to be seen in this source: