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

Latest commit

 

History

History
executable file
·
676 lines (577 loc) · 20.2 KB

SDL_windowsopengl.c

File metadata and controls

executable file
·
676 lines (577 loc) · 20.2 KB
 
Jun 22, 2011
Jun 22, 2011
1
2
/*
Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
Jun 22, 2011
Jun 22, 2011
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
Oct 31, 2011
Oct 31, 2011
23
24
#if SDL_VIDEO_DRIVER_WINDOWS
Jun 22, 2011
Jun 22, 2011
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "SDL_windowsvideo.h"
/* WGL implementation of SDL OpenGL support */
#if SDL_VIDEO_OPENGL_WGL
#include "SDL_opengl.h"
#define DEFAULT_OPENGL "OPENGL32.DLL"
#ifndef WGL_ARB_create_context
#define WGL_ARB_create_context
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
Jul 22, 2012
Jul 22, 2012
39
#define WGL_CONTEXT_FLAGS_ARB 0x2094
Jun 22, 2011
Jun 22, 2011
40
41
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
Feb 21, 2012
Feb 21, 2012
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef WGL_ARB_create_context_profile
#define WGL_ARB_create_context_profile
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
#endif
#ifndef WGL_ARB_create_context_robustness
#define WGL_ARB_create_context_robustness
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
#endif
#endif
#ifndef WGL_EXT_create_context_es2_profile
#define WGL_EXT_create_context_es2_profile
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
Jun 22, 2011
Jun 22, 2011
62
63
#endif
Aug 12, 2012
Aug 12, 2012
64
65
66
67
68
#ifndef WGL_EXT_create_context_es_profile
#define WGL_EXT_create_context_es_profile
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
#endif
Jun 22, 2011
Jun 22, 2011
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
HGLRC
hShareContext,
const int
*attribList);
int
WIN_GL_LoadLibrary(_THIS, const char *path)
{
LPTSTR wpath;
HANDLE handle;
if (path == NULL) {
path = SDL_getenv("SDL_OPENGL_LIBRARY");
}
if (path == NULL) {
path = DEFAULT_OPENGL;
}
wpath = WIN_UTF8ToString(path);
_this->gl_config.dll_handle = LoadLibrary(wpath);
SDL_free(wpath);
if (!_this->gl_config.dll_handle) {
char message[1024];
SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
path);
WIN_SetError(message);
return -1;
}
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
/* Allocate OpenGL memory */
_this->gl_data =
(struct SDL_GLDriverData *) SDL_calloc(1,
sizeof(struct
SDL_GLDriverData));
if (!_this->gl_data) {
SDL_OutOfMemory();
return -1;
}
/* Load function pointers */
handle = _this->gl_config.dll_handle;
_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");
Aug 12, 2012
Aug 12, 2012
120
121
_this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
GetProcAddress(handle, "wglShareLists");
Jun 22, 2011
Jun 22, 2011
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
233
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
if (!_this->gl_data->wglGetProcAddress ||
!_this->gl_data->wglCreateContext ||
!_this->gl_data->wglDeleteContext ||
!_this->gl_data->wglMakeCurrent) {
SDL_SetError("Could not retrieve OpenGL functions");
SDL_UnloadObject(handle);
return -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;
}
void
WIN_GL_UnloadLibrary(_THIS)
{
FreeLibrary((HMODULE) _this->gl_config.dll_handle);
_this->gl_config.dll_handle = NULL;
/* Free OpenGL memory */
SDL_free(_this->gl_data);
_this->gl_data = NULL;
}
static void
WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
{
SDL_zerop(pfd);
pfd->nSize = sizeof(*pfd);
pfd->nVersion = 1;
pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
if (_this->gl_config.double_buffer) {
pfd->dwFlags |= PFD_DOUBLEBUFFER;
}
if (_this->gl_config.stereo) {
pfd->dwFlags |= PFD_STEREO;
}
pfd->iLayerType = PFD_MAIN_PLANE;
pfd->iPixelType = PFD_TYPE_RGBA;
pfd->cRedBits = _this->gl_config.red_size;
pfd->cGreenBits = _this->gl_config.green_size;
pfd->cBlueBits = _this->gl_config.blue_size;
pfd->cAlphaBits = _this->gl_config.alpha_size;
if (_this->gl_config.buffer_size) {
pfd->cColorBits =
_this->gl_config.buffer_size - _this->gl_config.alpha_size;
} else {
pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
}
pfd->cAccumRedBits = _this->gl_config.accum_red_size;
pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
pfd->cAccumBits =
(pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
pfd->cAccumAlphaBits);
pfd->cDepthBits = _this->gl_config.depth_size;
pfd->cStencilBits = _this->gl_config.stencil_size;
}
/* Choose the closest pixel format that meets or exceeds the target.
FIXME: Should we weight any particular attribute over any other?
*/
static int
WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
{
PIXELFORMATDESCRIPTOR pfd;
int count, index, best = 0;
unsigned int dist, best_dist = ~0U;
count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
for (index = 1; index <= count; index++) {
if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
continue;
}
if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
continue;
}
if (pfd.iLayerType != target->iLayerType) {
continue;
}
if (pfd.iPixelType != target->iPixelType) {
continue;
}
dist = 0;
if (pfd.cColorBits < target->cColorBits) {
continue;
} else {
dist += (pfd.cColorBits - target->cColorBits);
}
if (pfd.cRedBits < target->cRedBits) {
continue;
} else {
dist += (pfd.cRedBits - target->cRedBits);
}
if (pfd.cGreenBits < target->cGreenBits) {
continue;
} else {
dist += (pfd.cGreenBits - target->cGreenBits);
}
if (pfd.cBlueBits < target->cBlueBits) {
continue;
} else {
dist += (pfd.cBlueBits - target->cBlueBits);
}
if (pfd.cAlphaBits < target->cAlphaBits) {
continue;
} else {
dist += (pfd.cAlphaBits - target->cAlphaBits);
}
if (pfd.cAccumBits < target->cAccumBits) {
continue;
} else {
dist += (pfd.cAccumBits - target->cAccumBits);
}
if (pfd.cAccumRedBits < target->cAccumRedBits) {
continue;
} else {
dist += (pfd.cAccumRedBits - target->cAccumRedBits);
}
if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
continue;
} else {
dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
}
if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
continue;
} else {
dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
}
if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
continue;
} else {
dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
}
if (pfd.cDepthBits < target->cDepthBits) {
continue;
} else {
dist += (pfd.cDepthBits - target->cDepthBits);
}
if (pfd.cStencilBits < target->cStencilBits) {
continue;
} else {
dist += (pfd.cStencilBits - target->cStencilBits);
}
if (dist < best_dist) {
best = index;
best_dist = dist;
}
}
return best;
}
static SDL_bool
HasExtension(const char *extension, const char *extensions)
{
const char *start;
const char *where, *terminator;
/* Extension names should not have spaces. */
where = SDL_strchr(extension, ' ');
if (where || *extension == '\0')
return SDL_FALSE;
if (!extensions)
return SDL_FALSE;
/* 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 (;;) {
where = SDL_strstr(start, extension);
if (!where)
break;
terminator = where + SDL_strlen(extension);
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return SDL_TRUE;
start = terminator;
}
return SDL_FALSE;
}
static void
WIN_GL_InitExtensions(_THIS, HDC hdc)
{
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
const char *extensions;
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
_this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
if (wglGetExtensionsStringARB) {
extensions = wglGetExtensionsStringARB(hdc);
} else {
extensions = NULL;
}
/* Check for WGL_ARB_pixel_format */
Aug 2, 2012
Aug 2, 2012
347
_this->gl_data->HAS_WGL_ARB_pixel_format = SDL_FALSE;
Jun 22, 2011
Jun 22, 2011
348
349
350
351
352
353
354
355
356
357
358
359
if (HasExtension("WGL_ARB_pixel_format", extensions)) {
_this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
(HDC, const int *,
const FLOAT *, UINT,
int *, UINT *))
WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
_this->gl_data->wglGetPixelFormatAttribivARB =
(BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
(_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
Aug 2, 2012
Aug 2, 2012
360
_this->gl_data->HAS_WGL_ARB_pixel_format = SDL_TRUE;
Jun 22, 2011
Jun 22, 2011
361
362
363
364
}
}
/* Check for WGL_EXT_swap_control */
Aug 2, 2012
Aug 2, 2012
365
_this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_FALSE;
Jun 22, 2011
Jun 22, 2011
366
367
368
369
370
if (HasExtension("WGL_EXT_swap_control", extensions)) {
_this->gl_data->wglSwapIntervalEXT =
WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
_this->gl_data->wglGetSwapIntervalEXT =
WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
Aug 2, 2012
Aug 2, 2012
371
372
373
if (HasExtension("WGL_EXT_swap_control_tear", extensions)) {
_this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_TRUE;
}
Jun 22, 2011
Jun 22, 2011
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
} else {
_this->gl_data->wglSwapIntervalEXT = NULL;
_this->gl_data->wglGetSwapIntervalEXT = NULL;
}
}
static int
WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
{
HWND hwnd;
HDC hdc;
PIXELFORMATDESCRIPTOR pfd;
HGLRC hglrc;
int pixel_format = 0;
unsigned int matching;
hwnd =
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
10, 10, NULL, NULL, SDL_Instance, NULL);
WIN_PumpEvents(_this);
hdc = GetDC(hwnd);
WIN_GL_SetupPixelFormat(_this, &pfd);
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
hglrc = _this->gl_data->wglCreateContext(hdc);
if (hglrc) {
_this->gl_data->wglMakeCurrent(hdc, hglrc);
WIN_GL_InitExtensions(_this, hdc);
Aug 2, 2012
Aug 2, 2012
407
if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
Jun 22, 2011
Jun 22, 2011
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
1, &pixel_format,
&matching);
}
_this->gl_data->wglMakeCurrent(NULL, NULL);
_this->gl_data->wglDeleteContext(hglrc);
}
ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);
WIN_PumpEvents(_this);
return pixel_format;
}
int
WIN_GL_SetupWindow(_THIS, SDL_Window * window)
{
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
PIXELFORMATDESCRIPTOR pfd;
Feb 21, 2012
Feb 21, 2012
428
int pixel_format = 0;
Jun 22, 2011
Jun 22, 2011
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
int iAttribs[64];
int *iAttr;
float fAttribs[1] = { 0 };
WIN_GL_SetupPixelFormat(_this, &pfd);
/* setup WGL_ARB_pixel_format attribs */
iAttr = &iAttribs[0];
*iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
*iAttr++ = GL_TRUE;
*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;
}
Feb 21, 2012
Feb 21, 2012
498
499
*iAttr++ = WGL_ACCELERATION_ARB;
*iAttr++ = WGL_FULL_ACCELERATION_ARB;
Jun 22, 2011
Jun 22, 2011
500
501
502
503
*iAttr = 0;
/* Choose and set the closest available pixel format */
Feb 21, 2012
Feb 21, 2012
504
505
506
507
508
509
510
if (_this->gl_config.accelerated != 0) {
pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
}
if (!pixel_format && _this->gl_config.accelerated != 1) {
iAttr[-1] = WGL_NO_ACCELERATION_ARB;
pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
}
Jun 22, 2011
Jun 22, 2011
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
if (!pixel_format) {
pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
}
if (!pixel_format) {
SDL_SetError("No matching GL pixel format available");
return -1;
}
if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
WIN_SetError("SetPixelFormat()");
return (-1);
}
return 0;
}
SDL_GLContext
WIN_GL_CreateContext(_THIS, SDL_Window * window)
{
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
Aug 12, 2012
Aug 12, 2012
529
530
531
532
533
534
535
HGLRC context, share_context;
if (_this->gl_config.share_with_current_context) {
share_context = (HGLRC)(_this->current_glctx);
} else {
share_context = 0;
}
Jun 22, 2011
Jun 22, 2011
536
Aug 12, 2012
Aug 12, 2012
537
538
539
540
if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* Create legacy context */
Jun 22, 2011
Jun 22, 2011
541
context = _this->gl_data->wglCreateContext(hdc);
Aug 12, 2012
Aug 12, 2012
542
543
544
if( share_context != 0 ) {
_this->gl_data->wglShareLists(share_context, hdc);
}
Jun 22, 2011
Jun 22, 2011
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
} else {
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
if (!temp_context) {
SDL_SetError("Could not create GL context");
return NULL;
}
/* Make the context current */
if (WIN_GL_MakeCurrent(_this, window, temp_context) < 0) {
WIN_GL_DeleteContext(_this, temp_context);
return NULL;
}
wglCreateContextAttribsARB =
(PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
wglGetProcAddress("wglCreateContextAttribsARB");
if (!wglCreateContextAttribsARB) {
SDL_SetError("GL 3.x is not supported");
context = temp_context;
} else {
Feb 21, 2012
Feb 21, 2012
566
567
/* max 8 attributes plus terminator */
int attribs[9] = {
Jun 22, 2011
Jun 22, 2011
568
569
570
571
WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
0
};
Feb 21, 2012
Feb 21, 2012
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
int iattr = 4;
/* SDL profile bits match WGL profile bits */
if( _this->gl_config.profile_mask != 0 ) {
attribs[iattr++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attribs[iattr++] = _this->gl_config.profile_mask;
}
/* SDL flags match WGL flags */
if( _this->gl_config.flags != 0 ) {
attribs[iattr++] = WGL_CONTEXT_FLAGS_ARB;
attribs[iattr++] = _this->gl_config.flags;
}
attribs[iattr++] = 0;
Jun 22, 2011
Jun 22, 2011
588
/* Create the GL 3.x context */
Aug 12, 2012
Aug 12, 2012
589
context = wglCreateContextAttribsARB(hdc, share_context, attribs);
Jun 22, 2011
Jun 22, 2011
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* Delete the GL 2.x context */
_this->gl_data->wglDeleteContext(temp_context);
}
}
if (!context) {
WIN_SetError("Could not create GL context");
return NULL;
}
if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
WIN_GL_DeleteContext(_this, context);
return NULL;
}
WIN_GL_InitExtensions(_this, hdc);
return context;
}
int
WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
HDC hdc;
int status;
if (window) {
hdc = ((SDL_WindowData *) window->driverdata)->hdc;
} else {
hdc = NULL;
}
if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
WIN_SetError("wglMakeCurrent()");
status = -1;
} else {
status = 0;
}
return status;
}
int
WIN_GL_SetSwapInterval(_THIS, int interval)
{
Aug 2, 2012
Aug 2, 2012
633
int retval = -1;
Aug 2, 2012
Aug 2, 2012
634
635
636
if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
SDL_SetError("Negative swap interval unsupported in this GL");
} else if (_this->gl_data->wglSwapIntervalEXT) {
Aug 2, 2012
Aug 2, 2012
637
638
639
640
641
if (_this->gl_data->wglSwapIntervalEXT(interval) == TRUE) {
retval = 0;
} else {
WIN_SetError("wglSwapIntervalEXT()");
}
Jun 22, 2011
Jun 22, 2011
642
643
644
} else {
SDL_Unsupported();
}
Aug 2, 2012
Aug 2, 2012
645
return retval;
Jun 22, 2011
Jun 22, 2011
646
647
648
649
650
}
int
WIN_GL_GetSwapInterval(_THIS)
{
Aug 2, 2012
Aug 2, 2012
651
int retval = 0;
Jun 22, 2011
Jun 22, 2011
652
if (_this->gl_data->wglGetSwapIntervalEXT) {
Aug 2, 2012
Aug 2, 2012
653
retval = _this->gl_data->wglGetSwapIntervalEXT();
Jun 22, 2011
Jun 22, 2011
654
}
Aug 2, 2012
Aug 2, 2012
655
return retval;
Jun 22, 2011
Jun 22, 2011
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
}
void
WIN_GL_SwapWindow(_THIS, SDL_Window * window)
{
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
SwapBuffers(hdc);
}
void
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
{
_this->gl_data->wglDeleteContext((HGLRC) context);
}
#endif /* SDL_VIDEO_OPENGL_WGL */
Oct 31, 2011
Oct 31, 2011
674
675
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
Jun 22, 2011
Jun 22, 2011
676
/* vi: set ts=4 sw=4 expandtab: */