Brent-Campbell
asked on
Fast OpenGL rendering with threads
Hi,
I've developed an application using C++ and OpenGL, all the rendering for the application is done using OpenGL. All works fine, but now I need some of the rendering to happen a little quicker. The plan was to create another thread which would just keep rendering the specific part which I believe would work, but nothing gets rendered. After some in-depth research I found that the reason that nothing gets rendered is because the OpenGL commands only work if they are called in the main thread. Is there anyway around this?
Many thanks in advance!
I've developed an application using C++ and OpenGL, all the rendering for the application is done using OpenGL. All works fine, but now I need some of the rendering to happen a little quicker. The plan was to create another thread which would just keep rendering the specific part which I believe would work, but nothing gets rendered. After some in-depth research I found that the reason that nothing gets rendered is because the OpenGL commands only work if they are called in the main thread. Is there anyway around this?
Many thanks in advance!
ASKER
Unfortunately that's not quite what I'm after, I need to know how to render OpenGL commands in other threads that I create or an alternative.
I seem to recall you need to create the opengl context from within the thread that will be making the low level GL calls on that context. I could be mistaken, as I usually thread OTHER things, and leave the GL rendering in the primary thread of the process (it's just easier that way). So you do computational stuff in secondary thread(s), and mutex/sync with the primary thread so it can render updated stuff without accessing data in the midst of being recalc'd.
However, I've spent many years with OpenGL, and very rarely does threading make a big difference. If you could explain in a bit more detail what you are doing, and what you think the threading will implement/help, it might be there are better approaches...
-d
However, I've spent many years with OpenGL, and very rarely does threading make a big difference. If you could explain in a bit more detail what you are doing, and what you think the threading will implement/help, it might be there are better approaches...
-d
ASKER
I read something about the opengl context elsewhere, do you know how I can go about creating it within a thread?
I'm actually using threading for other parts of the application but those threads need to render some data as well. The problem I'm facing is that if I create a thread to do something which then makes a call to a function that calls gl commands they don't get rendered, and even if I pass in a pointer to the main thread and call functions within that I have the same problem. There must be simple way around this.
Brent.
I'm actually using threading for other parts of the application but those threads need to render some data as well. The problem I'm facing is that if I create a thread to do something which then makes a call to a function that calls gl commands they don't get rendered, and even if I pass in a pointer to the main thread and call functions within that I have the same problem. There must be simple way around this.
Brent.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Brent - any further progress? Here to help if you hit any other roadblocks. GL in multiple threads can be REALLY tricky... ;)
ASKER
After a lot of discussion and research your right, you have to set the context to be the current rendering context within each thread that will be rendering, which isn't worth it due to the hastle of synchronising. I wonder if DirectX has this problem too?
Cheers,
Brent.
Cheers,
Brent.
http://www.gametutorials.com/gtstore/pc-80-1-frustum-culling.aspx
or This example
http://www.gametutorials.com/gtstore/pc-83-1-octree-part3.aspx
But its a start too get faster render results
this also might be interresting theory
http://www.flipcode.com/articles/article_frustumculling.shtml