Functions to exchange data between CUDA and OpenGL. More...
Functions | |
RXLF_API void | Rx::ApiLF::RxGlGetContext () |
Assigns the OpenGL context created by Rx::ApiLF::RxCudaSelectDevice to the calling thread. More... | |
RXLF_API void | Rx::ApiLF::RxGlGetTextureID (Rx::ApiLF::EImgID::ID eImgID, unsigned &uGlTextureID) |
Get the OpenGl texture ID corresponding to given parameter eImgID . The content of this texture can be updated with the Rx::ApiLF::RxGlUpdateTex function. More... | |
RXLF_API unsigned | Rx::ApiLF::RxGlGetTextureID (Rx::ApiLF::EImgID::ID eImgID) |
Get the OpenGl texture ID corresponding to given parameter eImgID . The content of this texture can be updated with the Rx::ApiLF::RxGlUpdateTex function. More... | |
RXLF_API void | Rx::ApiLF::RxGlGetVersion (int &iMajor, int &iMinor) |
Get OpenGL version of current OpenGL rendering context. More... | |
RXLF_API void | Rx::ApiLF::RxGlReleaseContext () |
Releases the OpenGL context owned by the calling thread. More... | |
RXLF_API void | Rx::ApiLF::RxGlUpdateTex (unsigned uIntImgIDs, bool bCreateMipmaps=false) |
Copy CUDA result images to OpenGL textures. More... | |
Functions to exchange data between CUDA and OpenGL.
CUDA/OpenGL interop. works as follows. After calling Rx::ApiLF::RxCudaSelectDevice with bUseGL set to true
, create an OpenGL rendering context. It is then possible for the Raytrix API to write directly to textures defined by OpenGL, which can in turn be displayed through OpenGL. This avoids having to copy CUDA result images from the CUDA device to host memory and then back again to display them. To work with OpenGL textures you can use Rx::ApiLF::RxGlGetTextureID with the image id (Rx::ApiLF::EImgID) of your choice, to receive the corresponding OpenGL texture id. For example if you want to work with the Rx::ApiLF::EImgID::RefocusBasic_VirtualSpace image you can generate it, using Rx::ApiLF::RxRefocusBasic. The result of this operation is stored on the device.
Call the Rx::ApiLF::RxGlUpdateTex function each time the internal refocused image has changed.
On the OpenGL side you have to display the texture by mapping it to a plane or some other geometric object. However, note that CUDA currently only supports writing to unnormalized textures, which means that you have to define a shader to display a texture written to by the Raytrix API. The texture is initialized by the Raytrix API with the appropriate size and type, the first time Rx::ApiLF::RxGlUpdateTex is called, or if the internal result image size of the Raytrix API has changed. For example, for an RGBA image with 8bit per color channel, and dimensions iWidth
by iHeight
, the texture is created internally as
The most basic shader to display such a texture on the OpenGL side is shown below. First of all, the vertex shader:
The fragment shader for color images:
The fragment shader for luminance images:
RXLF_API void Rx::ApiLF::RxGlGetContext | ( | ) |
Assigns the OpenGL context created by Rx::ApiLF::RxCudaSelectDevice to the calling thread.
RXLF_API void Rx::ApiLF::RxGlGetTextureID | ( | Rx::ApiLF::EImgID::ID | eImgID, |
unsigned & | uGlTextureID | ||
) |
Get the OpenGl texture ID corresponding to given parameter eImgID
. The content of this texture can be updated with the Rx::ApiLF::RxGlUpdateTex function.
eImgID | Identifier for the image. | |
[out] | uGlTextureID | Identifier for the gl texture. |
RXLF_API unsigned Rx::ApiLF::RxGlGetTextureID | ( | Rx::ApiLF::EImgID::ID | eImgID | ) |
Get the OpenGl texture ID corresponding to given parameter eImgID
. The content of this texture can be updated with the Rx::ApiLF::RxGlUpdateTex function.
eImgID | Identifier for the image. |
RXLF_API void Rx::ApiLF::RxGlGetVersion | ( | int & | iMajor, |
int & | iMinor | ||
) |
Get OpenGL version of current OpenGL rendering context.
[out] | iMajor | On return contains the OpenGL major version. |
[out] | iMinor | On return contains the OpenGL minor version. |
RXLF_API void Rx::ApiLF::RxGlReleaseContext | ( | ) |
Releases the OpenGL context owned by the calling thread.
RXLF_API void Rx::ApiLF::RxGlUpdateTex | ( | unsigned | uIntImgIDs, |
bool | bCreateMipmaps = false |
||
) |
Copy CUDA result images to OpenGL textures.
The internal image IDs that can be used with this function are those declared in Rx::ApiLF::EImgID. Combining a number of image IDs by OR, updates all the related textures.
uIntImgIDs | Internal image ID. A number of internal image IDs can be combined with OR operation. |
bCreateMipmaps | (optional) the create mipmaps flag. |