We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1145

Summary: GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch
Product: SDL Reporter: Matthias <matthias.schweinoch>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Minimal program to reproduce the error
glxinfo output
Proposed patch for SDL_x11opengl.c

Description Matthias 2011-02-23 09:37:51 UTC
Created attachment 585 [details]
Minimal program to reproduce the error

Please view the attached source file. Using this minimal program (as attached), it creates an OpenGL 2.0 context with a cleared color buffer. If I set the OpenGL version to 3.2, the function SDL_GL_CreateContext fails (or more specifically, glXMakeCurrent fails) with an X11 BadMatch error:


X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  128 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  153
  Current serial number in output stream:  153


Also note that if I do not specify the alpha buffer size, the program works for OpenGL 2.0 and OpenGL 3.2.
Comment 1 Matthias 2011-02-23 09:41:17 UTC
Created attachment 586 [details]
glxinfo output

This is the output of glxinfo for the machine on which the issue arose. The machine has an nvidia 9800 gtx installed, and is running the 195.36.24 driver (64 bit, ubuntu 10.04 LTS)
Comment 2 Matthias 2011-02-23 09:43:07 UTC
Correction on the attached program: As it is attached, it creates an OpenGL 3.2 context, and this actually fails. It uses OpenGL 2.0 if the #define in line 13 is changed to 1, and then the program also does as expected.
Comment 3 Matthias 2011-02-23 14:13:54 UTC
After some further analysis, I believe I have found the problem. The specific issue is in:

SDL_x11opengl.c::X11_GL_CreateContext. 

Note that for OpenGL 3.2 contexts, the GLXFBConfig to use is chosen as the best match from glXChooseFBConfig. However, opengl attributes originally set with SDL_GL_SetAttribute are not mapped to GLX attributes and then passed to the glXChooseFBConfig function. According to the GLX 1.4 specification, if the attributes are not specified, the function falls back to defaults (which, in this particular case, prefer alpha channel size == 0).

For testing purposes, I modified the call to glXChooseFBConfig to look something like this:


int glxAttribs[] = 
{
 GLX_RED_SIZE,8,
 GLX_GREEN_SIZE,8,
 GLX_BLUE_SIZE,8,
 GLX_ALPHA_SIZE,8,
 None
};

if (!glXChooseFBConfig || 
 !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), glxAttribs, &fbcount))) 
{
 ...
}


The best match GLXFBConfig then supports 8 bit alpha channel. The program then works as intended. 


Hope this helps!
Comment 4 Matthias 2011-02-24 10:46:56 UTC
Created attachment 589 [details]
Proposed patch for SDL_x11opengl.c

Attached archive contains a modified version of SDL_x11opengl.c as well as a patch file describing the changes. 

I took the lines of code from the X11_GL_GetVisual function, which get the GLX attributes from _this, and moved them to a separate function X11_GL_GetAttributes. X11_GL_GetVisual now calls that function instead. 

The function X11_GL_GetAttributes is now also used to retrieve the GLX attributes within the function X11_GL_CreateContext, and these are passed to glXChooseFBConfig.
Comment 5 Sam Lantinga 2011-02-24 12:33:12 UTC
Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?
Comment 6 Matthias 2011-02-24 12:46:37 UTC
(In reply to comment #5)
> Thank you very much for your patch for SDL 1.3!

Glad I could help!:-)
 
> Do you give me permission to release your code with SDL 1.3 and future
> versions of SDL under both the LGPL and a closed-source commercial
> license?

Yes, I'm fine with that.
Comment 7 Sam Lantinga 2011-02-24 17:54:33 UTC
Your patch looks great, thanks!
http://hg.libsdl.org/SDL/rev/f0e399961f3a