Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For an engine I'm developing I've decided to allow users to set up multiple windows showing differing views of the same "world." This is being developed using OpenGL (hopefully aiming for 3.2 core eventually if that affects the ansmer) and SDL 1.3. The basic structure I've got set up is:

class Window {
    SDL_Window *sdl_window;
    SDL_GLContext context;

    Window(...) {
        sdl_window = SDL_CreateWindow(...);

        // Rest of the setup of world etc.
    }

    gl_init() {
        context = SDL_GL_CreateContext(sdl_window);

        // Set up initial OpenGL settings.
    }

    render() {
        SDL_GL_MakeCurrent(sdl_window, context);

        // Rendering the world.

        SDL_GL_SwapWindow(sdl_window);
    }
}

This all compiles and runs fine with the rest of the demo code I've developed so far, simply showing a pair of slightly offset views. However, there's no really performance heavy stuff implemented yet.

  • Is this the correct approach to use?
  • Are there any major performance implications with switching the context twice (or more) a frame? (other than the expected double (or more) rendering occurring).
    • For example, does switching contexts force a flush of the graphics memory to the system RAM or something equally frame-rate killing?
  • Is there an alternative method that would allow setting up two different viewpoints and rendering them in one pass?
  • If this is the best way to do it is there a way of sharing data between contexts? I'm thinking once I switch to VBO's over display lists, if the views overlap in some way they should be sharing VBO's for that portion.
share|improve this question
add comment

1 Answer

Is there an alternative method that would allow setting up two different viewpoints and rendering them in one pass?

What do you mean by this? Having two contexts means having two windows. This means that you have two windows that can be positioned and operated independently of one another.

If all you're using these two windows to do is to have two viewports into the same scene, that's really not necessary. You can do that with one context and one window. Just use glViewport and glScissor to set up multiple views within the same window. You set one view, render stuff, then you set up another view, and render stuff to that.

If this is the best way to do it is there a way of sharing data between contexts?

The big objects can be shared between contexts. wglShareLists is how you do it for Win32 OpenGL.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.