OpenGL 3.0 Context Creation

Hi all,

I’ve attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I’ve added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).

Sample code:

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("Unable to initialize SDL: %s\n", SDL_GetError());
    return 1;
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without

these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL |

SDL_FULLSCREEN );

I’ve implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn’t provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.

P.S. Kevin Rogovin has also sent a similar patch but that one doesn’t
provide a way of choosing the GL version and doesn’t have a Windows
implementation. (Sorry to steal your thunder Kevin :slight_smile: )
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdl_opengl3.patch
Type: text/x-patch
Size: 7914 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090322/17c837ab/attachment.bin

Is SDL_GL_CONTEXT_MINOR_VERSION even necessary? It would seem to simplify
things if there were just one call:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_VERSION, 3, 0);

Or even to forget about minor versions, since an incompatibility in contexts
is hardly “minor”:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_VERSION, 3);

Jonny D

2009/3/22 Luke Benstead > Hi all,

I’ve attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I’ve added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).

Sample code:

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without
these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL |
SDL_FULLSCREEN );

I’ve implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn’t provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.

P.S. Kevin Rogovin has also sent a similar patch but that one doesn’t
provide a way of choosing the GL version and doesn’t have a Windows
implementation. (Sorry to steal your thunder Kevin :slight_smile: )


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

Well, I guess the three arguments isn’t possible here :wink:

Jonny DOn Sun, Mar 22, 2009 at 3:52 PM, Jonathan Dearborn <@Jonathan_Dearborn>wrote:

Is SDL_GL_CONTEXT_MINOR_VERSION even necessary? It would seem to simplify
things if there were just one call:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_VERSION, 3, 0);

Or even to forget about minor versions, since an incompatibility in
contexts is hardly “minor”:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_VERSION, 3);

Jonny D

2009/3/22 Luke Benstead

Hi all,

I’ve attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I’ve added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).

Sample code:

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without
these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL |
SDL_FULLSCREEN );

I’ve implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn’t provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.

P.S. Kevin Rogovin has also sent a similar patch but that one doesn’t
provide a way of choosing the GL version and doesn’t have a Windows
implementation. (Sorry to steal your thunder Kevin :slight_smile: )


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

Luke Benstead <kazade gmail.com> writes:

[snip]
P.S. Kevin Rogovin has also sent a similar patch but that one doesn’t
provide a way of choosing the GL version and doesn’t have a Windows
implementation. (Sorry to steal your thunder Kevin :slight_smile: )

my patch was only for X and was for SDL 1.2, not 1.3 in SVN. I am glad (and
relieved) that someone made a 3.x context creation patch for SDL 1.3 that also
works in Win32 (I have not yet gotten around to doing the Win32 bit yet fr SDL
1.2, if people want I can still make a 1.2 patch for GL3.x and just copy the API
you made for it as well, and the two reasons why one may wish to use SDL 1.2 are:

  1. SDL 1.3 API is a touch incompatible with the SDL 1.2 API
  2. SDL 1.3 API I think is still unstable, is it?

But for new projects, I bet starting with SDL1.3 from the start might be best…

We should also add an API that adds allows one to specify the two bit fields:
“forward compatible” and “debug” context creation, probably just add a 32 bit
integer to set the flags with default value 0 (that mirrors the context creation
in glX and Win32)… Does anyone know what the status of OpenGL 3.x on OSX? has
Apple integrated the latest and greatest from ATI and nVidia into their systems
at all?

Best Regards
-Kevin

2009/3/28 Kevin Rogovin <kevin.rogovin at gmail.com>:

?We should also add an API that adds allows one to specify the two bit fields:
“forward compatible” and “debug” context creation, probably just add a 32 bit
integer to set the flags with default value 0 (that mirrors the context creation
in glX and Win32)… Does anyone know what the status of OpenGL 3.x on OSX? has
Apple integrated the latest and greatest from ATI and nVidia into their systems
at all?

Best Regards
?-Kevin


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

Adding the forward compatible and debug flags is very easy to do, and
I hope to submit a patch over the next week. The thing I’m thinking
about at the moment is sharing resources between contexts…

For those not up to date with the wonderful world of GL 3.x here are
the prototypes for the new context creation functions:

HGLRC wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const
int *attribList)
GLXContext glXCreateContextAttribsARB(Display *dpy, GLXFBConfig
config, GLXContext share_context, Bool direct, const int
*attrib_list);

Note the “hShareContext” and “share_context” arguments which allow
resource sharing between the context being created, and a previously
created context. I’m trying to figure out how to allow the user to
specify the previously created window to share resources with. Is
SDL_SetVideoMode being replaced with SDL_CreateWindow? Do they do the
same thing (but the latter obviously allows multiple windows)?

If that’s the case, then this should be a possible way to share contexts

SDL_GL_SetAttribute(GL_CONTEXT_MAJOR_VERSION, 3); //Set to opengl 3.0
SDL_GL_SetAttribute(GL_CONTEXT_MINOR_VERSION, 0);

SDL_WindowID firstID = SDL_CreateWindow( … ); //Create first window

SDL_GL_SetAttribute(GL_CONTEXT_SHARED_CONTEXT, firstID); //Set the
shared context ID to this window

SDL_WindowID secondID = SDL_CreateWindow( … ); //Uses the stored
window ID to lookup the context when creating the GL 3 context

SDL_GL_SetAttribute(GL_CONTEXT_SHARED_CONTEXT, secondID); //Set the
shared context ID to the second window

SDL_WindowID thirdID = SDL_CreateWindow( … ); //You could probably chain them

Does that make sense? I’m assuming that there is a way to internally
get to the HGLRC and GLXContext from a SDL_WindowID.

Sam, if that’s a suitable API for this then I’ll go ahead and attempt
to write a patch for it (unless someone here can think of a better way
of doing it of course :slight_smile: ). The other thing worth considering, is that
you can share resources with OpenGL 2.x contexts as well (e.g.
wglShareLists) perhaps the API should work no matter what the GL
version. I don’t think that would be hard to do.

Luke.