14

For rendering I have a current GL context associated with a window. In the case where the application renders multiple scenes (for example using accumulation or different viewports) I believe it is ok to reuse the same context.

My question is, why should I use multiple GL contexts? I read in the ARB_framebuffer_object extension spec that calls to MakeCurrent can be expensive, and in the case the ARB_framebuffer_object extension is present I can render on a generic buffer without using MakeCurrent.

Apparently the only reason to use multiple GL context is to avoid to setup context state (pixel store, transfer, point size, polygon stipple...) or to have available multiple render buffers configuration (one context with accumulation, another without). How should I decide when it is better to use an alternative context instead of setting context state?

Samuel Harmer
4,4305 gold badges37 silver badges68 bronze badges
asked Sep 4, 2009 at 5:23

4 Answers 4

14

I usually tend to use additional contexts only when I absolutely have to, such as rendering to multiple GUI windows. For everything else, I use framebuffer objects or state changes.

However, performance recommendations like this do not apply to all cases. If in doubt, you should measure your own application on your own hardware. gDEBugger might help, there's a trial version available.

answered Sep 5, 2009 at 1:42
Sign up to request clarification or add additional context in comments.

Comments

8

IIRC, objects like textures and buffer objects can be shared between contexts, so technically you could create a second context in a second thread and load the textures asynchronously there, without worrying whether the first thread is performing the rendering.

answered Mar 31, 2010 at 0:34

Comments

5

If you want to address multiple GPU's, you need to use multiple context since you have at least one drawable per GPU, with a GPU-specific context.

answered Mar 29, 2010 at 10:18

Comments

2

In GUI programs you can have multiple opengl views, where some of them run in the same thread as the GUI and others run in their own thread. Further more you can run opengl in offscreen mode. At least one context per thread.

Not sure if it makes sense to have more contexts per thread.

answered Sep 4, 2009 at 6:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.