Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11opengl.c @ 3249:2befcf0c5ce0
Fix build on native 64-bit architecture
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Sep 2009 14:22:12 +0000 |
parents | 08c5964f2a34 |
children | d559edc85610 |
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 |
2859 | 3 Copyright (C) 1997-2009 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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with _this library; if not, write to the Free Software |
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 |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
67 #endif |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
68 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 #define OPENGL_REQUIRS_DLOPEN |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 #if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 #include <dlfcn.h> |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 #define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL)) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 #define GL_LoadFunction dlsym |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 #define GL_UnloadObject dlclose |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 #else |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 #define GL_LoadObject SDL_LoadObject |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 #define GL_LoadFunction SDL_LoadFunction |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 #define GL_UnloadObject SDL_UnloadObject |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
81 static void X11_GL_InitExtensions(_THIS); |
2322 | 82 |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
83 /* Typedef for the GL 3.0 context creation function */ |
3139 | 84 typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy, |
85 GLXFBConfig config, | |
86 GLXContext | |
87 share_context, | |
88 Bool direct, | |
89 const int | |
90 *attrib_list); | |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
91 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 X11_GL_LoadLibrary(_THIS, const char *path) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 void *handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
97 /* Load the OpenGL library */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
98 if (path == NULL) { |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
99 path = SDL_getenv("SDL_OPENGL_LIBRARY"); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
100 } |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
101 if (path == NULL) { |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
102 path = DEFAULT_OPENGL; |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
103 } |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
104 _this->gl_config.dll_handle = SDL_LoadObject(path); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
105 if (!_this->gl_config.dll_handle) { |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
106 return -1; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
108 SDL_strlcpy(_this->gl_config.driver_path, path, |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
109 SDL_arraysize(_this->gl_config.driver_path)); |
2244 | 110 |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
111 /* Allocate OpenGL memory */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
112 _this->gl_data = |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
113 (struct SDL_GLDriverData *) SDL_calloc(1, |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
114 sizeof(struct |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
115 SDL_GLDriverData)); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
116 if (!_this->gl_data) { |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
117 SDL_OutOfMemory(); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
118 return -1; |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
119 } |
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 /* Load function pointers */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
122 handle = _this->gl_config.dll_handle; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 _this->gl_data->glXGetProcAddress = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 (void *(*)(const GLubyte *)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 "glXGetProcAddressARB"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 _this->gl_data->glXChooseVisual = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 (XVisualInfo * (*)(Display *, int, int *)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 "glXChooseVisual"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 _this->gl_data->glXCreateContext = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int)) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 GL_LoadFunction(handle, "glXCreateContext"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 _this->gl_data->glXDestroyContext = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 (void (*)(Display *, GLXContext)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 "glXDestroyContext"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 _this->gl_data->glXMakeCurrent = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 (int (*)(Display *, GLXDrawable, GLXContext)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 "glXMakeCurrent"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 _this->gl_data->glXSwapBuffers = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 (void (*)(Display *, GLXDrawable)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 "glXSwapBuffers"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 if (!_this->gl_data->glXChooseVisual || |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 !_this->gl_data->glXCreateContext || |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 !_this->gl_data->glXDestroyContext || |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1955
diff
changeset
|
145 !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 SDL_SetError("Could not retrieve OpenGL functions"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 return -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
150 /* Initialize extensions */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
151 X11_GL_InitExtensions(_this); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
152 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 return 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 void * |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 X11_GL_GetProcAddress(_THIS, const char *proc) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 void *handle; |
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 handle = _this->gl_config.dll_handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 if (_this->gl_data->glXGetProcAddress) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 return _this->gl_data->glXGetProcAddress((const GLubyte *) proc); |
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 return GL_LoadFunction(handle, proc); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
168 void |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 X11_GL_UnloadLibrary(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 { |
3057
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
171 /* 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
|
172 * X11 shutdown hooks, per the notes at: |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
173 * http://dri.sourceforge.net/doc/DRIuserguide.html |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
174 */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
175 #if 0 |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
176 GL_UnloadObject(_this->gl_config.dll_handle); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
177 _this->gl_config.dll_handle = NULL; |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
178 #endif |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
179 |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
180 /* Free OpenGL memory */ |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
181 SDL_free(_this->gl_data); |
089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents:
3013
diff
changeset
|
182 _this->gl_data = NULL; |
1952
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 static SDL_bool |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 HasExtension(const char *extension, const char *extensions) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 const char *start; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 const char *where, *terminator; |
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 /* Extension names should not have spaces. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 where = SDL_strchr(extension, ' '); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 if (where || *extension == '\0') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 return SDL_FALSE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 if (!extensions) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 return SDL_FALSE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 /* 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
|
200 * OpenGL extensions string. Don't be fooled by sub-strings, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 * etc. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 start = extensions; |
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 for (;;) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 where = SDL_strstr(start, extension); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 if (!where) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 break; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 terminator = where + SDL_strlen(extension); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 if (where == start || *(where - 1) == ' ') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 if (*terminator == ' ' || *terminator == '\0') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 return SDL_TRUE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 start = terminator; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 return SDL_FALSE; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 static void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 X11_GL_InitExtensions(_THIS) |
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 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 int screen = ((SDL_DisplayData *) SDL_CurrentDisplay.driverdata)->screen; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 XVisualInfo *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 XSetWindowAttributes xattr; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 Window w; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 GLXContext context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 const char *(*glXQueryExtensionsStringFunc) (Display *, int); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 const char *extensions; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 vinfo = X11_GL_GetVisual(_this, display, screen); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 if (!vinfo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 return; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 xattr.background_pixel = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 xattr.border_pixel = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 xattr.colormap = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 XCreateColormap(display, RootWindow(display, screen), vinfo->visual, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 AllocNone); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 vinfo->depth, InputOutput, vinfo->visual, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 (CWBackPixel | CWBorderPixel | CWColormap), &xattr); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 if (context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 _this->gl_data->glXMakeCurrent(display, w, context); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 XFree(vinfo); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 glXQueryExtensionsStringFunc = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 "glXQueryExtensionsString"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 if (glXQueryExtensionsStringFunc) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 extensions = glXQueryExtensionsStringFunc(display, screen); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 extensions = NULL; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 /* 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
|
260 if (HasExtension("GLX_SGI_swap_control", extensions)) { |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 _this->gl_data->glXSwapIntervalSGI = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI"); |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 /* Check for GLX_MESA_swap_control */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 if (HasExtension("GLX_MESA_swap_control", extensions)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 _this->gl_data->glXSwapIntervalMESA = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 (GLint(*)(unsigned)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 "glXSwapIntervalMESA"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 _this->gl_data->glXGetSwapIntervalMESA = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 (GLint(*)(void)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 "glXGetSwapIntervalMESA"); |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 /* Check for GLX_EXT_visual_rating */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 if (HasExtension("GLX_EXT_visual_rating", extensions)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 if (context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 _this->gl_data->glXMakeCurrent(display, None, NULL); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 _this->gl_data->glXDestroyContext(display, context); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 XDestroyWindow(display, w); |
2323
4ac07ae446d3
Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents:
2322
diff
changeset
|
285 X11_PumpEvents(_this); |
1952
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 XVisualInfo * |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 X11_GL_GetVisual(_THIS, Display * display, int screen) |
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 XVisualInfo *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 /* 64 seems nice. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 int attribs[64]; |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
295 int i = 0; |
3139 | 296 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 /* Setup our GLX attributes according to the gl_config. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 attribs[i++] = GLX_RGBA; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 attribs[i++] = GLX_RED_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 attribs[i++] = _this->gl_config.red_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 attribs[i++] = GLX_GREEN_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 attribs[i++] = _this->gl_config.green_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 attribs[i++] = GLX_BLUE_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 attribs[i++] = _this->gl_config.blue_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 if (_this->gl_config.alpha_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 attribs[i++] = GLX_ALPHA_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 attribs[i++] = _this->gl_config.alpha_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 if (_this->gl_config.buffer_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 attribs[i++] = GLX_BUFFER_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 attribs[i++] = _this->gl_config.buffer_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 if (_this->gl_config.double_buffer) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 attribs[i++] = GLX_DOUBLEBUFFER; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 attribs[i++] = GLX_DEPTH_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 attribs[i++] = _this->gl_config.depth_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 if (_this->gl_config.stencil_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 attribs[i++] = GLX_STENCIL_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 attribs[i++] = _this->gl_config.stencil_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 if (_this->gl_config.accum_red_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 attribs[i++] = GLX_ACCUM_RED_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 attribs[i++] = _this->gl_config.accum_red_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 if (_this->gl_config.accum_green_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 attribs[i++] = _this->gl_config.accum_green_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 if (_this->gl_config.accum_blue_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 attribs[i++] = _this->gl_config.accum_blue_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 if (_this->gl_config.accum_alpha_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 attribs[i++] = _this->gl_config.accum_alpha_size; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 if (_this->gl_config.stereo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 attribs[i++] = GLX_STEREO; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 if (_this->gl_config.multisamplebuffers) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 attribs[i++] = _this->gl_config.multisamplebuffers; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 if (_this->gl_config.multisamplesamples) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 attribs[i++] = GLX_SAMPLES_ARB; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 attribs[i++] = _this->gl_config.multisamplesamples; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 } |
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 if (_this->gl_config.accelerated >= 0 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 && _this->gl_data->HAS_GLX_EXT_visual_rating) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 attribs[i++] = GLX_VISUAL_CAVEAT_EXT; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 attribs[i++] = GLX_NONE_EXT; |
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 #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
|
368 if (X11_UseDirectColorVisuals()) { |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 attribs[i++] = GLX_X_VISUAL_TYPE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 attribs[i++] = GLX_DIRECT_COLOR; |
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 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 attribs[i++] = None; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 #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
|
377 if (!vinfo && X11_UseDirectColorVisuals()) { /* No DirectColor visual? Try again.. */ |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 attribs[i - 3] = None; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 if (!vinfo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 SDL_SetError("Couldn't find matching GLX visual"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 return vinfo; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 SDL_GLContext |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 X11_GL_CreateContext(_THIS, SDL_Window * window) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 Display *display = data->videodata->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 int screen = |
3013
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
394 ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)-> |
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
395 driverdata)->screen; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 XWindowAttributes xattr; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 XVisualInfo v, *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 int n; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 GLXContext context = NULL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 |
1955 | 401 /* 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
|
402 XSync(display, False); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 XGetWindowAttributes(display, data->window, &xattr); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 v.screen = screen; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 v.visualid = XVisualIDFromVisual(xattr.visual); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 if (vinfo) { |
3139 | 408 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
|
409 context = |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
410 _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
|
411 } else { |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
412 /* 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
|
413 context to grab the new context creation function */ |
3139 | 414 GLXContext temp_context = |
415 _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
|
416 if (!temp_context) { |
3139 | 417 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
|
418 return NULL; |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
419 } else { |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
420 int attribs[] = { |
3139 | 421 GLX_CONTEXT_MAJOR_VERSION_ARB, |
422 _this->gl_config.major_version, | |
423 GLX_CONTEXT_MINOR_VERSION_ARB, | |
424 _this->gl_config.minor_version, | |
425 0 | |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
426 }; |
3139 | 427 |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
428 /* Get a pointer to the context creation function for GL 3.0 */ |
3139 | 429 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = |
430 (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data-> | |
431 glXGetProcAddress((GLubyte *) | |
432 "glXCreateContextAttribsARB"); | |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
433 if (!glXCreateContextAttribs) { |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
434 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
|
435 context = temp_context; |
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
436 } else { |
3105 | 437 /* 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
|
438 GLXFBConfig *framebuffer_config = NULL; |
3139 | 439 int fbcount = 0; |
440 GLXFBConfig *(*glXChooseFBConfig) (Display * disp, | |
441 int screen, | |
442 const int *attrib_list, | |
443 int *nelements); | |
3105 | 444 |
3139 | 445 glXChooseFBConfig = |
446 (GLXFBConfig * | |
447 (*)(Display *, int, const int *, | |
448 int *)) _this->gl_data-> | |
449 glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); | |
3105 | 450 |
3139 | 451 if (!glXChooseFBConfig |
452 || !(framebuffer_config = | |
453 glXChooseFBConfig(display, | |
454 DefaultScreen(display), NULL, | |
455 &fbcount))) { | |
456 SDL_SetError | |
457 ("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
|
458 context = temp_context; |
3139 | 459 } else { |
460 context = | |
461 glXCreateContextAttribs(display, | |
462 framebuffer_config[0], | |
463 NULL, True, attribs); | |
464 _this->gl_data->glXDestroyContext(display, | |
465 temp_context); | |
3100
7dc982143c06
Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
3057
diff
changeset
|
466 } |
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 } |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 XFree(vinfo); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 XSync(display, False); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 if (!context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 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
|
476 return NULL; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 } |
2178
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
478 |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
479 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
|
480 X11_GL_DeleteContext(_this, context); |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
481 return NULL; |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
482 } |
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 return context; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 } |
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 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) |
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 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 Window drawable = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 (window ? ((SDL_WindowData *) window->driverdata)->window : None); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 GLXContext glx_context = (GLXContext) context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 int status; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 status = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 SDL_SetError("Unable to make GL context current"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 status = -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 XSync(display, False); |
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 return (status); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 |
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
|
506 /* |
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 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 */ |
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 static int swapinterval = -1; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 X11_GL_SetSwapInterval(_THIS, int interval) |
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 int 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 if (_this->gl_data->glXSwapIntervalMESA) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 status = _this->gl_data->glXSwapIntervalMESA(interval); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
523 if (status != 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 SDL_SetError("glxSwapIntervalMESA failed"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
525 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
|
526 } 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
|
527 swapinterval = interval; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
528 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
529 } else if (_this->gl_data->glXSwapIntervalSGI) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
530 status = _this->gl_data->glXSwapIntervalSGI(interval); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 if (status != 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 SDL_SetError("glxSwapIntervalSGI failed"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 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
|
534 } 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
|
535 swapinterval = interval; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
538 SDL_Unsupported(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 status = -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 return status; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 } |
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 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 X11_GL_GetSwapInterval(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 if (_this->gl_data->glXGetSwapIntervalMESA) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 return _this->gl_data->glXGetSwapIntervalMESA(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 } 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
|
550 return swapinterval; |
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 } |
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 void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 X11_GL_SwapWindow(_THIS, SDL_Window * window) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
558 Display *display = data->videodata->display; |
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 _this->gl_data->glXSwapBuffers(display, data->window); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
561 } |
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 void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 X11_GL_DeleteContext(_THIS, SDL_GLContext context) |
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 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 GLXContext glx_context = (GLXContext) context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
568 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 _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
|
570 XSync(display, False); |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 } |
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 #endif /* SDL_VIDEO_OPENGL_GLX */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 /* vi: set ts=4 sw=4 expandtab: */ |