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 1588

Summary: glX doesn't need a temp context to build a GL3 context.
Product: SDL Reporter: Ryan C. Gordon <icculus>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq, matthias.bentrup
Version: HG 2.0   
Hardware: x86   
OS: Other   

Description Ryan C. Gordon 2012-08-28 12:36:40 UTC
(I think.)

In X11_GL_CreateContext(), we create a legacy context, then call glXGetProcAddress("glXCreateContextAttribsARB"), throw that context away and build the new context.

This isn't necessary. It was probably built this way because WGL requires it, because wglGetProcAddress() needs a current context. glXGetProcAddress(), however, has to provide a valid function pointer even if there is no context at all and it's up to the app to make sure it's allowed to call it for a given context.

Details are here: http://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL

So we can probably delete this code and, if glXCreateContextAttribsARB exists, just create the 3.x context.

--ryan.
Comment 1 Ryan C. Gordon 2013-07-12 22:15:55 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 2.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 2 Ryan C. Gordon 2013-07-15 01:40:04 UTC
Taking this one.

--ryan.
Comment 3 Ryan C. Gordon 2013-07-26 23:43:42 UTC
Oh, it turns out we return the (otherwise temporary) pre-3.x context if we fail to make the 3.x context.

The Windows code is doing this too. The Cocoa code returns NULL in this case.

I tend to think returning a < 3 context is a bug if the user asked for >= 3. There are a lot of assumptions the app is making about OpenGL if they ask for a specific version, including removal of cruft from the API, and more importantly, functions and features that are expected to be there.

I'm tossing this back to Sam to consider. If you want to punt on this for 2.0.0, just remove the target-2.0.0 tag for now.

--ryan.
Comment 4 Ryan C. Gordon 2013-07-27 01:21:38 UTC
Eh, screw it, I'm yanking the target-2.0.0 tag. Look at this later.

--ryan.
Comment 5 Sam Lantinga 2013-07-27 04:03:00 UTC
Yeah, returning a < 3 context is a bug if the user asked for >= 3. I'm not sure how that relates to the original bug report, but I agree.

Tossing back to you, this is fine to fix now or later, your call.  I'd lean toward sooner if leaving it there for 2.0 means some poor sod may suddenly have their game break when we fix it
Comment 6 Gabriel Jacobo 2013-08-22 23:31:13 UTC
This probably applies to X11_GL_InitExtensions as well, I commented out the context creation stuff there and the extension query seemed to work fine.
Comment 7 Matthias Bentrup 2013-11-13 11:38:53 UTC
There is another problem in the context creation code: you assume that glXCreateContextAttribsARB is supported if glXgetProcAddressARB returns a non-NULL value, but the specs allow to (and some drivers do) return a dummy function instead of NULL.

The only reliable way is to check for the presence of the GLX_ARB_create_context_profile extension.
Comment 8 Ryan C. Gordon 2015-02-18 04:14:47 UTC
(In reply to Sam Lantinga from comment #5)
> Yeah, returning a < 3 context is a bug if the user asked for >= 3. I'm not
> sure how that relates to the original bug report, but I agree.

Just that it was our existing behavior. No relation otherwise. But the existing behavior was basically going to cause the game to crash or act strangely if the GL wasn't up to the task, so I decided the change was okay.

> Tossing back to you, this is fine to fix now or later, your call.  I'd lean
> toward sooner if leaving it there for 2.0 means some poor sod may suddenly
> have their game break when we fix it

Fixed this in https://hg.libsdl.org/SDL/rev/26eb20aad02f .

(In reply to Matthias Bentrup from comment #7)
> There is another problem in the context creation code: you assume that
> glXCreateContextAttribsARB is supported if glXgetProcAddressARB returns a
> non-NULL value, but the specs allow to (and some drivers do) return a dummy
> function instead of NULL.

This was fixed, too.

(In reply to Gabriel Jacobo from comment #6)
> This probably applies to X11_GL_InitExtensions as well, I commented out the
> context creation stuff there and the extension query seemed to work fine.

Removed that code too: https://hg.libsdl.org/SDL/rev/0d1e81f10b7e

--ryan.