Multiple views of the same scene in multiple wndws

Hi my application needs to provide multiple views of the same scene (different cameras) on different windows.

What would be the best way of doing that? As fas as I know, each window must have its own render context. Each render context can share its resources with other render contexts, which would not be a problem.

However, I think it would be better if there was only one OpenGL render context to be shared among all windows. Is this possible?

Thanks in advance.

no that is not possible, your first solution is the right way to go.

wglMakeCurrent

The second solution is indeed the right way to go and very well possible, as well as ‘legal’.

You can share the same rendercontext among all windows. You render one window after another, each time switching the same rendercontext (HGLRC) to a different device context (HDC) using wglMakeCurrent(). The only requirement is that you have to call SetPixelFormat() on each HDC with exactly the same pixelformat ID.

I did a quick benchmark to test this, with 4 sceneviewers rendering one scene, in the first test, I used:

wglMakeCurrent(dc1, rc1);

wglMakeCurrent(dc2, rc1);

wglMakeCurrent(dc3, rc1);

wglMakeCurrent(dc4, rc1);

In the second I used:
wglMakeCurrent(dc1, rc1);

wglMakeCurrent(dc2, rc2);

wglMakeCurrent(dc3, rc3);

wglMakeCurrent(dc4, rc4);

I got 1950 FPS in the first case, 1750 FPS in the second case
(about 0.06 ms difference in frame time), which translates to about 0.2 Frames/second at ~60 Hz (60.2 FPS using a single context instead of 60 FPS using separate contexts)

What other benefits/disadvantages are there apart from speed wise?
a) Could separate contexts potentially be faster in future, if they were used to render in parallel?
b) Would you need to modify more state if you’re using 1 context + viewing the same scene with different viewing locations/lights etc.
c) Is Direct3D closer to the 1 context for several windows model?
d) Approximately how much memory is used per context?

a) Could separate contexts potentially be faster in future, if they were used to render in parallel?

Rendering in parallel requires you to use more than one rendercontext; one for each thread. You are not allowed to bind the same rendercontext in several threads at the same time. Also, I doubt that talking to one GPU via multiple threads at the same time is beneficial for performance.

b) Would you need to modify more state if you’re using 1 context + viewing the same scene with different viewing locations/lights etc.

I don’t think so. It will be harder to maintain state between several rendercontexts. Viewing the scene with different light settings will require you to change the lights once per view. CHanging a state once per view will hardly impact performance.

c) Is Direct3D closer to the 1 context for several windows model?

In Direct3D the “D3D10Device” object is what comes closest to a rendercontext in OpenGL terms. In the D3D world it seems unusual to have more than one device running at the same time… except maybe if you need to talk to multiple GPUs.

d) Approximately how much memory is used per context?
Apart from the amount of resources you use (textures, VBOs, FBOs, shader etc…) this should be negligible. But keep in mind, that the driver has to manage/synchronize all rendercontexts behind the curtains, so there probably is some extra amount of work to be done on the driver side, whe using multiple contexts.