I have a dll that does some rendering using OpenGL. I need to render it to a texture and use that texture in direct x 11. My current attempt has been to render the OpenGL to a texture on one process, and then use Cuda to encode the texture to a h264 video stream, and then decode that stream on another process using cuda / directx 11. However, I'm wondering if there is an easier way to get a portion of a scene rendered OpenGL to DirectX11.
The ideal way to do this would involve OpenGL and D3D sharing the texture memory on the GPU. But there is unfortunately no practical way to do that (as far as I am aware).
Thus, you're going to have to shuffle the texture data around on the CPU. The process is fairly straightforward though. Once your render-to-texture has completed in OpenGL, map the texture to the CPU (via
glGetTexImage or something fancier), which gives you access to the pixel data of the texture.
If you're going to do this repeatedly you'll want to make sure you create both textures with the appropriate flags to suggest dynamic updates to the API.
Really the most elegant solution would be to replicate the functionality in Direct3d 11, but presumably this is unfeasable for you because of reasons™. You could also consider whether using the dll is more trouble than it's worth, there are no easy solutions here.
If you really, REALLY need this you could :
- Look into memory-mapping like Josh Petrie suggested
- Use the underlying DXGI layer which is the infrastructure Windows uses for drivers to the hardware. I don't know enough to present a complete solution but can at least point you in the right direction.
Either way will probably require some serious low-level hacking so think really long and hard if you want to take that plunge.
You might want to look at the DX_Interop OpenGL extensions. Since the extensions were contributed by NVIDIA, they might not be available on every card, but since you mentioned using CUDA, you should be covered.