Window creation vs. context creation, and GL context attributes

I’m one of the developers for Pioneer [1], which has recently switched
from SDL 1.2 to SDL 2.

In our SDL 1.2 initialisation code, we first try to SetVideoMode with
a multisampled backbuffer, and if this fails we turn multisampling off
with SDL_GL_SetAttribute and try again. This works fine – if
multisampling is supported then we get it, otherwise we don’t.

However, with SDL 2, there are two steps, create a window, and then
create a GL context, which raises a question:
Is it correct to reuse the same window after changing GL attributes?
Or do (some) GL attributes affect window creation too, on any
platform?

It looks to me like the GL attributes are involved at window creation
time at least on Win32 (see WIN_GL_SetupWindow in [2], which is called
from WIN_CreateWindow in [3]), but I would appreciate a confirmation
that this understanding is correct and matches the intended behaviour
of the API. If this is correct, then I assume that to implement the
fallback we must:

  1. setup GL attributes
  2. create window
  3. create context
  4. if window or context creation failed: destroy window, setup
    fallback GL attributes, and repeat steps 2 & 3.

Unless perhaps there is a way to detect multisampling support before
we create the window & context in the first place?

Thanks,

John B

[1] http://pioneerspacesim.net/
[2] http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowsopengl.c
[3] http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowswindow.c

In order to avoid code duplication, you could write a function to create the window and the GL context like this:

[code]
/* set attributes */
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

CreateWindowAndContext(title, x,y,w,h, flags, &window, &context);

if (!context) {
/disable multisampling/
CreateWindowAndContext(…);
}

[/code]On Oct 3, 2013, at 1:07 AM, John Bartholomew <jpa.bartholomew at gmail.com> wrote:

I’m one of the developers for Pioneer [1], which has recently switched
from SDL 1.2 to SDL 2.

In our SDL 1.2 initialisation code, we first try to SetVideoMode with
a multisampled backbuffer, and if this fails we turn multisampling off
with SDL_GL_SetAttribute and try again. This works fine – if
multisampling is supported then we get it, otherwise we don’t.

However, with SDL 2, there are two steps, create a window, and then
create a GL context, which raises a question:
Is it correct to reuse the same window after changing GL attributes?
Or do (some) GL attributes affect window creation too, on any
platform?

It looks to me like the GL attributes are involved at window creation
time at least on Win32 (see WIN_GL_SetupWindow in [2], which is called
from WIN_CreateWindow in [3]), but I would appreciate a confirmation
that this understanding is correct and matches the intended behaviour
of the API. If this is correct, then I assume that to implement the
fallback we must:

  1. setup GL attributes
  2. create window
  3. create context
  4. if window or context creation failed: destroy window, setup
    fallback GL attributes, and repeat steps 2 & 3.

Unless perhaps there is a way to detect multisampling support before
we create the window & context in the first place?

Thanks,

John B

[1] http://pioneerspacesim.net/
[2] http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowsopengl.c
[3] http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowswindow.c


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, to be sure you have a matching window and context you should create
them together.On Wed, Oct 2, 2013 at 3:07 PM, John Bartholomew <jpa.bartholomew at gmail.com>wrote:

I’m one of the developers for Pioneer [1], which has recently switched
from SDL 1.2 to SDL 2.

In our SDL 1.2 initialisation code, we first try to SetVideoMode with
a multisampled backbuffer, and if this fails we turn multisampling off
with SDL_GL_SetAttribute and try again. This works fine – if
multisampling is supported then we get it, otherwise we don’t.

However, with SDL 2, there are two steps, create a window, and then
create a GL context, which raises a question:
Is it correct to reuse the same window after changing GL attributes?
Or do (some) GL attributes affect window creation too, on any
platform?

It looks to me like the GL attributes are involved at window creation
time at least on Win32 (see WIN_GL_SetupWindow in [2], which is called
from WIN_CreateWindow in [3]), but I would appreciate a confirmation
that this understanding is correct and matches the intended behaviour
of the API. If this is correct, then I assume that to implement the
fallback we must:

  1. setup GL attributes
  2. create window
  3. create context
  4. if window or context creation failed: destroy window, setup
    fallback GL attributes, and repeat steps 2 & 3.

Unless perhaps there is a way to detect multisampling support before
we create the window & context in the first place?

Thanks,

John B

[1] http://pioneerspacesim.net/
[2]
http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowsopengl.c
[3]
http://hg.libsdl.org/SDL/file/6b3cc8b7c589/src/video/windows/SDL_windowswindow.c


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sam Lantinga wrote:

Yes, to be sure you have a matching window and context you should create
them together.

Ok. Thanks for the confirmation.

John B