Commit graph

76 commits

Author SHA1 Message Date
Sam Lantinga
08dfaaa2e6 Christoph Mallon: Remove pointless if (x) before SDL_free(x) 2013-08-29 08:29:21 -07:00
Gabriel Jacobo
ac6a540788 Fixes for -Wdeclaration-after-statement 2013-08-21 10:12:16 -03:00
Gabriel Jacobo
ef4a588d99 Fixes bug #2037, common EGL code for Android and X11 2013-08-19 16:29:46 -03:00
Sam Lantinga
9583071066 Fix for recent GLX error bug
Lee Salzman

I messed up in the patch I sent you regarding gobbling up the GLX error codes signaled when trying to create a context. After reading the spec I realized those error codes are relative to a base error that needs to be queried when setting up the GLX extension...

So I have made a patch that fixes it for a user I had who was still getting the bug with my old patch.

Without this patch my previous one won't work, so it is recommended to merge this...
2013-07-23 19:20:03 -07:00
Ryan C. Gordon
52b4a55049 Minor indentation clean up. 2013-07-15 01:12:15 -04:00
Sam Lantinga
db4086463f Fixed cast of the OpenGL context type 2013-07-11 23:05:02 -07:00
Sam Lantinga
35275fc714 Fixed bug 1946 - OpenGL contexts in threads
The SDL OpenGL context code is now properly thread aware.  There are two new functions which return the current OpenGL window and context for the current thread.

There are still places in the cocoa driver where the OpenGL context needs to be updated when the view changes.  These will need a different solution and still use the last globally set context to avoid changing behavior.
2013-07-11 22:59:20 -07:00
Sam Lantinga
0cb6385637 File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00
Ryan C. Gordon
4f438b70a2 Make SDL_SetError and friends unconditionally return -1.
This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
2013-03-31 12:48:50 -04:00
Sam Lantinga
2422c520ac Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Lee Salzman

When using SDL_GL_CreateContext() to create a >= 3.0 version or core/forward-compatible context, internally glXCreateContextAttribsARB is used. Mesa in particular seems to be having trouble with this call and returning all sorts of errors, so it is dangerous to poll for the highest GL version by using calls to SDL_GL_CreateContext unless you are sure, a priori, that the call will suceed, defeating the point of its use.

X11 protocol errors are of the following form, with varying details depending on user, but the cause is always SDL_GL_CreateContext as above...

X Error of failed request:  GLXBadFBConfig
  Major opcode of failed request:  153 (GLX)
  Minor opcode of failed request:  34 ()
  Serial number of failed request:  215
  Current serial number in output stream:  221

These sorts of errors can be temporarily filtered out by setting an X11 error handler to catch and ignore them, which is safe with respect to SDL_GL_CreateContext behavior because this function is allowed to return NULL to indicate failure.

A patch is attached to do this temporary filtering/catching of errors generated by trying to use glXCreateContextAttribs and friends...
2013-03-10 09:07:23 -07:00
Sam Lantinga
c6dc8b64e7 Remove XSync from X11_GL_MakeCurrent() function 2013-03-01 11:27:01 -08:00
Sam Lantinga
95dcfa4c28 Happy New Year! 2013-02-15 08:47:44 -08:00
Sam Lantinga
cf60f13a01 Fixed compiler warnings 2013-02-11 18:18:34 -08:00
Sam Lantinga
8ec12be05a Workaround for NVIDIA bug in glXSwapIntervalEXT.
This works around a bug in NVIDIA's implementation of
       glXSwapIntervalEXT, where it ignores updates to what it *thinks* is the
       current value, even though glXQueryDrawable returns a different value.

       Bug reported to NVIDIA and will hopefully be a part of 319.xx.

       Also a fix for invalidly treating glXSwapIntervalEXT as having an int
       return value (it's void).
2013-02-11 17:02:13 -08:00
Ryan C. Gordon
d41de59fc9 Cleaned out a few C++ single-line comments.
Should we bother doing this anymore? Is there really a C compiler we care
 about that doesn't support this?
2013-01-21 02:50:11 -05:00
Edward Rudd
088842729f Corrected call to glXMakeCurrent() when setting a NULL context.
Fixes Bugzilla #1675.
2012-12-31 19:16:52 -05:00
Michael Sartain
5d4e794683 Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Our new X11 window was being created with the TrueColor attribute, and trying to set the gamma
on that would fail. This change checks for the visual_info extension, and uses that to ask for
DirectColor if available.
2012-10-11 09:41:43 -07:00
Sam Lantinga
8c71219642 The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist. 2012-09-30 01:08:48 -07:00
Sam Lantinga
f380ecb137 Removed executable bit from source files 2012-09-27 14:35:28 -07:00
Sam Lantinga
99502c82fd Fixed bug 1565 - some small GL context creation enhancements
Matthias Bentrup 2012-08-09 12:53:17 PDT

With OpenGL 4.3 the ARB added a new context flag for context reset isolation
and renamed the existing ES2 profile bit to ES profile bit, as it can be used
to request GLES 3 compatible contexts, too.

This patch adds these changes to SDL on Linux and Windows.

Also SDL lacks the ability to create shared contexts. This patch also adds a
new GL attribute to enable context sharing. As casting a GL context to int is
not portable, I added only a boolean attribute
SDL_GL_SHARE_WITH_CURRENT_CONTEXT, which makes the new context share resources
with the context current on the creating thread.
2012-08-12 11:16:24 -07:00
Ryan C. Gordon
2cd5fc4e97 Add support for (GLX|WGL)_EXT_swap_control_tear.
This required a small public API change: SDL_GL_SetSwapInterval() now accepts
 negative values, and SDL_GL_GetSwapInterval() doesn't report errors anymore
 (if it can't work, it'll return zero as a reasonable default).

If you need to test for errors, such as a lack of swap_control_tear support,
 check the results of SDL_GL_SetSwapInterval() when you set your desired
 value.
2012-08-01 20:29:36 -04:00
Ryan C. Gordon
82ebf2d4ff Fixed some minor compiler warnings.
--HG--
extra : rebase_source : 9466732b4e5ab87e92e8eb9e2377aa5405bdc23b
2012-07-20 13:33:15 -04:00
Sam Lantinga
1277706b2b More OpenGL ES fixes from Scott Percival 2012-07-19 09:36:58 -07:00
Sam Lantinga
b3219a6db1 Improved simultaneous support for OpenGL and OpenGL ES
From Scott Percival

Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.

- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
        - Only useful for the X11 video driver at the moment
        - Set to 1 for an EGL context, 0 to use the default for the video driver
        - Default is 0, unless library is built for EGL only
        - Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider

This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
2012-07-18 15:17:27 -07:00
Ryan C. Gordon
0e49fa682a Patched to compile on FreeBSD 8.2. 2012-07-11 22:20:02 -04:00
Ryan C. Gordon
e3e3adf168 Removed unused variable to silence compiler warning. 2012-07-11 22:04:19 -04:00
Sam Lantinga
38463b3a0c Add OpenGL 3.X context creation support
Matthias Bentrup 2011-10-30 03:58:24 PDT

I've updated the context creation patch to include the bugfixes by Martin
Schreiber and also included a profile bit to request a ES2 compatible profile.

The wgl context creation may use 2 call to wglChoosePixelFormat if no
acceleration attribute is selected, this should work around a bug with buggy
AMD drivers (see #1254).
2012-02-20 23:37:57 -05:00
Ryan C. Gordon
3e4b380d2c Removed GLX_BUFFER_SIZE attribute; it doesn't do anything with GLX_RGBA. 2012-02-07 02:11:42 -05:00
Ryan C. Gordon
df8784cd61 Replaced some assert macros with SDL_assert. 2012-02-07 02:11:15 -05:00
Sam Lantinga
0975880949 The #define was asking to use dlopen(), but the code wasn't doing it.
Also added error message in case the library open failed in that case.
2012-01-07 21:02:39 -08:00
Sam Lantinga
5b2a5e3412 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Don't crash if the gl_data isn't valid, just return NULL.
2012-01-07 23:33:15 -05:00
Sam Lantinga
028e5dcdbd Happy New Year! 2011-12-31 09:28:07 -05:00
Sam Lantinga
ad2a21d404 Lots of fixes importing SDL source wholesale into a new iOS project
--HG--
rename : src/libm/math.h => src/libm/math_libm.h
2011-10-31 05:56:58 -04:00
Ryan C. Gordon
bc13816375 Fixed a whole slew of compiler warnings that -Wall exposed. 2011-10-13 01:08:30 -04:00
Ryan C. Gordon
08f49bd2d3 Apparently glXSwapIntervalEXT() _does_ return a value.
Revision 6 of the GLX_EXT_swap_control spec has a typo; the function
signature they list is void, but the docs talk about a return value, and the
glxext.h headers list "int".
2011-08-22 02:26:11 -04:00
Ryan C. Gordon
1a862ae6d3 Patched to compile on older GLX headers. 2011-07-18 14:55:24 -07:00
Ryan C. Gordon
93d2b83299 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
This allows the Nvidia Linux drivers to use SDL_GL_SetSwapInterval(0).
2011-07-18 14:34:19 -07:00
Sam Lantinga
b0660ba5ff SDL 1.3 is now under the zlib license. 2011-04-08 13:03:26 -07:00
Sam Lantinga
1a2a914b33 Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Matthias      2011-02-23 09:37:51 PST

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.

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!
2011-02-24 17:52:47 -08:00
Sam Lantinga
e5803d148c Happy 2011! :) 2011-02-11 22:37:15 -08:00
Sam Lantinga
018af55e16 Window coordinates are in the global space and windows are not tied to a particular display.
Also added Ctrl-Enter keybinding to the test code to toggle fullscreen mode for testing.
2011-02-10 14:44:25 -08:00
Sam Lantinga
e9689c29d5 Be explicit about what display you're querying. The default display is 0. 2011-02-10 12:14:37 -08:00
Sam Lantinga
e0f869b698 Removed gamma support since it wasn't widely used and not well supported. 2011-02-10 11:39:08 -08:00
Sam Lantinga
c53fea3bcc Fixed build against 10.4 SDK 2011-01-18 14:57:39 -08:00
Sam Lantinga
d16468c1cb Fixed compiler error with the latest Xcode package 2011-01-18 14:26:30 -08:00
Sam Lantinga
5ae90a3bef Fixed bug 1006
Get the GLX functions with glXGetProcAddress() when available.
2010-07-18 11:18:36 -07:00
Sam Lantinga
4d3df8b3e3 Fixed bug #926
Updated copyright to LGPL version 2.1 and year 2010

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404453
2010-01-24 21:10:53 +00:00
Sam Lantinga
a0e019f786 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404438
2010-01-21 06:21:52 +00:00
Sam Lantinga
240b5fcaab Default to allow either accelerated or not
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404320
2009-12-15 20:53:09 +00:00
Sam Lantinga
fe2b42f86c OpenGL hardware acceleration defaults on
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404319
2009-12-15 20:36:31 +00:00