Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gl.c @ 1614:6162b8d921ce
Date: Wed, 29 Mar 2006 17:26:55 +0200 CEST
From: "Fran���is Revol"
Subject: [SDL] BeOS port fix: PrintScreen key crashing
It seems the latest SDL crashes when someone hits the PrtScrn key in
ZETA (BeOS R6), somewhere it gets a negative value as key code (or a
big unsigned maybe ?), and uses it as an index in the keysym table...
I'll investigate the cause for the negative value, but it's always
better to check for bounds correctly when indexing a table. The
attached diff fixes it.
Fran���is Revol
--
Software Architect
yellowTAB GmbH
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 31 Mar 2006 06:16:20 +0000 |
parents | d75c2d78e87d |
children | 96c2f89cc7e1 3b2a92126f4d |
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 |
0 | 46 XVisualInfo *X11_GL_GetVisual(_THIS) |
47 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
48 #if SDL_VIDEO_OPENGL_GLX |
0 | 49 /* 64 seems nice. */ |
50 int attribs[64]; | |
51 int i; | |
52 | |
53 /* load the gl driver from a default path */ | |
54 if ( ! this->gl_config.driver_loaded ) { | |
55 /* no driver has been loaded, use default (ourselves) */ | |
56 if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { | |
57 return NULL; | |
58 } | |
59 } | |
60 | |
61 /* See if we already have a window which we must use */ | |
62 if ( SDL_windowid ) { | |
63 XWindowAttributes a; | |
64 XVisualInfo vi_in; | |
65 int out_count; | |
66 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
67 XGetWindowAttributes(SDL_Display, SDL_Window, &a); |
0 | 68 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
|
69 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
|
70 glx_visualinfo = XGetVisualInfo(SDL_Display, |
0 | 71 VisualScreenMask|VisualIDMask, &vi_in, &out_count); |
72 return glx_visualinfo; | |
73 } | |
74 | |
75 /* 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
|
76 i = 0; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
77 attribs[i++] = GLX_RGBA; |
0 | 78 attribs[i++] = GLX_RED_SIZE; |
79 attribs[i++] = this->gl_config.red_size; | |
80 attribs[i++] = GLX_GREEN_SIZE; | |
81 attribs[i++] = this->gl_config.green_size; | |
82 attribs[i++] = GLX_BLUE_SIZE; | |
83 attribs[i++] = this->gl_config.blue_size; | |
84 | |
85 if( this->gl_config.alpha_size ) { | |
86 attribs[i++] = GLX_ALPHA_SIZE; | |
87 attribs[i++] = this->gl_config.alpha_size; | |
88 } | |
89 | |
90 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
|
91 attribs[i++] = GLX_BUFFER_SIZE; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 attribs[i++] = this->gl_config.buffer_size; |
0 | 93 } |
94 | |
95 if( this->gl_config.double_buffer ) { | |
96 attribs[i++] = GLX_DOUBLEBUFFER; | |
97 } | |
98 | |
99 attribs[i++] = GLX_DEPTH_SIZE; | |
100 attribs[i++] = this->gl_config.depth_size; | |
101 | |
102 if( this->gl_config.stencil_size ) { | |
103 attribs[i++] = GLX_STENCIL_SIZE; | |
104 attribs[i++] = this->gl_config.stencil_size; | |
105 } | |
106 | |
107 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
|
108 attribs[i++] = GLX_ACCUM_RED_SIZE; |
0 | 109 attribs[i++] = this->gl_config.accum_red_size; |
110 } | |
111 | |
112 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
|
113 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
0 | 114 attribs[i++] = this->gl_config.accum_green_size; |
115 } | |
116 | |
117 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
|
118 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
0 | 119 attribs[i++] = this->gl_config.accum_blue_size; |
120 } | |
121 | |
122 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
|
123 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
0 | 124 attribs[i++] = this->gl_config.accum_alpha_size; |
125 } | |
126 | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
127 if( this->gl_config.stereo ) { |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
128 attribs[i++] = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
129 } |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
130 |
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
|
131 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
|
132 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
|
133 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
|
134 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
135 |
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
|
136 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
|
137 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
|
138 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
|
139 } |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
140 |
0 | 141 #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
|
142 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
|
143 attribs[i++] = GLX_X_VISUAL_TYPE; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
144 attribs[i++] = GLX_DIRECT_COLOR; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
145 } |
0 | 146 #endif |
147 attribs[i++] = None; | |
148 | |
149 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
150 SDL_Screen, attribs); | |
151 #ifdef GLX_DIRECT_COLOR | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1315
diff
changeset
|
152 if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ |
0 | 153 attribs[i-3] = None; |
154 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
155 SDL_Screen, attribs); | |
156 } | |
157 #endif | |
158 if( !glx_visualinfo ) { | |
159 SDL_SetError( "Couldn't find matching GLX visual"); | |
160 return NULL; | |
161 } | |
1315
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
162 /* |
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
163 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
|
164 */ |
0 | 165 return glx_visualinfo; |
166 #else | |
167 SDL_SetError("X11 driver not configured with OpenGL"); | |
168 return NULL; | |
169 #endif | |
170 } | |
171 | |
172 int X11_GL_CreateWindow(_THIS, int w, int h) | |
173 { | |
174 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
|
175 #if SDL_VIDEO_OPENGL_GLX |
0 | 176 XSetWindowAttributes attributes; |
177 unsigned long mask; | |
178 unsigned long black; | |
179 | |
180 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, | |
181 SDL_Screen)) | |
182 ? BlackPixel(SDL_Display, SDL_Screen) : 0; | |
183 attributes.background_pixel = black; | |
184 attributes.border_pixel = black; | |
185 attributes.colormap = SDL_XColorMap; | |
186 mask = CWBackPixel | CWBorderPixel | CWColormap; | |
187 | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
188 SDL_Window = XCreateWindow(SDL_Display, WMwindow, |
0 | 189 0, 0, w, h, 0, glx_visualinfo->depth, |
190 InputOutput, glx_visualinfo->visual, | |
191 mask, &attributes); | |
192 if ( !SDL_Window ) { | |
193 SDL_SetError("Could not create window"); | |
194 return -1; | |
195 } | |
196 retval = 0; | |
197 #else | |
198 SDL_SetError("X11 driver not configured with OpenGL"); | |
199 retval = -1; | |
200 #endif | |
201 return(retval); | |
202 } | |
203 | |
204 int X11_GL_CreateContext(_THIS) | |
205 { | |
206 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
|
207 #if SDL_VIDEO_OPENGL_GLX |
0 | 208 /* 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
|
209 XSync( SDL_Display, False ); |
0 | 210 glx_context = this->gl_data->glXCreateContext(GFX_Display, |
211 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
|
212 XSync( GFX_Display, False ); |
0 | 213 |
214 if (glx_context == NULL) { | |
215 SDL_SetError("Could not create GL context"); | |
216 return -1; | |
217 } | |
218 | |
219 gl_active = 1; | |
220 #else | |
221 SDL_SetError("X11 driver not configured with OpenGL"); | |
222 #endif | |
223 if ( gl_active ) { | |
224 retval = 0; | |
225 } else { | |
226 retval = -1; | |
227 } | |
228 return(retval); | |
229 } | |
230 | |
231 void X11_GL_Shutdown(_THIS) | |
232 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
233 #if SDL_VIDEO_OPENGL_GLX |
0 | 234 /* Clean up OpenGL */ |
235 if( glx_context ) { | |
236 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); | |
237 | |
238 if (glx_context != NULL) | |
239 this->gl_data->glXDestroyContext(GFX_Display, glx_context); | |
240 | |
241 glx_context = NULL; | |
242 } | |
243 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
|
244 #endif /* SDL_VIDEO_OPENGL_GLX */ |
0 | 245 } |
246 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
247 #if SDL_VIDEO_OPENGL_GLX |
0 | 248 |
249 /* Make the current context active */ | |
250 int X11_GL_MakeCurrent(_THIS) | |
251 { | |
252 int retval; | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
253 |
0 | 254 retval = 0; |
255 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, | |
256 SDL_Window, glx_context) ) { | |
257 SDL_SetError("Unable to make GL context current"); | |
258 retval = -1; | |
259 } | |
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 |
262 /* More Voodoo X server workarounds... Grr... */ | |
263 SDL_Lock_EventThread(); | |
264 X11_CheckDGAMouse(this); | |
265 SDL_Unlock_EventThread(); | |
266 | |
267 return(retval); | |
268 } | |
269 | |
270 /* Get attribute data from glX. */ | |
271 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
272 { | |
273 int retval; | |
274 int glx_attrib = None; | |
275 | |
276 switch( attrib ) { | |
277 case SDL_GL_RED_SIZE: | |
278 glx_attrib = GLX_RED_SIZE; | |
279 break; | |
280 case SDL_GL_GREEN_SIZE: | |
281 glx_attrib = GLX_GREEN_SIZE; | |
282 break; | |
283 case SDL_GL_BLUE_SIZE: | |
284 glx_attrib = GLX_BLUE_SIZE; | |
285 break; | |
286 case SDL_GL_ALPHA_SIZE: | |
287 glx_attrib = GLX_ALPHA_SIZE; | |
288 break; | |
289 case SDL_GL_DOUBLEBUFFER: | |
290 glx_attrib = GLX_DOUBLEBUFFER; | |
291 break; | |
292 case SDL_GL_BUFFER_SIZE: | |
293 glx_attrib = GLX_BUFFER_SIZE; | |
294 break; | |
295 case SDL_GL_DEPTH_SIZE: | |
296 glx_attrib = GLX_DEPTH_SIZE; | |
297 break; | |
298 case SDL_GL_STENCIL_SIZE: | |
299 glx_attrib = GLX_STENCIL_SIZE; | |
300 break; | |
301 case SDL_GL_ACCUM_RED_SIZE: | |
302 glx_attrib = GLX_ACCUM_RED_SIZE; | |
303 break; | |
304 case SDL_GL_ACCUM_GREEN_SIZE: | |
305 glx_attrib = GLX_ACCUM_GREEN_SIZE; | |
306 break; | |
307 case SDL_GL_ACCUM_BLUE_SIZE: | |
308 glx_attrib = GLX_ACCUM_BLUE_SIZE; | |
309 break; | |
310 case SDL_GL_ACCUM_ALPHA_SIZE: | |
311 glx_attrib = GLX_ACCUM_ALPHA_SIZE; | |
312 break; | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
313 case SDL_GL_STEREO: |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
314 glx_attrib = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
315 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
|
316 case SDL_GL_MULTISAMPLEBUFFERS: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
317 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
|
318 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
|
319 case SDL_GL_MULTISAMPLESAMPLES: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
320 glx_attrib = GLX_SAMPLES_ARB; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
321 break; |
0 | 322 default: |
323 return(-1); | |
324 } | |
325 | |
326 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); | |
327 | |
328 return retval; | |
329 } | |
330 | |
331 void X11_GL_SwapBuffers(_THIS) | |
332 { | |
333 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); | |
334 } | |
335 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
336 #endif /* SDL_VIDEO_OPENGL_GLX */ |
0 | 337 |
338 void X11_GL_UnloadLibrary(_THIS) | |
339 { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
340 #if SDL_VIDEO_OPENGL_GLX |
0 | 341 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
|
342 |
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
|
343 SDL_UnloadObject(this->gl_config.dll_handle); |
0 | 344 |
345 this->gl_data->glXGetProcAddress = NULL; | |
346 this->gl_data->glXChooseVisual = NULL; | |
347 this->gl_data->glXCreateContext = NULL; | |
348 this->gl_data->glXDestroyContext = NULL; | |
349 this->gl_data->glXMakeCurrent = NULL; | |
350 this->gl_data->glXSwapBuffers = NULL; | |
351 | |
352 this->gl_config.dll_handle = NULL; | |
353 this->gl_config.driver_loaded = 0; | |
354 } | |
355 #endif | |
356 } | |
357 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
358 #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
|
359 |
0 | 360 /* Passing a NULL path means load pointers from the application */ |
361 int X11_GL_LoadLibrary(_THIS, const char* path) | |
362 { | |
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
|
363 void* handle = NULL; |
0 | 364 |
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
|
365 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
|
366 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
|
367 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
|
368 } |
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
|
369 |
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
|
370 if ( path == NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1315
diff
changeset
|
371 path = SDL_getenv("SDL_VIDEO_GL_DRIVER"); |
0 | 372 if ( path == NULL ) { |
373 path = DEFAULT_OPENGL; | |
374 } | |
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
|
375 } |
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
|
376 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
377 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
|
378 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
|
379 /* 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
|
380 return -1; |
0 | 381 } |
382 | |
383 /* Unload the old driver and reset the pointers */ | |
384 X11_GL_UnloadLibrary(this); | |
385 | |
386 /* Load new function pointers */ | |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
387 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
|
388 (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
|
389 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
|
390 (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
|
391 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
|
392 (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
|
393 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
|
394 (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
|
395 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
|
396 (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
|
397 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
|
398 (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
|
399 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
|
400 (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
|
401 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
|
402 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
403 |
1315
e94b0d7c33bc
Merged useful fixes from 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
404 |
0 | 405 if ( (this->gl_data->glXChooseVisual == NULL) || |
406 (this->gl_data->glXCreateContext == NULL) || | |
407 (this->gl_data->glXDestroyContext == NULL) || | |
408 (this->gl_data->glXMakeCurrent == NULL) || | |
409 (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
|
410 (this->gl_data->glXGetConfig == NULL) || |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
411 (this->gl_data->glXQueryExtensionsString == NULL)) { |
0 | 412 SDL_SetError("Could not retrieve OpenGL functions"); |
413 return -1; | |
414 } | |
415 | |
416 this->gl_config.dll_handle = handle; | |
417 this->gl_config.driver_loaded = 1; | |
418 if ( path ) { | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
419 SDL_strlcpy(this->gl_config.driver_path, path, |
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
420 SDL_arraysize(this->gl_config.driver_path)); |
0 | 421 } else { |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
422 *this->gl_config.driver_path = '\0'; |
0 | 423 } |
424 return 0; | |
425 } | |
426 | |
427 void *X11_GL_GetProcAddress(_THIS, const char* proc) | |
428 { | |
429 void* handle; | |
430 | |
431 handle = this->gl_config.dll_handle; | |
432 if ( this->gl_data->glXGetProcAddress ) { | |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1191
diff
changeset
|
433 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); |
0 | 434 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
435 return SDL_LoadFunction(handle, proc); |
0 | 436 } |
437 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
438 #endif /* SDL_VIDEO_OPENGL_GLX */ |