Many contexts vs. many viewports in one context.

I am writing an application that has a single large window divided into 4 quadrants, with each quadrant showing different information rendered by OpenGL. The quadrants share common texture data and call lists. Three of the quadrants will share the exact same OpenGL state – so there are two states to maintain. I also need the ability to draw objects that span multiple quadrants (e.g. a message drawn across the entire window). The interface is animated so all quadrants are being constantly redrawn at the same time (therefore I do not care about optimizing away unnecessary redraws).

The two options I’m considering are:

  1. Maintaining 4 OpenGL contexts rendering to the 4 quadrants of the window, using context sharing to share texture and call list data. To draw objects that span multiple quadrants, draw the object in each quadrant separately so that it appears to span multiple ones (e.g. when drawing a message, draw a quarter of the message in each quadrant). Maintaining states is easy since OpenGL state is maintained per context.

  2. Maintaining a single OpenGL context, and use glViewport along with glScissor to draw to each of the quadrants. Data sharing is not an issue since it’s all in the same context. To draw objects that span multiple quadrants, simply set the viewport and scissor rectangle appropriately. Maintaining states is slightly more complex – the OpenGL state will have to be set up before drawing the 1 “special” quadrant, then set up again before drawing the remaining 3.

My questions are:

A) What is the best way to do this? Is there a 3rd option?

B) Is there a major performance hit to option #2 above? I eliminate 4 context switches for every redraw, but as a result I add 4 glViewport/glScissor calls and a scissor test as well as explicitly setting transformation matrices and GL state.

The application is going to be doing some pretty GPU intensive rendering, and the target frame rate is low – around 20-30 FPS – however, it will generally be run on recent, powerful graphics hardware. Since the rendering itself is so intensive, and also since the hardware will generally be pretty fast, performance hits with #1 vs. #2 may be negligible, so I’m not sure if it even matters.

The application is currently in the design phase and I’m not really sure how to proceed. It’s convenient to keep 4 separate contexts, context sharing is easy, but then drawing across multiple quadrants is an issue. I am using GLX so perhaps there is a GLX trick that may help?

Thanks,
Jason

I would just go with option 2 - It is simpler (at least it is for me) and a few extra state and scissor/view port calls are not really going to affect rendering performance much.

Option 2 should be better. Avoid multiple contexts when you can!

I agree, option 2 is much simpler, and that’s the way I will go. Thanks for your input! :slight_smile:

Jason