Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11opengl.c @ 2243:5523312f311e
Date: Wed, 15 Aug 2007 01:08:38 +0200
From: Couriersud
Subject: Some SDL1.3 patches
LoadLibrary will call X11_GL_Initialize. If LoadLibrary is called before
a window is created, it will crash since structures are not properly set
up.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 15 Aug 2007 03:34:14 +0000 |
parents | 114a541cfae2 |
children | 5234868559fa |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 #ifndef GLX_ARB_multisample |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 #define GLX_ARB_multisample |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 #define GLX_SAMPLE_BUFFERS_ARB 100000 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 #define GLX_SAMPLES_ARB 100001 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 #ifndef GLX_EXT_visual_rating |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 #define GLX_EXT_visual_rating |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 #define GLX_VISUAL_CAVEAT_EXT 0x20 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 #define GLX_NONE_EXT 0x8000 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 #define GLX_SLOW_VISUAL_EXT 0x8001 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 #define OPENGL_REQUIRS_DLOPEN |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 #if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 #include <dlfcn.h> |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 #define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL)) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 #define GL_LoadFunction dlsym |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 #define GL_UnloadObject dlclose |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 #else |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 #define GL_LoadObject SDL_LoadObject |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 #define GL_LoadFunction SDL_LoadFunction |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 #define GL_UnloadObject SDL_UnloadObject |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 X11_GL_LoadLibrary(_THIS, const char *path) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 void *handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 if (_this->gl_config.driver_loaded) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 if (path) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 SDL_SetError("OpenGL library already loaded"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 return -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 ++_this->gl_config.driver_loaded; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 return 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 if (path == NULL) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 path = SDL_getenv("SDL_OPENGL_LIBRARY"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 if (path == NULL) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 path = DEFAULT_OPENGL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 handle = GL_LoadObject(path); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 if (!handle) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 return -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
2243
5523312f311e
Date: Wed, 15 Aug 2007 01:08:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2178
diff
changeset
|
93 // LoadLibrary may be called before WindowCreate! |
5523312f311e
Date: Wed, 15 Aug 2007 01:08:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2178
diff
changeset
|
94 X11_GL_Initialize(_this); |
5523312f311e
Date: Wed, 15 Aug 2007 01:08:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2178
diff
changeset
|
95 |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 /* Load new function pointers */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 _this->gl_data->glXGetProcAddress = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 (void *(*)(const GLubyte *)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 "glXGetProcAddressARB"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 _this->gl_data->glXChooseVisual = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 (XVisualInfo * (*)(Display *, int, int *)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 "glXChooseVisual"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 _this->gl_data->glXCreateContext = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int)) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 GL_LoadFunction(handle, "glXCreateContext"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 _this->gl_data->glXDestroyContext = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 (void (*)(Display *, GLXContext)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 "glXDestroyContext"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 _this->gl_data->glXMakeCurrent = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 (int (*)(Display *, GLXDrawable, GLXContext)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 "glXMakeCurrent"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 _this->gl_data->glXSwapBuffers = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 (void (*)(Display *, GLXDrawable)) GL_LoadFunction(handle, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 "glXSwapBuffers"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 if (!_this->gl_data->glXChooseVisual || |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 !_this->gl_data->glXCreateContext || |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 !_this->gl_data->glXDestroyContext || |
1956
ba0d62354872
Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents:
1955
diff
changeset
|
119 !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 SDL_SetError("Could not retrieve OpenGL functions"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 return -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 _this->gl_config.dll_handle = handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 SDL_strlcpy(_this->gl_config.driver_path, path, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 SDL_arraysize(_this->gl_config.driver_path)); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 _this->gl_config.driver_loaded = 1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 return 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 void * |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 X11_GL_GetProcAddress(_THIS, const char *proc) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 void *handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 handle = _this->gl_config.dll_handle; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 if (_this->gl_data->glXGetProcAddress) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 return _this->gl_data->glXGetProcAddress((const GLubyte *) proc); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 return GL_LoadFunction(handle, proc); |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 static void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 X11_GL_UnloadLibrary(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 if (_this->gl_config.driver_loaded > 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 if (--_this->gl_config.driver_loaded > 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 return; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 GL_UnloadObject(_this->gl_config.dll_handle); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 _this->gl_config.dll_handle = NULL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 } |
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 static SDL_bool |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 HasExtension(const char *extension, const char *extensions) |
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 const char *start; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 const char *where, *terminator; |
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 /* Extension names should not have spaces. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 where = SDL_strchr(extension, ' '); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 if (where || *extension == '\0') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 return SDL_FALSE; |
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 if (!extensions) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 return SDL_FALSE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 /* 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
|
170 * OpenGL extensions string. Don't be fooled by sub-strings, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 * etc. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 start = extensions; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 for (;;) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 where = SDL_strstr(start, extension); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 if (!where) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 break; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 terminator = where + SDL_strlen(extension); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 if (where == start || *(where - 1) == ' ') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 if (*terminator == ' ' || *terminator == '\0') |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 return SDL_TRUE; |
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 start = terminator; |
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 return SDL_FALSE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 } |
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 static void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 X11_GL_InitExtensions(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 int screen = ((SDL_DisplayData *) SDL_CurrentDisplay.driverdata)->screen; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 XVisualInfo *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 XSetWindowAttributes xattr; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 Window w; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 GLXContext context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 const char *(*glXQueryExtensionsStringFunc) (Display *, int); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 const char *extensions; |
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 vinfo = X11_GL_GetVisual(_this, display, screen); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 if (!vinfo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 return; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 xattr.background_pixel = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 xattr.border_pixel = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 xattr.colormap = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 XCreateColormap(display, RootWindow(display, screen), vinfo->visual, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 AllocNone); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 vinfo->depth, InputOutput, vinfo->visual, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 (CWBackPixel | CWBorderPixel | CWColormap), &xattr); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 if (context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 _this->gl_data->glXMakeCurrent(display, w, context); |
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 XFree(vinfo); |
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 glXQueryExtensionsStringFunc = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 "glXQueryExtensionsString"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 if (glXQueryExtensionsStringFunc) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 extensions = glXQueryExtensionsStringFunc(display, screen); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 extensions = NULL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 /* 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
|
230 if (HasExtension("GLX_SGI_swap_control", extensions)) { |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 _this->gl_data->glXSwapIntervalSGI = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 } |
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 /* Check for GLX_MESA_swap_control */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 if (HasExtension("GLX_MESA_swap_control", extensions)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 _this->gl_data->glXSwapIntervalMESA = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 (GLint(*)(unsigned)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 "glXSwapIntervalMESA"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 _this->gl_data->glXGetSwapIntervalMESA = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 (GLint(*)(void)) X11_GL_GetProcAddress(_this, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 "glXGetSwapIntervalMESA"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 /* Check for GLX_EXT_visual_rating */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 if (HasExtension("GLX_EXT_visual_rating", extensions)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 if (context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 _this->gl_data->glXMakeCurrent(display, None, NULL); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 _this->gl_data->glXDestroyContext(display, context); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 XDestroyWindow(display, w); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 X11_PumpEvents(_this); |
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 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 X11_GL_Initialize(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 if (_this->gl_data) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 ++_this->gl_data->initialized; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 return 0; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 _this->gl_data = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 (struct SDL_GLDriverData *) SDL_calloc(1, |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 sizeof(struct |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 SDL_GLDriverData)); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 if (!_this->gl_data) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 SDL_OutOfMemory(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 return -1; |
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 _this->gl_data->initialized = 1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 if (X11_GL_LoadLibrary(_this, NULL) < 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 return -1; |
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 /* Initialize extensions */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 X11_GL_InitExtensions(_this); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 return 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 X11_GL_Shutdown(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 if (!_this->gl_data || (--_this->gl_data->initialized > 0)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 return; |
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 |
1954
c20e158a9299
Don't unload the OpenGL library before the X display is closed.
Sam Lantinga <slouken@libsdl.org>
parents:
1953
diff
changeset
|
293 /* Don't actually unload the library, since it may have registered |
c20e158a9299
Don't unload the OpenGL library before the X display is closed.
Sam Lantinga <slouken@libsdl.org>
parents:
1953
diff
changeset
|
294 * X11 shutdown hooks, per the notes at: |
c20e158a9299
Don't unload the OpenGL library before the X display is closed.
Sam Lantinga <slouken@libsdl.org>
parents:
1953
diff
changeset
|
295 * http://dri.sourceforge.net/doc/DRIuserguide.html |
c20e158a9299
Don't unload the OpenGL library before the X display is closed.
Sam Lantinga <slouken@libsdl.org>
parents:
1953
diff
changeset
|
296 * //X11_GL_UnloadLibrary(_this); |
c20e158a9299
Don't unload the OpenGL library before the X display is closed.
Sam Lantinga <slouken@libsdl.org>
parents:
1953
diff
changeset
|
297 */ |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 SDL_free(_this->gl_data); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 _this->gl_data = NULL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 XVisualInfo * |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 X11_GL_GetVisual(_THIS, Display * display, int screen) |
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 XVisualInfo *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 /* 64 seems nice. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 int attribs[64]; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 int i; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 /* Setup our GLX attributes according to the gl_config. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 i = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 attribs[i++] = GLX_RGBA; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 attribs[i++] = GLX_RED_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 attribs[i++] = _this->gl_config.red_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 attribs[i++] = GLX_GREEN_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 attribs[i++] = _this->gl_config.green_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 attribs[i++] = GLX_BLUE_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 attribs[i++] = _this->gl_config.blue_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.alpha_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 attribs[i++] = GLX_ALPHA_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 attribs[i++] = _this->gl_config.alpha_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.buffer_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 attribs[i++] = GLX_BUFFER_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 attribs[i++] = _this->gl_config.buffer_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.double_buffer) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 attribs[i++] = GLX_DOUBLEBUFFER; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 attribs[i++] = GLX_DEPTH_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 attribs[i++] = _this->gl_config.depth_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 if (_this->gl_config.stencil_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 attribs[i++] = GLX_STENCIL_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 attribs[i++] = _this->gl_config.stencil_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 if (_this->gl_config.accum_red_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 attribs[i++] = GLX_ACCUM_RED_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 attribs[i++] = _this->gl_config.accum_red_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 if (_this->gl_config.accum_green_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 attribs[i++] = _this->gl_config.accum_green_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 if (_this->gl_config.accum_blue_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 attribs[i++] = _this->gl_config.accum_blue_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 if (_this->gl_config.accum_alpha_size) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 attribs[i++] = _this->gl_config.accum_alpha_size; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 if (_this->gl_config.stereo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 attribs[i++] = GLX_STEREO; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 if (_this->gl_config.multisamplebuffers) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 attribs[i++] = _this->gl_config.multisamplebuffers; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 if (_this->gl_config.multisamplesamples) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 attribs[i++] = GLX_SAMPLES_ARB; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 attribs[i++] = _this->gl_config.multisamplesamples; |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 if (_this->gl_config.accelerated >= 0 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 && _this->gl_data->HAS_GLX_EXT_visual_rating) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 attribs[i++] = GLX_VISUAL_CAVEAT_EXT; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 attribs[i++] = GLX_NONE_EXT; |
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 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 if (!SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR")) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 attribs[i++] = GLX_X_VISUAL_TYPE; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 attribs[i++] = GLX_DIRECT_COLOR; |
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 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 attribs[i++] = None; |
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 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 #ifdef GLX_DIRECT_COLOR |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 if (!vinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR")) { /* No DirectColor visual? Try again.. */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 attribs[i - 3] = None; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 #endif |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 if (!vinfo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 SDL_SetError("Couldn't find matching GLX visual"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 return vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 SDL_GLContext |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 X11_GL_CreateContext(_THIS, SDL_Window * window) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 Display *display = data->videodata->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 int screen = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata)-> |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 screen; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 XWindowAttributes xattr; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 XVisualInfo v, *vinfo; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 int n; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 GLXContext context = NULL; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
1955 | 417 /* 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
|
418 XSync(display, False); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 XGetWindowAttributes(display, data->window, &xattr); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 v.screen = screen; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 v.visualid = XVisualIDFromVisual(xattr.visual); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 if (vinfo) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 context = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 _this->gl_data->glXCreateContext(display, vinfo, NULL, True); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 XFree(vinfo); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 XSync(display, False); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 if (!context) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 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
|
432 return NULL; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 } |
2178
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
434 |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
435 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
|
436 X11_GL_DeleteContext(_this, context); |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
437 return NULL; |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
438 } |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
439 |
114a541cfae2
Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents:
2105
diff
changeset
|
440 return context; |
1952
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 Window drawable = |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 (window ? ((SDL_WindowData *) window->driverdata)->window : None); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 GLXContext glx_context = (GLXContext) context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 int status; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 status = 0; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 SDL_SetError("Unable to make GL context current"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 status = -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 XSync(display, False); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 return (status); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 X11_GL_SetSwapInterval(_THIS, int interval) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 int status; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 if (_this->gl_data->glXSwapIntervalMESA) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 status = _this->gl_data->glXSwapIntervalMESA(interval); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 if (status != 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 SDL_SetError("glxSwapIntervalMESA failed"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 status = -1; |
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 } else if (_this->gl_data->glXSwapIntervalSGI) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 status = _this->gl_data->glXSwapIntervalSGI(interval); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 if (status != 0) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 SDL_SetError("glxSwapIntervalSGI failed"); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 status = -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 SDL_Unsupported(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 status = -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 return status; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
484 } |
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 int |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 X11_GL_GetSwapInterval(_THIS) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 if (_this->gl_data->glXGetSwapIntervalMESA) { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 return _this->gl_data->glXGetSwapIntervalMESA(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 } else { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 SDL_Unsupported(); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 return -1; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 } |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 X11_GL_SwapWindow(_THIS, SDL_Window * window) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 Display *display = data->videodata->display; |
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 _this->gl_data->glXSwapBuffers(display, data->window); |
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 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 void |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 X11_GL_DeleteContext(_THIS, SDL_GLContext context) |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 { |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 GLXContext glx_context = (GLXContext) context; |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 _this->gl_data->glXDestroyContext(display, glx_context); |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 } |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 #endif /* SDL_VIDEO_OPENGL_GLX */ |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 |
420716272158
Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 /* vi: set ts=4 sw=4 expandtab: */ |