src/video/wincommon/SDL_wingl.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2004 15:48:44 +0000
changeset 766 ed57c876700d
parent 677 92a933bf2f0f
child 769 b8d311d90021
permissions -rw-r--r--
Date: Wed, 26 Nov 2003 01:52:02 +0800
From: "Andy Pfiffer"
Subject: [SDL] patch: PocketPC 2000 diffs for release_1_2_6

I was making a backup of my current workspace of SDL for PocketPC,
and thought I would send out my diffs.

Apologies in advance if the patch has become whitespace mangled.

These diffs are relative to CVS tag release_1_2_6, and contain (I think)
all changes that have been mentioned on the mailing list in the last
few months.

I only have PocketPC 2000 & an ARM-based device (iPaq 3635), and I
only use Embedded Visual Tools 3.0, so I can't say for sure if it
breaks other PocketPC 200[023] builds.
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@655
    28
#include <string.h>
slouken@655
    29
slouken@0
    30
/* WGL implementation of SDL OpenGL support */
slouken@0
    31
slouken@453
    32
#ifdef HAVE_OPENGL
slouken@327
    33
#include "SDL_opengl.h"
slouken@453
    34
#endif
slouken@0
    35
#include "SDL_error.h"
slouken@0
    36
#include "SDL_lowvideo.h"
slouken@0
    37
#include "SDL_wingl_c.h"
slouken@0
    38
slouken@0
    39
#ifdef HAVE_OPENGL
slouken@0
    40
#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
slouken@0
    41
#endif
slouken@0
    42
slouken@373
    43
/* If setting the HDC fails, we may need to recreate the window (MSDN) */
slouken@373
    44
static int WIN_GL_ResetWindow(_THIS)
slouken@373
    45
{
slouken@373
    46
	int status = 0;
slouken@373
    47
	int can_reset = 1;
slouken@373
    48
slouken@373
    49
	/* If we were passed a window, then we can't create a new one */
slouken@373
    50
	if ( SDL_windowid ) {
slouken@373
    51
		can_reset = 0;
slouken@373
    52
	}
slouken@373
    53
#ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
slouken@373
    54
	if ( can_reset ) {
slouken@373
    55
		/* Save the existing window attributes */
slouken@373
    56
		LONG style;
slouken@373
    57
		RECT rect = { 0, 0, 0, 0 };
slouken@373
    58
		style = GetWindowLong(SDL_Window, GWL_STYLE);
slouken@373
    59
		GetWindowRect(SDL_Window, &rect);
slouken@373
    60
		DestroyWindow(SDL_Window);
slouken@373
    61
		SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
slouken@373
    62
		                          style,
slouken@373
    63
					  rect.left, rect.top,
slouken@373
    64
                                          (rect.right-rect.left)+1,
slouken@373
    65
                                          (rect.top-rect.bottom)+1,
slouken@373
    66
		                          NULL, NULL, SDL_Instance, NULL);
slouken@373
    67
		if ( SDL_Window ) {
slouken@373
    68
			this->SetCaption(this, this->wm_title, this->wm_icon);
slouken@373
    69
		} else {
slouken@373
    70
			SDL_SetError("Couldn't create window");
slouken@373
    71
			status = -1;
slouken@373
    72
		}
slouken@373
    73
	} else
slouken@373
    74
#endif /* !_WIN32_WCE */
slouken@373
    75
	{
slouken@373
    76
		SDL_SetError("Unable to reset window for OpenGL context");
slouken@373
    77
		status = -1;
slouken@373
    78
	}
slouken@373
    79
	return(status);
slouken@373
    80
}
slouken@0
    81
slouken@766
    82
#ifdef HAVE_OPENGL
slouken@677
    83
static void Init_WGL_ARB_extensions(_THIS)
slouken@655
    84
{
slouken@655
    85
	HWND hwnd;
slouken@655
    86
	HDC hdc;
slouken@655
    87
	HGLRC hglrc;
slouken@655
    88
	int pformat;
slouken@655
    89
	const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0;
slouken@655
    90
	
slouken@671
    91
	hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
slouken@655
    92
	                    0, 0, 10, 10,
slouken@655
    93
	                    NULL, NULL, SDL_Instance,NULL);
slouken@655
    94
	hdc = GetDC(hwnd);
slouken@655
    95
slouken@655
    96
	pformat = ChoosePixelFormat(hdc, &GL_pfd);
slouken@655
    97
	SetPixelFormat(hdc, pformat, &GL_pfd);
slouken@655
    98
slouken@655
    99
	hglrc = this->gl_data->wglCreateContext(hdc);
slouken@671
   100
	if ( hglrc ) {
slouken@671
   101
		this->gl_data->wglMakeCurrent(hdc, hglrc);
slouken@671
   102
	}
slouken@655
   103
slouken@655
   104
	wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC))
slouken@655
   105
		this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
slouken@655
   106
slouken@655
   107
	if(wglGetExtensionsStringARB && strstr(wglGetExtensionsStringARB(hdc),"WGL_ARB_pixel_format")) {
slouken@655
   108
		this->gl_data->wglChoosePixelFormatARB =
slouken@655
   109
			(BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))
slouken@655
   110
			this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
slouken@655
   111
		this->gl_data->wglGetPixelFormatAttribivARB =
slouken@655
   112
			(BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *))
slouken@655
   113
			this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
slouken@655
   114
slouken@655
   115
		if( (this->gl_data->wglChoosePixelFormatARB != NULL) &&
slouken@655
   116
		    (this->gl_data->wglGetPixelFormatAttribivARB != NULL) )
slouken@655
   117
			this->gl_data->wgl_arb_pixel_format = 1;
slouken@655
   118
		else 
slouken@655
   119
			this->gl_data->wgl_arb_pixel_format = 0;
slouken@655
   120
	} else {
slouken@655
   121
		this->gl_data->wgl_arb_pixel_format = 0;
slouken@655
   122
	}
slouken@655
   123
	
slouken@671
   124
	if ( hglrc ) {
slouken@671
   125
		this->gl_data->wglMakeCurrent(NULL, NULL);
slouken@671
   126
		this->gl_data->wglDeleteContext(hglrc);
slouken@671
   127
	}
slouken@655
   128
	ReleaseDC(hwnd, hdc);
slouken@655
   129
	DestroyWindow(hwnd);
slouken@655
   130
}
slouken@766
   131
#endif /* !HAVE_OPENGL */
slouken@655
   132
slouken@0
   133
int WIN_GL_SetupWindow(_THIS)
slouken@0
   134
{
slouken@0
   135
	int retval;
slouken@0
   136
#ifdef HAVE_OPENGL
slouken@373
   137
	int i;
slouken@655
   138
	unsigned int matching;
slouken@655
   139
	int iAttribs[64];
slouken@655
   140
	int *iAttr;
slouken@655
   141
	float fAttribs[1] = { 0 };
slouken@0
   142
slouken@0
   143
	/* load the gl driver from a default path */
slouken@0
   144
	if ( ! this->gl_config.driver_loaded ) {
slouken@0
   145
		/* no driver has been loaded, use default (ourselves) */
slouken@0
   146
		if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) {
slouken@0
   147
			return(-1);
slouken@0
   148
		}
slouken@0
   149
	}
slouken@0
   150
slouken@373
   151
	for ( i=0; ; ++i ) {
slouken@373
   152
		/* Get the window device context for our OpenGL drawing */
slouken@373
   153
		GL_hdc = GetDC(SDL_Window);
slouken@373
   154
		if ( GL_hdc == NULL ) {
slouken@373
   155
			SDL_SetError("Unable to get DC for SDL_Window");
slouken@373
   156
			return(-1);
slouken@373
   157
		}
slouken@0
   158
slouken@373
   159
		/* Set up the pixel format descriptor with our needed format */
slouken@373
   160
		memset(&GL_pfd, 0, sizeof(GL_pfd));
slouken@373
   161
		GL_pfd.nSize = sizeof(GL_pfd);
slouken@373
   162
		GL_pfd.nVersion = 1;
slouken@373
   163
		GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
slouken@373
   164
		if ( this->gl_config.double_buffer ) {
slouken@373
   165
			GL_pfd.dwFlags |= PFD_DOUBLEBUFFER;
slouken@373
   166
		}
slouken@450
   167
		if ( this->gl_config.stereo ) {
slouken@450
   168
			GL_pfd.dwFlags |= PFD_STEREO;
slouken@450
   169
		}
slouken@373
   170
		GL_pfd.iPixelType = PFD_TYPE_RGBA;
slouken@373
   171
		GL_pfd.cColorBits = this->gl_config.buffer_size;
slouken@373
   172
		GL_pfd.cRedBits = this->gl_config.red_size;
slouken@373
   173
		GL_pfd.cGreenBits = this->gl_config.green_size;
slouken@373
   174
		GL_pfd.cBlueBits = this->gl_config.blue_size;
slouken@373
   175
		GL_pfd.cAlphaBits = this->gl_config.alpha_size;
slouken@373
   176
		GL_pfd.cAccumRedBits = this->gl_config.accum_red_size;
slouken@373
   177
		GL_pfd.cAccumGreenBits = this->gl_config.accum_green_size;
slouken@373
   178
		GL_pfd.cAccumBlueBits = this->gl_config.accum_blue_size;
slouken@373
   179
		GL_pfd.cAccumAlphaBits = this->gl_config.accum_alpha_size;
slouken@373
   180
		GL_pfd.cAccumBits =
slouken@373
   181
			(GL_pfd.cAccumRedBits + GL_pfd.cAccumGreenBits +
slouken@373
   182
			 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits);
slouken@373
   183
		GL_pfd.cDepthBits = this->gl_config.depth_size;
slouken@373
   184
		GL_pfd.cStencilBits = this->gl_config.stencil_size;
slouken@0
   185
slouken@655
   186
		/* initialize WGL_ARB_pixel_format */
slouken@655
   187
		Init_WGL_ARB_extensions(this);
slouken@655
   188
slouken@655
   189
		/* setup WGL_ARB_pixel_format attribs */
slouken@655
   190
		iAttr = &iAttribs[0];
slouken@655
   191
slouken@655
   192
		*iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
slouken@655
   193
		*iAttr++ = GL_TRUE;
slouken@655
   194
		*iAttr++ = WGL_ACCELERATION_ARB;
slouken@655
   195
		*iAttr++ = WGL_FULL_ACCELERATION_ARB;
slouken@655
   196
		*iAttr++ = WGL_RED_BITS_ARB;
slouken@655
   197
		*iAttr++ = this->gl_config.red_size;
slouken@655
   198
		*iAttr++ = WGL_GREEN_BITS_ARB;
slouken@655
   199
		*iAttr++ = this->gl_config.green_size;
slouken@655
   200
		*iAttr++ = WGL_BLUE_BITS_ARB;
slouken@655
   201
		*iAttr++ = this->gl_config.blue_size;
slouken@655
   202
		
slouken@655
   203
		if ( this->gl_config.alpha_size ) {
slouken@655
   204
			*iAttr++ = WGL_ALPHA_BITS_ARB;
slouken@655
   205
			*iAttr++ = this->gl_config.alpha_size;
slouken@655
   206
		}
slouken@655
   207
slouken@655
   208
		if ( this->gl_config.double_buffer ) {
slouken@655
   209
			*iAttr ++ = WGL_DOUBLE_BUFFER_ARB;
slouken@655
   210
			*iAttr ++ = GL_TRUE;
slouken@655
   211
		}
slouken@655
   212
slouken@655
   213
		*iAttr++ = WGL_DEPTH_BITS_ARB;
slouken@655
   214
		*iAttr++ = this->gl_config.depth_size;
slouken@655
   215
slouken@655
   216
		if ( this->gl_config.stencil_size ) {
slouken@655
   217
			*iAttr++ = WGL_STENCIL_BITS_ARB;
slouken@655
   218
			*iAttr++ = this->gl_config.stencil_size;
slouken@655
   219
		}
slouken@655
   220
slouken@655
   221
		if ( this->gl_config.accum_red_size ) {
slouken@655
   222
			*iAttr++ = WGL_ACCUM_RED_BITS_ARB;
slouken@655
   223
			*iAttr++ = this->gl_config.accum_red_size;
slouken@655
   224
		}
slouken@655
   225
slouken@655
   226
		if ( this->gl_config.accum_green_size ) {
slouken@655
   227
			*iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
slouken@655
   228
			*iAttr++ = this->gl_config.accum_green_size;
slouken@655
   229
		}
slouken@655
   230
slouken@655
   231
		if ( this->gl_config.accum_blue_size ) {
slouken@655
   232
			*iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
slouken@655
   233
			*iAttr++ = this->gl_config.accum_blue_size;
slouken@655
   234
		}
slouken@655
   235
slouken@655
   236
		if ( this->gl_config.accum_alpha_size ) {
slouken@655
   237
			*iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
slouken@655
   238
			*iAttr++ = this->gl_config.accum_alpha_size;
slouken@655
   239
		}
slouken@655
   240
slouken@655
   241
		if ( this->gl_config.stereo ) {
slouken@655
   242
			*iAttr++ = WGL_STEREO_ARB;
slouken@655
   243
			*iAttr++ = this->gl_config.stereo;
slouken@655
   244
		}
slouken@655
   245
slouken@656
   246
		if ( this->gl_config.multisamplebuffers ) {
slouken@655
   247
			*iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
slouken@656
   248
			*iAttr++ = this->gl_config.multisamplebuffers;
slouken@655
   249
		}
slouken@655
   250
slouken@656
   251
		if ( this->gl_config.multisamplesamples ) {
slouken@655
   252
			*iAttr++ = WGL_SAMPLES_ARB;
slouken@656
   253
			*iAttr++ = this->gl_config.multisamplesamples;
slouken@655
   254
		}
slouken@655
   255
slouken@655
   256
		*iAttr = 0;
slouken@655
   257
slouken@373
   258
		/* Choose and set the closest available pixel format */
slouken@655
   259
		if ( !this->gl_data->wgl_arb_pixel_format ||
slouken@655
   260
		     !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) ||
slouken@655
   261
		     !matching ) {
slouken@655
   262
			pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
slouken@655
   263
			this->gl_data->wgl_arb_pixel_format = 0;
slouken@655
   264
		}
slouken@373
   265
		if ( !pixel_format ) {
slouken@373
   266
			SDL_SetError("No matching GL pixel format available");
slouken@373
   267
			return(-1);
slouken@373
   268
		}
slouken@655
   269
		if ( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
slouken@373
   270
			if ( i == 0 ) {
slouken@373
   271
				/* First time through, try resetting the window */
slouken@373
   272
				if ( WIN_GL_ResetWindow(this) < 0 ) {
slouken@373
   273
					return(-1);
slouken@373
   274
				}
slouken@373
   275
				continue;
slouken@373
   276
			}
slouken@373
   277
			SDL_SetError("Unable to set HDC pixel format");
slouken@373
   278
			return(-1);
slouken@373
   279
		}
slouken@373
   280
		/* We either succeeded or failed by this point */
slouken@373
   281
		break;
slouken@0
   282
	}
slouken@0
   283
	DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
slouken@0
   284
slouken@0
   285
	GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
slouken@655
   286
	if ( GL_hrc == NULL ) {
slouken@0
   287
		SDL_SetError("Unable to create GL context");
slouken@0
   288
		return(-1);
slouken@0
   289
	}
slouken@0
   290
	gl_active = 1;
slouken@0
   291
#else
slouken@0
   292
	SDL_SetError("WIN driver not configured with OpenGL");
slouken@0
   293
#endif
slouken@0
   294
	if ( gl_active ) {
slouken@0
   295
		retval = 0;
slouken@0
   296
	} else {
slouken@0
   297
		retval = -1;
slouken@0
   298
	}
slouken@0
   299
	return(retval);
slouken@0
   300
}
slouken@0
   301
slouken@0
   302
void WIN_GL_ShutDown(_THIS)
slouken@0
   303
{
slouken@0
   304
#ifdef HAVE_OPENGL
slouken@0
   305
	/* Clean up OpenGL */
slouken@0
   306
	if ( GL_hrc ) {
slouken@0
   307
		this->gl_data->wglMakeCurrent(NULL, NULL);
slouken@0
   308
		this->gl_data->wglDeleteContext(GL_hrc);
slouken@0
   309
		GL_hrc = NULL;
slouken@0
   310
	}
slouken@0
   311
	if ( GL_hdc ) {
slouken@0
   312
		ReleaseDC(SDL_Window, GL_hdc);
slouken@0
   313
		GL_hdc = NULL;
slouken@0
   314
	}
slouken@0
   315
	gl_active = 0;
slouken@0
   316
slouken@0
   317
	WIN_GL_UnloadLibrary(this);
slouken@0
   318
#endif /* HAVE_OPENGL */
slouken@0
   319
}
slouken@0
   320
slouken@0
   321
#ifdef HAVE_OPENGL
slouken@0
   322
slouken@0
   323
/* Make the current context active */
slouken@0
   324
int WIN_GL_MakeCurrent(_THIS)
slouken@0
   325
{
slouken@0
   326
	int retval;
slouken@0
   327
slouken@0
   328
	retval = 0;
slouken@0
   329
	if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) {
slouken@0
   330
		SDL_SetError("Unable to make GL context current");
slouken@0
   331
		retval = -1;
slouken@0
   332
	}
slouken@0
   333
	return(retval);
slouken@0
   334
}
slouken@0
   335
slouken@0
   336
/* Get attribute data from glX. */
slouken@0
   337
int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
slouken@0
   338
{
slouken@0
   339
	int retval;
slouken@655
   340
	
slouken@655
   341
	if ( this->gl_data->wgl_arb_pixel_format ) {
slouken@655
   342
		int wgl_attrib;
slouken@655
   343
slouken@655
   344
		switch(attrib) {
slouken@655
   345
		    case SDL_GL_RED_SIZE:
slouken@655
   346
			wgl_attrib = WGL_RED_BITS_ARB;
slouken@655
   347
			break;
slouken@655
   348
		    case SDL_GL_GREEN_SIZE:
slouken@655
   349
			wgl_attrib = WGL_GREEN_BITS_ARB;
slouken@655
   350
			break;
slouken@655
   351
		    case SDL_GL_BLUE_SIZE:
slouken@655
   352
			wgl_attrib = WGL_BLUE_BITS_ARB;
slouken@655
   353
			break;
slouken@655
   354
		    case SDL_GL_ALPHA_SIZE:
slouken@655
   355
			wgl_attrib = WGL_ALPHA_BITS_ARB;
slouken@655
   356
			break;
slouken@655
   357
		    case SDL_GL_DOUBLEBUFFER:
slouken@655
   358
			wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
slouken@655
   359
			break;
slouken@655
   360
		    case SDL_GL_BUFFER_SIZE:
slouken@655
   361
			wgl_attrib = WGL_COLOR_BITS_ARB;
slouken@655
   362
			break;
slouken@655
   363
		    case SDL_GL_DEPTH_SIZE:
slouken@655
   364
			wgl_attrib = WGL_DEPTH_BITS_ARB;
slouken@655
   365
			break;
slouken@655
   366
		    case SDL_GL_STENCIL_SIZE:
slouken@655
   367
			wgl_attrib = WGL_STENCIL_BITS_ARB;
slouken@655
   368
			break;
slouken@655
   369
		    case SDL_GL_ACCUM_RED_SIZE:
slouken@655
   370
			wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
slouken@655
   371
			break;
slouken@655
   372
		    case SDL_GL_ACCUM_GREEN_SIZE:
slouken@655
   373
			wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
slouken@655
   374
			break;
slouken@655
   375
		    case SDL_GL_ACCUM_BLUE_SIZE:
slouken@655
   376
			wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
slouken@655
   377
			break;
slouken@655
   378
		    case SDL_GL_ACCUM_ALPHA_SIZE:
slouken@655
   379
			wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
slouken@655
   380
			break;
slouken@655
   381
		    case SDL_GL_STEREO:
slouken@655
   382
			wgl_attrib = WGL_STEREO_ARB;
slouken@655
   383
			break;
slouken@656
   384
		    case SDL_GL_MULTISAMPLEBUFFERS:
slouken@655
   385
			wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
slouken@655
   386
			break;
slouken@656
   387
		    case SDL_GL_MULTISAMPLESAMPLES:
slouken@655
   388
			wgl_attrib = WGL_SAMPLES_ARB;
slouken@655
   389
			break;
slouken@655
   390
		    default:
slouken@655
   391
			return(-1);
slouken@655
   392
		}
slouken@655
   393
		this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
slouken@655
   394
slouken@655
   395
		return 0;
slouken@655
   396
	}
slouken@0
   397
slouken@0
   398
	retval = 0;
slouken@655
   399
	switch ( attrib ) {
slouken@0
   400
	    case SDL_GL_RED_SIZE:
slouken@0
   401
		*value = GL_pfd.cRedBits;
slouken@0
   402
		break;
slouken@0
   403
	    case SDL_GL_GREEN_SIZE:
slouken@0
   404
		*value = GL_pfd.cGreenBits;
slouken@0
   405
		break;
slouken@0
   406
	    case SDL_GL_BLUE_SIZE:
slouken@0
   407
		*value = GL_pfd.cBlueBits;
slouken@0
   408
		break;
slouken@0
   409
	    case SDL_GL_ALPHA_SIZE:
slouken@0
   410
		*value = GL_pfd.cAlphaBits;
slouken@0
   411
		break;
slouken@0
   412
	    case SDL_GL_DOUBLEBUFFER:
slouken@0
   413
		if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) {
slouken@0
   414
			*value = 1;
slouken@0
   415
		} else {
slouken@0
   416
			*value = 0;
slouken@0
   417
		}
slouken@0
   418
		break;
slouken@0
   419
	    case SDL_GL_BUFFER_SIZE:
slouken@0
   420
		*value = GL_pfd.cColorBits;
slouken@0
   421
		break;
slouken@0
   422
	    case SDL_GL_DEPTH_SIZE:
slouken@0
   423
		*value = GL_pfd.cDepthBits;
slouken@0
   424
		break;
slouken@0
   425
	    case SDL_GL_STENCIL_SIZE:
slouken@0
   426
		*value = GL_pfd.cStencilBits;
slouken@0
   427
		break;
slouken@0
   428
	    case SDL_GL_ACCUM_RED_SIZE:
slouken@0
   429
		*value = GL_pfd.cAccumRedBits;
slouken@0
   430
		break;
slouken@0
   431
	    case SDL_GL_ACCUM_GREEN_SIZE:
slouken@0
   432
		*value = GL_pfd.cAccumGreenBits;
slouken@0
   433
		break;
slouken@0
   434
	    case SDL_GL_ACCUM_BLUE_SIZE:
slouken@0
   435
		*value = GL_pfd.cAccumBlueBits;
slouken@0
   436
		break;
slouken@0
   437
	    case SDL_GL_ACCUM_ALPHA_SIZE:
slouken@0
   438
		*value = GL_pfd.cAccumAlphaBits;
slouken@0
   439
		break;
slouken@450
   440
	    case SDL_GL_STEREO:
slouken@450
   441
		if ( GL_pfd.dwFlags & PFD_STEREO ) {
slouken@450
   442
			*value = 1;
slouken@450
   443
		} else {
slouken@450
   444
			*value = 0;
slouken@450
   445
		}
slouken@450
   446
		break;
slouken@0
   447
	    default:
slouken@0
   448
		retval = -1;
slouken@0
   449
		break;
slouken@0
   450
	}
slouken@0
   451
	return retval;
slouken@0
   452
}
slouken@0
   453
slouken@0
   454
void WIN_GL_SwapBuffers(_THIS)
slouken@0
   455
{
slouken@0
   456
	SwapBuffers(GL_hdc);
slouken@0
   457
}
slouken@0
   458
slouken@0
   459
void WIN_GL_UnloadLibrary(_THIS)
slouken@0
   460
{
slouken@0
   461
	if ( this->gl_config.driver_loaded ) {
slouken@0
   462
		FreeLibrary((HMODULE)this->gl_config.dll_handle);
slouken@0
   463
slouken@0
   464
		this->gl_data->wglGetProcAddress = NULL;
slouken@0
   465
		this->gl_data->wglCreateContext = NULL;
slouken@0
   466
		this->gl_data->wglDeleteContext = NULL;
slouken@0
   467
		this->gl_data->wglMakeCurrent = NULL;
slouken@655
   468
		this->gl_data->wglChoosePixelFormatARB = NULL;
slouken@655
   469
		this->gl_data->wglGetPixelFormatAttribivARB = NULL;
slouken@0
   470
slouken@0
   471
		this->gl_config.dll_handle = NULL;
slouken@0
   472
		this->gl_config.driver_loaded = 0;
slouken@0
   473
	}
slouken@0
   474
}
slouken@0
   475
slouken@0
   476
/* Passing a NULL path means load pointers from the application */
slouken@0
   477
int WIN_GL_LoadLibrary(_THIS, const char* path) 
slouken@0
   478
{
slouken@0
   479
	HMODULE handle;
slouken@0
   480
slouken@0
   481
 	if ( gl_active ) {
slouken@0
   482
 		SDL_SetError("OpenGL context already created");
slouken@0
   483
 		return -1;
slouken@0
   484
 	}
slouken@0
   485
slouken@0
   486
	if ( path == NULL ) {
slouken@0
   487
		path = DEFAULT_GL_DRIVER_PATH;
slouken@0
   488
	}
slouken@0
   489
	handle = LoadLibrary(path);
slouken@0
   490
	if ( handle == NULL ) {
slouken@0
   491
		SDL_SetError("Could not load OpenGL library");
slouken@0
   492
		return -1;
slouken@0
   493
	}
slouken@0
   494
slouken@0
   495
	/* Unload the old driver and reset the pointers */
slouken@0
   496
	WIN_GL_UnloadLibrary(this);
slouken@0
   497
slouken@0
   498
	/* Load new function pointers */
slouken@655
   499
	memset(this->gl_data, 0, sizeof(*this->gl_data));
slouken@0
   500
	this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *))
slouken@0
   501
		GetProcAddress(handle, "wglGetProcAddress");
slouken@0
   502
	this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC))
slouken@0
   503
		GetProcAddress(handle, "wglCreateContext");
slouken@0
   504
	this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
slouken@0
   505
		GetProcAddress(handle, "wglDeleteContext");
slouken@0
   506
	this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
slouken@0
   507
		GetProcAddress(handle, "wglMakeCurrent");
slouken@0
   508
slouken@0
   509
	if ( (this->gl_data->wglGetProcAddress == NULL) ||
slouken@0
   510
	     (this->gl_data->wglCreateContext == NULL) ||
slouken@0
   511
	     (this->gl_data->wglDeleteContext == NULL) ||
slouken@0
   512
	     (this->gl_data->wglMakeCurrent == NULL) ) {
slouken@0
   513
		SDL_SetError("Could not retrieve OpenGL functions");
slouken@0
   514
		FreeLibrary(handle);
slouken@0
   515
		return -1;
slouken@0
   516
	}
slouken@0
   517
slouken@0
   518
	this->gl_config.dll_handle = handle;
slouken@0
   519
	strcpy(this->gl_config.driver_path, path);
slouken@0
   520
	this->gl_config.driver_loaded = 1;
slouken@0
   521
	return 0;
slouken@0
   522
}
slouken@0
   523
slouken@0
   524
void *WIN_GL_GetProcAddress(_THIS, const char* proc)
slouken@0
   525
{
slouken@0
   526
	void *func;
slouken@0
   527
slouken@0
   528
	/* This is to pick up extensions */
slouken@0
   529
	func = this->gl_data->wglGetProcAddress(proc);
slouken@0
   530
	if ( ! func ) {
slouken@0
   531
		/* This is probably a normal GL function */
slouken@0
   532
		func = GetProcAddress(this->gl_config.dll_handle, proc);
slouken@0
   533
	}
slouken@0
   534
	return func;
slouken@0
   535
}
slouken@0
   536
slouken@0
   537
#endif /* HAVE_OPENGL */