Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use multiple OpenGL context

Tags:

opengl

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?

like image 418
Luca Avatar asked Sep 04 '09 05:09

Luca


2 Answers

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.

like image 165
Malte Clasen Avatar answered Oct 22 '22 06:10

Malte Clasen


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.

like image 36
GhassanPL Avatar answered Oct 22 '22 05:10

GhassanPL