Hello VTK Community.
Currently I’m working on a 3D streaming application utilizing OpenGL, NVENC and libavformat to capture the 3D context, encode it into H264 frames and send it via libavformat as RTP stream to a media server for client distribution.
Using Native OpenGL code I managed to successfully register a GL_TEXTURE_2D
to a cuda resource and transfering this buffer data to the NVEncoder for encoding.
Right now, I want to translate this native OpenGL code into higher level VTK-Code. Therefore, I somehow need to get the correct handle of the GL_TEXTURE_2D
of the currently rendered frame to register it with CUDA.
I tried:
auto openGLRenWin = vtkOpenGLRenderWindow::SafeDownCast(renderWindow);
auto fbo = openGLRenWin->GetDisplayFramebuffer();
fbo->SaveCurrentBindingsAndBuffers();
int numColors = fbo->GetNumberOfColorAttachments(); // returns 2 (?)
auto texture = fbo->GetColorAttachmentAsTextureObject(0); // also tried index 1 --> same result
cudaGraphicsGLRegisterImage(&cuda_tex_screen_resource, *tex_screen,
GL_TEXTURE_2D, cudaGraphicsMapFlagsReadOnly)
There has to be something wrong with my code as the resulting encoded frame is all black - rest of my code is identical to the native OpenGL version, where i create and register the texture as followed:
// create a texture
glGenTextures(1, tex_screen);
glBindTexture(GL_TEXTURE_2D, *tex_screen);
// set basic parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// buffer data
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, size_x, size_y, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
// Register CUDA resource
cudaGraphicsGLRegisterImage(&cuda_tex_screen_resource, *tex_screen,
GL_TEXTURE_2D, cudaGraphicsMapFlagsReadOnly)
My question is: What is the proper way to get the correct handle of the currently rendered frame (texture) in order to register the CUDA resource?
When processing the CUDA resource, do I have to Bind/Active any VTK buffer objects beforehand?
Thanks in advance,
Philipp