Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Multiple views of the same scene in multiple wndws

  1. #1
    Intern Contributor
    Join Date
    Dec 2000
    Location
    Almazora, Spain
    Posts
    95

    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.

  2. #2
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    293

    Re: Multiple views of the same scene in multiple wndws

    Quote Originally Posted by Sansus
    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?
    no that is not possible, your first solution is the right way to go.

  3. #3
    Intern Contributor
    Join Date
    Jul 2009
    Posts
    53

    Re: Multiple views of the same scene in multiple wndws


  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    666

    Re: Multiple views of the same scene in multiple wndws

    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.

  5. #5
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456

    Re: Multiple views of the same scene in multiple wndws

    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?

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    666

    Re: Multiple views of the same scene in multiple wndws

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •