src/video/x11/SDL_x11opengl.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 12 Aug 2012 11:16:24 -0700
changeset 6393 a773384edf20
parent 6382 64d54101773a
child 6522 edacce9402fb
permissions -rwxr-xr-x
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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     7
  arising from the use of this software.
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    11
  freely, subject to the following restrictions:
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
    24
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_x11video.h"
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5630
diff changeset
    26
#include "SDL_assert.h"
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
/* GLX implementation of SDL OpenGL support */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#if SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "SDL_loadso.h"
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
    32
#include "SDL_x11opengles.h"
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#if defined(__IRIX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
/* IRIX doesn't have a GL library versioning system */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#define DEFAULT_OPENGL	"libGL.so"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#elif defined(__MACOSX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#elif defined(__QNXNTO__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
#define DEFAULT_OPENGL	"libGL.so.3"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
#define DEFAULT_OPENGL	"libGL.so.1"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    45
#ifndef GLX_NONE_EXT
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    46
#define GLX_NONE_EXT                       0x8000
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    47
#endif
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    48
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
#ifndef GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
#define GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
#define GLX_SAMPLE_BUFFERS_ARB             100000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
#define GLX_SAMPLES_ARB                    100001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
#ifndef GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
#define GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
#define GLX_VISUAL_CAVEAT_EXT              0x20
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
#define GLX_NONE_EXT                       0x8000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
#define GLX_SLOW_VISUAL_EXT                0x8001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
#define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    63
#ifndef GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    64
#define GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    65
#define GLX_CONTEXT_MAJOR_VERSION_ARB      0x2091
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    66
#define GLX_CONTEXT_MINOR_VERSION_ARB      0x2092
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    67
#define GLX_CONTEXT_FLAGS_ARB              0x2094
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    68
#define GLX_CONTEXT_DEBUG_BIT_ARB          0x0001
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    69
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
5021
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    70
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    71
/* Typedef for the GL 3.0 context creation function */
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    72
typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    73
                                                        GLXFBConfig config,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    74
                                                        GLXContext
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    75
                                                        share_context,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    76
                                                        Bool direct,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    77
                                                        const int
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    78
                                                        *attrib_list);
6360
efd48af40ec3 Patched to compile on FreeBSD 8.2.
Ryan C. Gordon <icculus@icculus.org>
parents: 6359
diff changeset
    79
#endif
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    80
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    81
#ifndef GLX_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    82
#define GLX_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    83
#define GLX_CONTEXT_PROFILE_MASK_ARB       0x9126
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    84
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB   0x00000001
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    85
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    86
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    87
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    88
#ifndef GLX_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    89
#define GLX_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    90
#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB  0x00000004
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    91
#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB     0x8256
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    92
#define GLX_NO_RESET_NOTIFICATION_ARB                   0x8261
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    93
#define GLX_LOSE_CONTEXT_ON_RESET_ARB                   0x8252
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    94
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    95
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    96
#ifndef GLX_EXT_create_context_es2_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    97
#define GLX_EXT_create_context_es2_profile
6375
93f9a24d1c02 Fixed some minor compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
    98
#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    99
#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT    0x00000002
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   100
#endif
6375
93f9a24d1c02 Fixed some minor compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   101
#endif
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   102
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   103
#ifndef GLX_EXT_swap_control
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   104
#define GLX_SWAP_INTERVAL_EXT              0x20F1
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   105
#define GLX_MAX_SWAP_INTERVAL_EXT          0x20F2
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   106
#endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   107
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   108
#ifndef GLX_EXT_swap_control_tear
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   109
#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   110
#endif
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   111
6183
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   112
#define OPENGL_REQUIRES_DLOPEN
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   113
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
#include <dlfcn.h>
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
#define GL_LoadFunction		dlsym
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
#define GL_UnloadObject		dlclose
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
#else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
#define GL_LoadObject	SDL_LoadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
#define GL_LoadFunction	SDL_LoadFunction
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
#define GL_UnloadObject	SDL_UnloadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   124
static void X11_GL_InitExtensions(_THIS);
2322
c25d45b7add3 Fixing valgrind errors.
Bob Pendleton <bob@pendleton.com>
parents: 2320
diff changeset
   125
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   126
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
X11_GL_LoadLibrary(_THIS, const char *path)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    void *handle;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   132
    if (_this->gl_data) {
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   133
        SDL_SetError("OpenGL context already created");
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   134
        return -1;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   135
    }
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   136
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   137
    /* If SDL_GL_CONTEXT_EGL has been changed to 1, switch over to X11_GLES functions  */
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   138
    if (_this->gl_config.use_egl == 1) {
6373
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   139
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   140
        _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   141
        _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   142
        _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   143
        _this->GL_CreateContext = X11_GLES_CreateContext;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   144
        _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   145
        _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   146
        _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   147
        _this->GL_SwapWindow = X11_GLES_SwapWindow;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   148
        _this->GL_DeleteContext = X11_GLES_DeleteContext;
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   149
        return X11_GLES_LoadLibrary(_this, path);
6373
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   150
#else
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   151
        SDL_SetError("SDL not configured with OpenGL ES/EGL support");
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   152
        return -1;
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   153
#endif
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   154
    }
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   155
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   156
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   157
    /* Load the OpenGL library */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   158
    if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   159
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   160
    }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   161
    if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   162
        path = DEFAULT_OPENGL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   163
    }
6183
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   164
    _this->gl_config.dll_handle = GL_LoadObject(path);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   165
    if (!_this->gl_config.dll_handle) {
6183
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   166
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   167
        SDL_SetError("Failed loading %s: %s", path, dlerror());
6d9a266e04bb The #define was asking to use dlopen(), but the code wasn't doing it.
Sam Lantinga <slouken@libsdl.org>
parents: 6181
diff changeset
   168
#endif
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   169
        return -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   171
    SDL_strlcpy(_this->gl_config.driver_path, path,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   172
                SDL_arraysize(_this->gl_config.driver_path));
2244
Sam Lantinga <slouken@libsdl.org>
parents: 2243
diff changeset
   173
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   174
    /* Allocate OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   175
    _this->gl_data =
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   176
        (struct SDL_GLDriverData *) SDL_calloc(1,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   177
                                               sizeof(struct
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   178
                                                      SDL_GLDriverData));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   179
    if (!_this->gl_data) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   180
        SDL_OutOfMemory();
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   181
        return -1;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   182
    }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   183
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   184
    /* Load function pointers */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   185
    handle = _this->gl_config.dll_handle;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
    _this->gl_data->glXGetProcAddress =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   187
        (void *(*)(const GLubyte *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   188
            GL_LoadFunction(handle, "glXGetProcAddressARB");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
    _this->gl_data->glXChooseVisual =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   190
        (XVisualInfo * (*)(Display *, int, int *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   191
            X11_GL_GetProcAddress(_this, "glXChooseVisual");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
    _this->gl_data->glXCreateContext =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
        (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   194
            X11_GL_GetProcAddress(_this, "glXCreateContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
    _this->gl_data->glXDestroyContext =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   196
        (void (*)(Display *, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   197
            X11_GL_GetProcAddress(_this, "glXDestroyContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    _this->gl_data->glXMakeCurrent =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   199
        (int (*)(Display *, GLXDrawable, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   200
            X11_GL_GetProcAddress(_this, "glXMakeCurrent");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    _this->gl_data->glXSwapBuffers =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   202
        (void (*)(Display *, GLXDrawable))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   203
            X11_GL_GetProcAddress(_this, "glXSwapBuffers");
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   204
    _this->gl_data->glXQueryDrawable =
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   205
        (void (*)(Display*,GLXDrawable,int,unsigned int*))
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   206
            X11_GL_GetProcAddress(_this, "glXQueryDrawable");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    if (!_this->gl_data->glXChooseVisual ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
        !_this->gl_data->glXCreateContext ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
        !_this->gl_data->glXDestroyContext ||
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   211
        !_this->gl_data->glXMakeCurrent ||
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   212
        !_this->gl_data->glXSwapBuffers) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        SDL_SetError("Could not retrieve OpenGL functions");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
        return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   217
    /* Initialize extensions */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   218
    X11_GL_InitExtensions(_this);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   219
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
    return 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
void *
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
X11_GL_GetProcAddress(_THIS, const char *proc)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
    if (_this->gl_data->glXGetProcAddress) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
        return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    }
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   229
    return GL_LoadFunction(_this->gl_config.dll_handle, proc);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   232
void
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
X11_GL_UnloadLibrary(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   235
    /* Don't actually unload the library, since it may have registered
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   236
     * X11 shutdown hooks, per the notes at:
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   237
     * http://dri.sourceforge.net/doc/DRIuserguide.html
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   238
     */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   239
#if 0
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   240
    GL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   241
    _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   242
#endif
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   243
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   244
    /* Free OpenGL memory */
6181
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   245
    if (_this->gl_data) {
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   246
        SDL_free(_this->gl_data);
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   247
        _this->gl_data = NULL;
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   248
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
static SDL_bool
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
HasExtension(const char *extension, const char *extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
    const char *start;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    const char *where, *terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
    /* Extension names should not have spaces. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
    where = SDL_strchr(extension, ' ');
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
    if (where || *extension == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
        return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
    if (!extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
        return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
    /* It takes a bit of care to be fool-proof about parsing the
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
     * OpenGL extensions string. Don't be fooled by sub-strings,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
     * etc. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    start = extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    for (;;) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
        where = SDL_strstr(start, extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
        if (!where)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
            break;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
        terminator = where + SDL_strlen(extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
        if (where == start || *(where - 1) == ' ')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
            if (*terminator == ' ' || *terminator == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
                return SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
        start = terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
    return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
static void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
X11_GL_InitExtensions(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
5244
762e40fb8e28 Be explicit about what display you're querying. The default display is 0.
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
   290
    int screen = DefaultScreen(display);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    XSetWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
    Window w;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    GLXContext context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    const char *(*glXQueryExtensionsStringFunc) (Display *, int);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    const char *extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    vinfo = X11_GL_GetVisual(_this, display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
        return;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
    xattr.background_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
    xattr.border_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
    xattr.colormap =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
        XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
                        AllocNone);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
    w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
                      vinfo->depth, InputOutput, vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
                      (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
        _this->gl_data->glXMakeCurrent(display, w, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
    glXQueryExtensionsStringFunc =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
        (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
                                                                "glXQueryExtensionsString");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    if (glXQueryExtensionsStringFunc) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
        extensions = glXQueryExtensionsStringFunc(display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
        extensions = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   325
    /* Check for GLX_EXT_swap_control(_tear) */
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   326
    _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_FALSE;
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   327
    if (HasExtension("GLX_EXT_swap_control", extensions)) {
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   328
        _this->gl_data->glXSwapIntervalEXT =
5630
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   329
            (int (*)(Display*,GLXDrawable,int))
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   330
                X11_GL_GetProcAddress(_this, "glXSwapIntervalEXT");
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   331
        if (HasExtension("GLX_EXT_swap_control_tear", extensions)) {
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   332
            _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_TRUE;
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   333
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
    /* Check for GLX_MESA_swap_control */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    if (HasExtension("GLX_MESA_swap_control", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
        _this->gl_data->glXSwapIntervalMESA =
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   339
            (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
        _this->gl_data->glXGetSwapIntervalMESA =
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   341
            (int(*)(void)) X11_GL_GetProcAddress(_this,
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
                                                   "glXGetSwapIntervalMESA");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   345
    /* Check for GLX_SGI_swap_control */
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   346
    if (HasExtension("GLX_SGI_swap_control", extensions)) {
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   347
        _this->gl_data->glXSwapIntervalSGI =
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   348
            (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   349
    }
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   350
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
    /* Check for GLX_EXT_visual_rating */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
    if (HasExtension("GLX_EXT_visual_rating", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
        _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
    if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
        _this->gl_data->glXMakeCurrent(display, None, NULL);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
        _this->gl_data->glXDestroyContext(display, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
    XDestroyWindow(display, w);
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   361
    X11_PumpEvents(_this);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   364
/* glXChooseVisual and glXChooseFBConfig have some small differences in
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   365
 * the attribute encoding, it can be chosen with the for_FBConfig parameter. 
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   366
 */
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   367
int 
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   368
X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size, Bool for_FBConfig)
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
{
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   370
    int i = 0;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   372
    /* assert buffer is large enough to hold all SDL attributes. */ 
6281
e46d6f4b469e Replaced some assert macros with SDL_assert.
Ryan C. Gordon <icculus@icculus.org>
parents: 6183
diff changeset
   373
    SDL_assert(size >= 32);
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   374
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
    /* Setup our GLX attributes according to the gl_config. */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   376
    if( for_FBConfig ) {
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   377
        attribs[i++] = GLX_RENDER_TYPE;
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   378
	attribs[i++] = GLX_RGBA_BIT;
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   379
    } else {
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   380
        attribs[i++] = GLX_RGBA;
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   381
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
    attribs[i++] = GLX_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
    attribs[i++] = _this->gl_config.red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
    attribs[i++] = GLX_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
    attribs[i++] = _this->gl_config.green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
    attribs[i++] = GLX_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
    attribs[i++] = _this->gl_config.blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
    if (_this->gl_config.alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
        attribs[i++] = GLX_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
        attribs[i++] = _this->gl_config.alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
    if (_this->gl_config.double_buffer) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
        attribs[i++] = GLX_DOUBLEBUFFER;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   396
	if( for_FBConfig )
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   397
	    attribs[i++] = True;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
    attribs[i++] = GLX_DEPTH_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    attribs[i++] = _this->gl_config.depth_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
    if (_this->gl_config.stencil_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
        attribs[i++] = GLX_STENCIL_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
        attribs[i++] = _this->gl_config.stencil_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
    if (_this->gl_config.accum_red_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
        attribs[i++] = GLX_ACCUM_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
        attribs[i++] = _this->gl_config.accum_red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
    if (_this->gl_config.accum_green_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
        attribs[i++] = GLX_ACCUM_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
        attribs[i++] = _this->gl_config.accum_green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    if (_this->gl_config.accum_blue_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
        attribs[i++] = GLX_ACCUM_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
        attribs[i++] = _this->gl_config.accum_blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
    if (_this->gl_config.accum_alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
        attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
        attribs[i++] = _this->gl_config.accum_alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
    if (_this->gl_config.stereo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
        attribs[i++] = GLX_STEREO;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   430
	if( for_FBConfig )
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   431
	    attribs[i++] = True;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
    if (_this->gl_config.multisamplebuffers) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
        attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
        attribs[i++] = _this->gl_config.multisamplebuffers;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
    if (_this->gl_config.multisamplesamples) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
        attribs[i++] = GLX_SAMPLES_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
        attribs[i++] = _this->gl_config.multisamplesamples;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
3571
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   444
    if (_this->gl_config.accelerated >= 0 &&
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   445
        _this->gl_data->HAS_GLX_EXT_visual_rating) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
        attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   447
        attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   448
                                                      GLX_SLOW_VISUAL_EXT;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
    }
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   450
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
    attribs[i++] = None;
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   452
 
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   453
    return i;
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   454
}
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   455
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   456
XVisualInfo *
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   457
X11_GL_GetVisual(_THIS, Display * display, int screen)
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   458
{
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   459
    XVisualInfo *vinfo;
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   460
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   461
    /* 64 seems nice. */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   462
    int attribs[64];
6359
b2a768065c32 Removed unused variable to silence compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 6296
diff changeset
   463
    X11_GL_GetAttributes(_this,display,screen,attribs,64,SDL_FALSE);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
6181
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   465
    if (!_this->gl_data) {
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   466
        /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   467
        return NULL;
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   468
    }
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   469
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
    vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
    if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
        SDL_SetError("Couldn't find matching GLX visual");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
    return vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
SDL_GLContext
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
X11_GL_CreateContext(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
    int screen =
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5244
diff changeset
   483
        ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
    XWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
    XVisualInfo v, *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
    int n;
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   487
    GLXContext context = NULL, share_context;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   488
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   489
    if (_this->gl_config.share_with_current_context) {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   490
        share_context = (GLXContext)(_this->current_glctx);
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   491
    } else {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   492
        share_context = NULL;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   493
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
1955
Sam Lantinga <slouken@libsdl.org>
parents: 1954
diff changeset
   495
    /* We do this to create a clean separation between X and GLX errors. */
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
    XSync(display, False);
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3571
diff changeset
   497
    XGetWindowAttributes(display, data->xwindow, &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
    v.screen = screen;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
    v.visualid = XVisualIDFromVisual(xattr.visual);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
    vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
    if (vinfo) {
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   502
        if (_this->gl_config.major_version < 3 &&
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   503
            _this->gl_config.profile_mask == 0 &&
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   504
            _this->gl_config.flags == 0) {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   505
            /* Create legacy context */
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   506
            context =
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   507
                _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   508
        } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   509
            /* If we want a GL 3.0 context or later we need to get a temporary
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   510
               context to grab the new context creation function */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   511
            GLXContext temp_context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   512
                _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   513
            if (!temp_context) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   514
                SDL_SetError("Could not create GL context");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   515
                return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   516
            } else {
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   517
                /* max 8 attributes plus terminator */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   518
                int attribs[9] = {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   519
                    GLX_CONTEXT_MAJOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   520
                    _this->gl_config.major_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   521
                    GLX_CONTEXT_MINOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   522
                    _this->gl_config.minor_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   523
                    0
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   524
                };
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   525
                int iattr = 4;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   526
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   527
                /* SDL profile bits match GLX profile bits */
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   528
                if( _this->gl_config.profile_mask != 0 ) {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   529
                    attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   530
                    attribs[iattr++] = _this->gl_config.profile_mask;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   531
                }
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   532
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   533
                /* SDL flags match GLX flags */
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   534
                if( _this->gl_config.flags != 0 ) {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   535
                    attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   536
                    attribs[iattr++] = _this->gl_config.flags;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   537
                }
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   538
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   539
                attribs[iattr++] = 0;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   540
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   541
                /* Get a pointer to the context creation function for GL 3.0 */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   542
                PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   543
                    (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   544
                    glXGetProcAddress((GLubyte *)
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   545
                                      "glXCreateContextAttribsARB");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   546
                if (!glXCreateContextAttribs) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   547
                    SDL_SetError("GL 3.x is not supported");
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   548
                    context = temp_context;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   549
                } else {
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   550
                    int glxAttribs[64];
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   551
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   552
                    /* Create a GL 3.x context */
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   553
                    GLXFBConfig *framebuffer_config = NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   554
                    int fbcount = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   555
                    GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   556
                                                       int screen,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   557
                                                       const int *attrib_list,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   558
                                                       int *nelements);
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   559
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   560
                    glXChooseFBConfig =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   561
                        (GLXFBConfig *
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   562
                         (*)(Display *, int, const int *,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   563
                             int *)) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   564
                        glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   565
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   566
                    X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE);
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   567
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   568
                    if (!glXChooseFBConfig
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   569
                        || !(framebuffer_config =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   570
                             glXChooseFBConfig(display,
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   571
                                               DefaultScreen(display), glxAttribs,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   572
                                               &fbcount))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   573
                        SDL_SetError
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   574
                            ("No good framebuffers found. GL 3.x disabled");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   575
                        context = temp_context;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   576
                    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   577
                        context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   578
                            glXCreateContextAttribs(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   579
                                                    framebuffer_config[0],
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   580
                                                    share_context, True, attribs);
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   581
                        _this->gl_data->glXDestroyContext(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   582
                                                          temp_context);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   583
                    }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   584
                }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   585
            }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   586
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
        XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
    XSync(display, False);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
    if (!context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
        SDL_SetError("Could not create GL context");
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   593
        return NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
    }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   595
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   596
    if (X11_GL_MakeCurrent(_this, window, context) < 0) {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   597
        X11_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   598
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   599
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   600
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   601
    return context;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
    Window drawable =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3571
diff changeset
   609
        (window ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
    GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
    int status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
    status = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
    if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
        SDL_SetError("Unable to make GL context current");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
        status = -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
    XSync(display, False);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
    return (status);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   623
/* 
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   624
   0 is a valid argument to glxSwapInterval(MESA|EXT) and setting it to 0
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   625
   will undo the effect of a previous call with a value that is greater
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   626
   than zero (or at least that is what the docs say). OTOH, 0 is an invalid
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   627
   argument to glxSwapIntervalSGI and it returns an error if you call it
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   628
   with 0 as an argument.
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   629
*/
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   630
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   631
static int swapinterval = -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
X11_GL_SetSwapInterval(_THIS, int interval)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
{
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   635
    int status = -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   637
    if ((interval < 0) && (!_this->gl_data->HAS_GLX_EXT_swap_control_tear)) {
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   638
        SDL_SetError("Negative swap interval unsupported in this GL");
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   639
    } else if (_this->gl_data->glXSwapIntervalEXT) {
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   640
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   641
        const SDL_WindowData *windowdata = (SDL_WindowData *)
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   642
            _this->current_glwin->driverdata;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   643
        Window drawable = windowdata->xwindow;
5630
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   644
        status = _this->gl_data->glXSwapIntervalEXT(display,drawable,interval);
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   645
        if (status != 0) {
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   646
            SDL_SetError("glxSwapIntervalEXT failed");
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   647
        } else {
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   648
            swapinterval = interval;
39e74dab5ebb Apparently glXSwapIntervalEXT() _does_ return a value.
Ryan C. Gordon <icculus@icculus.org>
parents: 5573
diff changeset
   649
        }
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   650
    } else if (_this->gl_data->glXSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
        status = _this->gl_data->glXSwapIntervalMESA(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
        if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
            SDL_SetError("glxSwapIntervalMESA failed");
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   654
        } else {
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   655
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
    } else if (_this->gl_data->glXSwapIntervalSGI) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   658
        status = _this->gl_data->glXSwapIntervalSGI(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
        if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
            SDL_SetError("glxSwapIntervalSGI failed");
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   661
        } else {
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   662
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   665
        SDL_Unsupported();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   666
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
    return status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
X11_GL_GetSwapInterval(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
{
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   673
    if (_this->gl_data->glXSwapIntervalEXT) {
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   674
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   675
        const SDL_WindowData *windowdata = (SDL_WindowData *)
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   676
            _this->current_glwin->driverdata;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   677
        Window drawable = windowdata->xwindow;
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   678
        unsigned int allow_late_swap_tearing = 0;
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   679
        unsigned int interval = 0;
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   680
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   681
        if (_this->gl_data->HAS_GLX_EXT_swap_control_tear) {
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   682
            _this->gl_data->glXQueryDrawable(display, drawable,
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   683
                                            GLX_LATE_SWAPS_TEAR_EXT,
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   684
                                            &allow_late_swap_tearing);
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   685
        }
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   686
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   687
        _this->gl_data->glXQueryDrawable(display, drawable,
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   688
                                         GLX_SWAP_INTERVAL_EXT, &interval);
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   689
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   690
        if ((allow_late_swap_tearing) && (interval > 0)) {
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   691
            return -((int) interval);
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   692
        }
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   693
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   694
        return (int) interval;
5572
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   695
    } else if (_this->gl_data->glXGetSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
        return _this->gl_data->glXGetSwapIntervalMESA();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
    } else {
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   698
        return swapinterval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
X11_GL_SwapWindow(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   705
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3571
diff changeset
   708
    _this->gl_data->glXSwapBuffers(display, data->xwindow);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
X11_GL_DeleteContext(_THIS, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
    GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   717
    _this->gl_data->glXDestroyContext(display, glx_context);
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   718
    XSync(display, False);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   719
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   720
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   721
#endif /* SDL_VIDEO_OPENGL_GLX */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
   723
#endif /* SDL_VIDEO_DRIVER_X11 */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
   724
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   725
/* vi: set ts=4 sw=4 expandtab: */