Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gl.c @ 1658:e49147870aac SDL-1.3
glSDL support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 01 May 2006 06:58:33 +0000 |
parents | 96c2f89cc7e1 |
children | 14717b52abc0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1247
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #include "SDL_x11video.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
25 #include "../../events/SDL_events_c.h" |
0 | 26 #include "SDL_x11dga_c.h" |
27 #include "SDL_x11gl_c.h" | |
28 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
29 #if defined(__IRIX__) |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
30 /* 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
|
31 #define DEFAULT_OPENGL "libGL.so" |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
32 #elif defined(__MACOSX__) |
1191
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
33 #define DEFAULT_OPENGL "/usr/X11R6/lib/libGL.1.dylib" |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
34 #elif defined(__QNXNTO__) |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
35 #define DEFAULT_OPENGL "libGL.so.3" |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
36 #else |
0 | 37 #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
|
38 #endif |
0 | 39 |
667
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
40 #ifndef GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
41 #define GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
42 #define GLX_SAMPLE_BUFFERS_ARB 100000 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
43 #define GLX_SAMPLES_ARB 100001 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
44 #endif |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
45 |
1656 | 46 #ifndef GLX_EXT_visual_rating |
47 #define GLX_EXT_visual_rating | |
48 #define GLX_VISUAL_CAVEAT_EXT 0x20 | |
49 #define GLX_SLOW_VISUAL_EXT 0x8001 | |
50 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D | |
51 #endif | |
52 | |
53 #if SDL_VIDEO_OPENGL_GLX | |
54 static int glXExtensionSupported(_THIS, const char *extension) | |
55 { | |
56 const char *extensions; | |
57 const char *start; | |
58 const char *where, *terminator; | |
59 | |
60 /* Extension names should not have spaces. */ | |
61 where = SDL_strchr(extension, ' '); | |
62 if ( where || *extension == '\0' ) { | |
63 return 0; | |
64 } | |
65 | |
66 extensions = this->gl_data->glXQueryExtensionsString(GFX_Display,SDL_Screen); | |
67 /* It takes a bit of care to be fool-proof about parsing the | |
68 * OpenGL extensions string. Don't be fooled by sub-strings, etc. | |
69 */ | |
70 | |
71 start = extensions; | |
72 | |
73 for (;;) { | |
74 where = SDL_strstr(start, extension); | |
75 if (!where) break; | |
76 | |
77 terminator = where + strlen(extension); | |
78 if (where == start || *(where - 1) == ' ') | |
79 if (*terminator == ' ' || *terminator == '\0') return 1; | |
80 | |
81 start = terminator; | |
82 } | |
83 return 0; | |
84 } | |
85 #endif /* SDL_VIDEO_OPENGL_GLX */ | |
86 | |
0 | 87 XVisualInfo *X11_GL_GetVisual(_THIS) |
88 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
89 #if SDL_VIDEO_OPENGL_GLX |
0 | 90 /* 64 seems nice. */ |
91 int attribs[64]; | |
92 int i; | |
93 | |
94 /* load the gl driver from a default path */ | |
95 if ( ! this->gl_config.driver_loaded ) { | |
96 /* no driver has been loaded, use default (ourselves) */ | |
97 if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { | |
98 return NULL; | |
99 } | |
100 } | |
101 | |
102 /* See if we already have a window which we must use */ | |
103 if ( SDL_windowid ) { | |
104 XWindowAttributes a; | |
105 XVisualInfo vi_in; | |
106 int out_count; | |
107 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
108 XGetWindowAttributes(SDL_Display, SDL_Window, &a); |
0 | 109 vi_in.screen = SDL_Screen; |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
110 vi_in.visualid = XVisualIDFromVisual(a.visual); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
111 glx_visualinfo = XGetVisualInfo(SDL_Display, |
0 | 112 VisualScreenMask|VisualIDMask, &vi_in, &out_count); |
113 return glx_visualinfo; | |
114 } | |
115 | |
116 /* 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
|
117 i = 0; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
118 attribs[i++] = GLX_RGBA; |
0 | 119 attribs[i++] = GLX_RED_SIZE; |
120 attribs[i++] = this->gl_config.red_size; | |
121 attribs[i++] = GLX_GREEN_SIZE; | |
122 attribs[i++] = this->gl_config.green_size; | |
123 attribs[i++] = GLX_BLUE_SIZE; | |
124 attribs[i++] = this->gl_config.blue_size; | |
125 | |
126 if( this->gl_config.alpha_size ) { | |
127 attribs[i++] = GLX_ALPHA_SIZE; | |
128 attribs[i++] = this->gl_config.alpha_size; | |
129 } | |
130 | |
131 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
|
132 attribs[i++] = GLX_BUFFER_SIZE; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
133 attribs[i++] = this->gl_config.buffer_size; |
0 | 134 } |
135 | |
136 if( this->gl_config.double_buffer ) { | |
137 attribs[i++] = GLX_DOUBLEBUFFER; | |
138 } | |
139 | |
140 attribs[i++] = GLX_DEPTH_SIZE; | |
141 attribs[i++] = this->gl_config.depth_size; | |
142 | |
143 if( this->gl_config.stencil_size ) { | |
144 attribs[i++] = GLX_STENCIL_SIZE; | |
145 attribs[i++] = this->gl_config.stencil_size; | |
146 } | |
147 | |
148 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
|
149 attribs[i++] = GLX_ACCUM_RED_SIZE; |
0 | 150 attribs[i++] = this->gl_config.accum_red_size; |
151 } | |
152 | |
153 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
|
154 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
0 | 155 attribs[i++] = this->gl_config.accum_green_size; |
156 } | |
157 | |
158 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
|
159 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
0 | 160 attribs[i++] = this->gl_config.accum_blue_size; |
161 } | |
162 | |
163 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
|
164 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
0 | 165 attribs[i++] = this->gl_config.accum_alpha_size; |
166 } | |
167 | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
168 if( this->gl_config.stereo ) { |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
169 attribs[i++] = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
170 } |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
171 |
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
|
172 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
|
173 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
|
174 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
|
175 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
176 |
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
|
177 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
|
178 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
|
179 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
|
180 } |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
181 |
1656 | 182 if( this->gl_config.accelerated >= 0 && |
183 glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { | |
184 attribs[i++] = GLX_VISUAL_CAVEAT_EXT; | |
185 attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE; | |
186 } | |
187 | |
0 | 188 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1315
diff
changeset
|
189 if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { |
1060
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
190 attribs[i++] = GLX_X_VISUAL_TYPE; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
191 attribs[i++] = GLX_DIRECT_COLOR; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
192 } |
0 | 193 #endif |
194 attribs[i++] = None; | |
195 | |
196 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
197 SDL_Screen, attribs); | |
198 #ifdef GLX_DIRECT_COLOR | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1315
diff
changeset
|
199 if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ |
0 | 200 attribs[i-3] = None; |
201 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
202 SDL_Screen, attribs); | |
203 } | |
204 #endif | |
205 if( !glx_visualinfo ) { | |
206 SDL_SetError( "Couldn't find matching GLX visual"); | |
207 return NULL; | |
208 } | |
1315
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
209 /* |
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
210 printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid); |
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
211 */ |
0 | 212 return glx_visualinfo; |
213 #else | |
214 SDL_SetError("X11 driver not configured with OpenGL"); | |
215 return NULL; | |
216 #endif | |
217 } | |
218 | |
219 int X11_GL_CreateWindow(_THIS, int w, int h) | |
220 { | |
221 int retval; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
222 #if SDL_VIDEO_OPENGL_GLX |
0 | 223 XSetWindowAttributes attributes; |
224 unsigned long mask; | |
225 unsigned long black; | |
226 | |
227 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, | |
228 SDL_Screen)) | |
229 ? BlackPixel(SDL_Display, SDL_Screen) : 0; | |
230 attributes.background_pixel = black; | |
231 attributes.border_pixel = black; | |
232 attributes.colormap = SDL_XColorMap; | |
233 mask = CWBackPixel | CWBorderPixel | CWColormap; | |
234 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
235 SDL_Window = XCreateWindow(SDL_Display, WMwindow, |
0 | 236 0, 0, w, h, 0, glx_visualinfo->depth, |
237 InputOutput, glx_visualinfo->visual, | |
238 mask, &attributes); | |
239 if ( !SDL_Window ) { | |
240 SDL_SetError("Could not create window"); | |
241 return -1; | |
242 } | |
243 retval = 0; | |
244 #else | |
245 SDL_SetError("X11 driver not configured with OpenGL"); | |
246 retval = -1; | |
247 #endif | |
248 return(retval); | |
249 } | |
250 | |
251 int X11_GL_CreateContext(_THIS) | |
252 { | |
253 int retval; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
254 #if SDL_VIDEO_OPENGL_GLX |
1656 | 255 |
0 | 256 /* We do this to create a clean separation between X and GLX errors. */ |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
257 XSync( SDL_Display, False ); |
0 | 258 glx_context = this->gl_data->glXCreateContext(GFX_Display, |
259 glx_visualinfo, NULL, True); | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
260 XSync( GFX_Display, False ); |
0 | 261 |
1656 | 262 if ( glx_context == NULL ) { |
0 | 263 SDL_SetError("Could not create GL context"); |
1656 | 264 return(-1); |
265 } | |
266 if ( X11_GL_MakeCurrent(this) < 0 ) { | |
267 return(-1); | |
268 } | |
269 gl_active = 1; | |
270 | |
271 if ( !glXExtensionSupported(this, "SGI_swap_control") ) { | |
272 this->gl_data->glXSwapIntervalSGI = NULL; | |
0 | 273 } |
1656 | 274 if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { |
275 this->gl_data->glXSwapIntervalMESA = NULL; | |
276 this->gl_data->glXGetSwapIntervalMESA = NULL; | |
277 } | |
278 if ( this->gl_config.swap_control >= 0 ) { | |
279 if ( this->gl_data->glXSwapIntervalMESA ) { | |
280 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control); | |
281 } else if ( this->gl_data->glXSwapIntervalSGI ) { | |
282 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control); | |
283 } | |
284 } | |
0 | 285 #else |
286 SDL_SetError("X11 driver not configured with OpenGL"); | |
287 #endif | |
288 if ( gl_active ) { | |
289 retval = 0; | |
290 } else { | |
291 retval = -1; | |
292 } | |
293 return(retval); | |
294 } | |
295 | |
296 void X11_GL_Shutdown(_THIS) | |
297 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
298 #if SDL_VIDEO_OPENGL_GLX |
0 | 299 /* Clean up OpenGL */ |
300 if( glx_context ) { | |
301 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); | |
302 | |
303 if (glx_context != NULL) | |
304 this->gl_data->glXDestroyContext(GFX_Display, glx_context); | |
305 | |
306 glx_context = NULL; | |
307 } | |
308 gl_active = 0; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
309 #endif /* SDL_VIDEO_OPENGL_GLX */ |
0 | 310 } |
311 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
312 #if SDL_VIDEO_OPENGL_GLX |
0 | 313 |
314 /* Make the current context active */ | |
315 int X11_GL_MakeCurrent(_THIS) | |
316 { | |
317 int retval; | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
318 |
0 | 319 retval = 0; |
320 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, | |
321 SDL_Window, glx_context) ) { | |
322 SDL_SetError("Unable to make GL context current"); | |
323 retval = -1; | |
324 } | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
325 XSync( GFX_Display, False ); |
0 | 326 |
327 /* More Voodoo X server workarounds... Grr... */ | |
328 SDL_Lock_EventThread(); | |
329 X11_CheckDGAMouse(this); | |
330 SDL_Unlock_EventThread(); | |
331 | |
332 return(retval); | |
333 } | |
334 | |
335 /* Get attribute data from glX. */ | |
336 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
337 { | |
338 int retval; | |
339 int glx_attrib = None; | |
340 | |
341 switch( attrib ) { | |
342 case SDL_GL_RED_SIZE: | |
343 glx_attrib = GLX_RED_SIZE; | |
344 break; | |
345 case SDL_GL_GREEN_SIZE: | |
346 glx_attrib = GLX_GREEN_SIZE; | |
347 break; | |
348 case SDL_GL_BLUE_SIZE: | |
349 glx_attrib = GLX_BLUE_SIZE; | |
350 break; | |
351 case SDL_GL_ALPHA_SIZE: | |
352 glx_attrib = GLX_ALPHA_SIZE; | |
353 break; | |
354 case SDL_GL_DOUBLEBUFFER: | |
355 glx_attrib = GLX_DOUBLEBUFFER; | |
356 break; | |
357 case SDL_GL_BUFFER_SIZE: | |
358 glx_attrib = GLX_BUFFER_SIZE; | |
359 break; | |
360 case SDL_GL_DEPTH_SIZE: | |
361 glx_attrib = GLX_DEPTH_SIZE; | |
362 break; | |
363 case SDL_GL_STENCIL_SIZE: | |
364 glx_attrib = GLX_STENCIL_SIZE; | |
365 break; | |
366 case SDL_GL_ACCUM_RED_SIZE: | |
367 glx_attrib = GLX_ACCUM_RED_SIZE; | |
368 break; | |
369 case SDL_GL_ACCUM_GREEN_SIZE: | |
370 glx_attrib = GLX_ACCUM_GREEN_SIZE; | |
371 break; | |
372 case SDL_GL_ACCUM_BLUE_SIZE: | |
373 glx_attrib = GLX_ACCUM_BLUE_SIZE; | |
374 break; | |
375 case SDL_GL_ACCUM_ALPHA_SIZE: | |
376 glx_attrib = GLX_ACCUM_ALPHA_SIZE; | |
377 break; | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
378 case SDL_GL_STEREO: |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
379 glx_attrib = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
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_MULTISAMPLEBUFFERS: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
382 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
|
383 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
|
384 case SDL_GL_MULTISAMPLESAMPLES: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
385 glx_attrib = GLX_SAMPLES_ARB; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
386 break; |
1656 | 387 case SDL_GL_ACCELERATED_VISUAL: |
388 if ( glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { | |
389 glx_attrib = GLX_VISUAL_CAVEAT_EXT; | |
390 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); | |
391 if ( *value == GLX_SLOW_VISUAL_EXT ) { | |
392 *value = SDL_FALSE; | |
393 } else { | |
394 *value = SDL_TRUE; | |
395 } | |
396 return retval; | |
397 } else { | |
398 return(-1); | |
399 } | |
400 break; | |
401 case SDL_GL_SWAP_CONTROL: | |
402 if ( this->gl_data->glXGetSwapIntervalMESA ) { | |
403 return this->gl_data->glXGetSwapIntervalMESA(); | |
404 } else { | |
405 return(-1)/*(this->gl_config.swap_control > 0)*/; | |
406 } | |
407 break; | |
0 | 408 default: |
409 return(-1); | |
410 } | |
411 | |
412 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); | |
413 | |
414 return retval; | |
415 } | |
416 | |
417 void X11_GL_SwapBuffers(_THIS) | |
418 { | |
419 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); | |
420 } | |
421 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
422 #endif /* SDL_VIDEO_OPENGL_GLX */ |
0 | 423 |
424 void X11_GL_UnloadLibrary(_THIS) | |
425 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
426 #if SDL_VIDEO_OPENGL_GLX |
0 | 427 if ( this->gl_config.driver_loaded ) { |
1191
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
428 |
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
429 SDL_UnloadObject(this->gl_config.dll_handle); |
0 | 430 |
431 this->gl_data->glXGetProcAddress = NULL; | |
432 this->gl_data->glXChooseVisual = NULL; | |
433 this->gl_data->glXCreateContext = NULL; | |
434 this->gl_data->glXDestroyContext = NULL; | |
435 this->gl_data->glXMakeCurrent = NULL; | |
436 this->gl_data->glXSwapBuffers = NULL; | |
1656 | 437 this->gl_data->glXSwapIntervalSGI = NULL; |
438 this->gl_data->glXSwapIntervalMESA = NULL; | |
439 this->gl_data->glXGetSwapIntervalMESA = NULL; | |
0 | 440 |
441 this->gl_config.dll_handle = NULL; | |
442 this->gl_config.driver_loaded = 0; | |
443 } | |
444 #endif | |
445 } | |
446 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
447 #if SDL_VIDEO_OPENGL_GLX |
1182
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
448 |
0 | 449 /* Passing a NULL path means load pointers from the application */ |
450 int X11_GL_LoadLibrary(_THIS, const char* path) | |
451 { | |
1191
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
452 void* handle = NULL; |
0 | 453 |
1182
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
454 if ( gl_active ) { |
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
455 SDL_SetError("OpenGL context already created"); |
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
456 return -1; |
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
457 } |
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
458 |
e8e8dcb68e7a
X11 driver now chooses "libGL.so.1" as a default when a NULL is passed to
Ryan C. Gordon <icculus@icculus.org>
parents:
1168
diff
changeset
|
459 if ( path == NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1315
diff
changeset
|
460 path = SDL_getenv("SDL_VIDEO_GL_DRIVER"); |
0 | 461 if ( path == NULL ) { |
462 path = DEFAULT_OPENGL; | |
463 } | |
1191
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
464 } |
2bd4cec0de63
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
Ryan C. Gordon <icculus@icculus.org>
parents:
1182
diff
changeset
|
465 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
466 handle = SDL_LoadObject(path); |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
467 if ( handle == NULL ) { |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
468 /* SDL_LoadObject() will call SDL_SetError() for us. */ |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
469 return -1; |
0 | 470 } |
471 | |
472 /* Unload the old driver and reset the pointers */ | |
473 X11_GL_UnloadLibrary(this); | |
474 | |
475 /* Load new function pointers */ | |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
476 this->gl_data->glXGetProcAddress = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
477 (void *(*)(const GLubyte *)) SDL_LoadFunction(handle, "glXGetProcAddressARB"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
478 this->gl_data->glXChooseVisual = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
479 (XVisualInfo *(*)(Display *, int, int *)) SDL_LoadFunction(handle, "glXChooseVisual"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
480 this->gl_data->glXCreateContext = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
481 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) SDL_LoadFunction(handle, "glXCreateContext"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
482 this->gl_data->glXDestroyContext = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
483 (void (*)(Display *, GLXContext)) SDL_LoadFunction(handle, "glXDestroyContext"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
484 this->gl_data->glXMakeCurrent = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
485 (int (*)(Display *, GLXDrawable, GLXContext)) SDL_LoadFunction(handle, "glXMakeCurrent"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
486 this->gl_data->glXSwapBuffers = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
487 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
488 this->gl_data->glXGetConfig = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
489 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
490 this->gl_data->glXQueryExtensionsString = |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
491 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString"); |
1656 | 492 this->gl_data->glXSwapIntervalSGI = |
493 (int (*)(int)) SDL_LoadFunction(handle, "glXSwapIntervalSGI"); | |
494 this->gl_data->glXSwapIntervalMESA = | |
495 (GLint (*)(unsigned)) SDL_LoadFunction(handle, "glXSwapIntervalMESA"); | |
496 this->gl_data->glXGetSwapIntervalMESA = | |
497 (GLint (*)(void)) SDL_LoadFunction(handle, "glXGetSwapIntervalMESA"); | |
1315
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
498 |
0 | 499 if ( (this->gl_data->glXChooseVisual == NULL) || |
500 (this->gl_data->glXCreateContext == NULL) || | |
501 (this->gl_data->glXDestroyContext == NULL) || | |
502 (this->gl_data->glXMakeCurrent == NULL) || | |
503 (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
|
504 (this->gl_data->glXGetConfig == NULL) || |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
505 (this->gl_data->glXQueryExtensionsString == NULL)) { |
0 | 506 SDL_SetError("Could not retrieve OpenGL functions"); |
507 return -1; | |
508 } | |
509 | |
510 this->gl_config.dll_handle = handle; | |
511 this->gl_config.driver_loaded = 1; | |
512 if ( path ) { | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
513 SDL_strlcpy(this->gl_config.driver_path, path, |
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
514 SDL_arraysize(this->gl_config.driver_path)); |
0 | 515 } else { |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
516 *this->gl_config.driver_path = '\0'; |
0 | 517 } |
518 return 0; | |
519 } | |
520 | |
521 void *X11_GL_GetProcAddress(_THIS, const char* proc) | |
522 { | |
523 void* handle; | |
524 | |
525 handle = this->gl_config.dll_handle; | |
526 if ( this->gl_data->glXGetProcAddress ) { | |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1191
diff
changeset
|
527 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); |
0 | 528 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
529 return SDL_LoadFunction(handle, proc); |
0 | 530 } |
531 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
532 #endif /* SDL_VIDEO_OPENGL_GLX */ |