slouken@0
|
1 |
/*
|
slouken@0
|
2 |
SDL - Simple DirectMedia Layer
|
slouken@297
|
3 |
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
|
slouken@0
|
4 |
|
slouken@0
|
5 |
This library is free software; you can redistribute it and/or
|
slouken@0
|
6 |
modify it under the terms of the GNU Library General Public
|
slouken@0
|
7 |
License as published by the Free Software Foundation; either
|
slouken@0
|
8 |
version 2 of the License, or (at your option) any later version.
|
slouken@0
|
9 |
|
slouken@0
|
10 |
This library is distributed in the hope that it will be useful,
|
slouken@0
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
slouken@0
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
slouken@0
|
13 |
Library General Public License for more details.
|
slouken@0
|
14 |
|
slouken@0
|
15 |
You should have received a copy of the GNU Library General Public
|
slouken@0
|
16 |
License along with this library; if not, write to the Free
|
slouken@0
|
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
slouken@0
|
18 |
|
slouken@0
|
19 |
Sam Lantinga
|
slouken@252
|
20 |
slouken@libsdl.org
|
slouken@0
|
21 |
*/
|
slouken@0
|
22 |
|
slouken@0
|
23 |
#ifdef SAVE_RCSID
|
slouken@0
|
24 |
static char rcsid =
|
slouken@0
|
25 |
"@(#) $Id$";
|
slouken@0
|
26 |
#endif
|
slouken@0
|
27 |
|
slouken@0
|
28 |
#include <stdlib.h> /* For getenv() prototype */
|
slouken@0
|
29 |
#include <string.h>
|
slouken@0
|
30 |
|
slouken@0
|
31 |
#include "SDL_events_c.h"
|
slouken@0
|
32 |
#include "SDL_error.h"
|
slouken@0
|
33 |
#include "SDL_x11video.h"
|
slouken@0
|
34 |
#include "SDL_x11dga_c.h"
|
slouken@0
|
35 |
#include "SDL_x11gl_c.h"
|
slouken@0
|
36 |
|
slouken@0
|
37 |
#define DEFAULT_OPENGL "libGL.so.1"
|
slouken@0
|
38 |
|
slouken@0
|
39 |
/* return the preferred visual to use for openGL graphics */
|
slouken@0
|
40 |
XVisualInfo *X11_GL_GetVisual(_THIS)
|
slouken@0
|
41 |
{
|
slouken@0
|
42 |
#ifdef HAVE_OPENGL
|
slouken@0
|
43 |
/* 64 seems nice. */
|
slouken@0
|
44 |
int attribs[64];
|
slouken@0
|
45 |
int i;
|
slouken@0
|
46 |
|
slouken@0
|
47 |
/* load the gl driver from a default path */
|
slouken@0
|
48 |
if ( ! this->gl_config.driver_loaded ) {
|
slouken@0
|
49 |
/* no driver has been loaded, use default (ourselves) */
|
slouken@0
|
50 |
if ( X11_GL_LoadLibrary(this, NULL) < 0 ) {
|
slouken@0
|
51 |
return NULL;
|
slouken@0
|
52 |
}
|
slouken@0
|
53 |
}
|
slouken@0
|
54 |
|
slouken@0
|
55 |
/* See if we already have a window which we must use */
|
slouken@0
|
56 |
if ( SDL_windowid ) {
|
slouken@0
|
57 |
XWindowAttributes a;
|
slouken@0
|
58 |
XVisualInfo vi_in;
|
slouken@0
|
59 |
int out_count;
|
slouken@0
|
60 |
|
slouken@0
|
61 |
XGetWindowAttributes(SDL_Display, SDL_Window, &a);
|
slouken@0
|
62 |
vi_in.screen = SDL_Screen;
|
slouken@0
|
63 |
vi_in.visualid = XVisualIDFromVisual(a.visual);
|
slouken@0
|
64 |
glx_visualinfo = XGetVisualInfo(SDL_Display,
|
slouken@0
|
65 |
VisualScreenMask|VisualIDMask, &vi_in, &out_count);
|
slouken@0
|
66 |
return glx_visualinfo;
|
slouken@0
|
67 |
}
|
slouken@0
|
68 |
|
slouken@0
|
69 |
/* Setup our GLX attributes according to the gl_config. */
|
slouken@450
|
70 |
i = 0;
|
slouken@450
|
71 |
attribs[i++] = GLX_RGBA;
|
slouken@0
|
72 |
attribs[i++] = GLX_RED_SIZE;
|
slouken@0
|
73 |
attribs[i++] = this->gl_config.red_size;
|
slouken@0
|
74 |
attribs[i++] = GLX_GREEN_SIZE;
|
slouken@0
|
75 |
attribs[i++] = this->gl_config.green_size;
|
slouken@0
|
76 |
attribs[i++] = GLX_BLUE_SIZE;
|
slouken@0
|
77 |
attribs[i++] = this->gl_config.blue_size;
|
slouken@0
|
78 |
|
slouken@0
|
79 |
if( this->gl_config.alpha_size ) {
|
slouken@0
|
80 |
attribs[i++] = GLX_ALPHA_SIZE;
|
slouken@0
|
81 |
attribs[i++] = this->gl_config.alpha_size;
|
slouken@0
|
82 |
}
|
slouken@0
|
83 |
|
slouken@0
|
84 |
if( this->gl_config.buffer_size ) {
|
slouken@450
|
85 |
attribs[i++] = GLX_BUFFER_SIZE;
|
slouken@450
|
86 |
attribs[i++] = this->gl_config.buffer_size;
|
slouken@0
|
87 |
}
|
slouken@0
|
88 |
|
slouken@0
|
89 |
if( this->gl_config.double_buffer ) {
|
slouken@0
|
90 |
attribs[i++] = GLX_DOUBLEBUFFER;
|
slouken@0
|
91 |
}
|
slouken@0
|
92 |
|
slouken@0
|
93 |
attribs[i++] = GLX_DEPTH_SIZE;
|
slouken@0
|
94 |
attribs[i++] = this->gl_config.depth_size;
|
slouken@0
|
95 |
|
slouken@0
|
96 |
if( this->gl_config.stencil_size ) {
|
slouken@0
|
97 |
attribs[i++] = GLX_STENCIL_SIZE;
|
slouken@0
|
98 |
attribs[i++] = this->gl_config.stencil_size;
|
slouken@0
|
99 |
}
|
slouken@0
|
100 |
|
slouken@0
|
101 |
if( this->gl_config.accum_red_size ) {
|
slouken@450
|
102 |
attribs[i++] = GLX_ACCUM_RED_SIZE;
|
slouken@0
|
103 |
attribs[i++] = this->gl_config.accum_red_size;
|
slouken@0
|
104 |
}
|
slouken@0
|
105 |
|
slouken@0
|
106 |
if( this->gl_config.accum_green_size ) {
|
slouken@450
|
107 |
attribs[i++] = GLX_ACCUM_GREEN_SIZE;
|
slouken@0
|
108 |
attribs[i++] = this->gl_config.accum_green_size;
|
slouken@0
|
109 |
}
|
slouken@0
|
110 |
|
slouken@0
|
111 |
if( this->gl_config.accum_blue_size ) {
|
slouken@450
|
112 |
attribs[i++] = GLX_ACCUM_BLUE_SIZE;
|
slouken@0
|
113 |
attribs[i++] = this->gl_config.accum_blue_size;
|
slouken@0
|
114 |
}
|
slouken@0
|
115 |
|
slouken@0
|
116 |
if( this->gl_config.accum_alpha_size ) {
|
slouken@450
|
117 |
attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
|
slouken@0
|
118 |
attribs[i++] = this->gl_config.accum_alpha_size;
|
slouken@0
|
119 |
}
|
slouken@0
|
120 |
|
slouken@450
|
121 |
if( this->gl_config.stereo ) {
|
slouken@450
|
122 |
attribs[i++] = GLX_STEREO;
|
slouken@450
|
123 |
attribs[i++] = this->gl_config.stereo;
|
slouken@450
|
124 |
}
|
slouken@450
|
125 |
|
slouken@0
|
126 |
#ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
|
slouken@0
|
127 |
attribs[i++] = GLX_X_VISUAL_TYPE;
|
slouken@0
|
128 |
attribs[i++] = GLX_DIRECT_COLOR;
|
slouken@0
|
129 |
#endif
|
slouken@0
|
130 |
attribs[i++] = None;
|
slouken@0
|
131 |
|
slouken@0
|
132 |
glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display,
|
slouken@0
|
133 |
SDL_Screen, attribs);
|
slouken@0
|
134 |
#ifdef GLX_DIRECT_COLOR
|
slouken@0
|
135 |
if( !glx_visualinfo ) { /* No DirectColor visual? Try again.. */
|
slouken@0
|
136 |
attribs[i-3] = None;
|
slouken@0
|
137 |
glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display,
|
slouken@0
|
138 |
SDL_Screen, attribs);
|
slouken@0
|
139 |
}
|
slouken@0
|
140 |
#endif
|
slouken@0
|
141 |
if( !glx_visualinfo ) {
|
slouken@0
|
142 |
SDL_SetError( "Couldn't find matching GLX visual");
|
slouken@0
|
143 |
return NULL;
|
slouken@0
|
144 |
}
|
slouken@0
|
145 |
return glx_visualinfo;
|
slouken@0
|
146 |
#else
|
slouken@0
|
147 |
SDL_SetError("X11 driver not configured with OpenGL");
|
slouken@0
|
148 |
return NULL;
|
slouken@0
|
149 |
#endif
|
slouken@0
|
150 |
}
|
slouken@0
|
151 |
|
slouken@0
|
152 |
int X11_GL_CreateWindow(_THIS, int w, int h)
|
slouken@0
|
153 |
{
|
slouken@0
|
154 |
int retval;
|
slouken@0
|
155 |
#ifdef HAVE_OPENGL
|
slouken@0
|
156 |
XSetWindowAttributes attributes;
|
slouken@0
|
157 |
unsigned long mask;
|
slouken@0
|
158 |
unsigned long black;
|
slouken@0
|
159 |
|
slouken@0
|
160 |
black = (glx_visualinfo->visual == DefaultVisual(SDL_Display,
|
slouken@0
|
161 |
SDL_Screen))
|
slouken@0
|
162 |
? BlackPixel(SDL_Display, SDL_Screen) : 0;
|
slouken@0
|
163 |
attributes.background_pixel = black;
|
slouken@0
|
164 |
attributes.border_pixel = black;
|
slouken@0
|
165 |
attributes.colormap = SDL_XColorMap;
|
slouken@0
|
166 |
mask = CWBackPixel | CWBorderPixel | CWColormap;
|
slouken@0
|
167 |
|
slouken@0
|
168 |
SDL_Window = XCreateWindow(SDL_Display, WMwindow,
|
slouken@0
|
169 |
0, 0, w, h, 0, glx_visualinfo->depth,
|
slouken@0
|
170 |
InputOutput, glx_visualinfo->visual,
|
slouken@0
|
171 |
mask, &attributes);
|
slouken@0
|
172 |
if ( !SDL_Window ) {
|
slouken@0
|
173 |
SDL_SetError("Could not create window");
|
slouken@0
|
174 |
return -1;
|
slouken@0
|
175 |
}
|
slouken@0
|
176 |
retval = 0;
|
slouken@0
|
177 |
#else
|
slouken@0
|
178 |
SDL_SetError("X11 driver not configured with OpenGL");
|
slouken@0
|
179 |
retval = -1;
|
slouken@0
|
180 |
#endif
|
slouken@0
|
181 |
return(retval);
|
slouken@0
|
182 |
}
|
slouken@0
|
183 |
|
slouken@0
|
184 |
int X11_GL_CreateContext(_THIS)
|
slouken@0
|
185 |
{
|
slouken@0
|
186 |
int retval;
|
slouken@0
|
187 |
#ifdef HAVE_OPENGL
|
slouken@0
|
188 |
/* We do this to create a clean separation between X and GLX errors. */
|
slouken@0
|
189 |
XSync( SDL_Display, False );
|
slouken@0
|
190 |
glx_context = this->gl_data->glXCreateContext(GFX_Display,
|
slouken@0
|
191 |
glx_visualinfo, NULL, True);
|
slouken@0
|
192 |
XSync( GFX_Display, False );
|
slouken@0
|
193 |
|
slouken@0
|
194 |
if (glx_context == NULL) {
|
slouken@0
|
195 |
SDL_SetError("Could not create GL context");
|
slouken@0
|
196 |
return -1;
|
slouken@0
|
197 |
}
|
slouken@0
|
198 |
|
slouken@0
|
199 |
gl_active = 1;
|
slouken@0
|
200 |
#else
|
slouken@0
|
201 |
SDL_SetError("X11 driver not configured with OpenGL");
|
slouken@0
|
202 |
#endif
|
slouken@0
|
203 |
if ( gl_active ) {
|
slouken@0
|
204 |
retval = 0;
|
slouken@0
|
205 |
} else {
|
slouken@0
|
206 |
retval = -1;
|
slouken@0
|
207 |
}
|
slouken@0
|
208 |
return(retval);
|
slouken@0
|
209 |
}
|
slouken@0
|
210 |
|
slouken@0
|
211 |
void X11_GL_Shutdown(_THIS)
|
slouken@0
|
212 |
{
|
slouken@0
|
213 |
#ifdef HAVE_OPENGL
|
slouken@0
|
214 |
/* Clean up OpenGL */
|
slouken@0
|
215 |
if( glx_context ) {
|
slouken@0
|
216 |
this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
|
slouken@0
|
217 |
|
slouken@0
|
218 |
if (glx_context != NULL)
|
slouken@0
|
219 |
this->gl_data->glXDestroyContext(GFX_Display, glx_context);
|
slouken@0
|
220 |
|
slouken@0
|
221 |
if( this->gl_data->glXReleaseBuffersMESA ) {
|
slouken@0
|
222 |
this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window);
|
slouken@0
|
223 |
}
|
slouken@0
|
224 |
glx_context = NULL;
|
slouken@0
|
225 |
}
|
slouken@0
|
226 |
gl_active = 0;
|
slouken@0
|
227 |
#endif /* HAVE_OPENGL */
|
slouken@0
|
228 |
}
|
slouken@0
|
229 |
|
slouken@0
|
230 |
#ifdef HAVE_OPENGL
|
slouken@0
|
231 |
|
slouken@0
|
232 |
/* Make the current context active */
|
slouken@0
|
233 |
int X11_GL_MakeCurrent(_THIS)
|
slouken@0
|
234 |
{
|
slouken@0
|
235 |
int retval;
|
slouken@0
|
236 |
|
slouken@0
|
237 |
retval = 0;
|
slouken@0
|
238 |
if ( ! this->gl_data->glXMakeCurrent(GFX_Display,
|
slouken@0
|
239 |
SDL_Window, glx_context) ) {
|
slouken@0
|
240 |
SDL_SetError("Unable to make GL context current");
|
slouken@0
|
241 |
retval = -1;
|
slouken@0
|
242 |
}
|
slouken@0
|
243 |
XSync( GFX_Display, False );
|
slouken@0
|
244 |
|
slouken@0
|
245 |
/* More Voodoo X server workarounds... Grr... */
|
slouken@0
|
246 |
SDL_Lock_EventThread();
|
slouken@0
|
247 |
X11_CheckDGAMouse(this);
|
slouken@0
|
248 |
SDL_Unlock_EventThread();
|
slouken@0
|
249 |
|
slouken@0
|
250 |
return(retval);
|
slouken@0
|
251 |
}
|
slouken@0
|
252 |
|
slouken@0
|
253 |
/* Get attribute data from glX. */
|
slouken@0
|
254 |
int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
|
slouken@0
|
255 |
{
|
slouken@0
|
256 |
int retval;
|
slouken@0
|
257 |
int glx_attrib = None;
|
slouken@0
|
258 |
|
slouken@0
|
259 |
switch( attrib ) {
|
slouken@0
|
260 |
case SDL_GL_RED_SIZE:
|
slouken@0
|
261 |
glx_attrib = GLX_RED_SIZE;
|
slouken@0
|
262 |
break;
|
slouken@0
|
263 |
case SDL_GL_GREEN_SIZE:
|
slouken@0
|
264 |
glx_attrib = GLX_GREEN_SIZE;
|
slouken@0
|
265 |
break;
|
slouken@0
|
266 |
case SDL_GL_BLUE_SIZE:
|
slouken@0
|
267 |
glx_attrib = GLX_BLUE_SIZE;
|
slouken@0
|
268 |
break;
|
slouken@0
|
269 |
case SDL_GL_ALPHA_SIZE:
|
slouken@0
|
270 |
glx_attrib = GLX_ALPHA_SIZE;
|
slouken@0
|
271 |
break;
|
slouken@0
|
272 |
case SDL_GL_DOUBLEBUFFER:
|
slouken@0
|
273 |
glx_attrib = GLX_DOUBLEBUFFER;
|
slouken@0
|
274 |
break;
|
slouken@0
|
275 |
case SDL_GL_BUFFER_SIZE:
|
slouken@0
|
276 |
glx_attrib = GLX_BUFFER_SIZE;
|
slouken@0
|
277 |
break;
|
slouken@0
|
278 |
case SDL_GL_DEPTH_SIZE:
|
slouken@0
|
279 |
glx_attrib = GLX_DEPTH_SIZE;
|
slouken@0
|
280 |
break;
|
slouken@0
|
281 |
case SDL_GL_STENCIL_SIZE:
|
slouken@0
|
282 |
glx_attrib = GLX_STENCIL_SIZE;
|
slouken@0
|
283 |
break;
|
slouken@0
|
284 |
case SDL_GL_ACCUM_RED_SIZE:
|
slouken@0
|
285 |
glx_attrib = GLX_ACCUM_RED_SIZE;
|
slouken@0
|
286 |
break;
|
slouken@0
|
287 |
case SDL_GL_ACCUM_GREEN_SIZE:
|
slouken@0
|
288 |
glx_attrib = GLX_ACCUM_GREEN_SIZE;
|
slouken@0
|
289 |
break;
|
slouken@0
|
290 |
case SDL_GL_ACCUM_BLUE_SIZE:
|
slouken@0
|
291 |
glx_attrib = GLX_ACCUM_BLUE_SIZE;
|
slouken@0
|
292 |
break;
|
slouken@0
|
293 |
case SDL_GL_ACCUM_ALPHA_SIZE:
|
slouken@0
|
294 |
glx_attrib = GLX_ACCUM_ALPHA_SIZE;
|
slouken@0
|
295 |
break;
|
slouken@450
|
296 |
case SDL_GL_STEREO:
|
slouken@450
|
297 |
glx_attrib = GLX_STEREO;
|
slouken@450
|
298 |
break;
|
slouken@0
|
299 |
default:
|
slouken@0
|
300 |
return(-1);
|
slouken@0
|
301 |
}
|
slouken@0
|
302 |
|
slouken@0
|
303 |
retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
|
slouken@0
|
304 |
|
slouken@0
|
305 |
return retval;
|
slouken@0
|
306 |
}
|
slouken@0
|
307 |
|
slouken@0
|
308 |
void X11_GL_SwapBuffers(_THIS)
|
slouken@0
|
309 |
{
|
slouken@0
|
310 |
this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
|
slouken@0
|
311 |
}
|
slouken@0
|
312 |
|
slouken@0
|
313 |
#endif /* HAVE_OPENGL */
|
slouken@0
|
314 |
|
slouken@0
|
315 |
void X11_GL_UnloadLibrary(_THIS)
|
slouken@0
|
316 |
{
|
slouken@0
|
317 |
#ifdef HAVE_OPENGL
|
slouken@0
|
318 |
if ( this->gl_config.driver_loaded ) {
|
slouken@0
|
319 |
dlclose(this->gl_config.dll_handle);
|
slouken@0
|
320 |
|
slouken@0
|
321 |
this->gl_data->glXGetProcAddress = NULL;
|
slouken@0
|
322 |
this->gl_data->glXChooseVisual = NULL;
|
slouken@0
|
323 |
this->gl_data->glXCreateContext = NULL;
|
slouken@0
|
324 |
this->gl_data->glXDestroyContext = NULL;
|
slouken@0
|
325 |
this->gl_data->glXMakeCurrent = NULL;
|
slouken@0
|
326 |
this->gl_data->glXSwapBuffers = NULL;
|
slouken@0
|
327 |
|
slouken@0
|
328 |
this->gl_config.dll_handle = NULL;
|
slouken@0
|
329 |
this->gl_config.driver_loaded = 0;
|
slouken@0
|
330 |
}
|
slouken@0
|
331 |
#endif
|
slouken@0
|
332 |
}
|
slouken@0
|
333 |
|
slouken@0
|
334 |
#ifdef HAVE_OPENGL
|
slouken@0
|
335 |
|
slouken@0
|
336 |
/* Passing a NULL path means load pointers from the application */
|
slouken@0
|
337 |
int X11_GL_LoadLibrary(_THIS, const char* path)
|
slouken@0
|
338 |
{
|
slouken@0
|
339 |
void* handle;
|
slouken@0
|
340 |
int dlopen_flags;
|
slouken@0
|
341 |
|
slouken@0
|
342 |
if ( gl_active ) {
|
slouken@0
|
343 |
SDL_SetError("OpenGL context already created");
|
slouken@0
|
344 |
return -1;
|
slouken@0
|
345 |
}
|
slouken@0
|
346 |
|
slouken@0
|
347 |
#ifdef RTLD_GLOBAL
|
slouken@0
|
348 |
dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
|
slouken@0
|
349 |
#else
|
slouken@0
|
350 |
dlopen_flags = RTLD_LAZY;
|
slouken@0
|
351 |
#endif
|
slouken@0
|
352 |
handle = dlopen(path, dlopen_flags);
|
slouken@0
|
353 |
/* Catch the case where the application isn't linked with GL */
|
slouken@0
|
354 |
if ( (dlsym(handle, "glXChooseVisual") == NULL) && (path == NULL) ) {
|
slouken@0
|
355 |
dlclose(handle);
|
slouken@0
|
356 |
path = getenv("SDL_VIDEO_GL_DRIVER");
|
slouken@0
|
357 |
if ( path == NULL ) {
|
slouken@0
|
358 |
path = DEFAULT_OPENGL;
|
slouken@0
|
359 |
}
|
slouken@0
|
360 |
handle = dlopen(path, dlopen_flags);
|
slouken@0
|
361 |
}
|
slouken@0
|
362 |
if ( handle == NULL ) {
|
slouken@0
|
363 |
SDL_SetError("Could not load OpenGL library");
|
slouken@0
|
364 |
return -1;
|
slouken@0
|
365 |
}
|
slouken@0
|
366 |
|
slouken@0
|
367 |
/* Unload the old driver and reset the pointers */
|
slouken@0
|
368 |
X11_GL_UnloadLibrary(this);
|
slouken@0
|
369 |
|
slouken@0
|
370 |
/* Load new function pointers */
|
slouken@180
|
371 |
this->gl_data->glXGetProcAddress =
|
slouken@180
|
372 |
(void *(*)(const GLubyte *)) dlsym(handle, "glXGetProcAddressARB");
|
slouken@180
|
373 |
this->gl_data->glXChooseVisual =
|
slouken@180
|
374 |
(XVisualInfo *(*)(Display *, int, int *)) dlsym(handle, "glXChooseVisual");
|
slouken@180
|
375 |
this->gl_data->glXCreateContext =
|
slouken@180
|
376 |
(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) dlsym(handle, "glXCreateContext");
|
slouken@180
|
377 |
this->gl_data->glXDestroyContext =
|
slouken@180
|
378 |
(void (*)(Display *, GLXContext)) dlsym(handle, "glXDestroyContext");
|
slouken@180
|
379 |
this->gl_data->glXMakeCurrent =
|
slouken@180
|
380 |
(int (*)(Display *, GLXDrawable, GLXContext)) dlsym(handle, "glXMakeCurrent");
|
slouken@180
|
381 |
this->gl_data->glXSwapBuffers =
|
slouken@180
|
382 |
(void (*)(Display *, GLXDrawable)) dlsym(handle, "glXSwapBuffers");
|
slouken@180
|
383 |
this->gl_data->glXGetConfig =
|
slouken@180
|
384 |
(int (*)(Display *, XVisualInfo *, int, int *)) dlsym(handle, "glXGetConfig");
|
slouken@0
|
385 |
/* We don't compare below for this in case we're not using Mesa. */
|
slouken@180
|
386 |
this->gl_data->glXReleaseBuffersMESA =
|
slouken@180
|
387 |
(void (*)(Display *, GLXDrawable)) dlsym( handle, "glXReleaseBuffersMESA" );
|
slouken@0
|
388 |
|
slouken@0
|
389 |
if ( (this->gl_data->glXChooseVisual == NULL) ||
|
slouken@0
|
390 |
(this->gl_data->glXCreateContext == NULL) ||
|
slouken@0
|
391 |
(this->gl_data->glXDestroyContext == NULL) ||
|
slouken@0
|
392 |
(this->gl_data->glXMakeCurrent == NULL) ||
|
slouken@0
|
393 |
(this->gl_data->glXSwapBuffers == NULL) ||
|
slouken@0
|
394 |
(this->gl_data->glXGetConfig == NULL) ) {
|
slouken@0
|
395 |
SDL_SetError("Could not retrieve OpenGL functions");
|
slouken@0
|
396 |
return -1;
|
slouken@0
|
397 |
}
|
slouken@0
|
398 |
|
slouken@0
|
399 |
this->gl_config.dll_handle = handle;
|
slouken@0
|
400 |
this->gl_config.driver_loaded = 1;
|
slouken@0
|
401 |
if ( path ) {
|
slouken@0
|
402 |
strncpy(this->gl_config.driver_path, path,
|
slouken@0
|
403 |
sizeof(this->gl_config.driver_path)-1);
|
slouken@0
|
404 |
} else {
|
slouken@0
|
405 |
strcpy(this->gl_config.driver_path, "");
|
slouken@0
|
406 |
}
|
slouken@0
|
407 |
return 0;
|
slouken@0
|
408 |
}
|
slouken@0
|
409 |
|
slouken@0
|
410 |
void *X11_GL_GetProcAddress(_THIS, const char* proc)
|
slouken@0
|
411 |
{
|
slouken@110
|
412 |
static char procname[1024];
|
slouken@0
|
413 |
void* handle;
|
slouken@110
|
414 |
void* retval;
|
slouken@0
|
415 |
|
slouken@0
|
416 |
handle = this->gl_config.dll_handle;
|
slouken@0
|
417 |
#if 0 /* This doesn't work correctly yet */
|
slouken@0
|
418 |
if ( this->gl_data->glXGetProcAddress ) {
|
slouken@0
|
419 |
void *func, *func2;
|
slouken@0
|
420 |
func = this->gl_data->glXGetProcAddress(proc);
|
slouken@0
|
421 |
func2 = dlsym(handle, proc);
|
slouken@0
|
422 |
if ( func != func2 ) {
|
slouken@0
|
423 |
fprintf(stderr, "glXGetProcAddress returned %p and dlsym returned %p for %s\n", func, func2, proc);
|
slouken@0
|
424 |
}
|
slouken@0
|
425 |
return this->gl_data->glXGetProcAddress(proc);
|
slouken@0
|
426 |
}
|
slouken@0
|
427 |
#endif
|
slouken@110
|
428 |
#if defined(__OpenBSD__) && !defined(__ELF__)
|
slouken@110
|
429 |
#undef dlsym(x,y);
|
slouken@110
|
430 |
#endif
|
slouken@110
|
431 |
retval = dlsym(handle, proc);
|
slouken@110
|
432 |
if (!retval && strlen(proc) <= 1022) {
|
slouken@127
|
433 |
procname[0] = '_';
|
slouken@110
|
434 |
strcpy(procname + 1, proc);
|
slouken@110
|
435 |
retval = dlsym(handle, procname);
|
slouken@110
|
436 |
}
|
slouken@110
|
437 |
return retval;
|
slouken@0
|
438 |
}
|
slouken@0
|
439 |
|
slouken@0
|
440 |
#endif /* HAVE_OPENGL */
|