Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gl.c @ 1143:71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
requested this effort on the mailing list, apparently because of binary
compatibility issues between 10.4 and earlier systems (or gcc4 and earlier
compilers?).
Works fine with SDL12/test/testcdrom.c, with this command line:
./testcdrom -status -list -play -sleep 5000 -pause -sleep 3000 -resume \
-sleep 5000 -stop -sleep 3000 -play -sleep 3000 -stop \
-sleep 3000 -eject
Unix Makefiles work, XCode project still need updating for new filenames.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 22 Sep 2005 08:48:16 +0000 |
parents | 86885b40a53b |
children | 045f186426e1 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
667
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
180
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> /* For getenv() prototype */ | |
29 #include <string.h> | |
30 | |
31 #include "SDL_events_c.h" | |
32 #include "SDL_error.h" | |
33 #include "SDL_x11video.h" | |
34 #include "SDL_x11dga_c.h" | |
35 #include "SDL_x11gl_c.h" | |
36 | |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
37 #if defined(sgi) |
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
38 /* IRIX doesn't have a GL library versioning system */ |
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
39 #define DEFAULT_OPENGL "libGL.so" |
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
40 #else |
0 | 41 #define DEFAULT_OPENGL "libGL.so.1" |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
42 #endif |
0 | 43 |
667
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
44 #ifndef GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
45 #define GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
46 #define GLX_SAMPLE_BUFFERS_ARB 100000 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
47 #define GLX_SAMPLES_ARB 100001 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
48 #endif |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
49 |
0 | 50 /* return the preferred visual to use for openGL graphics */ |
51 XVisualInfo *X11_GL_GetVisual(_THIS) | |
52 { | |
53 #ifdef HAVE_OPENGL | |
54 /* 64 seems nice. */ | |
55 int attribs[64]; | |
56 int i; | |
57 | |
58 /* load the gl driver from a default path */ | |
59 if ( ! this->gl_config.driver_loaded ) { | |
60 /* no driver has been loaded, use default (ourselves) */ | |
61 if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { | |
62 return NULL; | |
63 } | |
64 } | |
65 | |
66 /* See if we already have a window which we must use */ | |
67 if ( SDL_windowid ) { | |
68 XWindowAttributes a; | |
69 XVisualInfo vi_in; | |
70 int out_count; | |
71 | |
72 XGetWindowAttributes(SDL_Display, SDL_Window, &a); | |
73 vi_in.screen = SDL_Screen; | |
74 vi_in.visualid = XVisualIDFromVisual(a.visual); | |
75 glx_visualinfo = XGetVisualInfo(SDL_Display, | |
76 VisualScreenMask|VisualIDMask, &vi_in, &out_count); | |
77 return glx_visualinfo; | |
78 } | |
79 | |
80 /* Setup our GLX attributes according to the gl_config. */ | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
81 i = 0; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
82 attribs[i++] = GLX_RGBA; |
0 | 83 attribs[i++] = GLX_RED_SIZE; |
84 attribs[i++] = this->gl_config.red_size; | |
85 attribs[i++] = GLX_GREEN_SIZE; | |
86 attribs[i++] = this->gl_config.green_size; | |
87 attribs[i++] = GLX_BLUE_SIZE; | |
88 attribs[i++] = this->gl_config.blue_size; | |
89 | |
90 if( this->gl_config.alpha_size ) { | |
91 attribs[i++] = GLX_ALPHA_SIZE; | |
92 attribs[i++] = this->gl_config.alpha_size; | |
93 } | |
94 | |
95 if( this->gl_config.buffer_size ) { | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
96 attribs[i++] = GLX_BUFFER_SIZE; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 attribs[i++] = this->gl_config.buffer_size; |
0 | 98 } |
99 | |
100 if( this->gl_config.double_buffer ) { | |
101 attribs[i++] = GLX_DOUBLEBUFFER; | |
102 } | |
103 | |
104 attribs[i++] = GLX_DEPTH_SIZE; | |
105 attribs[i++] = this->gl_config.depth_size; | |
106 | |
107 if( this->gl_config.stencil_size ) { | |
108 attribs[i++] = GLX_STENCIL_SIZE; | |
109 attribs[i++] = this->gl_config.stencil_size; | |
110 } | |
111 | |
112 if( this->gl_config.accum_red_size ) { | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
113 attribs[i++] = GLX_ACCUM_RED_SIZE; |
0 | 114 attribs[i++] = this->gl_config.accum_red_size; |
115 } | |
116 | |
117 if( this->gl_config.accum_green_size ) { | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
118 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
0 | 119 attribs[i++] = this->gl_config.accum_green_size; |
120 } | |
121 | |
122 if( this->gl_config.accum_blue_size ) { | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
123 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
0 | 124 attribs[i++] = this->gl_config.accum_blue_size; |
125 } | |
126 | |
127 if( this->gl_config.accum_alpha_size ) { | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
128 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
0 | 129 attribs[i++] = this->gl_config.accum_alpha_size; |
130 } | |
131 | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
132 if( this->gl_config.stereo ) { |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
133 attribs[i++] = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
134 attribs[i++] = this->gl_config.stereo; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
135 } |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
136 |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
137 if( this->gl_config.multisamplebuffers ) { |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
138 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
139 attribs[i++] = this->gl_config.multisamplebuffers; |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
140 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
141 |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
142 if( this->gl_config.multisamplesamples ) { |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
143 attribs[i++] = GLX_SAMPLES_ARB; |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
144 attribs[i++] = this->gl_config.multisamplesamples; |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
145 } |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
146 |
0 | 147 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ |
1060
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
148 if ( !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
149 attribs[i++] = GLX_X_VISUAL_TYPE; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
150 attribs[i++] = GLX_DIRECT_COLOR; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
151 } |
0 | 152 #endif |
153 attribs[i++] = None; | |
154 | |
155 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
156 SDL_Screen, attribs); | |
157 #ifdef GLX_DIRECT_COLOR | |
1060
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
158 if( !glx_visualinfo && !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ |
0 | 159 attribs[i-3] = None; |
160 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
161 SDL_Screen, attribs); | |
162 } | |
163 #endif | |
164 if( !glx_visualinfo ) { | |
165 SDL_SetError( "Couldn't find matching GLX visual"); | |
166 return NULL; | |
167 } | |
168 return glx_visualinfo; | |
169 #else | |
170 SDL_SetError("X11 driver not configured with OpenGL"); | |
171 return NULL; | |
172 #endif | |
173 } | |
174 | |
175 int X11_GL_CreateWindow(_THIS, int w, int h) | |
176 { | |
177 int retval; | |
178 #ifdef HAVE_OPENGL | |
179 XSetWindowAttributes attributes; | |
180 unsigned long mask; | |
181 unsigned long black; | |
182 | |
183 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, | |
184 SDL_Screen)) | |
185 ? BlackPixel(SDL_Display, SDL_Screen) : 0; | |
186 attributes.background_pixel = black; | |
187 attributes.border_pixel = black; | |
188 attributes.colormap = SDL_XColorMap; | |
189 mask = CWBackPixel | CWBorderPixel | CWColormap; | |
190 | |
191 SDL_Window = XCreateWindow(SDL_Display, WMwindow, | |
192 0, 0, w, h, 0, glx_visualinfo->depth, | |
193 InputOutput, glx_visualinfo->visual, | |
194 mask, &attributes); | |
195 if ( !SDL_Window ) { | |
196 SDL_SetError("Could not create window"); | |
197 return -1; | |
198 } | |
199 retval = 0; | |
200 #else | |
201 SDL_SetError("X11 driver not configured with OpenGL"); | |
202 retval = -1; | |
203 #endif | |
204 return(retval); | |
205 } | |
206 | |
207 int X11_GL_CreateContext(_THIS) | |
208 { | |
209 int retval; | |
210 #ifdef HAVE_OPENGL | |
211 /* We do this to create a clean separation between X and GLX errors. */ | |
212 XSync( SDL_Display, False ); | |
213 glx_context = this->gl_data->glXCreateContext(GFX_Display, | |
214 glx_visualinfo, NULL, True); | |
215 XSync( GFX_Display, False ); | |
216 | |
217 if (glx_context == NULL) { | |
218 SDL_SetError("Could not create GL context"); | |
219 return -1; | |
220 } | |
221 | |
222 gl_active = 1; | |
223 #else | |
224 SDL_SetError("X11 driver not configured with OpenGL"); | |
225 #endif | |
226 if ( gl_active ) { | |
227 retval = 0; | |
228 } else { | |
229 retval = -1; | |
230 } | |
231 return(retval); | |
232 } | |
233 | |
234 void X11_GL_Shutdown(_THIS) | |
235 { | |
236 #ifdef HAVE_OPENGL | |
237 /* Clean up OpenGL */ | |
238 if( glx_context ) { | |
239 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); | |
240 | |
241 if (glx_context != NULL) | |
242 this->gl_data->glXDestroyContext(GFX_Display, glx_context); | |
243 | |
244 if( this->gl_data->glXReleaseBuffersMESA ) { | |
245 this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window); | |
246 } | |
247 glx_context = NULL; | |
248 } | |
249 gl_active = 0; | |
250 #endif /* HAVE_OPENGL */ | |
251 } | |
252 | |
253 #ifdef HAVE_OPENGL | |
254 | |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
255 static int ExtensionSupported(const char *extension) |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
256 { |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
257 const GLubyte *extensions = NULL; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
258 const GLubyte *start; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
259 GLubyte *where, *terminator; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
260 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
261 /* Extension names should not have spaces. */ |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
262 where = (GLubyte *) strchr(extension, ' '); |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
263 if (where || *extension == '\0') |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
264 return 0; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
265 |
643
564716cfb502
Removed direct dependency on OpenGL (call current_video->glGetString() instead
Ryan C. Gordon <icculus@icculus.org>
parents:
638
diff
changeset
|
266 extensions = current_video->glGetString(GL_EXTENSIONS); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
267 /* It takes a bit of care to be fool-proof about parsing the |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
268 * OpenGL extensions string. Don't be fooled by sub-strings, |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
269 * etc. */ |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
270 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
271 start = extensions; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
272 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
273 for (;;) |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
274 { |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
275 where = (GLubyte *) strstr((const char *) start, extension); |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
276 if (!where) break; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
277 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
278 terminator = where + strlen(extension); |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
279 if (where == start || *(where - 1) == ' ') |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
280 if (*terminator == ' ' || *terminator == '\0') return 1; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
281 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
282 start = terminator; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
283 } |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
284 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
285 return 0; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
286 } |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
287 |
0 | 288 /* Make the current context active */ |
289 int X11_GL_MakeCurrent(_THIS) | |
290 { | |
291 int retval; | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
292 |
0 | 293 retval = 0; |
294 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, | |
295 SDL_Window, glx_context) ) { | |
296 SDL_SetError("Unable to make GL context current"); | |
297 retval = -1; | |
298 } | |
299 XSync( GFX_Display, False ); | |
300 | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
301 /* |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
302 * The context is now current, check for glXReleaseBuffersMESA() |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
303 * extension. If extension is _not_ supported, destroy the pointer |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
304 * (to make sure it will not be called in X11_GL_Shutdown() ). |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
305 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
306 * DRI/Mesa drivers include glXReleaseBuffersMESA() in the libGL.so, |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
307 * but there's no need to call it (is is only needed for some old |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
308 * non-DRI drivers). |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
309 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
310 * When using for example glew (http://glew.sf.net), dlsym() for |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
311 * glXReleaseBuffersMESA() returns the pointer from the glew library |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
312 * (namespace conflict). |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
313 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
314 * The glXReleaseBuffersMESA() pointer in the glew is NULL, if the |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
315 * driver doesn't support this extension. So blindly calling it will |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
316 * cause segfault with DRI/Mesa drivers! |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
317 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
318 */ |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
319 |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
320 if ( ! ExtensionSupported("glXReleaseBuffersMESA") ) { |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
321 this->gl_data->glXReleaseBuffersMESA = NULL; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
322 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
323 |
0 | 324 /* More Voodoo X server workarounds... Grr... */ |
325 SDL_Lock_EventThread(); | |
326 X11_CheckDGAMouse(this); | |
327 SDL_Unlock_EventThread(); | |
328 | |
329 return(retval); | |
330 } | |
331 | |
332 /* Get attribute data from glX. */ | |
333 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
334 { | |
335 int retval; | |
336 int glx_attrib = None; | |
337 | |
338 switch( attrib ) { | |
339 case SDL_GL_RED_SIZE: | |
340 glx_attrib = GLX_RED_SIZE; | |
341 break; | |
342 case SDL_GL_GREEN_SIZE: | |
343 glx_attrib = GLX_GREEN_SIZE; | |
344 break; | |
345 case SDL_GL_BLUE_SIZE: | |
346 glx_attrib = GLX_BLUE_SIZE; | |
347 break; | |
348 case SDL_GL_ALPHA_SIZE: | |
349 glx_attrib = GLX_ALPHA_SIZE; | |
350 break; | |
351 case SDL_GL_DOUBLEBUFFER: | |
352 glx_attrib = GLX_DOUBLEBUFFER; | |
353 break; | |
354 case SDL_GL_BUFFER_SIZE: | |
355 glx_attrib = GLX_BUFFER_SIZE; | |
356 break; | |
357 case SDL_GL_DEPTH_SIZE: | |
358 glx_attrib = GLX_DEPTH_SIZE; | |
359 break; | |
360 case SDL_GL_STENCIL_SIZE: | |
361 glx_attrib = GLX_STENCIL_SIZE; | |
362 break; | |
363 case SDL_GL_ACCUM_RED_SIZE: | |
364 glx_attrib = GLX_ACCUM_RED_SIZE; | |
365 break; | |
366 case SDL_GL_ACCUM_GREEN_SIZE: | |
367 glx_attrib = GLX_ACCUM_GREEN_SIZE; | |
368 break; | |
369 case SDL_GL_ACCUM_BLUE_SIZE: | |
370 glx_attrib = GLX_ACCUM_BLUE_SIZE; | |
371 break; | |
372 case SDL_GL_ACCUM_ALPHA_SIZE: | |
373 glx_attrib = GLX_ACCUM_ALPHA_SIZE; | |
374 break; | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
375 case SDL_GL_STEREO: |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
376 glx_attrib = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
377 break; |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
378 case SDL_GL_MULTISAMPLEBUFFERS: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
379 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
380 break; |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
381 case SDL_GL_MULTISAMPLESAMPLES: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
382 glx_attrib = GLX_SAMPLES_ARB; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
383 break; |
0 | 384 default: |
385 return(-1); | |
386 } | |
387 | |
388 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); | |
389 | |
390 return retval; | |
391 } | |
392 | |
393 void X11_GL_SwapBuffers(_THIS) | |
394 { | |
395 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); | |
396 } | |
397 | |
398 #endif /* HAVE_OPENGL */ | |
399 | |
400 void X11_GL_UnloadLibrary(_THIS) | |
401 { | |
402 #ifdef HAVE_OPENGL | |
403 if ( this->gl_config.driver_loaded ) { | |
404 dlclose(this->gl_config.dll_handle); | |
405 | |
406 this->gl_data->glXGetProcAddress = NULL; | |
407 this->gl_data->glXChooseVisual = NULL; | |
408 this->gl_data->glXCreateContext = NULL; | |
409 this->gl_data->glXDestroyContext = NULL; | |
410 this->gl_data->glXMakeCurrent = NULL; | |
411 this->gl_data->glXSwapBuffers = NULL; | |
412 | |
413 this->gl_config.dll_handle = NULL; | |
414 this->gl_config.driver_loaded = 0; | |
415 } | |
416 #endif | |
417 } | |
418 | |
419 #ifdef HAVE_OPENGL | |
420 | |
421 /* Passing a NULL path means load pointers from the application */ | |
422 int X11_GL_LoadLibrary(_THIS, const char* path) | |
423 { | |
424 void* handle; | |
425 int dlopen_flags; | |
426 | |
427 if ( gl_active ) { | |
428 SDL_SetError("OpenGL context already created"); | |
429 return -1; | |
430 } | |
431 | |
432 #ifdef RTLD_GLOBAL | |
433 dlopen_flags = RTLD_LAZY | RTLD_GLOBAL; | |
434 #else | |
435 dlopen_flags = RTLD_LAZY; | |
436 #endif | |
437 handle = dlopen(path, dlopen_flags); | |
438 /* Catch the case where the application isn't linked with GL */ | |
439 if ( (dlsym(handle, "glXChooseVisual") == NULL) && (path == NULL) ) { | |
440 dlclose(handle); | |
441 path = getenv("SDL_VIDEO_GL_DRIVER"); | |
442 if ( path == NULL ) { | |
443 path = DEFAULT_OPENGL; | |
444 } | |
445 handle = dlopen(path, dlopen_flags); | |
446 } | |
447 if ( handle == NULL ) { | |
448 SDL_SetError("Could not load OpenGL library"); | |
449 return -1; | |
450 } | |
451 | |
452 /* Unload the old driver and reset the pointers */ | |
453 X11_GL_UnloadLibrary(this); | |
454 | |
455 /* Load new function pointers */ | |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
456 this->gl_data->glXGetProcAddress = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
457 (void *(*)(const GLubyte *)) dlsym(handle, "glXGetProcAddressARB"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
458 this->gl_data->glXChooseVisual = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
459 (XVisualInfo *(*)(Display *, int, int *)) dlsym(handle, "glXChooseVisual"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
460 this->gl_data->glXCreateContext = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
461 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) dlsym(handle, "glXCreateContext"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
462 this->gl_data->glXDestroyContext = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
463 (void (*)(Display *, GLXContext)) dlsym(handle, "glXDestroyContext"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
464 this->gl_data->glXMakeCurrent = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
465 (int (*)(Display *, GLXDrawable, GLXContext)) dlsym(handle, "glXMakeCurrent"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
466 this->gl_data->glXSwapBuffers = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
467 (void (*)(Display *, GLXDrawable)) dlsym(handle, "glXSwapBuffers"); |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
468 this->gl_data->glXGetConfig = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
469 (int (*)(Display *, XVisualInfo *, int, int *)) dlsym(handle, "glXGetConfig"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
470 this->gl_data->glXQueryExtensionsString = |
646
0f2029a70548
Fixed incorrect prototype for glXQueryExtensionsString()
Sam Lantinga <slouken@libsdl.org>
parents:
643
diff
changeset
|
471 (const char *(*)(Display *, int)) dlsym(handle, "glXQueryExtensionsString"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
472 |
0 | 473 /* We don't compare below for this in case we're not using Mesa. */ |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
474 this->gl_data->glXReleaseBuffersMESA = |
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
475 (void (*)(Display *, GLXDrawable)) dlsym( handle, "glXReleaseBuffersMESA" ); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
476 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
477 |
0 | 478 if ( (this->gl_data->glXChooseVisual == NULL) || |
479 (this->gl_data->glXCreateContext == NULL) || | |
480 (this->gl_data->glXDestroyContext == NULL) || | |
481 (this->gl_data->glXMakeCurrent == NULL) || | |
482 (this->gl_data->glXSwapBuffers == NULL) || | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
483 (this->gl_data->glXGetConfig == NULL) || |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
484 (this->gl_data->glXQueryExtensionsString == NULL)) { |
0 | 485 SDL_SetError("Could not retrieve OpenGL functions"); |
486 return -1; | |
487 } | |
488 | |
489 this->gl_config.dll_handle = handle; | |
490 this->gl_config.driver_loaded = 1; | |
491 if ( path ) { | |
492 strncpy(this->gl_config.driver_path, path, | |
493 sizeof(this->gl_config.driver_path)-1); | |
494 } else { | |
495 strcpy(this->gl_config.driver_path, ""); | |
496 } | |
497 return 0; | |
498 } | |
499 | |
500 void *X11_GL_GetProcAddress(_THIS, const char* proc) | |
501 { | |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
502 static char procname[1024]; |
0 | 503 void* handle; |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
504 void* retval; |
0 | 505 |
506 handle = this->gl_config.dll_handle; | |
507 if ( this->gl_data->glXGetProcAddress ) { | |
566
d6e7d7006062
Enable the glXGetProcAddressARB code (fixes problems with NVidia drivers)
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
508 return this->gl_data->glXGetProcAddress(proc); |
0 | 509 } |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
510 #if defined(__OpenBSD__) && !defined(__ELF__) |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
511 #undef dlsym(x,y); |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
512 #endif |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
513 retval = dlsym(handle, proc); |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
514 if (!retval && strlen(proc) <= 1022) { |
127
0bcae11eba14
Oops, that wasn't right...
Sam Lantinga <slouken@libsdl.org>
parents:
110
diff
changeset
|
515 procname[0] = '_'; |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
516 strcpy(procname + 1, proc); |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
517 retval = dlsym(handle, procname); |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
518 } |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
519 return retval; |
0 | 520 } |
521 | |
522 #endif /* HAVE_OPENGL */ |