Skip to content

Latest commit

 

History

History
573 lines (499 loc) · 14.8 KB

SDL_wingl.c

File metadata and controls

573 lines (499 loc) · 14.8 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
/* WGL implementation of SDL OpenGL support */
Feb 16, 2006
Feb 16, 2006
26
#if SDL_VIDEO_OPENGL
Mar 31, 2002
Mar 31, 2002
27
#include "SDL_opengl.h"
Aug 20, 2002
Aug 20, 2002
28
#endif
Apr 26, 2001
Apr 26, 2001
29
30
31
#include "SDL_lowvideo.h"
#include "SDL_wingl_c.h"
Feb 16, 2006
Feb 16, 2006
32
#if SDL_VIDEO_OPENGL
Apr 26, 2001
Apr 26, 2001
33
34
35
#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
#endif
May 19, 2002
May 19, 2002
36
37
38
39
40
/* If setting the HDC fails, we may need to recreate the window (MSDN) */
static int WIN_GL_ResetWindow(_THIS)
{
int status = 0;
May 16, 2004
May 16, 2004
41
#if 0 /* This doesn't work with DirectX code (see CVS comments) */
May 19, 2002
May 19, 2002
42
#ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
Jan 29, 2006
Jan 29, 2006
43
44
/* If we were passed a window, then we can't create a new one */
if ( !SDL_windowid ) {
May 19, 2002
May 19, 2002
45
46
47
/* Save the existing window attributes */
LONG style;
RECT rect = { 0, 0, 0, 0 };
Mar 6, 2006
Mar 6, 2006
48
style = GetWindowLongPtr(SDL_Window, GWL_STYLE);
May 19, 2002
May 19, 2002
49
50
51
52
GetWindowRect(SDL_Window, &rect);
DestroyWindow(SDL_Window);
SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
style,
Feb 1, 2006
Feb 1, 2006
53
54
55
rect.left, rect.top,
(rect.right-rect.left)+1,
(rect.top-rect.bottom)+1,
May 19, 2002
May 19, 2002
56
57
58
59
60
61
62
63
64
NULL, NULL, SDL_Instance, NULL);
if ( SDL_Window ) {
this->SetCaption(this, this->wm_title, this->wm_icon);
} else {
SDL_SetError("Couldn't create window");
status = -1;
}
} else
#endif /* !_WIN32_WCE */
May 16, 2004
May 16, 2004
65
#endif
May 19, 2002
May 19, 2002
66
67
68
69
70
71
{
SDL_SetError("Unable to reset window for OpenGL context");
status = -1;
}
return(status);
}
Apr 26, 2001
Apr 26, 2001
72
Feb 16, 2006
Feb 16, 2006
73
#if SDL_VIDEO_OPENGL
Feb 1, 2006
Feb 1, 2006
74
75
76
77
78
79
80
static int ExtensionSupported(const char *extension, const char *extensions)
{
const char *start;
const char *where, *terminator;
/* Extension names should not have spaces. */
Feb 7, 2006
Feb 7, 2006
81
where = SDL_strchr(extension, ' ');
Feb 1, 2006
Feb 1, 2006
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if ( where || *extension == '\0' )
return 0;
if ( ! extensions )
return 0;
/* It takes a bit of care to be fool-proof about parsing the
* OpenGL extensions string. Don't be fooled by sub-strings,
* etc. */
start = extensions;
for (;;)
{
Feb 7, 2006
Feb 7, 2006
96
where = SDL_strstr(start, extension);
Feb 1, 2006
Feb 1, 2006
97
98
if (!where) break;
Feb 7, 2006
Feb 7, 2006
99
terminator = where + SDL_strlen(extension);
Feb 1, 2006
Feb 1, 2006
100
101
102
103
104
105
106
107
108
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0') return 1;
start = terminator;
}
return 0;
}
Aug 9, 2003
Aug 9, 2003
109
static void Init_WGL_ARB_extensions(_THIS)
Jul 22, 2003
Jul 22, 2003
110
111
112
113
114
115
{
HWND hwnd;
HDC hdc;
HGLRC hglrc;
int pformat;
const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0;
Feb 1, 2006
Feb 1, 2006
116
const char *extensions;
Jul 22, 2003
Jul 22, 2003
117
Aug 8, 2003
Aug 8, 2003
118
hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
Jul 22, 2003
Jul 22, 2003
119
0, 0, 10, 10,
Feb 1, 2006
Feb 1, 2006
120
NULL, NULL, SDL_Instance, NULL);
Jul 22, 2003
Jul 22, 2003
121
122
123
124
125
126
hdc = GetDC(hwnd);
pformat = ChoosePixelFormat(hdc, &GL_pfd);
SetPixelFormat(hdc, pformat, &GL_pfd);
hglrc = this->gl_data->wglCreateContext(hdc);
Aug 8, 2003
Aug 8, 2003
127
128
129
if ( hglrc ) {
this->gl_data->wglMakeCurrent(hdc, hglrc);
}
Jul 22, 2003
Jul 22, 2003
130
131
132
133
wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC))
this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
Feb 1, 2006
Feb 1, 2006
134
135
136
137
138
139
140
141
if( wglGetExtensionsStringARB ) {
extensions = wglGetExtensionsStringARB(hdc);
} else {
extensions = NULL;
}
this->gl_data->WGL_ARB_pixel_format = 0;
if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) {
Jul 22, 2003
Jul 22, 2003
142
143
144
145
146
147
148
149
this->gl_data->wglChoosePixelFormatARB =
(BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))
this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
this->gl_data->wglGetPixelFormatAttribivARB =
(BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *))
this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
if( (this->gl_data->wglChoosePixelFormatARB != NULL) &&
Feb 1, 2006
Feb 1, 2006
150
151
152
(this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) {
this->gl_data->WGL_ARB_pixel_format = 1;
}
Jul 22, 2003
Jul 22, 2003
153
154
}
Aug 8, 2003
Aug 8, 2003
155
156
157
158
if ( hglrc ) {
this->gl_data->wglMakeCurrent(NULL, NULL);
this->gl_data->wglDeleteContext(hglrc);
}
Jul 22, 2003
Jul 22, 2003
159
160
161
ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);
}
Feb 1, 2006
Feb 1, 2006
162
Feb 16, 2006
Feb 16, 2006
163
#endif /* SDL_VIDEO_OPENGL */
Jul 22, 2003
Jul 22, 2003
164
Apr 26, 2001
Apr 26, 2001
165
166
167
int WIN_GL_SetupWindow(_THIS)
{
int retval;
Feb 16, 2006
Feb 16, 2006
168
#if SDL_VIDEO_OPENGL
May 19, 2002
May 19, 2002
169
int i;
Jul 22, 2003
Jul 22, 2003
170
171
172
173
unsigned int matching;
int iAttribs[64];
int *iAttr;
float fAttribs[1] = { 0 };
Apr 26, 2001
Apr 26, 2001
174
175
176
177
178
179
180
181
182
/* load the gl driver from a default path */
if ( ! this->gl_config.driver_loaded ) {
/* no driver has been loaded, use default (ourselves) */
if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) {
return(-1);
}
}
May 19, 2002
May 19, 2002
183
184
185
186
187
188
189
for ( i=0; ; ++i ) {
/* Get the window device context for our OpenGL drawing */
GL_hdc = GetDC(SDL_Window);
if ( GL_hdc == NULL ) {
SDL_SetError("Unable to get DC for SDL_Window");
return(-1);
}
Apr 26, 2001
Apr 26, 2001
190
May 19, 2002
May 19, 2002
191
/* Set up the pixel format descriptor with our needed format */
Feb 7, 2006
Feb 7, 2006
192
SDL_memset(&GL_pfd, 0, sizeof(GL_pfd));
May 19, 2002
May 19, 2002
193
194
195
196
197
198
GL_pfd.nSize = sizeof(GL_pfd);
GL_pfd.nVersion = 1;
GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
if ( this->gl_config.double_buffer ) {
GL_pfd.dwFlags |= PFD_DOUBLEBUFFER;
}
Aug 19, 2002
Aug 19, 2002
199
200
201
if ( this->gl_config.stereo ) {
GL_pfd.dwFlags |= PFD_STEREO;
}
May 19, 2002
May 19, 2002
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
GL_pfd.iPixelType = PFD_TYPE_RGBA;
GL_pfd.cColorBits = this->gl_config.buffer_size;
GL_pfd.cRedBits = this->gl_config.red_size;
GL_pfd.cGreenBits = this->gl_config.green_size;
GL_pfd.cBlueBits = this->gl_config.blue_size;
GL_pfd.cAlphaBits = this->gl_config.alpha_size;
GL_pfd.cAccumRedBits = this->gl_config.accum_red_size;
GL_pfd.cAccumGreenBits = this->gl_config.accum_green_size;
GL_pfd.cAccumBlueBits = this->gl_config.accum_blue_size;
GL_pfd.cAccumAlphaBits = this->gl_config.accum_alpha_size;
GL_pfd.cAccumBits =
(GL_pfd.cAccumRedBits + GL_pfd.cAccumGreenBits +
GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits);
GL_pfd.cDepthBits = this->gl_config.depth_size;
GL_pfd.cStencilBits = this->gl_config.stencil_size;
Jul 22, 2003
Jul 22, 2003
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* initialize WGL_ARB_pixel_format */
Init_WGL_ARB_extensions(this);
/* setup WGL_ARB_pixel_format attribs */
iAttr = &iAttribs[0];
*iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
*iAttr++ = GL_TRUE;
*iAttr++ = WGL_ACCELERATION_ARB;
*iAttr++ = WGL_FULL_ACCELERATION_ARB;
*iAttr++ = WGL_RED_BITS_ARB;
*iAttr++ = this->gl_config.red_size;
*iAttr++ = WGL_GREEN_BITS_ARB;
*iAttr++ = this->gl_config.green_size;
*iAttr++ = WGL_BLUE_BITS_ARB;
*iAttr++ = this->gl_config.blue_size;
if ( this->gl_config.alpha_size ) {
*iAttr++ = WGL_ALPHA_BITS_ARB;
*iAttr++ = this->gl_config.alpha_size;
}
Feb 1, 2006
Feb 1, 2006
240
241
*iAttr++ = WGL_DOUBLE_BUFFER_ARB;
*iAttr++ = this->gl_config.double_buffer;
Jul 22, 2003
Jul 22, 2003
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
*iAttr++ = WGL_DEPTH_BITS_ARB;
*iAttr++ = this->gl_config.depth_size;
if ( this->gl_config.stencil_size ) {
*iAttr++ = WGL_STENCIL_BITS_ARB;
*iAttr++ = this->gl_config.stencil_size;
}
if ( this->gl_config.accum_red_size ) {
*iAttr++ = WGL_ACCUM_RED_BITS_ARB;
*iAttr++ = this->gl_config.accum_red_size;
}
if ( this->gl_config.accum_green_size ) {
*iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
*iAttr++ = this->gl_config.accum_green_size;
}
if ( this->gl_config.accum_blue_size ) {
*iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
*iAttr++ = this->gl_config.accum_blue_size;
}
if ( this->gl_config.accum_alpha_size ) {
*iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
*iAttr++ = this->gl_config.accum_alpha_size;
}
if ( this->gl_config.stereo ) {
*iAttr++ = WGL_STEREO_ARB;
Feb 1, 2006
Feb 1, 2006
273
*iAttr++ = GL_TRUE;
Jul 22, 2003
Jul 22, 2003
274
275
}
Jul 22, 2003
Jul 22, 2003
276
if ( this->gl_config.multisamplebuffers ) {
Jul 22, 2003
Jul 22, 2003
277
*iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
Jul 22, 2003
Jul 22, 2003
278
*iAttr++ = this->gl_config.multisamplebuffers;
Jul 22, 2003
Jul 22, 2003
279
280
}
Jul 22, 2003
Jul 22, 2003
281
if ( this->gl_config.multisamplesamples ) {
Jul 22, 2003
Jul 22, 2003
282
*iAttr++ = WGL_SAMPLES_ARB;
Jul 22, 2003
Jul 22, 2003
283
*iAttr++ = this->gl_config.multisamplesamples;
Jul 22, 2003
Jul 22, 2003
284
285
286
287
}
*iAttr = 0;
May 19, 2002
May 19, 2002
288
/* Choose and set the closest available pixel format */
Feb 1, 2006
Feb 1, 2006
289
if ( !this->gl_data->WGL_ARB_pixel_format ||
Jul 22, 2003
Jul 22, 2003
290
291
292
!this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) ||
!matching ) {
pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
Feb 1, 2006
Feb 1, 2006
293
this->gl_data->WGL_ARB_pixel_format = 0;
Jul 22, 2003
Jul 22, 2003
294
}
May 19, 2002
May 19, 2002
295
296
297
298
if ( !pixel_format ) {
SDL_SetError("No matching GL pixel format available");
return(-1);
}
Jul 22, 2003
Jul 22, 2003
299
if ( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
May 19, 2002
May 19, 2002
300
301
302
303
304
305
306
307
308
309
310
311
if ( i == 0 ) {
/* First time through, try resetting the window */
if ( WIN_GL_ResetWindow(this) < 0 ) {
return(-1);
}
continue;
}
SDL_SetError("Unable to set HDC pixel format");
return(-1);
}
/* We either succeeded or failed by this point */
break;
Apr 26, 2001
Apr 26, 2001
312
313
314
315
}
DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
Jul 22, 2003
Jul 22, 2003
316
if ( GL_hrc == NULL ) {
Apr 26, 2001
Apr 26, 2001
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
SDL_SetError("Unable to create GL context");
return(-1);
}
gl_active = 1;
#else
SDL_SetError("WIN driver not configured with OpenGL");
#endif
if ( gl_active ) {
retval = 0;
} else {
retval = -1;
}
return(retval);
}
void WIN_GL_ShutDown(_THIS)
{
Feb 16, 2006
Feb 16, 2006
334
#if SDL_VIDEO_OPENGL
Apr 26, 2001
Apr 26, 2001
335
336
337
338
339
340
341
342
343
344
345
346
347
/* Clean up OpenGL */
if ( GL_hrc ) {
this->gl_data->wglMakeCurrent(NULL, NULL);
this->gl_data->wglDeleteContext(GL_hrc);
GL_hrc = NULL;
}
if ( GL_hdc ) {
ReleaseDC(SDL_Window, GL_hdc);
GL_hdc = NULL;
}
gl_active = 0;
WIN_GL_UnloadLibrary(this);
Feb 16, 2006
Feb 16, 2006
348
#endif /* SDL_VIDEO_OPENGL */
Apr 26, 2001
Apr 26, 2001
349
350
}
Feb 16, 2006
Feb 16, 2006
351
#if SDL_VIDEO_OPENGL
Apr 26, 2001
Apr 26, 2001
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/* Make the current context active */
int WIN_GL_MakeCurrent(_THIS)
{
int retval;
retval = 0;
if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) {
SDL_SetError("Unable to make GL context current");
retval = -1;
}
return(retval);
}
/* Get attribute data from glX. */
int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
int retval;
Jul 22, 2003
Jul 22, 2003
370
Feb 1, 2006
Feb 1, 2006
371
if ( this->gl_data->WGL_ARB_pixel_format ) {
Jul 22, 2003
Jul 22, 2003
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
int wgl_attrib;
switch(attrib) {
case SDL_GL_RED_SIZE:
wgl_attrib = WGL_RED_BITS_ARB;
break;
case SDL_GL_GREEN_SIZE:
wgl_attrib = WGL_GREEN_BITS_ARB;
break;
case SDL_GL_BLUE_SIZE:
wgl_attrib = WGL_BLUE_BITS_ARB;
break;
case SDL_GL_ALPHA_SIZE:
wgl_attrib = WGL_ALPHA_BITS_ARB;
break;
case SDL_GL_DOUBLEBUFFER:
wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
break;
case SDL_GL_BUFFER_SIZE:
wgl_attrib = WGL_COLOR_BITS_ARB;
break;
case SDL_GL_DEPTH_SIZE:
wgl_attrib = WGL_DEPTH_BITS_ARB;
break;
case SDL_GL_STENCIL_SIZE:
wgl_attrib = WGL_STENCIL_BITS_ARB;
break;
case SDL_GL_ACCUM_RED_SIZE:
wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
break;
case SDL_GL_STEREO:
wgl_attrib = WGL_STEREO_ARB;
break;
Jul 22, 2003
Jul 22, 2003
414
case SDL_GL_MULTISAMPLEBUFFERS:
Jul 22, 2003
Jul 22, 2003
415
416
wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
break;
Jul 22, 2003
Jul 22, 2003
417
case SDL_GL_MULTISAMPLESAMPLES:
Jul 22, 2003
Jul 22, 2003
418
419
420
421
422
423
424
425
426
wgl_attrib = WGL_SAMPLES_ARB;
break;
default:
return(-1);
}
this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
return 0;
}
Apr 26, 2001
Apr 26, 2001
427
428
retval = 0;
Jul 22, 2003
Jul 22, 2003
429
switch ( attrib ) {
Apr 26, 2001
Apr 26, 2001
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
case SDL_GL_RED_SIZE:
*value = GL_pfd.cRedBits;
break;
case SDL_GL_GREEN_SIZE:
*value = GL_pfd.cGreenBits;
break;
case SDL_GL_BLUE_SIZE:
*value = GL_pfd.cBlueBits;
break;
case SDL_GL_ALPHA_SIZE:
*value = GL_pfd.cAlphaBits;
break;
case SDL_GL_DOUBLEBUFFER:
if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) {
*value = 1;
} else {
*value = 0;
}
break;
case SDL_GL_BUFFER_SIZE:
*value = GL_pfd.cColorBits;
break;
case SDL_GL_DEPTH_SIZE:
*value = GL_pfd.cDepthBits;
break;
case SDL_GL_STENCIL_SIZE:
*value = GL_pfd.cStencilBits;
break;
case SDL_GL_ACCUM_RED_SIZE:
*value = GL_pfd.cAccumRedBits;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
*value = GL_pfd.cAccumGreenBits;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
*value = GL_pfd.cAccumBlueBits;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
*value = GL_pfd.cAccumAlphaBits;
break;
Aug 19, 2002
Aug 19, 2002
470
471
472
473
474
475
476
case SDL_GL_STEREO:
if ( GL_pfd.dwFlags & PFD_STEREO ) {
*value = 1;
} else {
*value = 0;
}
break;
Jan 25, 2006
Jan 25, 2006
477
478
479
480
481
482
case SDL_GL_MULTISAMPLEBUFFERS:
*value = 0;
break;
case SDL_GL_MULTISAMPLESAMPLES:
*value = 1;
break;
Apr 26, 2001
Apr 26, 2001
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
default:
retval = -1;
break;
}
return retval;
}
void WIN_GL_SwapBuffers(_THIS)
{
SwapBuffers(GL_hdc);
}
void WIN_GL_UnloadLibrary(_THIS)
{
if ( this->gl_config.driver_loaded ) {
FreeLibrary((HMODULE)this->gl_config.dll_handle);
this->gl_data->wglGetProcAddress = NULL;
this->gl_data->wglCreateContext = NULL;
this->gl_data->wglDeleteContext = NULL;
this->gl_data->wglMakeCurrent = NULL;
Jul 22, 2003
Jul 22, 2003
504
505
this->gl_data->wglChoosePixelFormatARB = NULL;
this->gl_data->wglGetPixelFormatAttribivARB = NULL;
Apr 26, 2001
Apr 26, 2001
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
this->gl_config.dll_handle = NULL;
this->gl_config.driver_loaded = 0;
}
}
/* Passing a NULL path means load pointers from the application */
int WIN_GL_LoadLibrary(_THIS, const char* path)
{
HMODULE handle;
if ( gl_active ) {
SDL_SetError("OpenGL context already created");
return -1;
}
if ( path == NULL ) {
path = DEFAULT_GL_DRIVER_PATH;
}
handle = LoadLibrary(path);
if ( handle == NULL ) {
SDL_SetError("Could not load OpenGL library");
return -1;
}
/* Unload the old driver and reset the pointers */
WIN_GL_UnloadLibrary(this);
/* Load new function pointers */
Feb 7, 2006
Feb 7, 2006
535
SDL_memset(this->gl_data, 0, sizeof(*this->gl_data));
Apr 26, 2001
Apr 26, 2001
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *))
GetProcAddress(handle, "wglGetProcAddress");
this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC))
GetProcAddress(handle, "wglCreateContext");
this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
GetProcAddress(handle, "wglDeleteContext");
this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
GetProcAddress(handle, "wglMakeCurrent");
if ( (this->gl_data->wglGetProcAddress == NULL) ||
(this->gl_data->wglCreateContext == NULL) ||
(this->gl_data->wglDeleteContext == NULL) ||
(this->gl_data->wglMakeCurrent == NULL) ) {
SDL_SetError("Could not retrieve OpenGL functions");
FreeLibrary(handle);
return -1;
}
this->gl_config.dll_handle = handle;
Feb 19, 2006
Feb 19, 2006
555
SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path));
Apr 26, 2001
Apr 26, 2001
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
this->gl_config.driver_loaded = 1;
return 0;
}
void *WIN_GL_GetProcAddress(_THIS, const char* proc)
{
void *func;
/* This is to pick up extensions */
func = this->gl_data->wglGetProcAddress(proc);
if ( ! func ) {
/* This is probably a normal GL function */
func = GetProcAddress(this->gl_config.dll_handle, proc);
}
return func;
}
Feb 16, 2006
Feb 16, 2006
573
#endif /* SDL_VIDEO_OPENGL */