Binding an "external" texture to a framebuffer

I’m looking at how integrating OpenVR python binding with Panda3D and I think I have encountered a road block.

For OpenVR, submitting the rendered scene was quite simple, I “just” have to retrieve the texture handle from the texture context object returned by prepare_now() in the draw call, feed it to the compositor and voila :slight_smile:

For OpenXR, the workflow is different : OpenXR allocates the texture to render into and provides the handle. This texture can then be bind to a framebuffer and used to do the off-screen scene rendering.

So my question is: is there a way, using Python, to create a Panda3D texture from an existing OpenGL texture handle, or attach that texture handle to a Panda3D render buffer ?

Alternatively, if that’s not possible or too complicated, can I retrieve the framebuffer id and use raw OpenGL calls to do the dirty job myself in the draw call ?

There is not currently a way to bind an external OpenGL texture handle into a Texture object in Panda, unfortunately, or to specify it as a render-texture target. Though if you really need it, I’d be open to considering ways to add this feature to Panda.

The Oculus SDK also wants to create its own OpenGL texture objects, and what I ended up doing when implementing it was just subclassing GraphicsWindow and doing the bind calls in begin_scene / end_scene, etc. I can send you my files privately if you want to look at them.

In Python, rather than subclassing GraphicsWindow, you could probably create a CallbackGraphicsWindow that does the same thing. Of course in a draw callback you have complete flexibility to create and bind your own FBO and bind whatever textures you want to it.

Thank you for your explanations :slight_smile:

I don’t think that is a must have feature, at least for me, as this is still in exploratory phase. I think I can manage using a CallbackGraphicsWindow as you suggested and to the FBO binding manually (There are other configuration steps that I also have to do using glx anyway to manage context switches).

I wouldn’t mind if that’s not too much trouble for you, right now I aim at a pure Python implementation, but it could be useful and I could later give a try porting it to C++.