src/video/x11/SDL_x11opengl.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 20 May 2016 22:15:28 +0200
changeset 10173 5b0a869a9946
parent 10170 ccdb4d0934e9
permissions -rw-r--r--
X11: Fixed typos in error messages and source comments.
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
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9812
diff changeset
     3
  Copyright (C) 1997-2016 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7853
diff changeset
    21
#include "../../SDL_internal.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 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    36
#define DEFAULT_OPENGL  "libGL.so"
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#elif defined(__MACOSX__)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    38
#define DEFAULT_OPENGL  "/usr/X11R6/lib/libGL.1.dylib"
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#elif defined(__QNXNTO__)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    40
#define DEFAULT_OPENGL  "libGL.so.3"
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#else
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    42
#define DEFAULT_OPENGL  "libGL.so.1"
1952
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
6570
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    63
#ifndef GLX_EXT_visual_info
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    64
#define GLX_EXT_visual_info
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    65
#define GLX_X_VISUAL_TYPE_EXT              0x22
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    66
#define GLX_DIRECT_COLOR_EXT               0x8003
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    67
#endif
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
    68
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    69
#ifndef GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    70
#define GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    71
#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
    72
#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
    73
#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
    74
#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
    75
#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
    76
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    77
/* 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
    78
typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    79
                                                        GLXFBConfig config,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    80
                                                        GLXContext
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    81
                                                        share_context,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    82
                                                        Bool direct,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    83
                                                        const int
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    84
                                                        *attrib_list);
6360
efd48af40ec3 Patched to compile on FreeBSD 8.2.
Ryan C. Gordon <icculus@icculus.org>
parents: 6359
diff changeset
    85
#endif
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    86
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    87
#ifndef GLX_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    88
#define GLX_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    89
#define GLX_CONTEXT_PROFILE_MASK_ARB       0x9126
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    90
#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
    91
#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
    92
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    93
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    94
#ifndef GLX_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    95
#define GLX_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    96
#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
    97
#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
    98
#define GLX_NO_RESET_NOTIFICATION_ARB                   0x8261
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
    99
#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
   100
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   101
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   102
#ifndef GLX_EXT_create_context_es2_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   103
#define GLX_EXT_create_context_es2_profile
6375
93f9a24d1c02 Fixed some minor compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   104
#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
   105
#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
   106
#endif
6375
93f9a24d1c02 Fixed some minor compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   107
#endif
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   108
7853
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   109
#ifndef GLX_ARB_framebuffer_sRGB
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   110
#define GLX_ARB_framebuffer_sRGB
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   111
#ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   112
#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB                0x20B2
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   113
#endif
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   114
#endif
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   115
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   116
#ifndef GLX_EXT_swap_control
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   117
#define GLX_SWAP_INTERVAL_EXT              0x20F1
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   118
#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
   119
#endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   120
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   121
#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
   122
#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
   123
#endif
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   124
9412
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   125
#ifndef GLX_ARB_context_flush_control
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   126
#define GLX_ARB_context_flush_control
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   127
#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB   0x2097
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   128
#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB           0x0000
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   129
#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB          0x2098
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   130
#endif
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   131
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
   132
#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
   133
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
#include <dlfcn.h>
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   135
#define GL_LoadObject(X)    dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   136
#define GL_LoadFunction     dlsym
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   137
#define GL_UnloadObject     dlclose
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
#else
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   139
#define GL_LoadObject   SDL_LoadObject
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   140
#define GL_LoadFunction SDL_LoadFunction
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   141
#define GL_UnloadObject SDL_UnloadObject
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   144
static void X11_GL_InitExtensions(_THIS);
2322
c25d45b7add3 Fixing valgrind errors.
Bob Pendleton <bob@pendleton.com>
parents: 2320
diff changeset
   145
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   146
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
X11_GL_LoadLibrary(_THIS, const char *path)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
{
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   150
    Display *display;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    void *handle;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6360
diff changeset
   153
    if (_this->gl_data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   154
        return SDL_SetError("OpenGL context already created");
6370
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) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   180
        return SDL_OutOfMemory();
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   181
    }
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
    /* Load function pointers */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   184
    handle = _this->gl_config.dll_handle;
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   185
    _this->gl_data->glXQueryExtension =
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   186
        (Bool (*)(Display *, int *, int *))
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   187
            GL_LoadFunction(handle, "glXQueryExtension");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    _this->gl_data->glXGetProcAddress =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   189
        (void *(*)(const GLubyte *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   190
            GL_LoadFunction(handle, "glXGetProcAddressARB");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
    _this->gl_data->glXChooseVisual =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   192
        (XVisualInfo * (*)(Display *, int, int *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   193
            X11_GL_GetProcAddress(_this, "glXChooseVisual");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
    _this->gl_data->glXCreateContext =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
        (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   196
            X11_GL_GetProcAddress(_this, "glXCreateContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    _this->gl_data->glXDestroyContext =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   198
        (void (*)(Display *, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   199
            X11_GL_GetProcAddress(_this, "glXDestroyContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
    _this->gl_data->glXMakeCurrent =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   201
        (int (*)(Display *, GLXDrawable, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   202
            X11_GL_GetProcAddress(_this, "glXMakeCurrent");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    _this->gl_data->glXSwapBuffers =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   204
        (void (*)(Display *, GLXDrawable))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   205
            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
   206
    _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
   207
        (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
   208
            X11_GL_GetProcAddress(_this, "glXQueryDrawable");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   210
    if (!_this->gl_data->glXQueryExtension ||
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   211
        !_this->gl_data->glXChooseVisual ||
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
        !_this->gl_data->glXCreateContext ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        !_this->gl_data->glXDestroyContext ||
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   214
        !_this->gl_data->glXMakeCurrent ||
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   215
        !_this->gl_data->glXSwapBuffers) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   216
        return SDL_SetError("Could not retrieve OpenGL functions");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   219
    display = ((SDL_VideoData *) _this->driverdata)->display;
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   220
    if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) {
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   221
        return SDL_SetError("GLX is not supported");
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   222
    }
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   223
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   224
    /* Initialize extensions */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   225
    X11_GL_InitExtensions(_this);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   226
    
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   227
    /* If we need a GL ES context and there's no  
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   228
     * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions  
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   229
     */
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   230
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   231
        ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   232
#if SDL_VIDEO_OPENGL_EGL
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   233
        X11_GL_UnloadLibrary(_this);
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   234
        /* Better avoid conflicts! */
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   235
        if (_this->gl_config.dll_handle != NULL ) {
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   236
            GL_UnloadObject(_this->gl_config.dll_handle);
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   237
            _this->gl_config.dll_handle = NULL;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   238
        }
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   239
        _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   240
        _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   241
        _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   242
        _this->GL_CreateContext = X11_GLES_CreateContext;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   243
        _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   244
        _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   245
        _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   246
        _this->GL_SwapWindow = X11_GLES_SwapWindow;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   247
        _this->GL_DeleteContext = X11_GLES_DeleteContext;
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   248
        return X11_GLES_LoadLibrary(_this, NULL);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   249
#else
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7719
diff changeset
   250
        return SDL_SetError("SDL not configured with EGL support");
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   251
#endif
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   252
    }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   253
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
    return 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
}
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
void *
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
X11_GL_GetProcAddress(_THIS, const char *proc)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
    if (_this->gl_data->glXGetProcAddress) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
        return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
    }
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   263
    return GL_LoadFunction(_this->gl_config.dll_handle, proc);
1952
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
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   266
void
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
X11_GL_UnloadLibrary(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   269
    /* 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
   270
     * X11 shutdown hooks, per the notes at:
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   271
     * http://dri.sourceforge.net/doc/DRIuserguide.html
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   272
     */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   273
#if 0
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   274
    GL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   275
    _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   276
#endif
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   277
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   278
    /* Free OpenGL memory */
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   279
    SDL_free(_this->gl_data);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7679
diff changeset
   280
    _this->gl_data = NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
}
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
static SDL_bool
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
HasExtension(const char *extension, const char *extensions)
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
    const char *start;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    const char *where, *terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
9354
5709598d628a glX HasExtension(): check for NULL ext string first.
Ryan C. Gordon <icculus@icculus.org>
parents: 9330
diff changeset
   289
    if (!extensions)
5709598d628a glX HasExtension(): check for NULL ext string first.
Ryan C. Gordon <icculus@icculus.org>
parents: 9330
diff changeset
   290
        return SDL_FALSE;
5709598d628a glX HasExtension(): check for NULL ext string first.
Ryan C. Gordon <icculus@icculus.org>
parents: 9330
diff changeset
   291
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    /* Extension names should not have spaces. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
    where = SDL_strchr(extension, ' ');
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    if (where || *extension == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
        return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    /* 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
   298
     * OpenGL extensions string. Don't be fooled by sub-strings,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
     * etc. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
    start = extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
    for (;;) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
        where = SDL_strstr(start, extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
        if (!where)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
            break;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
        terminator = where + SDL_strlen(extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        if (where == start || *(where - 1) == ' ')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
            if (*terminator == ' ' || *terminator == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
                return SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
        start = terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
    return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
static void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
X11_GL_InitExtensions(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
9355
0d1e81f10b7e X11: Don't create a window and GL context to look up the glX extension string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9354
diff changeset
   322
    const int screen = DefaultScreen(display);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    const char *(*glXQueryExtensionsStringFunc) (Display *, int);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
    const char *extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    glXQueryExtensionsStringFunc =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
        (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
                                                                "glXQueryExtensionsString");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    if (glXQueryExtensionsStringFunc) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
        extensions = glXQueryExtensionsStringFunc(display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
        extensions = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   335
    /* 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
   336
    _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
   337
    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
   338
        _this->gl_data->glXSwapIntervalEXT =
6846
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   339
            (void (*)(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
   340
                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
   341
        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
   342
            _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
   343
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
    /* Check for GLX_MESA_swap_control */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    if (HasExtension("GLX_MESA_swap_control", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
        _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
   349
            (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
        _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
   351
            (int(*)(void)) X11_GL_GetProcAddress(_this,
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
                                                   "glXGetSwapIntervalMESA");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
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
   355
    /* 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
   356
    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
   357
        _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
   358
            (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
   359
    }
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   360
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   361
    /* Check for GLX_ARB_create_context */
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   362
    if (HasExtension("GLX_ARB_create_context", extensions)) {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   363
        _this->gl_data->glXCreateContextAttribsARB =
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   364
            (GLXContext (*)(Display*,GLXFBConfig,GLXContext,Bool,const int *))
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   365
                X11_GL_GetProcAddress(_this, "glXCreateContextAttribsARB");
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   366
        _this->gl_data->glXChooseFBConfig =
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   367
            (GLXFBConfig *(*)(Display *, int, const int *, int *))
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   368
                X11_GL_GetProcAddress(_this, "glXChooseFBConfig");
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   369
    }
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   370
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
    /* Check for GLX_EXT_visual_rating */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    if (HasExtension("GLX_EXT_visual_rating", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
        _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
6570
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   376
    /* Check for GLX_EXT_visual_info */
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   377
    if (HasExtension("GLX_EXT_visual_info", extensions)) {
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   378
        _this->gl_data->HAS_GLX_EXT_visual_info = SDL_TRUE;
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   379
    }
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   380
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   381
    /* Check for GLX_EXT_create_context_es2_profile */
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   382
    if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   383
        _this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7512
diff changeset
   384
    }
9412
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   385
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   386
    /* Check for GLX_ARB_context_flush_control */
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   387
    if (HasExtension("GLX_ARB_context_flush_control", extensions)) {
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   388
        _this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE;
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   389
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   392
/* glXChooseVisual and glXChooseFBConfig have some small differences in
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   393
 * the attribute encoding, it can be chosen with the for_FBConfig parameter.
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   394
 */
9458
543298b36b28 This function can be static.
Ryan C. Gordon <icculus@icculus.org>
parents: 9412
diff changeset
   395
static int
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   396
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
   397
{
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
   398
    int i = 0;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   399
    const int MAX_ATTRIBUTES = 64;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   401
    /* assert buffer is large enough to hold all SDL attributes. */
6570
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   402
    SDL_assert(size >= MAX_ATTRIBUTES);
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   403
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    /* 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
   405
    if( for_FBConfig ) {
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   406
        attribs[i++] = GLX_RENDER_TYPE;
7462
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   407
        attribs[i++] = GLX_RGBA_BIT;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   408
    } else {
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   409
        attribs[i++] = GLX_RGBA;
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   410
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    attribs[i++] = GLX_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
    attribs[i++] = _this->gl_config.red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
    attribs[i++] = GLX_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    attribs[i++] = _this->gl_config.green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    attribs[i++] = GLX_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    attribs[i++] = _this->gl_config.blue_size;
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.alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
        attribs[i++] = GLX_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
        attribs[i++] = _this->gl_config.alpha_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.double_buffer) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
        attribs[i++] = GLX_DOUBLEBUFFER;
7462
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   425
        if( for_FBConfig ) {
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   426
            attribs[i++] = True;
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   427
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
    attribs[i++] = GLX_DEPTH_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
    attribs[i++] = _this->gl_config.depth_size;
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
    if (_this->gl_config.stencil_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
        attribs[i++] = GLX_STENCIL_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
        attribs[i++] = _this->gl_config.stencil_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
    }
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
    if (_this->gl_config.accum_red_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
        attribs[i++] = GLX_ACCUM_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
        attribs[i++] = _this->gl_config.accum_red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
    }
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
    if (_this->gl_config.accum_green_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
        attribs[i++] = GLX_ACCUM_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
        attribs[i++] = _this->gl_config.accum_green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
    if (_this->gl_config.accum_blue_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
        attribs[i++] = GLX_ACCUM_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
        attribs[i++] = _this->gl_config.accum_blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    if (_this->gl_config.accum_alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
        attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
        attribs[i++] = _this->gl_config.accum_alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
    if (_this->gl_config.stereo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
        attribs[i++] = GLX_STEREO;
7462
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   460
        if( for_FBConfig ) {
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   461
            attribs[i++] = True;
66b536503733 Minor indentation clean up.
Ryan C. Gordon <icculus@icculus.org>
parents: 7413
diff changeset
   462
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
    if (_this->gl_config.multisamplebuffers) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
        attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
        attribs[i++] = _this->gl_config.multisamplebuffers;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
    if (_this->gl_config.multisamplesamples) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
        attribs[i++] = GLX_SAMPLES_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
        attribs[i++] = _this->gl_config.multisamplesamples;
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
7853
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   475
    if (_this->gl_config.framebuffer_srgb_capable) {
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   476
        attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
9459
f5b468964b0b X11: Always specify "True" if setting GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB.
Ryan C. Gordon <icculus@icculus.org>
parents: 9458
diff changeset
   477
        attribs[i++] = True;  /* always needed, for_FBConfig or not! */
7853
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   478
    }
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7827
diff changeset
   479
3571
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   480
    if (_this->gl_config.accelerated >= 0 &&
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   481
        _this->gl_data->HAS_GLX_EXT_visual_rating) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
        attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   483
        attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   484
                                                      GLX_SLOW_VISUAL_EXT;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
    }
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   486
6817
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6794
diff changeset
   487
    /* If we're supposed to use DirectColor visuals, and we've got the
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6794
diff changeset
   488
       EXT_visual_info extension, then add GLX_X_VISUAL_TYPE_EXT. */
6570
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   489
    if (X11_UseDirectColorVisuals() &&
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   490
        _this->gl_data->HAS_GLX_EXT_visual_info) {
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   491
        attribs[i++] = GLX_X_VISUAL_TYPE_EXT;
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   492
        attribs[i++] = GLX_DIRECT_COLOR_EXT;
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   493
    }
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   494
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
    attribs[i++] = None;
6570
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   496
45855398762c Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Michael Sartain <mikesart@valvesoftware.com>
parents: 6522
diff changeset
   497
    SDL_assert(i <= MAX_ATTRIBUTES);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   498
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
   499
    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
   500
}
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
   501
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
   502
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
   503
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
   504
{
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
   505
    /* 64 seems nice. */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   506
    int attribs[64];
8780
2d8d64a681ad Fixed crash if the OpenGL library hasn't been loaded yet
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   507
    XVisualInfo *vinfo;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
6181
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   509
    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
   510
        /* 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
   511
        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
   512
    }
e29f01fa2750 Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   513
8780
2d8d64a681ad Fixed crash if the OpenGL library hasn't been loaded yet
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   514
    X11_GL_GetAttributes(_this, display, screen, attribs, 64, SDL_FALSE);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
    vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
    if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
        SDL_SetError("Couldn't find matching GLX visual");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    return vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
6988
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   522
#ifndef GLXBadContext
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   523
#define GLXBadContext 0
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   524
#endif
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   525
#ifndef GLXBadFBConfig
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   526
#define GLXBadFBConfig 9
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   527
#endif
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   528
#ifndef GLXBadProfileARB
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   529
#define GLXBadProfileARB 13
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   530
#endif
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   531
static int (*handler) (Display *, XErrorEvent *) = NULL;
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   532
static const char *errorHandlerOperation = NULL;
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   533
static int errorBase = 0;
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   534
static int errorCode = 0;
6988
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   535
static int
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   536
X11_GL_ErrorHandler(Display * d, XErrorEvent * e)
6988
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   537
{
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   538
    char *x11_error = NULL;
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   539
    char x11_error_locale[256];
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   540
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   541
    errorCode = e->error_code;
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   542
    if (X11_XGetErrorText(d, errorCode, x11_error_locale, sizeof(x11_error_locale)) == Success)
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   543
    {
8967
8ca9ce569f65 Fixed null terminating the X11 error string
Sam Lantinga <slouken@libsdl.org>
parents: 8804
diff changeset
   544
        x11_error = SDL_iconv_string("UTF-8", "", x11_error_locale, SDL_strlen(x11_error_locale)+1);
6988
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   545
    }
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   546
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   547
    if (x11_error)
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   548
    {
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   549
        SDL_SetError("Could not %s: %s", errorHandlerOperation, x11_error);
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   550
        SDL_free(x11_error);
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   551
    }
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   552
    else
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   553
    {
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   554
        SDL_SetError("Could not %s: %i (Base %i)\n", errorHandlerOperation, errorCode, errorBase);
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   555
    }
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   556
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   557
    return (0);
6988
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   558
}
2aed1beaf5bc Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead
Sam Lantinga <slouken@libsdl.org>
parents: 6948
diff changeset
   559
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
SDL_GLContext
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
X11_GL_CreateContext(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
    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
   566
        ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
    XWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
    XVisualInfo v, *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
    int n;
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   570
    GLXContext context = NULL, share_context;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   571
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   572
    if (_this->gl_config.share_with_current_context) {
7413
30d42f6f2e8d Fixed cast of the OpenGL context type
Sam Lantinga <slouken@libsdl.org>
parents: 7412
diff changeset
   573
        share_context = (GLXContext)SDL_GL_GetCurrentContext();
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   574
    } else {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   575
        share_context = NULL;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   576
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
1955
Sam Lantinga <slouken@libsdl.org>
parents: 1954
diff changeset
   578
    /* We do this to create a clean separation between X and GLX errors. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   579
    X11_XSync(display, False);
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   580
    errorHandlerOperation = "create GL context";
7512
462839f2f408 Fix for recent GLX error bug
Sam Lantinga <slouken@libsdl.org>
parents: 7462
diff changeset
   581
    errorBase = _this->gl_data->errorBase;
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   582
    errorCode = Success;
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   583
    handler = X11_XSetErrorHandler(X11_GL_ErrorHandler);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   584
    X11_XGetWindowAttributes(display, data->xwindow, &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    v.screen = screen;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   586
    v.visualid = X11_XVisualIDFromVisual(xattr.visual);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   587
    vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    if (vinfo) {
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   589
        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
   590
            _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
   591
            _this->gl_config.flags == 0) {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   592
            /* Create legacy context */
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   593
            context =
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   594
                _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
   595
        } else {
9412
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   596
            /* max 10 attributes plus terminator */
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   597
            int attribs[11] = {
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   598
                GLX_CONTEXT_MAJOR_VERSION_ARB,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   599
                _this->gl_config.major_version,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   600
                GLX_CONTEXT_MINOR_VERSION_ARB,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   601
                _this->gl_config.minor_version,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   602
                0
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   603
            };
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   604
            int iattr = 4;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   605
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   606
            /* SDL profile bits match GLX profile bits */
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   607
            if( _this->gl_config.profile_mask != 0 ) {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   608
                attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   609
                attribs[iattr++] = _this->gl_config.profile_mask;
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   610
            }
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6282
diff changeset
   611
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   612
            /* SDL flags match GLX flags */
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   613
            if( _this->gl_config.flags != 0 ) {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   614
                attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   615
                attribs[iattr++] = _this->gl_config.flags;
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   616
            }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   617
9412
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   618
            /* only set if glx extension is available */
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   619
            if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) {
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   620
                attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB;
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   621
                attribs[iattr++] = 
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   622
                    _this->gl_config.release_behavior ? 
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   623
                    GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB : 
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   624
                    GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   625
            }
8b1436ce1028 Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
Marc Di Luzio <mdiluzio@feralinteractive.com>
parents: 9355
diff changeset
   626
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   627
            attribs[iattr++] = 0;
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
   628
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   629
            /* Get a pointer to the context creation function for GL 3.0 */
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   630
            if (!_this->gl_data->glXCreateContextAttribsARB) {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   631
                SDL_SetError("OpenGL 3.0 and later are not supported by this system");
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   632
            } else {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   633
                int glxAttribs[64];
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   634
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   635
                /* Create a GL 3.x context */
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   636
                GLXFBConfig *framebuffer_config = NULL;
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   637
                int fbcount = 0;
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   638
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   639
                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
   640
9330
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   641
                if (!_this->gl_data->glXChooseFBConfig
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   642
                    || !(framebuffer_config =
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   643
                        _this->gl_data->glXChooseFBConfig(display,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   644
                                          DefaultScreen(display), glxAttribs,
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   645
                                          &fbcount))) {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   646
                    SDL_SetError("No good framebuffers found. OpenGL 3.0 and later unavailable");
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   647
                } else {
26eb20aad02f X11: Fixes for OpenGL 3.0 and later context creation.
Ryan C. Gordon <icculus@icculus.org>
parents: 8967
diff changeset
   648
                    context = _this->gl_data->glXCreateContextAttribsARB(display,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   649
                                                    framebuffer_config[0],
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6382
diff changeset
   650
                                                    share_context, True, attribs);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   651
                }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   652
            }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   653
        }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   654
        X11_XFree(vinfo);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
    }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   656
    X11_XSync(display, False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   657
    X11_XSetErrorHandler(handler);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   658
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
    if (!context) {
8804
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   660
        if (errorCode == Success) {
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   661
            SDL_SetError("Could not create GL context");
a941cf4234c4 X11: Provide specific X error when SDL_GL_CreateContext fails.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 8780
diff changeset
   662
        }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   663
        return NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
    }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   665
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   666
    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
   667
        X11_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   668
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   669
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   670
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   671
    return context;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
    Window drawable =
6794
a0d42781fa92 Corrected call to glXMakeCurrent() when setting a NULL context.
Edward Rudd <urkle@outoforder.cc>
parents: 6570
diff changeset
   679
        (context ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
    GLXContext glx_context = (GLXContext) context;
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   681
    int rc;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   683
    if (!_this->gl_data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   684
        return SDL_SetError("OpenGL not initialized");
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   685
    }
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   686
9812
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   687
    /* We do this to create a clean separation between X and GLX errors. */
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   688
    X11_XSync(display, False);
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   689
    errorHandlerOperation = "make GL context current";
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   690
    errorBase = _this->gl_data->errorBase;
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   691
    errorCode = Success;
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   692
    handler = X11_XSetErrorHandler(X11_GL_ErrorHandler);
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   693
    rc = _this->gl_data->glXMakeCurrent(display, drawable, glx_context);
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   694
    X11_XSetErrorHandler(handler);
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   695
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   696
    if (errorCode != Success) {   /* uhoh, an X error was thrown! */
9b4dd9efb04e x11: Catch fatal X errors when calling glXMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   697
        return -1;  /* the error handler called SDL_SetError() already. */
10173
5b0a869a9946 X11: Fixed typos in error messages and source comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10170
diff changeset
   698
    } else if (!rc) {  /* glXMakeCurrent() failed without throwing an X error */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   699
        return SDL_SetError("Unable to make GL context current");
1952
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
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6988
diff changeset
   702
    return 0;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   705
/*
10173
5b0a869a9946 X11: Fixed typos in error messages and source comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10170
diff changeset
   706
   0 is a valid argument to glXSwapInterval(MESA|EXT) and setting it to 0
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
   707
   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
   708
   than zero (or at least that is what the docs say). OTOH, 0 is an invalid
10173
5b0a869a9946 X11: Fixed typos in error messages and source comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10170
diff changeset
   709
   argument to glXSwapIntervalSGI and it returns an error if you call it
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
   710
   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
   711
*/
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
   712
10170
ccdb4d0934e9 X11: Fixed SDL_GL_GetSwapInterval() returning -1 if interval is unknown.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9998
diff changeset
   713
static int swapinterval = 0;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
X11_GL_SetSwapInterval(_THIS, int interval)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
{
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   717
    int status = -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   718
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   719
    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
   720
        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
   721
    } 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
   722
        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
   723
        const SDL_WindowData *windowdata = (SDL_WindowData *)
7412
50211a1fd557 Fixed bug 1946 - OpenGL contexts in threads
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   724
            SDL_GL_GetCurrentWindow()->driverdata;
6846
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   725
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
   726
        Window drawable = windowdata->xwindow;
6846
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   727
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   728
        /*
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   729
         * This is a workaround for a bug in NVIDIA drivers. Bug has been reported
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   730
         * and will be fixed in a future release (probably 319.xx).
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   731
         *
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   732
         * There's a bug where glXSetSwapIntervalEXT ignores updates because
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   733
         * it has the wrong value cached. To work around it, we just run a no-op
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   734
         * update to the current value.
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   735
         */
6851
a58fc7ff4a0f Fixed compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents: 6846
diff changeset
   736
        int currentInterval = X11_GL_GetSwapInterval(_this);
6846
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   737
        _this->gl_data->glXSwapIntervalEXT(display, drawable, currentInterval);
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   738
        _this->gl_data->glXSwapIntervalEXT(display, drawable, interval);
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   739
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   740
        status = 0;
97eb26e2dee0 Workaround for NVIDIA bug in glXSwapIntervalEXT.
Sam Lantinga <slouken@libsdl.org>
parents: 6817
diff changeset
   741
        swapinterval = 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
   742
    } else if (_this->gl_data->glXSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
        status = _this->gl_data->glXSwapIntervalMESA(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
        if (status != 0) {
10173
5b0a869a9946 X11: Fixed typos in error messages and source comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10170
diff changeset
   745
            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
   746
        } 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
   747
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   749
    } else if (_this->gl_data->glXSwapIntervalSGI) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
        status = _this->gl_data->glXSwapIntervalSGI(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
        if (status != 0) {
10173
5b0a869a9946 X11: Fixed typos in error messages and source comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10170
diff changeset
   752
            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
   753
        } 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
   754
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
        SDL_Unsupported();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
    return status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
X11_GL_GetSwapInterval(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
{
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
   765
    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
   766
        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
   767
        const SDL_WindowData *windowdata = (SDL_WindowData *)
7412
50211a1fd557 Fixed bug 1946 - OpenGL contexts in threads
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   768
            SDL_GL_GetCurrentWindow()->driverdata;
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
   769
        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
   770
        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
   771
        unsigned int interval = 0;
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   772
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   773
        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
   774
            _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
   775
                                            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
   776
                                            &allow_late_swap_tearing);
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   777
        }
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   778
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
   779
        _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
   780
                                         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
   781
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   782
        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
   783
            return -((int) interval);
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   784
        }
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   785
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6375
diff changeset
   786
        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
   787
    } else if (_this->gl_data->glXGetSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
        return _this->gl_data->glXGetSwapIntervalMESA();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
    } 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
   790
        return swapinterval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
X11_GL_SwapWindow(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   796
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
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
   800
    _this->gl_data->glXSwapBuffers(display, data->xwindow);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   803
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
X11_GL_DeleteContext(_THIS, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   806
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
    GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   809
    if (!_this->gl_data) {
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   810
        return;
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6393
diff changeset
   811
    }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
    _this->gl_data->glXDestroyContext(display, glx_context);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7723
diff changeset
   813
    X11_XSync(display, False);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   814
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   815
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   816
#endif /* SDL_VIDEO_OPENGL_GLX */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   817
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
   818
#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
   819
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   820
/* vi: set ts=4 sw=4 expandtab: */