Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
671 lines (591 loc) · 20.2 KB

SDL_wingl.c

File metadata and controls

671 lines (591 loc) · 20.2 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
/* If setting the HDC fails, we may need to recreate the window (MSDN) */
May 28, 2006
May 28, 2006
37
static int
May 29, 2006
May 29, 2006
38
WIN_GL_ResetWindow(_THIS)
May 19, 2002
May 19, 2002
39
{
May 28, 2006
May 28, 2006
40
41
42
43
44
int status = 0;
#ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
/* This doesn't work with DirectX code (see CVS comments) */
/* If we were passed a window, then we can't create a new one */
May 29, 2006
May 29, 2006
45
if (!SDL_windowid && SDL_strcmp(this->name, "windib") == 0) {
May 28, 2006
May 28, 2006
46
47
48
/* Save the existing window attributes */
LONG style;
RECT rect = { 0, 0, 0, 0 };
May 29, 2006
May 29, 2006
49
50
51
52
53
54
55
56
57
58
59
60
style = GetWindowLong(SDL_Window, GWL_STYLE);
GetWindowRect(SDL_Window, &rect);
DestroyWindow(SDL_Window);
WIN_FlushMessageQueue();
SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
style,
rect.left, rect.top,
(rect.right - rect.left) + 1,
(rect.top - rect.bottom) + 1,
NULL, NULL, SDL_Instance, NULL);
WIN_FlushMessageQueue();
May 28, 2006
May 28, 2006
61
62
if (SDL_Window) {
May 29, 2006
May 29, 2006
63
this->SetCaption(this, this->wm_title, this->wm_icon);
May 28, 2006
May 28, 2006
64
} else {
May 29, 2006
May 29, 2006
65
SDL_SetError("Couldn't create window");
May 28, 2006
May 28, 2006
66
67
68
status = -1;
}
} else
May 19, 2002
May 19, 2002
69
#endif /* !_WIN32_WCE */
May 28, 2006
May 28, 2006
70
{
May 29, 2006
May 29, 2006
71
SDL_SetError("Unable to reset window for OpenGL context");
May 28, 2006
May 28, 2006
72
73
74
status = -1;
}
return (status);
May 19, 2002
May 19, 2002
75
}
Apr 26, 2001
Apr 26, 2001
76
Feb 16, 2006
Feb 16, 2006
77
#if SDL_VIDEO_OPENGL
Feb 1, 2006
Feb 1, 2006
78
May 28, 2006
May 28, 2006
79
static int
May 29, 2006
May 29, 2006
80
ExtensionSupported(const char *extension, const char *extensions)
Feb 1, 2006
Feb 1, 2006
81
{
May 28, 2006
May 28, 2006
82
83
84
85
const char *start;
const char *where, *terminator;
/* Extension names should not have spaces. */
May 29, 2006
May 29, 2006
86
where = SDL_strchr(extension, ' ');
May 28, 2006
May 28, 2006
87
88
89
90
91
92
93
94
95
96
97
98
99
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 (;;) {
May 29, 2006
May 29, 2006
100
where = SDL_strstr(start, extension);
May 28, 2006
May 28, 2006
101
102
103
if (!where)
break;
May 29, 2006
May 29, 2006
104
terminator = where + SDL_strlen(extension);
May 28, 2006
May 28, 2006
105
106
107
108
109
110
111
112
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return 1;
start = terminator;
}
return 0;
Feb 1, 2006
Feb 1, 2006
113
114
}
May 28, 2006
May 28, 2006
115
static void
May 29, 2006
May 29, 2006
116
Init_WGL_ARB_extensions(_THIS)
Jul 22, 2003
Jul 22, 2003
117
{
May 28, 2006
May 28, 2006
118
119
120
121
122
123
124
HWND hwnd;
HDC hdc;
HGLRC hglrc;
int pformat;
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
const char *extensions;
May 29, 2006
May 29, 2006
125
126
127
hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
0, 0, 10, 10, NULL, NULL, SDL_Instance, NULL);
WIN_FlushMessageQueue();
May 28, 2006
May 28, 2006
128
May 29, 2006
May 29, 2006
129
hdc = GetDC(hwnd);
May 28, 2006
May 28, 2006
130
May 29, 2006
May 29, 2006
131
132
pformat = ChoosePixelFormat(hdc, &GL_pfd);
SetPixelFormat(hdc, pformat, &GL_pfd);
May 28, 2006
May 28, 2006
133
May 29, 2006
May 29, 2006
134
hglrc = this->gl_data->wglCreateContext(hdc);
May 28, 2006
May 28, 2006
135
if (hglrc) {
May 29, 2006
May 29, 2006
136
this->gl_data->wglMakeCurrent(hdc, hglrc);
May 28, 2006
May 28, 2006
137
138
139
}
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
May 29, 2006
May 29, 2006
140
this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
May 28, 2006
May 28, 2006
141
142
if (wglGetExtensionsStringARB) {
May 29, 2006
May 29, 2006
143
extensions = wglGetExtensionsStringARB(hdc);
May 28, 2006
May 28, 2006
144
145
146
147
148
} else {
extensions = NULL;
}
this->gl_data->WGL_ARB_pixel_format = 0;
May 29, 2006
May 29, 2006
149
150
if (ExtensionSupported("WGL_ARB_pixel_format", extensions)) {
this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
May 28, 2006
May 28, 2006
151
152
(HDC, const int *,
const FLOAT *, UINT, int *,
Jun 24, 2006
Jun 24, 2006
153
154
UINT *))
this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
May 28, 2006
May 28, 2006
155
this->gl_data->wglGetPixelFormatAttribivARB =
May 29, 2006
May 29, 2006
156
157
(BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
May 28, 2006
May 28, 2006
158
159
160
161
162
163
164
165
if ((this->gl_data->wglChoosePixelFormatARB != NULL) &&
(this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
this->gl_data->WGL_ARB_pixel_format = 1;
}
}
if (hglrc) {
May 29, 2006
May 29, 2006
166
167
this->gl_data->wglMakeCurrent(NULL, NULL);
this->gl_data->wglDeleteContext(hglrc);
May 28, 2006
May 28, 2006
168
}
May 29, 2006
May 29, 2006
169
170
171
ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);
WIN_FlushMessageQueue();
Jul 22, 2003
Jul 22, 2003
172
}
Feb 1, 2006
Feb 1, 2006
173
Feb 16, 2006
Feb 16, 2006
174
#endif /* SDL_VIDEO_OPENGL */
Jul 22, 2003
Jul 22, 2003
175
May 28, 2006
May 28, 2006
176
int
May 29, 2006
May 29, 2006
177
WIN_GL_SetupWindow(_THIS)
Apr 26, 2001
Apr 26, 2001
178
{
May 28, 2006
May 28, 2006
179
int retval;
Feb 16, 2006
Feb 16, 2006
180
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
181
182
183
184
185
186
187
188
189
190
191
int i;
unsigned int matching;
int iAttribs[64];
int *iAttr;
float fAttribs[1] = { 0 };
const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
const char *wglext;
/* load the gl driver from a default path */
if (!this->gl_config.driver_loaded) {
/* no driver has been loaded, use default (ourselves) */
May 29, 2006
May 29, 2006
192
if (WIN_GL_LoadLibrary(this, NULL) < 0) {
May 28, 2006
May 28, 2006
193
194
195
196
197
198
return (-1);
}
}
for (i = 0;; ++i) {
/* Get the window device context for our OpenGL drawing */
May 29, 2006
May 29, 2006
199
GL_hdc = GetDC(SDL_Window);
May 28, 2006
May 28, 2006
200
if (GL_hdc == NULL) {
May 29, 2006
May 29, 2006
201
SDL_SetError("Unable to get DC for SDL_Window");
May 28, 2006
May 28, 2006
202
203
204
205
return (-1);
}
/* Set up the pixel format descriptor with our needed format */
May 29, 2006
May 29, 2006
206
207
SDL_memset(&GL_pfd, 0, sizeof(GL_pfd));
GL_pfd.nSize = sizeof(GL_pfd);
May 28, 2006
May 28, 2006
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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;
}
if (this->gl_config.stereo) {
GL_pfd.dwFlags |= PFD_STEREO;
}
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;
/* initialize WGL_ARB_pixel_format */
May 29, 2006
May 29, 2006
233
Init_WGL_ARB_extensions(this);
May 28, 2006
May 28, 2006
234
235
236
237
238
239
240
241
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* 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;
}
*iAttr++ = WGL_DOUBLE_BUFFER_ARB;
*iAttr++ = this->gl_config.double_buffer;
*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;
*iAttr++ = GL_TRUE;
}
if (this->gl_config.multisamplebuffers) {
*iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
*iAttr++ = this->gl_config.multisamplebuffers;
}
if (this->gl_config.multisamplesamples) {
*iAttr++ = WGL_SAMPLES_ARB;
*iAttr++ = this->gl_config.multisamplesamples;
}
if (this->gl_config.accelerated >= 0) {
*iAttr++ = WGL_ACCELERATION_ARB;
*iAttr++ =
(this->gl_config.
accelerated ? WGL_GENERIC_ACCELERATION_ARB :
WGL_NO_ACCELERATION_ARB);
}
*iAttr = 0;
/* Choose and set the closest available pixel format */
if (!this->gl_data->WGL_ARB_pixel_format ||
May 29, 2006
May 29, 2006
312
313
314
!this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs,
fAttribs, 1,
&pixel_format, &matching)
May 28, 2006
May 28, 2006
315
|| !matching) {
May 29, 2006
May 29, 2006
316
pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
May 28, 2006
May 28, 2006
317
318
319
this->gl_data->WGL_ARB_pixel_format = 0;
}
if (!pixel_format) {
May 29, 2006
May 29, 2006
320
SDL_SetError("No matching GL pixel format available");
May 28, 2006
May 28, 2006
321
322
return (-1);
}
May 29, 2006
May 29, 2006
323
if (!SetPixelFormat(GL_hdc, pixel_format, &GL_pfd)) {
May 28, 2006
May 28, 2006
324
325
if (i == 0) {
/* First time through, try resetting the window */
May 29, 2006
May 29, 2006
326
if (WIN_GL_ResetWindow(this) < 0) {
May 28, 2006
May 28, 2006
327
328
329
330
return (-1);
}
continue;
}
May 29, 2006
May 29, 2006
331
SDL_SetError("Unable to set HDC pixel format");
May 28, 2006
May 28, 2006
332
333
334
335
336
return (-1);
}
/* We either succeeded or failed by this point */
break;
}
May 29, 2006
May 29, 2006
337
DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
May 28, 2006
May 28, 2006
338
May 29, 2006
May 29, 2006
339
GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
May 28, 2006
May 28, 2006
340
if (GL_hrc == NULL) {
May 29, 2006
May 29, 2006
341
SDL_SetError("Unable to create GL context");
May 28, 2006
May 28, 2006
342
343
return (-1);
}
May 29, 2006
May 29, 2006
344
if (WIN_GL_MakeCurrent(this) < 0) {
May 28, 2006
May 28, 2006
345
346
347
348
349
350
351
352
return (-1);
}
gl_active = 1;
/* Vsync control under Windows. Checking glGetString here is
* somewhat a documented and reliable hack - it was originally
* as a feature added by mistake, but since so many people rely
* on it, it will not be removed. strstr should be safe here.*/
May 29, 2006
May 29, 2006
353
glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
May 28, 2006
May 28, 2006
354
if (glGetStringFunc) {
May 29, 2006
May 29, 2006
355
wglext = (const char *) glGetStringFunc(GL_EXTENSIONS);
May 28, 2006
May 28, 2006
356
357
358
359
} else {
/* Uh oh, something is seriously wrong here... */
wglext = NULL;
}
Jun 24, 2006
Jun 24, 2006
360
361
362
363
364
365
if (wglext && SDL_strstr(wglext, "WGL_EXT_swap_control")) {
this->gl_data->wglSwapIntervalEXT =
WIN_GL_GetProcAddress(this, "wglSwapIntervalEXT");
this->gl_data->wglGetSwapIntervalEXT =
WIN_GL_GetProcAddress(this, "wglGetSwapIntervalEXT");
} else {
May 28, 2006
May 28, 2006
366
367
368
369
370
this->gl_data->wglSwapIntervalEXT = NULL;
this->gl_data->wglGetSwapIntervalEXT = NULL;
}
if (this->gl_config.swap_control >= 0) {
if (this->gl_data->wglSwapIntervalEXT) {
May 29, 2006
May 29, 2006
371
this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
May 28, 2006
May 28, 2006
372
373
}
}
Apr 26, 2001
Apr 26, 2001
374
#else
May 29, 2006
May 29, 2006
375
SDL_SetError("WIN driver not configured with OpenGL");
Apr 26, 2001
Apr 26, 2001
376
#endif
May 28, 2006
May 28, 2006
377
378
379
380
381
382
if (gl_active) {
retval = 0;
} else {
retval = -1;
}
return (retval);
Apr 26, 2001
Apr 26, 2001
383
384
}
May 28, 2006
May 28, 2006
385
void
May 29, 2006
May 29, 2006
386
WIN_GL_ShutDown(_THIS)
Apr 26, 2001
Apr 26, 2001
387
{
Feb 16, 2006
Feb 16, 2006
388
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
389
390
/* Clean up OpenGL */
if (GL_hrc) {
May 29, 2006
May 29, 2006
391
392
this->gl_data->wglMakeCurrent(NULL, NULL);
this->gl_data->wglDeleteContext(GL_hrc);
May 28, 2006
May 28, 2006
393
394
395
GL_hrc = NULL;
}
if (GL_hdc) {
May 29, 2006
May 29, 2006
396
ReleaseDC(SDL_Window, GL_hdc);
May 28, 2006
May 28, 2006
397
398
399
400
GL_hdc = NULL;
}
gl_active = 0;
May 29, 2006
May 29, 2006
401
WIN_GL_UnloadLibrary(this);
Feb 16, 2006
Feb 16, 2006
402
#endif /* SDL_VIDEO_OPENGL */
Apr 26, 2001
Apr 26, 2001
403
404
}
Feb 16, 2006
Feb 16, 2006
405
#if SDL_VIDEO_OPENGL
Apr 26, 2001
Apr 26, 2001
406
407
/* Make the current context active */
May 28, 2006
May 28, 2006
408
int
May 29, 2006
May 29, 2006
409
WIN_GL_MakeCurrent(_THIS)
Apr 26, 2001
Apr 26, 2001
410
{
May 28, 2006
May 28, 2006
411
412
413
int retval;
retval = 0;
May 29, 2006
May 29, 2006
414
415
if (!this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc)) {
SDL_SetError("Unable to make GL context current");
May 28, 2006
May 28, 2006
416
417
418
retval = -1;
}
return (retval);
Apr 26, 2001
Apr 26, 2001
419
420
421
}
/* Get attribute data from glX. */
May 28, 2006
May 28, 2006
422
int
May 29, 2006
May 29, 2006
423
WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
Apr 26, 2001
Apr 26, 2001
424
{
May 28, 2006
May 28, 2006
425
426
427
428
429
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
470
471
472
473
474
475
476
477
int retval;
if (this->gl_data->WGL_ARB_pixel_format) {
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;
case SDL_GL_MULTISAMPLEBUFFERS:
wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
break;
case SDL_GL_MULTISAMPLESAMPLES:
wgl_attrib = WGL_SAMPLES_ARB;
break;
case SDL_GL_ACCELERATED_VISUAL:
wgl_attrib = WGL_ACCELERATION_ARB;
Jun 24, 2006
Jun 24, 2006
478
479
this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format,
0, 1, &wgl_attrib,
May 29, 2006
May 29, 2006
480
value);
May 28, 2006
May 28, 2006
481
482
483
484
485
486
487
488
489
if (*value == WGL_NO_ACCELERATION_ARB) {
*value = SDL_FALSE;
} else {
*value = SDL_TRUE;
}
return 0;
break;
case SDL_GL_SWAP_CONTROL:
if (this->gl_data->wglGetSwapIntervalEXT) {
Jun 24, 2006
Jun 24, 2006
490
491
*value = this->gl_data->wglGetSwapIntervalEXT();
return 0;
May 28, 2006
May 28, 2006
492
493
494
} else {
return -1;
}
Jun 24, 2006
Jun 24, 2006
495
break;
May 28, 2006
May 28, 2006
496
497
498
default:
return (-1);
}
Jun 24, 2006
Jun 24, 2006
499
500
this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0,
1, &wgl_attrib, value);
May 28, 2006
May 28, 2006
501
502
503
504
505
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
return 0;
}
retval = 0;
switch (attrib) {
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;
case SDL_GL_STEREO:
if (GL_pfd.dwFlags & PFD_STEREO) {
*value = 1;
} else {
*value = 0;
}
break;
case SDL_GL_MULTISAMPLEBUFFERS:
*value = 0;
break;
case SDL_GL_MULTISAMPLESAMPLES:
*value = 1;
break;
Jun 24, 2006
Jun 24, 2006
560
561
562
563
564
565
566
567
case SDL_GL_SWAP_CONTROL:
if (this->gl_data->wglGetSwapIntervalEXT) {
*value = this->gl_data->wglGetSwapIntervalEXT();
return 0;
} else {
return -1;
}
break;
May 28, 2006
May 28, 2006
568
569
570
571
572
default:
retval = -1;
break;
}
return retval;
Apr 26, 2001
Apr 26, 2001
573
574
}
May 28, 2006
May 28, 2006
575
void
May 29, 2006
May 29, 2006
576
WIN_GL_SwapBuffers(_THIS)
Apr 26, 2001
Apr 26, 2001
577
{
May 29, 2006
May 29, 2006
578
SwapBuffers(GL_hdc);
Apr 26, 2001
Apr 26, 2001
579
580
}
May 28, 2006
May 28, 2006
581
void
May 29, 2006
May 29, 2006
582
WIN_GL_UnloadLibrary(_THIS)
Apr 26, 2001
Apr 26, 2001
583
{
May 28, 2006
May 28, 2006
584
if (this->gl_config.driver_loaded) {
May 29, 2006
May 29, 2006
585
FreeLibrary((HMODULE) this->gl_config.dll_handle);
May 28, 2006
May 28, 2006
586
587
588
589
590
591
592
593
594
595
596
597
598
this->gl_data->wglGetProcAddress = NULL;
this->gl_data->wglCreateContext = NULL;
this->gl_data->wglDeleteContext = NULL;
this->gl_data->wglMakeCurrent = NULL;
this->gl_data->wglChoosePixelFormatARB = NULL;
this->gl_data->wglGetPixelFormatAttribivARB = NULL;
this->gl_data->wglSwapIntervalEXT = NULL;
this->gl_data->wglGetSwapIntervalEXT = NULL;
this->gl_config.dll_handle = NULL;
this->gl_config.driver_loaded = 0;
}
Apr 26, 2001
Apr 26, 2001
599
600
601
}
/* Passing a NULL path means load pointers from the application */
May 28, 2006
May 28, 2006
602
int
May 29, 2006
May 29, 2006
603
WIN_GL_LoadLibrary(_THIS, const char *path)
Apr 26, 2001
Apr 26, 2001
604
{
May 28, 2006
May 28, 2006
605
606
607
HMODULE handle;
if (gl_active) {
May 29, 2006
May 29, 2006
608
SDL_SetError("OpenGL context already created");
May 28, 2006
May 28, 2006
609
610
611
612
613
614
return -1;
}
if (path == NULL) {
path = DEFAULT_GL_DRIVER_PATH;
}
May 29, 2006
May 29, 2006
615
handle = LoadLibrary(path);
May 28, 2006
May 28, 2006
616
if (handle == NULL) {
May 29, 2006
May 29, 2006
617
SDL_SetError("Could not load OpenGL library");
May 28, 2006
May 28, 2006
618
619
620
621
return -1;
}
/* Unload the old driver and reset the pointers */
May 29, 2006
May 29, 2006
622
WIN_GL_UnloadLibrary(this);
May 28, 2006
May 28, 2006
623
624
/* Load new function pointers */
May 29, 2006
May 29, 2006
625
SDL_memset(this->gl_data, 0, sizeof(*this->gl_data));
May 28, 2006
May 28, 2006
626
this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
May 29, 2006
May 29, 2006
627
628
629
630
631
632
633
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");
May 28, 2006
May 28, 2006
634
this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
May 29, 2006
May 29, 2006
635
GetProcAddress(handle, "wglSwapIntervalEXT");
May 28, 2006
May 28, 2006
636
this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
May 29, 2006
May 29, 2006
637
GetProcAddress(handle, "wglGetSwapIntervalEXT");
May 28, 2006
May 28, 2006
638
639
640
641
642
if ((this->gl_data->wglGetProcAddress == NULL) ||
(this->gl_data->wglCreateContext == NULL) ||
(this->gl_data->wglDeleteContext == NULL) ||
(this->gl_data->wglMakeCurrent == NULL)) {
May 29, 2006
May 29, 2006
643
644
SDL_SetError("Could not retrieve OpenGL functions");
FreeLibrary(handle);
May 28, 2006
May 28, 2006
645
646
647
648
return -1;
}
this->gl_config.dll_handle = handle;
May 29, 2006
May 29, 2006
649
650
SDL_strlcpy(this->gl_config.driver_path, path,
SDL_arraysize(this->gl_config.driver_path));
May 28, 2006
May 28, 2006
651
652
this->gl_config.driver_loaded = 1;
return 0;
Apr 26, 2001
Apr 26, 2001
653
654
}
May 28, 2006
May 28, 2006
655
void *
May 29, 2006
May 29, 2006
656
WIN_GL_GetProcAddress(_THIS, const char *proc)
Apr 26, 2001
Apr 26, 2001
657
{
May 28, 2006
May 28, 2006
658
659
660
void *func;
/* This is to pick up extensions */
May 29, 2006
May 29, 2006
661
func = this->gl_data->wglGetProcAddress(proc);
May 28, 2006
May 28, 2006
662
663
if (!func) {
/* This is probably a normal GL function */
May 29, 2006
May 29, 2006
664
func = GetProcAddress(this->gl_config.dll_handle, proc);
May 28, 2006
May 28, 2006
665
666
}
return func;
Apr 26, 2001
Apr 26, 2001
667
668
}
Feb 16, 2006
Feb 16, 2006
669
#endif /* SDL_VIDEO_OPENGL */
Jun 24, 2006
Jun 24, 2006
670
May 28, 2006
May 28, 2006
671
/* vi: set ts=4 sw=4 expandtab: */