Reputation: 33
Ok I have a program with a number of threads (loaded from DLLs at run-time). Each thread has a separate OpenGL rendering context. What I want to do is, from the main thread, be able to draw the frame buffers of each opengl contexts and draw them where I choose in the main window (if that makes any sense). I have it set up multi-threaded because, when single threaded the "run-time processes"(just glorified functions), made the hole program hang while loading resources (run-time processes, can be created and terminated any time). Basicly I want to be able to "trick" opengl into drawing into a random buffer, take that buffer and in the main thread turn it into a opengl texture and draw it where it needs to be (the position is also determined during runtime and it subject to change). My question is this, is there any way to get a rendering context to draw to some allocated memory without drawing it in a window? Also is there any way to get the frame buffer from that context. If so i would just call "glTexImage2D" and in the "bytes" argument have the pointer to the memory. Don't worry about the thread syncing, i've gotten rather good at it...
Upvotes: 1
Views: 7748
Reputation: 162164
My question is this, is there any way to get a rendering context to draw to some allocated memory without drawing it in a window?
Yes. Those off-screen areas are called Framebuffer Objects (FBO).
Also is there any way to get the frame buffer from that context. If so i would just call "glTexImage2D" and in the "bytes" argument have the pointer to the memory.
In fact using FBOs you can render directly to textures. You can then use the texture to draw to a regular window.
I recommend you do not use multiple OpenGL rendering threads. The main reason is, that the GPU is a shared resource and having multiple OpenGL contexts/threads access it concurrently impairs performance. Do the renderings in sequence. You can use a single, shared context for this.
Multiple OpenGL contexts can share their data objects (textures, vertex buffer objects, pixel buffer objects); the exact API used for this depends on the operating sytem through. On Windows you use wglShareLists
to make the connection. Abstract state carrier objects (FBOs, VAOs) can not be shared though; as a rule of thumb, everthing you can upload bulk data to, can be shared between contexts.
Upvotes: 3
Reputation: 3911
On most platform a OGL context is bound to a window or view. The next best you may do is make such window/view invisible.
But why do you need multiple context anyway? OpenGL (on modern cards) do support rendering to off screen texture, although only one thread may be active at once, but if you are doing it right to utilize transfer throughput, you don't really need to have multiple threads with the context.
Upvotes: 0