src/video/x11/SDL_x11opengl.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 18 Jul 2011 14:55:24 -0700
changeset 5573 7dd4caf23bf5
parent 5572 32a785da3f49
child 5630 39e74dab5ebb
permissions -rw-r--r--
Patched to compile on older GLX headers.
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
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     7
  arising from the use of this software.
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    11
  freely, subject to the following restrictions:
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5395
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#include "SDL_x11video.h"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* GLX implementation of SDL OpenGL support */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#if SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_loadso.h"
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 defined(__IRIX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
/* IRIX doesn't have a GL library versioning system */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#define DEFAULT_OPENGL	"libGL.so"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#elif defined(__MACOSX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#elif defined(__QNXNTO__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#define DEFAULT_OPENGL	"libGL.so.3"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#define DEFAULT_OPENGL	"libGL.so.1"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    41
#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
    42
#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
    43
#endif
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
    44
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
#ifndef GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#define GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
#define GLX_SAMPLE_BUFFERS_ARB             100000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
#define GLX_SAMPLES_ARB                    100001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
#ifndef GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
#define GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
#define GLX_VISUAL_CAVEAT_EXT              0x20
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
#define GLX_NONE_EXT                       0x8000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
#define GLX_SLOW_VISUAL_EXT                0x8001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
#define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    59
#ifndef GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    60
#define GLX_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    61
#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
    62
#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
    63
#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
    64
#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
    65
#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
    66
5573
7dd4caf23bf5 Patched to compile on older GLX headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 5572
diff changeset
    67
#ifndef GLX_EXT_swap_control
7dd4caf23bf5 Patched to compile on older GLX headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 5572
diff changeset
    68
#define GLX_SWAP_INTERVAL_EXT              0x20F1
7dd4caf23bf5 Patched to compile on older GLX headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 5572
diff changeset
    69
#define GLX_MAX_SWAP_INTERVAL_EXT          0x20F2
7dd4caf23bf5 Patched to compile on older GLX headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 5572
diff changeset
    70
#endif
7dd4caf23bf5 Patched to compile on older GLX headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 5572
diff changeset
    71
5021
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    72
/* 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
    73
typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    74
                                                        GLXFBConfig config,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    75
                                                        GLXContext
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    76
                                                        share_context,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    77
                                                        Bool direct,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    78
                                                        const int
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
    79
                                                        *attrib_list);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    80
#endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    81
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
#define OPENGL_REQUIRS_DLOPEN
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
#include <dlfcn.h>
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
#define GL_LoadFunction		dlsym
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
#define GL_UnloadObject		dlclose
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
#else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
#define GL_LoadObject	SDL_LoadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
#define GL_LoadFunction	SDL_LoadFunction
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
#define GL_UnloadObject	SDL_UnloadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
    94
static void X11_GL_InitExtensions(_THIS);
2322
c25d45b7add3 Fixing valgrind errors.
Bob Pendleton <bob@pendleton.com>
parents: 2320
diff changeset
    95
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    96
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
X11_GL_LoadLibrary(_THIS, const char *path)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    void *handle;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   102
    /* Load the OpenGL library */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   103
    if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   104
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   105
    }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   106
    if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   107
        path = DEFAULT_OPENGL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   108
    }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   109
    _this->gl_config.dll_handle = SDL_LoadObject(path);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   110
    if (!_this->gl_config.dll_handle) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   111
        return -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   113
    SDL_strlcpy(_this->gl_config.driver_path, path,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   114
                SDL_arraysize(_this->gl_config.driver_path));
2244
Sam Lantinga <slouken@libsdl.org>
parents: 2243
diff changeset
   115
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   116
    /* Allocate OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   117
    _this->gl_data =
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   118
        (struct SDL_GLDriverData *) SDL_calloc(1,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   119
                                               sizeof(struct
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   120
                                                      SDL_GLDriverData));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   121
    if (!_this->gl_data) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   122
        SDL_OutOfMemory();
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   123
        return -1;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   124
    }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   125
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   126
    /* Load function pointers */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   127
    handle = _this->gl_config.dll_handle;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    _this->gl_data->glXGetProcAddress =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   129
        (void *(*)(const GLubyte *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   130
            GL_LoadFunction(handle, "glXGetProcAddressARB");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    _this->gl_data->glXChooseVisual =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   132
        (XVisualInfo * (*)(Display *, int, int *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   133
            X11_GL_GetProcAddress(_this, "glXChooseVisual");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
    _this->gl_data->glXCreateContext =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
        (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   136
            X11_GL_GetProcAddress(_this, "glXCreateContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
    _this->gl_data->glXDestroyContext =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   138
        (void (*)(Display *, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   139
            X11_GL_GetProcAddress(_this, "glXDestroyContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    _this->gl_data->glXMakeCurrent =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   141
        (int (*)(Display *, GLXDrawable, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   142
            X11_GL_GetProcAddress(_this, "glXMakeCurrent");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    _this->gl_data->glXSwapBuffers =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   144
        (void (*)(Display *, GLXDrawable))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   145
            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
   146
    _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
   147
        (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
   148
            X11_GL_GetProcAddress(_this, "glXQueryDrawable");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    if (!_this->gl_data->glXChooseVisual ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
        !_this->gl_data->glXCreateContext ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
        !_this->gl_data->glXDestroyContext ||
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   153
        !_this->gl_data->glXMakeCurrent ||
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   154
        !_this->gl_data->glXSwapBuffers) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        SDL_SetError("Could not retrieve OpenGL functions");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
        return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   159
    /* Initialize extensions */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   160
    X11_GL_InitExtensions(_this);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   161
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    return 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
void *
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
X11_GL_GetProcAddress(_THIS, const char *proc)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    if (_this->gl_data->glXGetProcAddress) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
        return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    }
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   171
    return GL_LoadFunction(_this->gl_config.dll_handle, proc);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   174
void
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
X11_GL_UnloadLibrary(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   177
    /* 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
   178
     * X11 shutdown hooks, per the notes at:
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   179
     * http://dri.sourceforge.net/doc/DRIuserguide.html
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   180
     */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   181
#if 0
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   182
    GL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   183
    _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   184
#endif
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   185
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   186
    /* Free OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   187
    SDL_free(_this->gl_data);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   188
    _this->gl_data = NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
static SDL_bool
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
HasExtension(const char *extension, const char *extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
    const char *start;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
    const char *where, *terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    /* Extension names should not have spaces. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    where = SDL_strchr(extension, ' ');
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    if (where || *extension == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
        return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
    if (!extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
        return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
    /* 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
   206
     * OpenGL extensions string. Don't be fooled by sub-strings,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
     * etc. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    start = extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    for (;;) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
        where = SDL_strstr(start, extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        if (!where)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
            break;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
        terminator = where + SDL_strlen(extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
        if (where == start || *(where - 1) == ' ')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
            if (*terminator == ' ' || *terminator == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
                return SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
        start = terminator;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
    return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
static void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
X11_GL_InitExtensions(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
5244
762e40fb8e28 Be explicit about what display you're querying. The default display is 0.
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
   230
    int screen = DefaultScreen(display);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
    XSetWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    Window w;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
    GLXContext context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    const char *(*glXQueryExtensionsStringFunc) (Display *, int);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
    const char *extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
    vinfo = X11_GL_GetVisual(_this, display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
    if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
        return;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
    xattr.background_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    xattr.border_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
    xattr.colormap =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
        XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
                        AllocNone);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
    w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
                      vinfo->depth, InputOutput, vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
                      (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
    context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
    if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
        _this->gl_data->glXMakeCurrent(display, w, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
    XFree(vinfo);
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
    glXQueryExtensionsStringFunc =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
        (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
                                                                "glXQueryExtensionsString");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
    if (glXQueryExtensionsStringFunc) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
        extensions = glXQueryExtensionsStringFunc(display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
        extensions = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
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
   265
    /* Check for GLX_EXT_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
   266
    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
   267
        _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
   268
            (void (*)(Display*,GLXDrawable,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
   269
                X11_GL_GetProcAddress(_this, "glXSwapIntervalEXT");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
    /* Check for GLX_MESA_swap_control */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
    if (HasExtension("GLX_MESA_swap_control", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
        _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
   275
            (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
        _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
   277
            (int(*)(void)) X11_GL_GetProcAddress(_this,
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
                                                   "glXGetSwapIntervalMESA");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
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
   281
    /* 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
   282
    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
   283
        _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
   284
            (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
   285
    }
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   286
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    /* Check for GLX_EXT_visual_rating */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
    if (HasExtension("GLX_EXT_visual_rating", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
        _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
        _this->gl_data->glXMakeCurrent(display, None, NULL);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
        _this->gl_data->glXDestroyContext(display, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    XDestroyWindow(display, w);
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   297
    X11_PumpEvents(_this);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
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
   300
int 
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
   301
X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size)
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
{
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
   303
    int i = 0;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
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
   305
    /* assert buffer is large enough to hold all SDL attributes. */ 
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
   306
    /* assert(size >= 32);*/
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   307
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
    /* Setup our GLX attributes according to the gl_config. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
    attribs[i++] = GLX_RGBA;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    attribs[i++] = GLX_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    attribs[i++] = _this->gl_config.red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
    attribs[i++] = GLX_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    attribs[i++] = _this->gl_config.green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    attribs[i++] = GLX_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
    attribs[i++] = _this->gl_config.blue_size;
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
    if (_this->gl_config.alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
        attribs[i++] = GLX_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
        attribs[i++] = _this->gl_config.alpha_size;
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
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
    if (_this->gl_config.buffer_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
        attribs[i++] = GLX_BUFFER_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
        attribs[i++] = _this->gl_config.buffer_size;
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
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    if (_this->gl_config.double_buffer) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
        attribs[i++] = GLX_DOUBLEBUFFER;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    attribs[i++] = GLX_DEPTH_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
    attribs[i++] = _this->gl_config.depth_size;
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
    if (_this->gl_config.stencil_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
        attribs[i++] = GLX_STENCIL_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
        attribs[i++] = _this->gl_config.stencil_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    if (_this->gl_config.accum_red_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
        attribs[i++] = GLX_ACCUM_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
        attribs[i++] = _this->gl_config.accum_red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
    if (_this->gl_config.accum_green_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
        attribs[i++] = GLX_ACCUM_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
        attribs[i++] = _this->gl_config.accum_green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    if (_this->gl_config.accum_blue_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
        attribs[i++] = GLX_ACCUM_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
        attribs[i++] = _this->gl_config.accum_blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
    }
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
    if (_this->gl_config.accum_alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
        attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
        attribs[i++] = _this->gl_config.accum_alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
    if (_this->gl_config.stereo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
        attribs[i++] = GLX_STEREO;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
    if (_this->gl_config.multisamplebuffers) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
        attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
        attribs[i++] = _this->gl_config.multisamplebuffers;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
    if (_this->gl_config.multisamplesamples) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
        attribs[i++] = GLX_SAMPLES_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
        attribs[i++] = _this->gl_config.multisamplesamples;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
3571
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   373
    if (_this->gl_config.accelerated >= 0 &&
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   374
        _this->gl_data->HAS_GLX_EXT_visual_rating) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
        attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   376
        attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   377
                                                      GLX_SLOW_VISUAL_EXT;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
    }
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
   379
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
    attribs[i++] = None;
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   381
 
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
   382
    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
   383
}
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
   384
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
   385
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
   386
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
   387
{
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
   388
    XVisualInfo *vinfo;
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   389
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
   390
    /* 64 seems nice. */
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
   391
    int attribs[64];
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   392
    int i = X11_GL_GetAttributes(_this,display,screen,attribs,64);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
    vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
    if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
        SDL_SetError("Couldn't find matching GLX visual");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    return vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
SDL_GLContext
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
X11_GL_CreateContext(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
    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
   407
        ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
    XWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
    XVisualInfo v, *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
    int n;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    GLXContext context = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
1955
Sam Lantinga <slouken@libsdl.org>
parents: 1954
diff changeset
   413
    /* We do this to create a clean separation between X and GLX errors. */
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    XSync(display, False);
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3571
diff changeset
   415
    XGetWindowAttributes(display, data->xwindow, &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    v.screen = screen;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
    v.visualid = XVisualIDFromVisual(xattr.visual);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
    if (vinfo) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   420
        if (_this->gl_config.major_version < 3) {
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   421
            context =
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   422
                _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   423
        } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   424
            /* If we want a GL 3.0 context or later we need to get a temporary
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   425
               context to grab the new context creation function */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   426
            GLXContext temp_context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   427
                _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   428
            if (!temp_context) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   429
                SDL_SetError("Could not create GL context");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   430
                return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   431
            } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   432
                int attribs[] = {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   433
                    GLX_CONTEXT_MAJOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   434
                    _this->gl_config.major_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   435
                    GLX_CONTEXT_MINOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   436
                    _this->gl_config.minor_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   437
                    0
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   438
                };
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   439
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   440
                /* Get a pointer to the context creation function for GL 3.0 */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   441
                PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   442
                    (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   443
                    glXGetProcAddress((GLubyte *)
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   444
                                      "glXCreateContextAttribsARB");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   445
                if (!glXCreateContextAttribs) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   446
                    SDL_SetError("GL 3.x is not supported");
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   447
                    context = temp_context;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   448
                } else {
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   449
                    int glxAttribs[64];
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   450
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   451
                    /* Create a GL 3.x context */
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   452
                    GLXFBConfig *framebuffer_config = NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   453
                    int fbcount = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   454
                    GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   455
                                                       int screen,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   456
                                                       const int *attrib_list,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   457
                                                       int *nelements);
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   458
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   459
                    glXChooseFBConfig =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   460
                        (GLXFBConfig *
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   461
                         (*)(Display *, int, const int *,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   462
                             int *)) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   463
                        glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   464
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
   465
                    X11_GL_GetAttributes(_this,display,screen,glxAttribs,64);
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   466
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   467
                    if (!glXChooseFBConfig
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   468
                        || !(framebuffer_config =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   469
                             glXChooseFBConfig(display,
5395
f0e399961f3a Fixed bug 1145 (GL Context creation fails for OpenGL 3.2 + Alpha buffer with X11 BadMatch)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   470
                                               DefaultScreen(display), glxAttribs,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   471
                                               &fbcount))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   472
                        SDL_SetError
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   473
                            ("No good framebuffers found. GL 3.x disabled");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   474
                        context = temp_context;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   475
                    } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   476
                        context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   477
                            glXCreateContextAttribs(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   478
                                                    framebuffer_config[0],
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   479
                                                    NULL, True, attribs);
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   480
                        _this->gl_data->glXDestroyContext(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   481
                                                          temp_context);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   482
                    }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   483
                }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   484
            }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   485
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
        XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
    XSync(display, False);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
    if (!context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
        SDL_SetError("Could not create GL context");
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   492
        return NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
    }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   494
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   495
    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
   496
        X11_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   497
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   498
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   499
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
   500
    return context;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
    Window drawable =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3571
diff changeset
   508
        (window ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
    GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
    int status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
    status = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
    if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
        SDL_SetError("Unable to make GL context current");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
        status = -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
    XSync(display, False);
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 (status);
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
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
   522
/* 
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
   523
   0 is a valid argument to glxSwapInterval(MESA|EXT) and setting it to 0
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   524
   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
   525
   than zero (or at least that is what the docs say). OTOH, 0 is an invalid
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   526
   argument to glxSwapIntervalSGI and it returns an error if you call it
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   527
   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
   528
*/
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
   529
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
   530
static int swapinterval = -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
X11_GL_SetSwapInterval(_THIS, int interval)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
    int status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
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
   536
    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
   537
        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
   538
        const SDL_WindowData *windowdata = (SDL_WindowData *)
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   539
            _this->current_glwin->driverdata;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   540
        Window drawable = windowdata->xwindow;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   541
        _this->gl_data->glXSwapIntervalEXT(display, drawable, interval);
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   542
        status = 0;  /* always succeeds, apparently. */
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   543
        swapinterval = interval;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   544
    } else if (_this->gl_data->glXSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
        status = _this->gl_data->glXSwapIntervalMESA(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
        if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
            SDL_SetError("glxSwapIntervalMESA failed");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
            status = -1;
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
   549
        } 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
   550
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
    } else if (_this->gl_data->glXSwapIntervalSGI) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
        status = _this->gl_data->glXSwapIntervalSGI(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
        if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
            SDL_SetError("glxSwapIntervalSGI failed");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
            status = -1;
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
   557
        } 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
   558
            swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
    } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
        SDL_Unsupported();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
        status = -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
    return status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
X11_GL_GetSwapInterval(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
{
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
   570
    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
   571
        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
   572
        const SDL_WindowData *windowdata = (SDL_WindowData *)
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   573
            _this->current_glwin->driverdata;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   574
        Window drawable = windowdata->xwindow;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   575
        unsigned int value = 0;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   576
        _this->gl_data->glXQueryDrawable(display, drawable,
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   577
                                         GLX_SWAP_INTERVAL_EXT, &value);
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   578
        return (int) value;
32a785da3f49 Added support for GLX_EXT_swap_control, and cleaned up some other extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   579
    } else if (_this->gl_data->glXGetSwapIntervalMESA) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
        return _this->gl_data->glXGetSwapIntervalMESA();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
    } 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
   582
        return swapinterval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
X11_GL_SwapWindow(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
    Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
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
   592
    _this->gl_data->glXSwapBuffers(display, data->xwindow);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
X11_GL_DeleteContext(_THIS, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
{
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
    GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
    _this->gl_data->glXDestroyContext(display, glx_context);
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   602
    XSync(display, False);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
}
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
#endif /* SDL_VIDEO_OPENGL_GLX */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
/* vi: set ts=4 sw=4 expandtab: */