I am starting to learn OpenGL and I was wondering if it is possible to have it draw on a video memory buffer that I've obtained through other libraries?
-
What other libraries? Are these "libraries" for direct hardware access, too (e.g. Direct3D, CUDA, OpenCL) or using such functionalities under the hood? – Christian Rau Sep 25 '11 at 23:25
2 Answers
For drawing into video memory you can use framebuffer objects to draw into OpenGL textures or renderbuffers (VRAM areas for offscreen rendering), like Stefan suggested.
When it comes to a VRAM buffer created by another library, it depends what library you are talking about. If this library also uses OpenGL under the hood, you need some insight into the library to get that "buffer" (be it a texture, into which you can render directly using FBOs, or a GL buffer object, into which you can read rendered pixel data using PBOs.
If this library uses some other API to interface the GPU, there are not so many possibilities. If it uses OpenCL or CUDA, these APIs have functions to directly use their memory buffers or images as OpenGL buffers or textures, which you can then render into with the mentioned techniques.
If this library uses Direct3D under the hood, it gets a bit more difficult. But at least nVidia has an extension to directly use Direct3D 9 surfaces and textures as OpenGL buffers and textures, but I don't have any experience with this and neither do I know if this is widely supported.

- 45,360
- 10
- 108
- 185
You cannot let OpenGL draw directly to arbitrary memory, one reason is that in most implementations OpenGL drawing happens in video RAM, not system memory. You can however draw to an OpenGL offscreen context and then read back the result to any place in system memory. A web search for framebuffer objects (FBOs) should point you to documentation and tutorials.
If the memory you have is already in VRAM, for example decoded by hardware acceleration, then you might be able to draw to it directly if it is available as an OpenGL texture - then you can use some render to texture techniques that will save you transferring data from and to VRAM.

- 440
- 2
- 7
-
some small notational problems: 1. The OP already spoke of video memory 2. framebuffer objects don't comprise an offscreen context, only an offscreen buffer (maybe you thought of Pbuffers). 3. render to texture is exactly what FBOs are usually used for. – Christian Rau Sep 25 '11 at 23:23
-
I wasn't quite sure from the question if "video memory buffer" meant a memory buffer in VRAM or a memory buffer containing video. – Stefan Werner Sep 26 '11 at 17:01
-
Ah, I didn't think about this. I saw video memory and immediately thought of VRAM. But you're right in that it could also mean CPU RAM with video data. – Christian Rau Sep 26 '11 at 17:30