annotate src/video/x11/SDL_x11opengl.c @ 5198:bb45ecd958d8

Renamed files for consistency
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Feb 2011 12:01:11 -0800
parents cd3a1d87cab7
children 3a8a452b49f0
rev   line source
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
3361
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
16 License along with this library; if not, write to the Free Software
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_x11video.h"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* GLX implementation of SDL OpenGL support */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #if SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "SDL_loadso.h"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #if defined(__IRIX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 /* IRIX doesn't have a GL library versioning system */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #define DEFAULT_OPENGL "libGL.so"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #elif defined(__MACOSX__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #define DEFAULT_OPENGL "/usr/X11R6/lib/libGL.1.dylib"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #elif defined(__QNXNTO__)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #define DEFAULT_OPENGL "libGL.so.3"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #define DEFAULT_OPENGL "libGL.so.1"
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
42 #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
43 #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
44 #endif
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
45
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #ifndef GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #define GLX_ARB_multisample
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define GLX_SAMPLE_BUFFERS_ARB 100000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #define GLX_SAMPLES_ARB 100001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #ifndef GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #define GLX_EXT_visual_rating
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 #define GLX_VISUAL_CAVEAT_EXT 0x20
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 #define GLX_NONE_EXT 0x8000
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 #define GLX_SLOW_VISUAL_EXT 0x8001
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 #endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
60 #ifndef 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_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
62 #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
63 #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
64 #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
65 #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
66 #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
67
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
68 /* 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
69 typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
70 GLXFBConfig config,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
71 GLXContext
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
72 share_context,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
73 Bool direct,
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
74 const int
cd3a1d87cab7 Fixed build against 10.4 SDK
Sam Lantinga <slouken@libsdl.org>
parents: 5020
diff changeset
75 *attrib_list);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
76 #endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
77
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 #define OPENGL_REQUIRS_DLOPEN
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 #if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 #include <dlfcn.h>
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 #define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 #define GL_LoadFunction dlsym
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #define GL_UnloadObject dlclose
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 #else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 #define GL_LoadObject SDL_LoadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 #define GL_LoadFunction SDL_LoadFunction
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #define GL_UnloadObject SDL_UnloadObject
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 #endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
90 static void X11_GL_InitExtensions(_THIS);
2322
c25d45b7add3 Fixing valgrind errors.
Bob Pendleton <bob@pendleton.com>
parents: 2320
diff changeset
91
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
92
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 X11_GL_LoadLibrary(_THIS, const char *path)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 void *handle;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
98 /* Load the OpenGL library */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
99 if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
100 path = SDL_getenv("SDL_OPENGL_LIBRARY");
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
101 }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
102 if (path == NULL) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
103 path = DEFAULT_OPENGL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
104 }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
105 _this->gl_config.dll_handle = SDL_LoadObject(path);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
106 if (!_this->gl_config.dll_handle) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
107 return -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
109 SDL_strlcpy(_this->gl_config.driver_path, path,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
110 SDL_arraysize(_this->gl_config.driver_path));
2244
Sam Lantinga <slouken@libsdl.org>
parents: 2243
diff changeset
111
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
112 /* Allocate OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
113 _this->gl_data =
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
114 (struct SDL_GLDriverData *) SDL_calloc(1,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
115 sizeof(struct
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
116 SDL_GLDriverData));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
117 if (!_this->gl_data) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
118 SDL_OutOfMemory();
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
119 return -1;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
120 }
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
121
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
122 /* Load function pointers */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
123 handle = _this->gl_config.dll_handle;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 _this->gl_data->glXGetProcAddress =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
125 (void *(*)(const GLubyte *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
126 GL_LoadFunction(handle, "glXGetProcAddressARB");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 _this->gl_data->glXChooseVisual =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
128 (XVisualInfo * (*)(Display *, int, int *))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
129 X11_GL_GetProcAddress(_this, "glXChooseVisual");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 _this->gl_data->glXCreateContext =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
132 X11_GL_GetProcAddress(_this, "glXCreateContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 _this->gl_data->glXDestroyContext =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
134 (void (*)(Display *, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
135 X11_GL_GetProcAddress(_this, "glXDestroyContext");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 _this->gl_data->glXMakeCurrent =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
137 (int (*)(Display *, GLXDrawable, GLXContext))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
138 X11_GL_GetProcAddress(_this, "glXMakeCurrent");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 _this->gl_data->glXSwapBuffers =
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
140 (void (*)(Display *, GLXDrawable))
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
141 X11_GL_GetProcAddress(_this, "glXSwapBuffers");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 if (!_this->gl_data->glXChooseVisual ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 !_this->gl_data->glXCreateContext ||
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 !_this->gl_data->glXDestroyContext ||
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
146 !_this->gl_data->glXMakeCurrent ||
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
147 !_this->gl_data->glXSwapBuffers) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 SDL_SetError("Could not retrieve OpenGL functions");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
152 /* Initialize extensions */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
153 X11_GL_InitExtensions(_this);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
154
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 return 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 }
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 void *
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 X11_GL_GetProcAddress(_THIS, const char *proc)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 if (_this->gl_data->glXGetProcAddress) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 }
4550
e4e462f591d7 Fixed bug 1006
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
164 return GL_LoadFunction(_this->gl_config.dll_handle, proc);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
167 void
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 X11_GL_UnloadLibrary(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 {
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
170 /* 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
171 * X11 shutdown hooks, per the notes at:
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
172 * http://dri.sourceforge.net/doc/DRIuserguide.html
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
173 */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
174 #if 0
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
175 GL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
176 _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
177 #endif
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
178
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
179 /* Free OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
180 SDL_free(_this->gl_data);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
181 _this->gl_data = NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 static SDL_bool
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 HasExtension(const char *extension, const char *extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 const char *start;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 const char *where, *terminator;
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 /* Extension names should not have spaces. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 where = SDL_strchr(extension, ' ');
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 if (where || *extension == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 if (!extensions)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 /* 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
199 * OpenGL extensions string. Don't be fooled by sub-strings,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 * etc. */
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 start = extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 for (;;) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 where = SDL_strstr(start, extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if (!where)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 break;
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 terminator = where + SDL_strlen(extension);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 if (where == start || *(where - 1) == ' ')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 if (*terminator == ' ' || *terminator == '\0')
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 return SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 start = terminator;
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 return SDL_FALSE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 static void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 X11_GL_InitExtensions(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 Display *display = ((SDL_VideoData *) _this->driverdata)->display;
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
223 int screen = ((SDL_DisplayData *) SDL_CurrentDisplay->driverdata)->screen;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 XSetWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 Window w;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 GLXContext context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 const char *(*glXQueryExtensionsStringFunc) (Display *, int);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 const char *extensions;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 vinfo = X11_GL_GetVisual(_this, display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 return;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 xattr.background_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 xattr.border_pixel = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 xattr.colormap =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 AllocNone);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 vinfo->depth, InputOutput, vinfo->visual,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 _this->gl_data->glXMakeCurrent(display, w, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 glXQueryExtensionsStringFunc =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 "glXQueryExtensionsString");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 if (glXQueryExtensionsStringFunc) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 extensions = glXQueryExtensionsStringFunc(display, screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 extensions = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 /* Check for SGI_swap_control */
2105
12bcd4fd2606 Date: Wed, 23 May 2007 00:39:47 +0300
Ryan C. Gordon <icculus@icculus.org>
parents: 1956
diff changeset
259 if (HasExtension("GLX_SGI_swap_control", extensions)) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 _this->gl_data->glXSwapIntervalSGI =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 }
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 /* Check for GLX_MESA_swap_control */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 if (HasExtension("GLX_MESA_swap_control", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 _this->gl_data->glXSwapIntervalMESA =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 (GLint(*)(unsigned)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 "glXSwapIntervalMESA");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 _this->gl_data->glXGetSwapIntervalMESA =
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 (GLint(*)(void)) X11_GL_GetProcAddress(_this,
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 "glXGetSwapIntervalMESA");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 /* Check for GLX_EXT_visual_rating */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 if (HasExtension("GLX_EXT_visual_rating", extensions)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 if (context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 _this->gl_data->glXMakeCurrent(display, None, NULL);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 _this->gl_data->glXDestroyContext(display, context);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 XDestroyWindow(display, w);
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
284 X11_PumpEvents(_this);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 XVisualInfo *
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 X11_GL_GetVisual(_THIS, Display * display, int screen)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 XVisualInfo *vinfo;
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 /* 64 seems nice. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 int attribs[64];
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
294 int i = 0;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
295
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 /* Setup our GLX attributes according to the gl_config. */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 attribs[i++] = GLX_RGBA;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 attribs[i++] = GLX_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 attribs[i++] = _this->gl_config.red_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 attribs[i++] = GLX_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 attribs[i++] = _this->gl_config.green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 attribs[i++] = GLX_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 attribs[i++] = _this->gl_config.blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 if (_this->gl_config.alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 attribs[i++] = GLX_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 attribs[i++] = _this->gl_config.alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 if (_this->gl_config.buffer_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 attribs[i++] = GLX_BUFFER_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 attribs[i++] = _this->gl_config.buffer_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 if (_this->gl_config.double_buffer) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 attribs[i++] = GLX_DOUBLEBUFFER;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 attribs[i++] = GLX_DEPTH_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 attribs[i++] = _this->gl_config.depth_size;
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.stencil_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 attribs[i++] = GLX_STENCIL_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 attribs[i++] = _this->gl_config.stencil_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.accum_red_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 attribs[i++] = GLX_ACCUM_RED_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 attribs[i++] = _this->gl_config.accum_red_size;
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
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 if (_this->gl_config.accum_green_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 attribs[i++] = GLX_ACCUM_GREEN_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 attribs[i++] = _this->gl_config.accum_green_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 if (_this->gl_config.accum_blue_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 attribs[i++] = GLX_ACCUM_BLUE_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 attribs[i++] = _this->gl_config.accum_blue_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 if (_this->gl_config.accum_alpha_size) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 attribs[i++] = _this->gl_config.accum_alpha_size;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 if (_this->gl_config.stereo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 attribs[i++] = GLX_STEREO;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 if (_this->gl_config.multisamplebuffers) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 attribs[i++] = _this->gl_config.multisamplebuffers;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 if (_this->gl_config.multisamplesamples) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 attribs[i++] = GLX_SAMPLES_ARB;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 attribs[i++] = _this->gl_config.multisamplesamples;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360
3571
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
361 if (_this->gl_config.accelerated >= 0 &&
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
362 _this->gl_data->HAS_GLX_EXT_visual_rating) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
364 attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
365 GLX_SLOW_VISUAL_EXT;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 }
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
367
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
2963
ee331407574f Don't use DirectColor visuals until we implement DirectColor colormap support
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
369 if (X11_UseDirectColorVisuals()) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 attribs[i++] = GLX_X_VISUAL_TYPE;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 attribs[i++] = GLX_DIRECT_COLOR;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 #endif
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3361
diff changeset
374
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 attribs[i++] = None;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 #ifdef GLX_DIRECT_COLOR
2963
ee331407574f Don't use DirectColor visuals until we implement DirectColor colormap support
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
379 if (!vinfo && X11_UseDirectColorVisuals()) { /* No DirectColor visual? Try again.. */
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 attribs[i - 3] = None;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 #endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 SDL_SetError("Couldn't find matching GLX visual");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 return vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 SDL_GLContext
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 X11_GL_CreateContext(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 int screen =
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
396 ((SDL_DisplayData *) window->display->driverdata)->screen;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 XWindowAttributes xattr;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 XVisualInfo v, *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 int n;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 GLXContext context = NULL;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401
1955
Sam Lantinga <slouken@libsdl.org>
parents: 1954
diff changeset
402 /* 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
403 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
404 XGetWindowAttributes(display, data->xwindow, &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 v.screen = screen;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 v.visualid = XVisualIDFromVisual(xattr.visual);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 if (vinfo) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
409 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
410 context =
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
411 _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
412 } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
413 /* 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
414 context to grab the new context creation function */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
415 GLXContext temp_context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
416 _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
417 if (!temp_context) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
418 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
419 return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
420 } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
421 int attribs[] = {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
422 GLX_CONTEXT_MAJOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
423 _this->gl_config.major_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
424 GLX_CONTEXT_MINOR_VERSION_ARB,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
425 _this->gl_config.minor_version,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
426 0
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
427 };
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
428
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
429 /* Get a pointer to the context creation function for GL 3.0 */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
430 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
431 (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
432 glXGetProcAddress((GLubyte *)
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
433 "glXCreateContextAttribsARB");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
434 if (!glXCreateContextAttribs) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
435 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
436 context = temp_context;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
437 } else {
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
438 /* 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
439 GLXFBConfig *framebuffer_config = NULL;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
440 int fbcount = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
441 GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
442 int screen,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
443 const int *attrib_list,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
444 int *nelements);
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
445
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
446 glXChooseFBConfig =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
447 (GLXFBConfig *
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
448 (*)(Display *, int, const int *,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
449 int *)) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
450 glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
451
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
452 if (!glXChooseFBConfig
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
453 || !(framebuffer_config =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
454 glXChooseFBConfig(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
455 DefaultScreen(display), NULL,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
456 &fbcount))) {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
457 SDL_SetError
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
458 ("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
459 context = temp_context;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
460 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
461 context =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
462 glXCreateContextAttribs(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
463 framebuffer_config[0],
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
464 NULL, True, attribs);
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
465 _this->gl_data->glXDestroyContext(display,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
466 temp_context);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
467 }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
468 }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
469 }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
470 }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 XSync(display, False);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 if (!context) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 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
477 return NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
479
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
480 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
481 X11_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
482 return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
483 }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
484
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2105
diff changeset
485 return context;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 }
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 int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 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
493 (window ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 int status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 status = 0;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 SDL_SetError("Unable to make GL context current");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 status = -1;
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 XSync(display, False);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 return (status);
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
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
507 /*
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
508 0 is a valid argument to glxSwapIntervalMESA and setting it to 0
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
509 with the MESA version of the extension will undo the effect of a
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
510 previous call with a value that is greater than zero (or at least
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
511 that is what the FM says. OTOH, 0 is an invalid argument to
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
512 glxSwapIntervalSGI and it returns an error if you call it with 0 as
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
513 an argument.
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
514 */
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
515
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
516 static int swapinterval = -1;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 X11_GL_SetSwapInterval(_THIS, int interval)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 int status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 if (_this->gl_data->glXSwapIntervalMESA) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 status = _this->gl_data->glXSwapIntervalMESA(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 SDL_SetError("glxSwapIntervalMESA failed");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 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
527 } 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
528 swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 } else if (_this->gl_data->glXSwapIntervalSGI) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 status = _this->gl_data->glXSwapIntervalSGI(interval);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 if (status != 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 SDL_SetError("glxSwapIntervalSGI failed");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 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
535 } 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
536 swapinterval = interval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 } else {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 SDL_Unsupported();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 status = -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 return status;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 int
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 X11_GL_GetSwapInterval(_THIS)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 if (_this->gl_data->glXGetSwapIntervalMESA) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 return _this->gl_data->glXGetSwapIntervalMESA();
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 } 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
551 return swapinterval;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 X11_GL_SwapWindow(_THIS, SDL_Window * window)
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 Display *display = data->videodata->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560
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
561 _this->gl_data->glXSwapBuffers(display, data->xwindow);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 void
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 X11_GL_DeleteContext(_THIS, SDL_GLContext context)
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 Display *display = ((SDL_VideoData *) _this->driverdata)->display;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 GLXContext glx_context = (GLXContext) context;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 _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
571 XSync(display, False);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 #endif /* SDL_VIDEO_OPENGL_GLX */
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 /* vi: set ts=4 sw=4 expandtab: */