SDL-1.2-13 made a GL3.0

Hello all,

I just spent some time making SDL-1.2.13 have the ability to create a context
for OpenGL 3.0 in X, on my hardware and OS it works, but I would like to make it
available so others can check if it is OK on their setups; where is a good place
to post the files that I have changed (or diffs if people insist), the code
additions are small.

Best Regards
-Kevin

If it’s a small diff, you could just post the patch as an email attachment…>----- Original Message ----

From: Kevin Rogovin <kevin.rogovin at gmail.com>
Subject: [SDL] SDL-1.2-13 made a GL3.0

Hello all,

I just spent some time making SDL-1.2.13 have the ability to create a context
for OpenGL 3.0 in X, on my hardware and OS it works, but I would like to make it
available so others can check if it is OK on their setups; where is a good place
to post the files that I have changed (or diffs if people insist), the code
additions are small.

Err, lacking the ability to attach e-mails from the web interface, here is just
a blob of C-source:

add to src/video/x11/SDL_x11gl.c:

[source]

#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#endif

#ifndef GLX_CONTEXT_MINOR_VERSION_ARB
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
#endif

typedef GLXContext (glXCreateContextAttribsARBProc)(Display, GLXFBConfig,
GLXContext, Bool, const int*);

void X11_GL_MakeGL30_Context(_THIS)
{
glXCreateContextAttribsARBProc glXCreateContextAttribsARB=NULL;
GLXContext null_context=NULL;
int glx_attribs[128];
int c=0;
GLXFBConfig *fbc;
int fbcount;

static int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
None
};

//use gl_config to pack the necessary data:
glx_attribs[c++] = GLX_RED_SIZE;
glx_attribs[c++] = this->gl_config.red_size;
glx_attribs[c++] = GLX_GREEN_SIZE;
glx_attribs[c++] = this->gl_config.green_size;
glx_attribs[c++] = GLX_BLUE_SIZE;
glx_attribs[c++] = this->gl_config.blue_size;
if( this->gl_config.alpha_size )
{
glx_attribs[c++] = GLX_ALPHA_SIZE;
glx_attribs[c++] = this->gl_config.alpha_size;
}
glx_attribs[c++] = GLX_DEPTH_SIZE;
glx_attribs[c++] = this->gl_config.depth_size;

if( this->gl_config.stencil_size )
{
glx_attribs[c++] = GLX_STENCIL_SIZE;
glx_attribs[c++] = this->gl_config.stencil_size;
}
if( this->gl_config.double_buffer )
{
glx_attribs[c++] = GLX_DOUBLEBUFFER;
glx_attribs[c++] = True;
}

if( this->gl_config.accum_red_size )
{
glx_attribs[c++] = GLX_ACCUM_RED_SIZE;
glx_attribs[c++] = this->gl_config.accum_red_size;
}
if( this->gl_config.accum_green_size )
{
glx_attribs[c++] = GLX_ACCUM_GREEN_SIZE;
glx_attribs[c++] = this->gl_config.accum_green_size;
}
if( this->gl_config.accum_blue_size )
{
glx_attribs[c++] = GLX_ACCUM_BLUE_SIZE;
glx_attribs[c++] = this->gl_config.accum_blue_size;
}
if( this->gl_config.accum_alpha_size )
{
glx_attribs[c++] = GLX_ACCUM_ALPHA_SIZE;
glx_attribs[c++] = this->gl_config.accum_alpha_size;
}

//signals end of preferences to glXChooseFBConfig
glx_attribs[c++]=None;

//printf("\nGetting FBConfigs…"); fflush(stdout);
fbc=glXChooseFBConfig(SDL_Display, DefaultScreen(SDL_Display), glx_attribs,
&fbcount);

if(fbc==NULL)
{
//printf(“Done\nNo good FBC’s available, GL3.0 will not be possible\n”);
fflush(stdout);
return;
}

//printf(“Done\nGetting proc address…”); fflush(stdout);
glXCreateContextAttribsARB=this->gl_data->glXGetProcAddress((const
GLubyte*)“glXCreateContextAttribsARB”);

if(glXCreateContextAttribsARB==NULL)
{
//printf(“Done\nFunction pointer NULL, GL3.0 will not be possible\n”);
fflush(stdout);
return;
}

//printf(“Done.\nMaking empty context current…”); fflush(stdout);
glXMakeCurrent(GFX_Display, 0, 0);

//printf(“Done.\nDeleting old context…”); fflush(stdout);
glXDestroyContext(GFX_Display, glx_context);

//printf(“Done.\nCreating 3.0 context…”); fflush(stdout);
glx_context=glXCreateContextAttribsARB(GFX_Display, fbc[0], null_context,
True, context_attribs);

//printf(“Done.\nmaking new context current\n”); fflush(stdout);
X11_GL_MakeCurrent(this);
}
[/source]

then, this is the ickier part add to src/video/x11/SDL_x11video.c,
two bits:

at the top (better place would be in a header file I suppose)
[source]
void X11_GL_MakeGL30_Context(_THIS);
[/source]

and at the end of X11_CreateWindow(), just before return (0),
at line 1098,

[source]
if ( flags & SDL_OPENGL ) {
X11_GL_MakeGL30_Context(this);
}
[/source]

I plan on ploughing through the Windows bit to get a GL3.0 context in windows as
well;

Comments:

  1. as far as I know, even under X, one needs a GL context to just make a 3.0
    context because one needs to get the function pointer for
    glXCreateContextAttribsARB, the above mess, just lets SDL-1.2.13 do its usual
    thing in making a GL context and then tries to make a 3.0 context afterwards; in
    truth it should make the context first, and if successful then delete the old
    one, the last bit of shine I leave for later, as of now it deletes the old one
    whenever it gets it has a valid fbc and can get the function pointer.

  2. TODO: check my X code; in truth I am not familiar at all with X programming,
    so if I made some X mistakes someone please post their fixes.

  3. TODO: add 3.0GL context creation to Windows target.

  4. TODO: add an interface to specify the context properties, right now it just
    does GL3.0 always… there are quite a few extras that
    glXCreateContextAttribsARB supports that should be added, the wgl analogue has
    similar extras too.

  5. TODO: add to SDL-1.3 as well (I am not using SDL1.3 right now as it is not
    stable and currently is not quite source compatible with SDL1.2)

Hello !

Err, lacking the ability to attach e-mails from the web interface, here is just
a blob of C-source:

Why are you not adding a diff as an attachment ?
GMail supports it.

CU

I did not know that Gmail supported newsgroups, I just figured it did not, I am
using the web interface at http://post.gmane.org/ to post… if someone knows
how to read news groups from gmail, in particular this one, please post it as
using the web interface at http://post.gmane.org/ does not have an attachments
button :slight_smile:

Hey,

this isn’t really a newsgroup, it’s a mailing list.

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You can subscribe to it there and send emails to the list, including attachments.

Cheers,
Pat> ----- Original Message -----

From: kevin.rogovin@gmail.com (Kevin Rogovin)
To: sdl at libsdl.org
Sent: Tuesday, March 17, 2009 10:57:01 AM
Subject: Re: [SDL] SDL-1.2-13 made a GL3.0

I did not know that Gmail supported newsgroups, I just figured it did not, I am
using the web interface at http://post.gmane.org/ to post… if someone knows
how to read news groups from gmail, in particular this one, please post it as
using the web interface at http://post.gmane.org/ does not have an attachments
button :slight_smile:


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

Attached is a diff created by:

diff -ur …/SDL-1.2.13/src src > …/SDL-1.2.13-GL30patch

to patch SDL-12.13 to create GL3.0 contexts. Caveats and ungoodness:

?1) changes are needed so that X does not barf on drivers that provide
glXCreateContextAttribsARBProc
but on hardware that is no 3.0 capable, i.e nVidia GeForce 7 or older;
in truth I do not know what
happens on GeForce 7 or older hardware with this patch, those with
that hardware please report
what happens. If I deliberately give bad numbers for
GLX_CONTEXT_MAJOR_VERSION_ARB and/or
GLX_CONTEXT_MINOR_VERSION_ARB SDL barfs on x errors, (for example making
GLX_CONTEXT_MAJOR_VERSION_ARB 3 and GLX_CONTEXT_MINOR_VERSION_ARB 1) generates:

“X Error of failed request: BadValue (integer parameter out of range
for operation)
Major opcode of failed request: 143 (GLX)
Minor opcode of failed request: 34 ()
Value in failed request: 0x3
Serial number of failed request: 41
Current serial number in output stream: 43
Locking assertion failure. Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0x14a767]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_lock+0x2e) [0x14a90e]
#2 /usr/lib/libX11.so.6 [0x4fe109]
#3 /usr/lib/libGL.so.1 [0x54b5e6d]”

?2) chances are we should make an interface to specify the attribute values
?passed to glXCreateContextAttribsARBProc, as of now they are fixed at:

??? GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
??? GLX_CONTEXT_MINOR_VERSION_ARB, 0,

there is also a bitfield paramater (commented out now) that
specifies weather or not to make a debug or forward compatible context.

  1. To come: patch windows subsystem for same purpose.

Best Regards
-Kevin Rogovin
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL-1.2.13-GL30patch
Type: application/octet-stream
Size: 4841 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090317/0a218f66/attachment.obj

Hello all,

Attached is a “better” patch for SDL’s X11 path to generate a GL3.0
context, this is a patch against SDL-1.2.13.ta.gz on libsdl.org;
the “better” part is that it only changes src/video/X11/SDL_x11gl.c,
and nothing else; for my hardware/OS it works fine, but
testing would be appreciated and we should probably make an API to
specify if to make a 30 context and what properties for it.
I’d greatly appreciate testing from those that have 3.0 aware drivers
but unable to do 3.0 (for example GeForce7 or less with nVidia
drivers).

I intend to patch the Windows code path next week, the code and what
to insert is very, very similar.

Best Regards
-Kevin
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL-1.2.13-GL30patch.diff
Type: text/x-patch
Size: 4885 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090318/3de8aed9/attachment.bin