Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
423 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...