src/video/x11/SDL_x11gl.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 01 Feb 2006 08:17:54 +0000
changeset 1315 e94b0d7c33bc
parent 1312 c9b51268668f
child 1336 3692456e7b0f
permissions -rw-r--r--
Merged useful fixes from 1.3 branch
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 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@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#include <stdlib.h>	/* For getenv() prototype */
slouken@0
    24
#include <string.h>
slouken@0
    25
slouken@0
    26
#include "SDL_events_c.h"
slouken@0
    27
#include "SDL_error.h"
slouken@0
    28
#include "SDL_x11video.h"
slouken@0
    29
#include "SDL_x11dga_c.h"
slouken@0
    30
#include "SDL_x11gl_c.h"
slouken@0
    31
slouken@862
    32
#if defined(sgi)
slouken@862
    33
/* IRIX doesn't have a GL library versioning system */
slouken@862
    34
#define DEFAULT_OPENGL	"libGL.so"
icculus@1191
    35
#elif defined(MACOSX)
icculus@1191
    36
#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
slouken@862
    37
#else
slouken@0
    38
#define DEFAULT_OPENGL	"libGL.so.1"
slouken@862
    39
#endif
slouken@0
    40
slouken@667
    41
#ifndef GLX_ARB_multisample
slouken@667
    42
#define GLX_ARB_multisample
slouken@667
    43
#define GLX_SAMPLE_BUFFERS_ARB             100000
slouken@667
    44
#define GLX_SAMPLES_ARB                    100001
slouken@667
    45
#endif
slouken@667
    46
slouken@0
    47
XVisualInfo *X11_GL_GetVisual(_THIS)
slouken@0
    48
{
icculus@1191
    49
#ifdef HAVE_OPENGL_X11
slouken@0
    50
	/* 64 seems nice. */
slouken@0
    51
	int attribs[64];
slouken@0
    52
	int i;
slouken@0
    53
slouken@0
    54
	/* load the gl driver from a default path */
slouken@0
    55
	if ( ! this->gl_config.driver_loaded ) {
slouken@0
    56
	        /* no driver has been loaded, use default (ourselves) */
slouken@0
    57
	        if ( X11_GL_LoadLibrary(this, NULL) < 0 ) {
slouken@0
    58
		        return NULL;
slouken@0
    59
		}
slouken@0
    60
	}
slouken@0
    61
slouken@0
    62
	/* See if we already have a window which we must use */
slouken@0
    63
	if ( SDL_windowid ) {
slouken@0
    64
		XWindowAttributes a;
slouken@0
    65
		XVisualInfo vi_in;
slouken@0
    66
		int out_count;
slouken@0
    67
icculus@1168
    68
		pXGetWindowAttributes(SDL_Display, SDL_Window, &a);
slouken@0
    69
		vi_in.screen = SDL_Screen;
icculus@1168
    70
		vi_in.visualid = pXVisualIDFromVisual(a.visual);
icculus@1168
    71
		glx_visualinfo = pXGetVisualInfo(SDL_Display,
slouken@0
    72
	                     VisualScreenMask|VisualIDMask, &vi_in, &out_count);
slouken@0
    73
		return glx_visualinfo;
slouken@0
    74
	}
slouken@0
    75
slouken@0
    76
        /* Setup our GLX attributes according to the gl_config. */
slouken@450
    77
	i = 0;
slouken@450
    78
	attribs[i++] = GLX_RGBA;
slouken@0
    79
	attribs[i++] = GLX_RED_SIZE;
slouken@0
    80
	attribs[i++] = this->gl_config.red_size;
slouken@0
    81
	attribs[i++] = GLX_GREEN_SIZE;
slouken@0
    82
	attribs[i++] = this->gl_config.green_size;
slouken@0
    83
	attribs[i++] = GLX_BLUE_SIZE;
slouken@0
    84
	attribs[i++] = this->gl_config.blue_size;
slouken@0
    85
slouken@0
    86
	if( this->gl_config.alpha_size ) {
slouken@0
    87
		attribs[i++] = GLX_ALPHA_SIZE;
slouken@0
    88
		attribs[i++] = this->gl_config.alpha_size;
slouken@0
    89
	}
slouken@0
    90
slouken@0
    91
	if( this->gl_config.buffer_size ) {
slouken@450
    92
		attribs[i++] = GLX_BUFFER_SIZE;
slouken@450
    93
		attribs[i++] = this->gl_config.buffer_size;
slouken@0
    94
	}
slouken@0
    95
slouken@0
    96
	if( this->gl_config.double_buffer ) {
slouken@0
    97
		attribs[i++] = GLX_DOUBLEBUFFER;
slouken@0
    98
	}
slouken@0
    99
slouken@0
   100
	attribs[i++] = GLX_DEPTH_SIZE;
slouken@0
   101
	attribs[i++] = this->gl_config.depth_size;
slouken@0
   102
slouken@0
   103
	if( this->gl_config.stencil_size ) {
slouken@0
   104
		attribs[i++] = GLX_STENCIL_SIZE;
slouken@0
   105
		attribs[i++] = this->gl_config.stencil_size;
slouken@0
   106
	}
slouken@0
   107
slouken@0
   108
	if( this->gl_config.accum_red_size ) {
slouken@450
   109
		attribs[i++] = GLX_ACCUM_RED_SIZE;
slouken@0
   110
		attribs[i++] = this->gl_config.accum_red_size;
slouken@0
   111
	}
slouken@0
   112
slouken@0
   113
	if( this->gl_config.accum_green_size ) {
slouken@450
   114
		attribs[i++] = GLX_ACCUM_GREEN_SIZE;
slouken@0
   115
		attribs[i++] = this->gl_config.accum_green_size;
slouken@0
   116
	}
slouken@0
   117
slouken@0
   118
	if( this->gl_config.accum_blue_size ) {
slouken@450
   119
		attribs[i++] = GLX_ACCUM_BLUE_SIZE;
slouken@0
   120
		attribs[i++] = this->gl_config.accum_blue_size;
slouken@0
   121
	}
slouken@0
   122
slouken@0
   123
	if( this->gl_config.accum_alpha_size ) {
slouken@450
   124
		attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
slouken@0
   125
		attribs[i++] = this->gl_config.accum_alpha_size;
slouken@0
   126
	}
slouken@0
   127
slouken@450
   128
	if( this->gl_config.stereo ) {
slouken@450
   129
		attribs[i++] = GLX_STEREO;
slouken@450
   130
		attribs[i++] = this->gl_config.stereo;
slouken@450
   131
	}
slouken@655
   132
	
slouken@656
   133
	if( this->gl_config.multisamplebuffers ) {
slouken@655
   134
		attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
slouken@656
   135
		attribs[i++] = this->gl_config.multisamplebuffers;
slouken@655
   136
	}
slouken@655
   137
	
slouken@656
   138
	if( this->gl_config.multisamplesamples ) {
slouken@655
   139
		attribs[i++] = GLX_SAMPLES_ARB;
slouken@656
   140
		attribs[i++] = this->gl_config.multisamplesamples;
slouken@655
   141
	}
slouken@450
   142
slouken@0
   143
#ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
slouken@1060
   144
	if ( !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
slouken@1060
   145
		attribs[i++] = GLX_X_VISUAL_TYPE;
slouken@1060
   146
		attribs[i++] = GLX_DIRECT_COLOR;
slouken@1060
   147
	}
slouken@0
   148
#endif
slouken@0
   149
	attribs[i++] = None;
slouken@0
   150
slouken@0
   151
 	glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, 
slouken@0
   152
						  SDL_Screen, attribs);
slouken@0
   153
#ifdef GLX_DIRECT_COLOR
slouken@1060
   154
	if( !glx_visualinfo && !getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual?  Try again.. */
slouken@0
   155
		attribs[i-3] = None;
slouken@0
   156
 		glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, 
slouken@0
   157
						  SDL_Screen, attribs);
slouken@0
   158
	}
slouken@0
   159
#endif
slouken@0
   160
	if( !glx_visualinfo ) {
slouken@0
   161
		SDL_SetError( "Couldn't find matching GLX visual");
slouken@0
   162
		return NULL;
slouken@0
   163
	}
slouken@1315
   164
/*
slouken@1315
   165
	printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid);
slouken@1315
   166
*/
slouken@0
   167
	return glx_visualinfo;
slouken@0
   168
#else
slouken@0
   169
	SDL_SetError("X11 driver not configured with OpenGL");
slouken@0
   170
	return NULL;
slouken@0
   171
#endif
slouken@0
   172
}
slouken@0
   173
slouken@0
   174
int X11_GL_CreateWindow(_THIS, int w, int h)
slouken@0
   175
{
slouken@0
   176
	int retval;
icculus@1191
   177
#ifdef HAVE_OPENGL_X11
slouken@0
   178
	XSetWindowAttributes attributes;
slouken@0
   179
	unsigned long mask;
slouken@0
   180
	unsigned long black;
slouken@0
   181
slouken@0
   182
	black = (glx_visualinfo->visual == DefaultVisual(SDL_Display,
slouken@0
   183
						 	SDL_Screen))
slouken@0
   184
	       	? BlackPixel(SDL_Display, SDL_Screen) : 0;
slouken@0
   185
	attributes.background_pixel = black;
slouken@0
   186
	attributes.border_pixel = black;
slouken@0
   187
	attributes.colormap = SDL_XColorMap;
slouken@0
   188
	mask = CWBackPixel | CWBorderPixel | CWColormap;
slouken@0
   189
icculus@1168
   190
	SDL_Window = pXCreateWindow(SDL_Display, WMwindow,
slouken@0
   191
			0, 0, w, h, 0, glx_visualinfo->depth,
slouken@0
   192
			InputOutput, glx_visualinfo->visual,
slouken@0
   193
			mask, &attributes);
slouken@0
   194
	if ( !SDL_Window ) {
slouken@0
   195
		SDL_SetError("Could not create window");
slouken@0
   196
		return -1;
slouken@0
   197
	}
slouken@0
   198
	retval = 0;
slouken@0
   199
#else
slouken@0
   200
	SDL_SetError("X11 driver not configured with OpenGL");
slouken@0
   201
	retval = -1;
slouken@0
   202
#endif
slouken@0
   203
	return(retval);
slouken@0
   204
}
slouken@0
   205
slouken@0
   206
int X11_GL_CreateContext(_THIS)
slouken@0
   207
{
slouken@0
   208
	int retval;
icculus@1191
   209
#ifdef HAVE_OPENGL_X11
slouken@0
   210
	/* We do this to create a clean separation between X and GLX errors. */
icculus@1168
   211
	pXSync( SDL_Display, False );
slouken@0
   212
	glx_context = this->gl_data->glXCreateContext(GFX_Display, 
slouken@0
   213
				     glx_visualinfo, NULL, True);
icculus@1168
   214
	pXSync( GFX_Display, False );
slouken@0
   215
slouken@0
   216
	if (glx_context == NULL) {
slouken@0
   217
		SDL_SetError("Could not create GL context");
slouken@0
   218
		return -1;
slouken@0
   219
	}
slouken@0
   220
slouken@0
   221
	gl_active = 1;
slouken@0
   222
#else
slouken@0
   223
	SDL_SetError("X11 driver not configured with OpenGL");
slouken@0
   224
#endif
slouken@0
   225
	if ( gl_active ) {
slouken@0
   226
		retval = 0;
slouken@0
   227
	} else {
slouken@0
   228
		retval = -1;
slouken@0
   229
	}
slouken@0
   230
	return(retval);
slouken@0
   231
}
slouken@0
   232
slouken@0
   233
void X11_GL_Shutdown(_THIS)
slouken@0
   234
{
icculus@1191
   235
#ifdef HAVE_OPENGL_X11
slouken@0
   236
	/* Clean up OpenGL */
slouken@0
   237
	if( glx_context ) {
slouken@0
   238
		this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
slouken@0
   239
slouken@0
   240
		if (glx_context != NULL)
slouken@0
   241
			this->gl_data->glXDestroyContext(GFX_Display, glx_context);
slouken@0
   242
slouken@0
   243
		glx_context = NULL;
slouken@0
   244
	}
slouken@0
   245
	gl_active = 0;
icculus@1191
   246
#endif /* HAVE_OPENGL_X11 */
slouken@0
   247
}
slouken@0
   248
icculus@1191
   249
#ifdef HAVE_OPENGL_X11
slouken@0
   250
slouken@0
   251
/* Make the current context active */
slouken@0
   252
int X11_GL_MakeCurrent(_THIS)
slouken@0
   253
{
slouken@0
   254
	int retval;
slouken@638
   255
	
slouken@0
   256
	retval = 0;
slouken@0
   257
	if ( ! this->gl_data->glXMakeCurrent(GFX_Display,
slouken@0
   258
	                                     SDL_Window, glx_context) ) {
slouken@0
   259
		SDL_SetError("Unable to make GL context current");
slouken@0
   260
		retval = -1;
slouken@0
   261
	}
icculus@1168
   262
	pXSync( GFX_Display, False );
slouken@0
   263
slouken@0
   264
	/* More Voodoo X server workarounds... Grr... */
slouken@0
   265
	SDL_Lock_EventThread();
slouken@0
   266
	X11_CheckDGAMouse(this);
slouken@0
   267
	SDL_Unlock_EventThread();
slouken@0
   268
slouken@0
   269
	return(retval);
slouken@0
   270
}
slouken@0
   271
slouken@0
   272
/* Get attribute data from glX. */
slouken@0
   273
int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
slouken@0
   274
{
slouken@0
   275
	int retval;
slouken@0
   276
	int glx_attrib = None;
slouken@0
   277
slouken@0
   278
	switch( attrib ) {
slouken@0
   279
	    case SDL_GL_RED_SIZE:
slouken@0
   280
		glx_attrib = GLX_RED_SIZE;
slouken@0
   281
		break;
slouken@0
   282
	    case SDL_GL_GREEN_SIZE:
slouken@0
   283
		glx_attrib = GLX_GREEN_SIZE;
slouken@0
   284
		break;
slouken@0
   285
	    case SDL_GL_BLUE_SIZE:
slouken@0
   286
		glx_attrib = GLX_BLUE_SIZE;
slouken@0
   287
		break;
slouken@0
   288
	    case SDL_GL_ALPHA_SIZE:
slouken@0
   289
		glx_attrib = GLX_ALPHA_SIZE;
slouken@0
   290
		break;
slouken@0
   291
	    case SDL_GL_DOUBLEBUFFER:
slouken@0
   292
		glx_attrib = GLX_DOUBLEBUFFER;
slouken@0
   293
		break;
slouken@0
   294
	    case SDL_GL_BUFFER_SIZE:
slouken@0
   295
		glx_attrib = GLX_BUFFER_SIZE;
slouken@0
   296
		break;
slouken@0
   297
	    case SDL_GL_DEPTH_SIZE:
slouken@0
   298
		glx_attrib = GLX_DEPTH_SIZE;
slouken@0
   299
		break;
slouken@0
   300
	    case SDL_GL_STENCIL_SIZE:
slouken@0
   301
		glx_attrib = GLX_STENCIL_SIZE;
slouken@0
   302
		break;
slouken@0
   303
	    case SDL_GL_ACCUM_RED_SIZE:
slouken@0
   304
		glx_attrib = GLX_ACCUM_RED_SIZE;
slouken@0
   305
		break;
slouken@0
   306
	    case SDL_GL_ACCUM_GREEN_SIZE:
slouken@0
   307
		glx_attrib = GLX_ACCUM_GREEN_SIZE;
slouken@0
   308
		break;
slouken@0
   309
	    case SDL_GL_ACCUM_BLUE_SIZE:
slouken@0
   310
		glx_attrib = GLX_ACCUM_BLUE_SIZE;
slouken@0
   311
		break;
slouken@0
   312
	    case SDL_GL_ACCUM_ALPHA_SIZE:
slouken@0
   313
		glx_attrib = GLX_ACCUM_ALPHA_SIZE;
slouken@0
   314
		break;
slouken@450
   315
	    case SDL_GL_STEREO:
slouken@450
   316
		glx_attrib = GLX_STEREO;
slouken@450
   317
		break;
slouken@656
   318
 	    case SDL_GL_MULTISAMPLEBUFFERS:
slouken@655
   319
 		glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
slouken@655
   320
 		break;
slouken@656
   321
 	    case SDL_GL_MULTISAMPLESAMPLES:
slouken@655
   322
 		glx_attrib = GLX_SAMPLES_ARB;
slouken@655
   323
 		break;
slouken@0
   324
	    default:
slouken@0
   325
		return(-1);
slouken@0
   326
	}
slouken@0
   327
slouken@0
   328
	retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
slouken@0
   329
slouken@0
   330
	return retval;
slouken@0
   331
}
slouken@0
   332
slouken@0
   333
void X11_GL_SwapBuffers(_THIS)
slouken@0
   334
{
slouken@0
   335
	this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
slouken@0
   336
}
slouken@0
   337
icculus@1191
   338
#endif /* HAVE_OPENGL_X11 */
slouken@0
   339
slouken@0
   340
void X11_GL_UnloadLibrary(_THIS)
slouken@0
   341
{
icculus@1191
   342
#ifdef HAVE_OPENGL_X11
slouken@0
   343
	if ( this->gl_config.driver_loaded ) {
icculus@1191
   344
icculus@1191
   345
		/* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */
icculus@1191
   346
		#ifdef USE_DLOPEN
slouken@0
   347
		dlclose(this->gl_config.dll_handle);
icculus@1191
   348
		#else
icculus@1191
   349
		SDL_UnloadObject(this->gl_config.dll_handle);
icculus@1191
   350
		#endif
slouken@0
   351
slouken@0
   352
		this->gl_data->glXGetProcAddress = NULL;
slouken@0
   353
		this->gl_data->glXChooseVisual = NULL;
slouken@0
   354
		this->gl_data->glXCreateContext = NULL;
slouken@0
   355
		this->gl_data->glXDestroyContext = NULL;
slouken@0
   356
		this->gl_data->glXMakeCurrent = NULL;
slouken@0
   357
		this->gl_data->glXSwapBuffers = NULL;
slouken@0
   358
slouken@0
   359
		this->gl_config.dll_handle = NULL;
slouken@0
   360
		this->gl_config.driver_loaded = 0;
slouken@0
   361
	}
slouken@0
   362
#endif
slouken@0
   363
}
slouken@0
   364
icculus@1191
   365
#ifdef HAVE_OPENGL_X11
slouken@0
   366
icculus@1191
   367
static void *do_dlsym(void *handle, const char *name)
icculus@1191
   368
{
icculus@1191
   369
	/* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */
icculus@1191
   370
#ifdef USE_DLOPEN
icculus@1191
   371
	return dlsym(handle, name);
icculus@1191
   372
#else
icculus@1191
   373
	return SDL_LoadFunction(handle, name);
icculus@1191
   374
#endif
icculus@1191
   375
}
icculus@1191
   376
icculus@1191
   377
#if defined(__OpenBSD__) && !defined(__ELF__)
icculus@1191
   378
#define do_dlsym(x,y) do_dlsym(x, "_" y)
icculus@1191
   379
#endif
icculus@1182
   380
slouken@0
   381
/* Passing a NULL path means load pointers from the application */
slouken@0
   382
int X11_GL_LoadLibrary(_THIS, const char* path) 
slouken@0
   383
{
icculus@1191
   384
	void* handle = NULL;
slouken@0
   385
icculus@1182
   386
	if ( gl_active ) {
icculus@1182
   387
		SDL_SetError("OpenGL context already created");
icculus@1182
   388
		return -1;
icculus@1182
   389
	}
icculus@1182
   390
icculus@1182
   391
	if ( path == NULL ) {
slouken@0
   392
		path = getenv("SDL_VIDEO_GL_DRIVER");
slouken@0
   393
		if ( path == NULL ) {
slouken@0
   394
			path = DEFAULT_OPENGL;
slouken@0
   395
		}
icculus@1191
   396
	}
icculus@1191
   397
icculus@1191
   398
	/* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */
icculus@1191
   399
	#ifdef USE_DLOPEN
icculus@1191
   400
	{
icculus@1191
   401
		#ifdef RTLD_GLOBAL
icculus@1191
   402
			int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
icculus@1191
   403
		#else
icculus@1191
   404
			int dlopen_flags = RTLD_LAZY;
icculus@1191
   405
		#endif
slouken@0
   406
		handle = dlopen(path, dlopen_flags);
icculus@1246
   407
		if ( handle == NULL ) {
icculus@1246
   408
			SDL_SetError("Could not load OpenGL library: %s", (const char *) dlerror());
icculus@1246
   409
			return -1;
icculus@1246
   410
		}
slouken@0
   411
	}
icculus@1191
   412
	#else
icculus@1191
   413
		handle = SDL_LoadObject(path);
icculus@1246
   414
		if ( handle == NULL ) {
icculus@1247
   415
			/* SDL_LoadObject() will call SDL_SetError() for us. */
icculus@1246
   416
			return -1;
icculus@1246
   417
		}
icculus@1191
   418
	#endif
icculus@1191
   419
slouken@0
   420
slouken@0
   421
	/* Unload the old driver and reset the pointers */
slouken@0
   422
	X11_GL_UnloadLibrary(this);
slouken@0
   423
slouken@0
   424
	/* Load new function pointers */
slouken@180
   425
	this->gl_data->glXGetProcAddress =
icculus@1191
   426
		(void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB");
slouken@180
   427
	this->gl_data->glXChooseVisual =
icculus@1191
   428
		(XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual");
slouken@180
   429
	this->gl_data->glXCreateContext =
icculus@1191
   430
		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext");
slouken@180
   431
	this->gl_data->glXDestroyContext =
icculus@1191
   432
		(void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext");
slouken@180
   433
	this->gl_data->glXMakeCurrent =
icculus@1191
   434
		(int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent");
slouken@180
   435
	this->gl_data->glXSwapBuffers =
icculus@1191
   436
		(void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers");
slouken@180
   437
	this->gl_data->glXGetConfig =
icculus@1191
   438
		(int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig");
slouken@638
   439
	this->gl_data->glXQueryExtensionsString =
icculus@1191
   440
		(const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
slouken@638
   441
	
slouken@1315
   442
slouken@0
   443
	if ( (this->gl_data->glXChooseVisual == NULL) || 
slouken@0
   444
	     (this->gl_data->glXCreateContext == NULL) ||
slouken@0
   445
	     (this->gl_data->glXDestroyContext == NULL) ||
slouken@0
   446
	     (this->gl_data->glXMakeCurrent == NULL) ||
slouken@0
   447
	     (this->gl_data->glXSwapBuffers == NULL) ||
slouken@638
   448
	     (this->gl_data->glXGetConfig == NULL) ||
slouken@638
   449
	     (this->gl_data->glXQueryExtensionsString == NULL)) {
slouken@0
   450
		SDL_SetError("Could not retrieve OpenGL functions");
slouken@0
   451
		return -1;
slouken@0
   452
	}
slouken@0
   453
slouken@0
   454
	this->gl_config.dll_handle = handle;
slouken@0
   455
	this->gl_config.driver_loaded = 1;
slouken@0
   456
	if ( path ) {
slouken@0
   457
		strncpy(this->gl_config.driver_path, path,
slouken@0
   458
			sizeof(this->gl_config.driver_path)-1);
slouken@0
   459
	} else {
slouken@0
   460
		strcpy(this->gl_config.driver_path, "");
slouken@0
   461
	}
slouken@0
   462
	return 0;
slouken@0
   463
}
slouken@0
   464
slouken@0
   465
void *X11_GL_GetProcAddress(_THIS, const char* proc)
slouken@0
   466
{
slouken@110
   467
	static char procname[1024];
slouken@0
   468
	void* handle;
slouken@110
   469
	void* retval;
slouken@0
   470
	
slouken@0
   471
	handle = this->gl_config.dll_handle;
slouken@0
   472
	if ( this->gl_data->glXGetProcAddress ) {
slouken@1196
   473
		return this->gl_data->glXGetProcAddress((const GLubyte *)proc);
slouken@0
   474
	}
slouken@110
   475
#if defined(__OpenBSD__) && !defined(__ELF__)
icculus@1191
   476
#undef do_dlsym
slouken@110
   477
#endif
icculus@1191
   478
	retval = do_dlsym(handle, proc);
slouken@110
   479
	if (!retval && strlen(proc) <= 1022) {
slouken@127
   480
		procname[0] = '_';
slouken@110
   481
		strcpy(procname + 1, proc);
icculus@1191
   482
		retval = do_dlsym(handle, procname);
slouken@110
   483
	}
slouken@110
   484
	return retval;
slouken@0
   485
}
slouken@0
   486
icculus@1191
   487
#endif /* HAVE_OPENGL_X11 */