comparison src/video/wincommon/SDL_wingl.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children a51dfda0ff33
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
33 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL" 33 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
34 #endif 34 #endif
35 35
36 /* If setting the HDC fails, we may need to recreate the window (MSDN) */ 36 /* If setting the HDC fails, we may need to recreate the window (MSDN) */
37 static int 37 static int
38 WIN_GL_ResetWindow (_THIS) 38 WIN_GL_ResetWindow(_THIS)
39 { 39 {
40 int status = 0; 40 int status = 0;
41 41
42 #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */ 42 #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */
43 /* This doesn't work with DirectX code (see CVS comments) */ 43 /* This doesn't work with DirectX code (see CVS comments) */
44 /* If we were passed a window, then we can't create a new one */ 44 /* If we were passed a window, then we can't create a new one */
45 if (!SDL_windowid && SDL_strcmp (this->name, "windib") == 0) { 45 if (!SDL_windowid && SDL_strcmp(this->name, "windib") == 0) {
46 /* Save the existing window attributes */ 46 /* Save the existing window attributes */
47 LONG style; 47 LONG style;
48 RECT rect = { 0, 0, 0, 0 }; 48 RECT rect = { 0, 0, 0, 0 };
49 style = GetWindowLong (SDL_Window, GWL_STYLE); 49 style = GetWindowLong(SDL_Window, GWL_STYLE);
50 GetWindowRect (SDL_Window, &rect); 50 GetWindowRect(SDL_Window, &rect);
51 DestroyWindow (SDL_Window); 51 DestroyWindow(SDL_Window);
52 WIN_FlushMessageQueue (); 52 WIN_FlushMessageQueue();
53 53
54 SDL_Window = CreateWindow (SDL_Appname, SDL_Appname, 54 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
55 style, 55 style,
56 rect.left, rect.top, 56 rect.left, rect.top,
57 (rect.right - rect.left) + 1, 57 (rect.right - rect.left) + 1,
58 (rect.top - rect.bottom) + 1, 58 (rect.top - rect.bottom) + 1,
59 NULL, NULL, SDL_Instance, NULL); 59 NULL, NULL, SDL_Instance, NULL);
60 WIN_FlushMessageQueue (); 60 WIN_FlushMessageQueue();
61 61
62 if (SDL_Window) { 62 if (SDL_Window) {
63 this->SetCaption (this, this->wm_title, this->wm_icon); 63 this->SetCaption(this, this->wm_title, this->wm_icon);
64 } else { 64 } else {
65 SDL_SetError ("Couldn't create window"); 65 SDL_SetError("Couldn't create window");
66 status = -1; 66 status = -1;
67 } 67 }
68 } else 68 } else
69 #endif /* !_WIN32_WCE */ 69 #endif /* !_WIN32_WCE */
70 { 70 {
71 SDL_SetError ("Unable to reset window for OpenGL context"); 71 SDL_SetError("Unable to reset window for OpenGL context");
72 status = -1; 72 status = -1;
73 } 73 }
74 return (status); 74 return (status);
75 } 75 }
76 76
77 #if SDL_VIDEO_OPENGL 77 #if SDL_VIDEO_OPENGL
78 78
79 static int 79 static int
80 ExtensionSupported (const char *extension, const char *extensions) 80 ExtensionSupported(const char *extension, const char *extensions)
81 { 81 {
82 const char *start; 82 const char *start;
83 const char *where, *terminator; 83 const char *where, *terminator;
84 84
85 /* Extension names should not have spaces. */ 85 /* Extension names should not have spaces. */
86 where = SDL_strchr (extension, ' '); 86 where = SDL_strchr(extension, ' ');
87 if (where || *extension == '\0') 87 if (where || *extension == '\0')
88 return 0; 88 return 0;
89 89
90 if (!extensions) 90 if (!extensions)
91 return 0; 91 return 0;
95 * etc. */ 95 * etc. */
96 96
97 start = extensions; 97 start = extensions;
98 98
99 for (;;) { 99 for (;;) {
100 where = SDL_strstr (start, extension); 100 where = SDL_strstr(start, extension);
101 if (!where) 101 if (!where)
102 break; 102 break;
103 103
104 terminator = where + SDL_strlen (extension); 104 terminator = where + SDL_strlen(extension);
105 if (where == start || *(where - 1) == ' ') 105 if (where == start || *(where - 1) == ' ')
106 if (*terminator == ' ' || *terminator == '\0') 106 if (*terminator == ' ' || *terminator == '\0')
107 return 1; 107 return 1;
108 108
109 start = terminator; 109 start = terminator;
111 111
112 return 0; 112 return 0;
113 } 113 }
114 114
115 static void 115 static void
116 Init_WGL_ARB_extensions (_THIS) 116 Init_WGL_ARB_extensions(_THIS)
117 { 117 {
118 HWND hwnd; 118 HWND hwnd;
119 HDC hdc; 119 HDC hdc;
120 HGLRC hglrc; 120 HGLRC hglrc;
121 int pformat; 121 int pformat;
122 const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0; 122 const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
123 const char *extensions; 123 const char *extensions;
124 124
125 hwnd = CreateWindow (SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, 125 hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
126 0, 0, 10, 10, NULL, NULL, SDL_Instance, NULL); 126 0, 0, 10, 10, NULL, NULL, SDL_Instance, NULL);
127 WIN_FlushMessageQueue (); 127 WIN_FlushMessageQueue();
128 128
129 hdc = GetDC (hwnd); 129 hdc = GetDC(hwnd);
130 130
131 pformat = ChoosePixelFormat (hdc, &GL_pfd); 131 pformat = ChoosePixelFormat(hdc, &GL_pfd);
132 SetPixelFormat (hdc, pformat, &GL_pfd); 132 SetPixelFormat(hdc, pformat, &GL_pfd);
133 133
134 hglrc = this->gl_data->wglCreateContext (hdc); 134 hglrc = this->gl_data->wglCreateContext(hdc);
135 if (hglrc) { 135 if (hglrc) {
136 this->gl_data->wglMakeCurrent (hdc, hglrc); 136 this->gl_data->wglMakeCurrent(hdc, hglrc);
137 } 137 }
138 138
139 wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC)) 139 wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
140 this->gl_data->wglGetProcAddress ("wglGetExtensionsStringARB"); 140 this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
141 141
142 if (wglGetExtensionsStringARB) { 142 if (wglGetExtensionsStringARB) {
143 extensions = wglGetExtensionsStringARB (hdc); 143 extensions = wglGetExtensionsStringARB(hdc);
144 } else { 144 } else {
145 extensions = NULL; 145 extensions = NULL;
146 } 146 }
147 147
148 this->gl_data->WGL_ARB_pixel_format = 0; 148 this->gl_data->WGL_ARB_pixel_format = 0;
149 if (ExtensionSupported ("WGL_ARB_pixel_format", extensions)) { 149 if (ExtensionSupported("WGL_ARB_pixel_format", extensions)) {
150 this->gl_data->wglChoosePixelFormatARB = (BOOL (WINAPI *) 150 this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
151 (HDC, const int *, 151 (HDC, const int *,
152 const FLOAT *, UINT, int *, 152 const FLOAT *, UINT, int *,
153 UINT *)) this->gl_data-> 153 UINT *)) this->gl_data->
154 wglGetProcAddress ("wglChoosePixelFormatARB"); 154 wglGetProcAddress("wglChoosePixelFormatARB");
155 this->gl_data->wglGetPixelFormatAttribivARB = 155 this->gl_data->wglGetPixelFormatAttribivARB =
156 (BOOL (WINAPI *) (HDC, int, int, UINT, const int *, int *)) 156 (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
157 this->gl_data->wglGetProcAddress ("wglGetPixelFormatAttribivARB"); 157 this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
158 158
159 if ((this->gl_data->wglChoosePixelFormatARB != NULL) && 159 if ((this->gl_data->wglChoosePixelFormatARB != NULL) &&
160 (this->gl_data->wglGetPixelFormatAttribivARB != NULL)) { 160 (this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
161 this->gl_data->WGL_ARB_pixel_format = 1; 161 this->gl_data->WGL_ARB_pixel_format = 1;
162 } 162 }
163 } 163 }
164 164
165 if (hglrc) { 165 if (hglrc) {
166 this->gl_data->wglMakeCurrent (NULL, NULL); 166 this->gl_data->wglMakeCurrent(NULL, NULL);
167 this->gl_data->wglDeleteContext (hglrc); 167 this->gl_data->wglDeleteContext(hglrc);
168 } 168 }
169 ReleaseDC (hwnd, hdc); 169 ReleaseDC(hwnd, hdc);
170 DestroyWindow (hwnd); 170 DestroyWindow(hwnd);
171 WIN_FlushMessageQueue (); 171 WIN_FlushMessageQueue();
172 } 172 }
173 173
174 #endif /* SDL_VIDEO_OPENGL */ 174 #endif /* SDL_VIDEO_OPENGL */
175 175
176 int 176 int
177 WIN_GL_SetupWindow (_THIS) 177 WIN_GL_SetupWindow(_THIS)
178 { 178 {
179 int retval; 179 int retval;
180 #if SDL_VIDEO_OPENGL 180 #if SDL_VIDEO_OPENGL
181 int i; 181 int i;
182 unsigned int matching; 182 unsigned int matching;
187 const char *wglext; 187 const char *wglext;
188 188
189 /* load the gl driver from a default path */ 189 /* load the gl driver from a default path */
190 if (!this->gl_config.driver_loaded) { 190 if (!this->gl_config.driver_loaded) {
191 /* no driver has been loaded, use default (ourselves) */ 191 /* no driver has been loaded, use default (ourselves) */
192 if (WIN_GL_LoadLibrary (this, NULL) < 0) { 192 if (WIN_GL_LoadLibrary(this, NULL) < 0) {
193 return (-1); 193 return (-1);
194 } 194 }
195 } 195 }
196 196
197 for (i = 0;; ++i) { 197 for (i = 0;; ++i) {
198 /* Get the window device context for our OpenGL drawing */ 198 /* Get the window device context for our OpenGL drawing */
199 GL_hdc = GetDC (SDL_Window); 199 GL_hdc = GetDC(SDL_Window);
200 if (GL_hdc == NULL) { 200 if (GL_hdc == NULL) {
201 SDL_SetError ("Unable to get DC for SDL_Window"); 201 SDL_SetError("Unable to get DC for SDL_Window");
202 return (-1); 202 return (-1);
203 } 203 }
204 204
205 /* Set up the pixel format descriptor with our needed format */ 205 /* Set up the pixel format descriptor with our needed format */
206 SDL_memset (&GL_pfd, 0, sizeof (GL_pfd)); 206 SDL_memset(&GL_pfd, 0, sizeof(GL_pfd));
207 GL_pfd.nSize = sizeof (GL_pfd); 207 GL_pfd.nSize = sizeof(GL_pfd);
208 GL_pfd.nVersion = 1; 208 GL_pfd.nVersion = 1;
209 GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL); 209 GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
210 if (this->gl_config.double_buffer) { 210 if (this->gl_config.double_buffer) {
211 GL_pfd.dwFlags |= PFD_DOUBLEBUFFER; 211 GL_pfd.dwFlags |= PFD_DOUBLEBUFFER;
212 } 212 }
228 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits); 228 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits);
229 GL_pfd.cDepthBits = this->gl_config.depth_size; 229 GL_pfd.cDepthBits = this->gl_config.depth_size;
230 GL_pfd.cStencilBits = this->gl_config.stencil_size; 230 GL_pfd.cStencilBits = this->gl_config.stencil_size;
231 231
232 /* initialize WGL_ARB_pixel_format */ 232 /* initialize WGL_ARB_pixel_format */
233 Init_WGL_ARB_extensions (this); 233 Init_WGL_ARB_extensions(this);
234 234
235 /* setup WGL_ARB_pixel_format attribs */ 235 /* setup WGL_ARB_pixel_format attribs */
236 iAttr = &iAttribs[0]; 236 iAttr = &iAttribs[0];
237 237
238 *iAttr++ = WGL_DRAW_TO_WINDOW_ARB; 238 *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
307 307
308 *iAttr = 0; 308 *iAttr = 0;
309 309
310 /* Choose and set the closest available pixel format */ 310 /* Choose and set the closest available pixel format */
311 if (!this->gl_data->WGL_ARB_pixel_format || 311 if (!this->gl_data->WGL_ARB_pixel_format ||
312 !this->gl_data->wglChoosePixelFormatARB (GL_hdc, iAttribs, 312 !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs,
313 fAttribs, 1, 313 fAttribs, 1,
314 &pixel_format, &matching) 314 &pixel_format, &matching)
315 || !matching) { 315 || !matching) {
316 pixel_format = ChoosePixelFormat (GL_hdc, &GL_pfd); 316 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
317 this->gl_data->WGL_ARB_pixel_format = 0; 317 this->gl_data->WGL_ARB_pixel_format = 0;
318 } 318 }
319 if (!pixel_format) { 319 if (!pixel_format) {
320 SDL_SetError ("No matching GL pixel format available"); 320 SDL_SetError("No matching GL pixel format available");
321 return (-1); 321 return (-1);
322 } 322 }
323 if (!SetPixelFormat (GL_hdc, pixel_format, &GL_pfd)) { 323 if (!SetPixelFormat(GL_hdc, pixel_format, &GL_pfd)) {
324 if (i == 0) { 324 if (i == 0) {
325 /* First time through, try resetting the window */ 325 /* First time through, try resetting the window */
326 if (WIN_GL_ResetWindow (this) < 0) { 326 if (WIN_GL_ResetWindow(this) < 0) {
327 return (-1); 327 return (-1);
328 } 328 }
329 continue; 329 continue;
330 } 330 }
331 SDL_SetError ("Unable to set HDC pixel format"); 331 SDL_SetError("Unable to set HDC pixel format");
332 return (-1); 332 return (-1);
333 } 333 }
334 /* We either succeeded or failed by this point */ 334 /* We either succeeded or failed by this point */
335 break; 335 break;
336 } 336 }
337 DescribePixelFormat (GL_hdc, pixel_format, sizeof (GL_pfd), &GL_pfd); 337 DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);
338 338
339 GL_hrc = this->gl_data->wglCreateContext (GL_hdc); 339 GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
340 if (GL_hrc == NULL) { 340 if (GL_hrc == NULL) {
341 SDL_SetError ("Unable to create GL context"); 341 SDL_SetError("Unable to create GL context");
342 return (-1); 342 return (-1);
343 } 343 }
344 if (WIN_GL_MakeCurrent (this) < 0) { 344 if (WIN_GL_MakeCurrent(this) < 0) {
345 return (-1); 345 return (-1);
346 } 346 }
347 gl_active = 1; 347 gl_active = 1;
348 348
349 /* Vsync control under Windows. Checking glGetString here is 349 /* Vsync control under Windows. Checking glGetString here is
350 * somewhat a documented and reliable hack - it was originally 350 * somewhat a documented and reliable hack - it was originally
351 * as a feature added by mistake, but since so many people rely 351 * as a feature added by mistake, but since so many people rely
352 * on it, it will not be removed. strstr should be safe here.*/ 352 * on it, it will not be removed. strstr should be safe here.*/
353 glGetStringFunc = WIN_GL_GetProcAddress (this, "glGetString"); 353 glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
354 if (glGetStringFunc) { 354 if (glGetStringFunc) {
355 wglext = (const char *) glGetStringFunc (GL_EXTENSIONS); 355 wglext = (const char *) glGetStringFunc(GL_EXTENSIONS);
356 } else { 356 } else {
357 /* Uh oh, something is seriously wrong here... */ 357 /* Uh oh, something is seriously wrong here... */
358 wglext = NULL; 358 wglext = NULL;
359 } 359 }
360 if (!wglext || !SDL_strstr (wglext, "WGL_EXT_swap_control")) { 360 if (!wglext || !SDL_strstr(wglext, "WGL_EXT_swap_control")) {
361 this->gl_data->wglSwapIntervalEXT = NULL; 361 this->gl_data->wglSwapIntervalEXT = NULL;
362 this->gl_data->wglGetSwapIntervalEXT = NULL; 362 this->gl_data->wglGetSwapIntervalEXT = NULL;
363 } 363 }
364 if (this->gl_config.swap_control >= 0) { 364 if (this->gl_config.swap_control >= 0) {
365 if (this->gl_data->wglSwapIntervalEXT) { 365 if (this->gl_data->wglSwapIntervalEXT) {
366 this->gl_data->wglSwapIntervalEXT (this->gl_config.swap_control); 366 this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
367 } 367 }
368 } 368 }
369 #else 369 #else
370 SDL_SetError ("WIN driver not configured with OpenGL"); 370 SDL_SetError("WIN driver not configured with OpenGL");
371 #endif 371 #endif
372 if (gl_active) { 372 if (gl_active) {
373 retval = 0; 373 retval = 0;
374 } else { 374 } else {
375 retval = -1; 375 retval = -1;
376 } 376 }
377 return (retval); 377 return (retval);
378 } 378 }
379 379
380 void 380 void
381 WIN_GL_ShutDown (_THIS) 381 WIN_GL_ShutDown(_THIS)
382 { 382 {
383 #if SDL_VIDEO_OPENGL 383 #if SDL_VIDEO_OPENGL
384 /* Clean up OpenGL */ 384 /* Clean up OpenGL */
385 if (GL_hrc) { 385 if (GL_hrc) {
386 this->gl_data->wglMakeCurrent (NULL, NULL); 386 this->gl_data->wglMakeCurrent(NULL, NULL);
387 this->gl_data->wglDeleteContext (GL_hrc); 387 this->gl_data->wglDeleteContext(GL_hrc);
388 GL_hrc = NULL; 388 GL_hrc = NULL;
389 } 389 }
390 if (GL_hdc) { 390 if (GL_hdc) {
391 ReleaseDC (SDL_Window, GL_hdc); 391 ReleaseDC(SDL_Window, GL_hdc);
392 GL_hdc = NULL; 392 GL_hdc = NULL;
393 } 393 }
394 gl_active = 0; 394 gl_active = 0;
395 395
396 WIN_GL_UnloadLibrary (this); 396 WIN_GL_UnloadLibrary(this);
397 #endif /* SDL_VIDEO_OPENGL */ 397 #endif /* SDL_VIDEO_OPENGL */
398 } 398 }
399 399
400 #if SDL_VIDEO_OPENGL 400 #if SDL_VIDEO_OPENGL
401 401
402 /* Make the current context active */ 402 /* Make the current context active */
403 int 403 int
404 WIN_GL_MakeCurrent (_THIS) 404 WIN_GL_MakeCurrent(_THIS)
405 { 405 {
406 int retval; 406 int retval;
407 407
408 retval = 0; 408 retval = 0;
409 if (!this->gl_data->wglMakeCurrent (GL_hdc, GL_hrc)) { 409 if (!this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc)) {
410 SDL_SetError ("Unable to make GL context current"); 410 SDL_SetError("Unable to make GL context current");
411 retval = -1; 411 retval = -1;
412 } 412 }
413 return (retval); 413 return (retval);
414 } 414 }
415 415
416 /* Get attribute data from glX. */ 416 /* Get attribute data from glX. */
417 int 417 int
418 WIN_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value) 418 WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
419 { 419 {
420 int retval; 420 int retval;
421 421
422 if (this->gl_data->WGL_ARB_pixel_format) { 422 if (this->gl_data->WGL_ARB_pixel_format) {
423 int wgl_attrib; 423 int wgl_attrib;
468 case SDL_GL_MULTISAMPLESAMPLES: 468 case SDL_GL_MULTISAMPLESAMPLES:
469 wgl_attrib = WGL_SAMPLES_ARB; 469 wgl_attrib = WGL_SAMPLES_ARB;
470 break; 470 break;
471 case SDL_GL_ACCELERATED_VISUAL: 471 case SDL_GL_ACCELERATED_VISUAL:
472 wgl_attrib = WGL_ACCELERATION_ARB; 472 wgl_attrib = WGL_ACCELERATION_ARB;
473 this->gl_data->wglGetPixelFormatAttribivARB (GL_hdc, 473 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc,
474 pixel_format, 0, 474 pixel_format, 0,
475 1, &wgl_attrib, 475 1, &wgl_attrib,
476 value); 476 value);
477 if (*value == WGL_NO_ACCELERATION_ARB) { 477 if (*value == WGL_NO_ACCELERATION_ARB) {
478 *value = SDL_FALSE; 478 *value = SDL_FALSE;
479 } else { 479 } else {
480 *value = SDL_TRUE; 480 *value = SDL_TRUE;
481 } 481 }
482 return 0; 482 return 0;
483 break; 483 break;
484 case SDL_GL_SWAP_CONTROL: 484 case SDL_GL_SWAP_CONTROL:
485 if (this->gl_data->wglGetSwapIntervalEXT) { 485 if (this->gl_data->wglGetSwapIntervalEXT) {
486 return this->gl_data->wglGetSwapIntervalEXT (); 486 return this->gl_data->wglGetSwapIntervalEXT();
487 } else { 487 } else {
488 return -1; 488 return -1;
489 } 489 }
490 default: 490 default:
491 return (-1); 491 return (-1);
492 } 492 }
493 this->gl_data->wglGetPixelFormatAttribivARB (GL_hdc, pixel_format, 493 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format,
494 0, 1, &wgl_attrib, 494 0, 1, &wgl_attrib, value);
495 value);
496 495
497 return 0; 496 return 0;
498 } 497 }
499 498
500 retval = 0; 499 retval = 0;
558 } 557 }
559 return retval; 558 return retval;
560 } 559 }
561 560
562 void 561 void
563 WIN_GL_SwapBuffers (_THIS) 562 WIN_GL_SwapBuffers(_THIS)
564 { 563 {
565 SwapBuffers (GL_hdc); 564 SwapBuffers(GL_hdc);
566 } 565 }
567 566
568 void 567 void
569 WIN_GL_UnloadLibrary (_THIS) 568 WIN_GL_UnloadLibrary(_THIS)
570 { 569 {
571 if (this->gl_config.driver_loaded) { 570 if (this->gl_config.driver_loaded) {
572 FreeLibrary ((HMODULE) this->gl_config.dll_handle); 571 FreeLibrary((HMODULE) this->gl_config.dll_handle);
573 572
574 this->gl_data->wglGetProcAddress = NULL; 573 this->gl_data->wglGetProcAddress = NULL;
575 this->gl_data->wglCreateContext = NULL; 574 this->gl_data->wglCreateContext = NULL;
576 this->gl_data->wglDeleteContext = NULL; 575 this->gl_data->wglDeleteContext = NULL;
577 this->gl_data->wglMakeCurrent = NULL; 576 this->gl_data->wglMakeCurrent = NULL;
585 } 584 }
586 } 585 }
587 586
588 /* Passing a NULL path means load pointers from the application */ 587 /* Passing a NULL path means load pointers from the application */
589 int 588 int
590 WIN_GL_LoadLibrary (_THIS, const char *path) 589 WIN_GL_LoadLibrary(_THIS, const char *path)
591 { 590 {
592 HMODULE handle; 591 HMODULE handle;
593 592
594 if (gl_active) { 593 if (gl_active) {
595 SDL_SetError ("OpenGL context already created"); 594 SDL_SetError("OpenGL context already created");
596 return -1; 595 return -1;
597 } 596 }
598 597
599 if (path == NULL) { 598 if (path == NULL) {
600 path = DEFAULT_GL_DRIVER_PATH; 599 path = DEFAULT_GL_DRIVER_PATH;
601 } 600 }
602 handle = LoadLibrary (path); 601 handle = LoadLibrary(path);
603 if (handle == NULL) { 602 if (handle == NULL) {
604 SDL_SetError ("Could not load OpenGL library"); 603 SDL_SetError("Could not load OpenGL library");
605 return -1; 604 return -1;
606 } 605 }
607 606
608 /* Unload the old driver and reset the pointers */ 607 /* Unload the old driver and reset the pointers */
609 WIN_GL_UnloadLibrary (this); 608 WIN_GL_UnloadLibrary(this);
610 609
611 /* Load new function pointers */ 610 /* Load new function pointers */
612 SDL_memset (this->gl_data, 0, sizeof (*this->gl_data)); 611 SDL_memset(this->gl_data, 0, sizeof(*this->gl_data));
613 this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *)) 612 this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
614 GetProcAddress (handle, "wglGetProcAddress"); 613 GetProcAddress(handle, "wglGetProcAddress");
615 this->gl_data->wglCreateContext = (HGLRC (WINAPI *) (HDC)) 614 this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
616 GetProcAddress (handle, "wglCreateContext"); 615 GetProcAddress(handle, "wglCreateContext");
617 this->gl_data->wglDeleteContext = (BOOL (WINAPI *) (HGLRC)) 616 this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
618 GetProcAddress (handle, "wglDeleteContext"); 617 GetProcAddress(handle, "wglDeleteContext");
619 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *) (HDC, HGLRC)) 618 this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
620 GetProcAddress (handle, "wglMakeCurrent"); 619 GetProcAddress(handle, "wglMakeCurrent");
621 this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int)) 620 this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
622 GetProcAddress (handle, "wglSwapIntervalEXT"); 621 GetProcAddress(handle, "wglSwapIntervalEXT");
623 this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void)) 622 this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
624 GetProcAddress (handle, "wglGetSwapIntervalEXT"); 623 GetProcAddress(handle, "wglGetSwapIntervalEXT");
625 624
626 if ((this->gl_data->wglGetProcAddress == NULL) || 625 if ((this->gl_data->wglGetProcAddress == NULL) ||
627 (this->gl_data->wglCreateContext == NULL) || 626 (this->gl_data->wglCreateContext == NULL) ||
628 (this->gl_data->wglDeleteContext == NULL) || 627 (this->gl_data->wglDeleteContext == NULL) ||
629 (this->gl_data->wglMakeCurrent == NULL)) { 628 (this->gl_data->wglMakeCurrent == NULL)) {
630 SDL_SetError ("Could not retrieve OpenGL functions"); 629 SDL_SetError("Could not retrieve OpenGL functions");
631 FreeLibrary (handle); 630 FreeLibrary(handle);
632 return -1; 631 return -1;
633 } 632 }
634 633
635 this->gl_config.dll_handle = handle; 634 this->gl_config.dll_handle = handle;
636 SDL_strlcpy (this->gl_config.driver_path, path, 635 SDL_strlcpy(this->gl_config.driver_path, path,
637 SDL_arraysize (this->gl_config.driver_path)); 636 SDL_arraysize(this->gl_config.driver_path));
638 this->gl_config.driver_loaded = 1; 637 this->gl_config.driver_loaded = 1;
639 return 0; 638 return 0;
640 } 639 }
641 640
642 void * 641 void *
643 WIN_GL_GetProcAddress (_THIS, const char *proc) 642 WIN_GL_GetProcAddress(_THIS, const char *proc)
644 { 643 {
645 void *func; 644 void *func;
646 645
647 /* This is to pick up extensions */ 646 /* This is to pick up extensions */
648 func = this->gl_data->wglGetProcAddress (proc); 647 func = this->gl_data->wglGetProcAddress(proc);
649 if (!func) { 648 if (!func) {
650 /* This is probably a normal GL function */ 649 /* This is probably a normal GL function */
651 func = GetProcAddress (this->gl_config.dll_handle, proc); 650 func = GetProcAddress(this->gl_config.dll_handle, proc);
652 } 651 }
653 return func; 652 return func;
654 } 653 }
655 654
656 #endif /* SDL_VIDEO_OPENGL */ 655 #endif /* SDL_VIDEO_OPENGL */