Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gl.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | ff73ee89ff4b |
children | e94b0d7c33bc |
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 */ |
22 | |
23 #include <stdlib.h> /* For getenv() prototype */ | |
24 #include <string.h> | |
25 | |
26 #include "SDL_events_c.h" | |
27 #include "SDL_error.h" | |
28 #include "SDL_x11video.h" | |
29 #include "SDL_x11dga_c.h" | |
30 #include "SDL_x11gl_c.h" | |
31 | |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
32 #if defined(sgi) |
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
33 /* 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
|
34 #define DEFAULT_OPENGL "libGL.so" |
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
|
35 #elif defined(MACOSX) |
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
|
36 #define DEFAULT_OPENGL "/usr/X11R6/lib/libGL.1.dylib" |
862
f7a8b0ca2ae3
IRIX doesn't have a GL library versioning system
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
37 #else |
0 | 38 #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
|
39 #endif |
0 | 40 |
667
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
41 #ifndef GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
42 #define GLX_ARB_multisample |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
43 #define GLX_SAMPLE_BUFFERS_ARB 100000 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
44 #define GLX_SAMPLES_ARB 100001 |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
45 #endif |
adbed8d7a991
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
46 |
0 | 47 /* return the preferred visual to use for openGL graphics */ |
48 XVisualInfo *X11_GL_GetVisual(_THIS) | |
49 { | |
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
|
50 #ifdef HAVE_OPENGL_X11 |
0 | 51 /* 64 seems nice. */ |
52 int attribs[64]; | |
53 int i; | |
54 | |
55 /* load the gl driver from a default path */ | |
56 if ( ! this->gl_config.driver_loaded ) { | |
57 /* no driver has been loaded, use default (ourselves) */ | |
58 if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { | |
59 return NULL; | |
60 } | |
61 } | |
62 | |
63 /* See if we already have a window which we must use */ | |
64 if ( SDL_windowid ) { | |
65 XWindowAttributes a; | |
66 XVisualInfo vi_in; | |
67 int out_count; | |
68 | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
69 pXGetWindowAttributes(SDL_Display, SDL_Window, &a); |
0 | 70 vi_in.screen = SDL_Screen; |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
71 vi_in.visualid = pXVisualIDFromVisual(a.visual); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
72 glx_visualinfo = pXGetVisualInfo(SDL_Display, |
0 | 73 VisualScreenMask|VisualIDMask, &vi_in, &out_count); |
74 return glx_visualinfo; | |
75 } | |
76 | |
77 /* 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
|
78 i = 0; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
79 attribs[i++] = GLX_RGBA; |
0 | 80 attribs[i++] = GLX_RED_SIZE; |
81 attribs[i++] = this->gl_config.red_size; | |
82 attribs[i++] = GLX_GREEN_SIZE; | |
83 attribs[i++] = this->gl_config.green_size; | |
84 attribs[i++] = GLX_BLUE_SIZE; | |
85 attribs[i++] = this->gl_config.blue_size; | |
86 | |
87 if( this->gl_config.alpha_size ) { | |
88 attribs[i++] = GLX_ALPHA_SIZE; | |
89 attribs[i++] = this->gl_config.alpha_size; | |
90 } | |
91 | |
92 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
|
93 attribs[i++] = GLX_BUFFER_SIZE; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
94 attribs[i++] = this->gl_config.buffer_size; |
0 | 95 } |
96 | |
97 if( this->gl_config.double_buffer ) { | |
98 attribs[i++] = GLX_DOUBLEBUFFER; | |
99 } | |
100 | |
101 attribs[i++] = GLX_DEPTH_SIZE; | |
102 attribs[i++] = this->gl_config.depth_size; | |
103 | |
104 if( this->gl_config.stencil_size ) { | |
105 attribs[i++] = GLX_STENCIL_SIZE; | |
106 attribs[i++] = this->gl_config.stencil_size; | |
107 } | |
108 | |
109 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
|
110 attribs[i++] = GLX_ACCUM_RED_SIZE; |
0 | 111 attribs[i++] = this->gl_config.accum_red_size; |
112 } | |
113 | |
114 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
|
115 attribs[i++] = GLX_ACCUM_GREEN_SIZE; |
0 | 116 attribs[i++] = this->gl_config.accum_green_size; |
117 } | |
118 | |
119 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
|
120 attribs[i++] = GLX_ACCUM_BLUE_SIZE; |
0 | 121 attribs[i++] = this->gl_config.accum_blue_size; |
122 } | |
123 | |
124 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
|
125 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; |
0 | 126 attribs[i++] = this->gl_config.accum_alpha_size; |
127 } | |
128 | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
129 if( this->gl_config.stereo ) { |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
130 attribs[i++] = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
131 attribs[i++] = this->gl_config.stereo; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
132 } |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
133 |
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
|
134 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
|
135 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
|
136 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
|
137 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
138 |
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 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
|
140 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
|
141 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
|
142 } |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
143 |
0 | 144 #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
|
145 if ( !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
146 attribs[i++] = GLX_X_VISUAL_TYPE; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
147 attribs[i++] = GLX_DIRECT_COLOR; |
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
148 } |
0 | 149 #endif |
150 attribs[i++] = None; | |
151 | |
152 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
153 SDL_Screen, attribs); | |
154 #ifdef GLX_DIRECT_COLOR | |
1060
86885b40a53b
Support SDL_VIDEO_X11_NODIRECTCOLOR for OpenGL visuals
Sam Lantinga <slouken@libsdl.org>
parents:
862
diff
changeset
|
155 if( !glx_visualinfo && !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ |
0 | 156 attribs[i-3] = None; |
157 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, | |
158 SDL_Screen, attribs); | |
159 } | |
160 #endif | |
161 if( !glx_visualinfo ) { | |
162 SDL_SetError( "Couldn't find matching GLX visual"); | |
163 return NULL; | |
164 } | |
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; | |
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
|
175 #ifdef HAVE_OPENGL_X11 |
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 | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
188 SDL_Window = pXCreateWindow(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; | |
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
|
207 #ifdef HAVE_OPENGL_X11 |
0 | 208 /* We do this to create a clean separation between X and GLX errors. */ |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
209 pXSync( SDL_Display, False ); |
0 | 210 glx_context = this->gl_data->glXCreateContext(GFX_Display, |
211 glx_visualinfo, NULL, True); | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
212 pXSync( 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 { | |
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
|
233 #ifdef HAVE_OPENGL_X11 |
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 if( this->gl_data->glXReleaseBuffersMESA ) { | |
242 this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window); | |
243 } | |
244 glx_context = NULL; | |
245 } | |
246 gl_active = 0; | |
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
|
247 #endif /* HAVE_OPENGL_X11 */ |
0 | 248 } |
249 | |
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
|
250 #ifdef HAVE_OPENGL_X11 |
0 | 251 |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
252 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
|
253 { |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
254 const GLubyte *extensions = NULL; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
255 const GLubyte *start; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
256 GLubyte *where, *terminator; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
257 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
258 /* 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
|
259 where = (GLubyte *) strchr(extension, ' '); |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
260 if (where || *extension == '\0') |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
261 return 0; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
262 |
643
564716cfb502
Removed direct dependency on OpenGL (call current_video->glGetString() instead
Ryan C. Gordon <icculus@icculus.org>
parents:
638
diff
changeset
|
263 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
|
264 /* 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
|
265 * 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
|
266 * etc. */ |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
267 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
268 start = extensions; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
269 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
270 for (;;) |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
271 { |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
272 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
|
273 if (!where) break; |
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 terminator = where + strlen(extension); |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
276 if (where == start || *(where - 1) == ' ') |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
277 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
|
278 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
279 start = terminator; |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
280 } |
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 return 0; |
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 |
0 | 285 /* Make the current context active */ |
286 int X11_GL_MakeCurrent(_THIS) | |
287 { | |
288 int retval; | |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
289 |
0 | 290 retval = 0; |
291 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, | |
292 SDL_Window, glx_context) ) { | |
293 SDL_SetError("Unable to make GL context current"); | |
294 retval = -1; | |
295 } | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
1060
diff
changeset
|
296 pXSync( GFX_Display, False ); |
0 | 297 |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
298 /* |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
299 * 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
|
300 * 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
|
301 * (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
|
302 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
303 * 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
|
304 * 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
|
305 * non-DRI drivers). |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
306 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
307 * 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
|
308 * 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
|
309 * (namespace conflict). |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
310 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
311 * 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
|
312 * 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
|
313 * 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
|
314 * |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
315 */ |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
316 |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
317 if ( ! ExtensionSupported("glXReleaseBuffersMESA") ) { |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
318 this->gl_data->glXReleaseBuffersMESA = NULL; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
319 } |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
320 |
0 | 321 /* More Voodoo X server workarounds... Grr... */ |
322 SDL_Lock_EventThread(); | |
323 X11_CheckDGAMouse(this); | |
324 SDL_Unlock_EventThread(); | |
325 | |
326 return(retval); | |
327 } | |
328 | |
329 /* Get attribute data from glX. */ | |
330 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
331 { | |
332 int retval; | |
333 int glx_attrib = None; | |
334 | |
335 switch( attrib ) { | |
336 case SDL_GL_RED_SIZE: | |
337 glx_attrib = GLX_RED_SIZE; | |
338 break; | |
339 case SDL_GL_GREEN_SIZE: | |
340 glx_attrib = GLX_GREEN_SIZE; | |
341 break; | |
342 case SDL_GL_BLUE_SIZE: | |
343 glx_attrib = GLX_BLUE_SIZE; | |
344 break; | |
345 case SDL_GL_ALPHA_SIZE: | |
346 glx_attrib = GLX_ALPHA_SIZE; | |
347 break; | |
348 case SDL_GL_DOUBLEBUFFER: | |
349 glx_attrib = GLX_DOUBLEBUFFER; | |
350 break; | |
351 case SDL_GL_BUFFER_SIZE: | |
352 glx_attrib = GLX_BUFFER_SIZE; | |
353 break; | |
354 case SDL_GL_DEPTH_SIZE: | |
355 glx_attrib = GLX_DEPTH_SIZE; | |
356 break; | |
357 case SDL_GL_STENCIL_SIZE: | |
358 glx_attrib = GLX_STENCIL_SIZE; | |
359 break; | |
360 case SDL_GL_ACCUM_RED_SIZE: | |
361 glx_attrib = GLX_ACCUM_RED_SIZE; | |
362 break; | |
363 case SDL_GL_ACCUM_GREEN_SIZE: | |
364 glx_attrib = GLX_ACCUM_GREEN_SIZE; | |
365 break; | |
366 case SDL_GL_ACCUM_BLUE_SIZE: | |
367 glx_attrib = GLX_ACCUM_BLUE_SIZE; | |
368 break; | |
369 case SDL_GL_ACCUM_ALPHA_SIZE: | |
370 glx_attrib = GLX_ACCUM_ALPHA_SIZE; | |
371 break; | |
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
372 case SDL_GL_STEREO: |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
373 glx_attrib = GLX_STEREO; |
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
374 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
|
375 case SDL_GL_MULTISAMPLEBUFFERS: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
376 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
|
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_MULTISAMPLESAMPLES: |
655
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
379 glx_attrib = GLX_SAMPLES_ARB; |
9c42ee1b7d77
Date: Thu, 24 Apr 2003 15:13:47 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
646
diff
changeset
|
380 break; |
0 | 381 default: |
382 return(-1); | |
383 } | |
384 | |
385 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); | |
386 | |
387 return retval; | |
388 } | |
389 | |
390 void X11_GL_SwapBuffers(_THIS) | |
391 { | |
392 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); | |
393 } | |
394 | |
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
|
395 #endif /* HAVE_OPENGL_X11 */ |
0 | 396 |
397 void X11_GL_UnloadLibrary(_THIS) | |
398 { | |
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
|
399 #ifdef HAVE_OPENGL_X11 |
0 | 400 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
|
401 |
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
|
402 /* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */ |
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
|
403 #ifdef USE_DLOPEN |
0 | 404 dlclose(this->gl_config.dll_handle); |
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
|
405 #else |
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
|
406 SDL_UnloadObject(this->gl_config.dll_handle); |
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
|
407 #endif |
0 | 408 |
409 this->gl_data->glXGetProcAddress = NULL; | |
410 this->gl_data->glXChooseVisual = NULL; | |
411 this->gl_data->glXCreateContext = NULL; | |
412 this->gl_data->glXDestroyContext = NULL; | |
413 this->gl_data->glXMakeCurrent = NULL; | |
414 this->gl_data->glXSwapBuffers = NULL; | |
415 | |
416 this->gl_config.dll_handle = NULL; | |
417 this->gl_config.driver_loaded = 0; | |
418 } | |
419 #endif | |
420 } | |
421 | |
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
|
422 #ifdef HAVE_OPENGL_X11 |
0 | 423 |
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
|
424 static void *do_dlsym(void *handle, const char *name) |
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
|
425 { |
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
|
426 /* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */ |
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
|
427 #ifdef USE_DLOPEN |
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 return dlsym(handle, name); |
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 #else |
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
|
430 return SDL_LoadFunction(handle, name); |
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
|
431 #endif |
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
|
432 } |
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
|
433 |
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
|
434 #if defined(__OpenBSD__) && !defined(__ELF__) |
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
|
435 #define do_dlsym(x,y) do_dlsym(x, "_" y) |
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
|
436 #endif |
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
|
437 |
0 | 438 /* Passing a NULL path means load pointers from the application */ |
439 int X11_GL_LoadLibrary(_THIS, const char* path) | |
440 { | |
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
|
441 void* handle = NULL; |
0 | 442 |
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
|
443 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
|
444 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
|
445 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
|
446 } |
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
|
447 |
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 if ( path == NULL ) { |
0 | 449 path = getenv("SDL_VIDEO_GL_DRIVER"); |
450 if ( path == NULL ) { | |
451 path = DEFAULT_OPENGL; | |
452 } | |
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
|
453 } |
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
|
454 |
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
|
455 /* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */ |
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
|
456 #ifdef USE_DLOPEN |
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
|
457 { |
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
|
458 #ifdef RTLD_GLOBAL |
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
|
459 int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL; |
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
|
460 #else |
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
|
461 int dlopen_flags = RTLD_LAZY; |
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
|
462 #endif |
0 | 463 handle = dlopen(path, dlopen_flags); |
1246
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
464 if ( handle == NULL ) { |
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
465 SDL_SetError("Could not load OpenGL library: %s", (const char *) dlerror()); |
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
466 return -1; |
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
467 } |
0 | 468 } |
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
|
469 #else |
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
|
470 handle = SDL_LoadObject(path); |
1246
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
471 if ( handle == NULL ) { |
1247
ff73ee89ff4b
Don't trample SDL_LoadObject()'s error message in GL loader.
Ryan C. Gordon <icculus@icculus.org>
parents:
1246
diff
changeset
|
472 /* SDL_LoadObject() will call SDL_SetError() for us. */ |
1246
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
473 return -1; |
ca51a76a7328
Make error message meaningful if dlopen() fails on libX11.
Ryan C. Gordon <icculus@icculus.org>
parents:
1196
diff
changeset
|
474 } |
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
|
475 #endif |
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
|
476 |
0 | 477 |
478 /* Unload the old driver and reset the pointers */ | |
479 X11_GL_UnloadLibrary(this); | |
480 | |
481 /* Load new function pointers */ | |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
482 this->gl_data->glXGetProcAddress = |
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
|
483 (void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
484 this->gl_data->glXChooseVisual = |
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
|
485 (XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
486 this->gl_data->glXCreateContext = |
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
|
487 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
488 this->gl_data->glXDestroyContext = |
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
|
489 (void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
490 this->gl_data->glXMakeCurrent = |
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
|
491 (int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
492 this->gl_data->glXSwapBuffers = |
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
|
493 (void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers"); |
180
578815880307
Do proper typecasting so this compiles on IRIX
Sam Lantinga <slouken@libsdl.org>
parents:
127
diff
changeset
|
494 this->gl_data->glXGetConfig = |
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
|
495 (int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
496 this->gl_data->glXQueryExtensionsString = |
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
|
497 (const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString"); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
498 |
0 | 499 /* 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
|
500 this->gl_data->glXReleaseBuffersMESA = |
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
|
501 (void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" ); |
638
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
502 |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
503 |
0 | 504 if ( (this->gl_data->glXChooseVisual == NULL) || |
505 (this->gl_data->glXCreateContext == NULL) || | |
506 (this->gl_data->glXDestroyContext == NULL) || | |
507 (this->gl_data->glXMakeCurrent == NULL) || | |
508 (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
|
509 (this->gl_data->glXGetConfig == NULL) || |
b0108e9dea53
Date: Sun, 11 May 2003 19:59:06 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
566
diff
changeset
|
510 (this->gl_data->glXQueryExtensionsString == NULL)) { |
0 | 511 SDL_SetError("Could not retrieve OpenGL functions"); |
512 return -1; | |
513 } | |
514 | |
515 this->gl_config.dll_handle = handle; | |
516 this->gl_config.driver_loaded = 1; | |
517 if ( path ) { | |
518 strncpy(this->gl_config.driver_path, path, | |
519 sizeof(this->gl_config.driver_path)-1); | |
520 } else { | |
521 strcpy(this->gl_config.driver_path, ""); | |
522 } | |
523 return 0; | |
524 } | |
525 | |
526 void *X11_GL_GetProcAddress(_THIS, const char* proc) | |
527 { | |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
528 static char procname[1024]; |
0 | 529 void* handle; |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
530 void* retval; |
0 | 531 |
532 handle = this->gl_config.dll_handle; | |
533 if ( this->gl_data->glXGetProcAddress ) { | |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1191
diff
changeset
|
534 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); |
0 | 535 } |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
536 #if defined(__OpenBSD__) && !defined(__ELF__) |
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
|
537 #undef do_dlsym |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
538 #endif |
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
|
539 retval = do_dlsym(handle, proc); |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
540 if (!retval && strlen(proc) <= 1022) { |
127
0bcae11eba14
Oops, that wasn't right...
Sam Lantinga <slouken@libsdl.org>
parents:
110
diff
changeset
|
541 procname[0] = '_'; |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
542 strcpy(procname + 1, proc); |
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
|
543 retval = do_dlsym(handle, procname); |
110
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
544 } |
7edee9f0f2cc
SDL GL dynamic loading fix for OpenBSD
Sam Lantinga <slouken@lokigames.com>
parents:
29
diff
changeset
|
545 return retval; |
0 | 546 } |
547 | |
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
|
548 #endif /* HAVE_OPENGL_X11 */ |