~ubuntu-branches/ubuntu/lucid/libsdl1.2/lucid-proposed

« back to all changes in this revision

Viewing changes to src/video/wincommon/SDL_wingl.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-07-03 11:30:59 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113059-wtkvnv5lb2tnht1r
Tags: 1.2.10-3ubuntu1
* Merge from debian unstable. Remaining Ubuntu changes:
  - debian/control: Drop libsvga1-dev build dependency and dependencies,
    adapt package descriptions.

Show diffs side-by-side

added added

removed removed

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