comparison src/video/win32/SDL_win32opengl.c @ 1936:83946ee0ff1f

Implemented OpenGL support on Mac OS X The OpenGL renderer works without changes, yay! :)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 25 Jul 2006 06:22:42 +0000
parents 307355678142
children 420716272158
comparison
equal deleted inserted replaced
1935:8a9b367a80f3 1936:83946ee0ff1f
26 /* WGL implementation of SDL OpenGL support */ 26 /* WGL implementation of SDL OpenGL support */
27 27
28 #if SDL_VIDEO_OPENGL 28 #if SDL_VIDEO_OPENGL
29 #include "SDL_opengl.h" 29 #include "SDL_opengl.h"
30 30
31 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL" 31 #define DEFAULT_OPENGL_PATH "OPENGL32.DLL"
32 32
33 33
34 int 34 int
35 WIN_GL_LoadLibrary(_THIS, const char *path) 35 WIN_GL_LoadLibrary(_THIS, const char *path)
36 { 36 {
45 ++_this->gl_config.driver_loaded; 45 ++_this->gl_config.driver_loaded;
46 return 0; 46 return 0;
47 } 47 }
48 } 48 }
49 if (path == NULL) { 49 if (path == NULL) {
50 path = DEFAULT_GL_DRIVER_PATH; 50 path = DEFAULT_OPENGL_PATH;
51 } 51 }
52 wpath = WIN_UTF8ToString(path); 52 wpath = WIN_UTF8ToString(path);
53 handle = LoadLibrary(wpath); 53 handle = LoadLibrary(wpath);
54 SDL_free(wpath); 54 SDL_free(wpath);
55 if (!handle) { 55 if (!handle) {
412 WIN_GL_CleanupWindow(_THIS, SDL_Window * window) 412 WIN_GL_CleanupWindow(_THIS, SDL_Window * window)
413 { 413 {
414 WIN_GL_Shutdown(_this); 414 WIN_GL_Shutdown(_this);
415 } 415 }
416 416
417 int
418 WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window, SDL_GLattr attrib,
419 int *value)
420 {
421 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
422 int pixel_format;
423
424 pixel_format = GetPixelFormat(hdc);
425
426 if (_this->gl_data->WGL_ARB_pixel_format) {
427 int wgl_attrib;
428
429 switch (attrib) {
430 case SDL_GL_RED_SIZE:
431 wgl_attrib = WGL_RED_BITS_ARB;
432 break;
433 case SDL_GL_GREEN_SIZE:
434 wgl_attrib = WGL_GREEN_BITS_ARB;
435 break;
436 case SDL_GL_BLUE_SIZE:
437 wgl_attrib = WGL_BLUE_BITS_ARB;
438 break;
439 case SDL_GL_ALPHA_SIZE:
440 wgl_attrib = WGL_ALPHA_BITS_ARB;
441 break;
442 case SDL_GL_DOUBLEBUFFER:
443 wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
444 break;
445 case SDL_GL_BUFFER_SIZE:
446 wgl_attrib = WGL_COLOR_BITS_ARB;
447 break;
448 case SDL_GL_DEPTH_SIZE:
449 wgl_attrib = WGL_DEPTH_BITS_ARB;
450 break;
451 case SDL_GL_STENCIL_SIZE:
452 wgl_attrib = WGL_STENCIL_BITS_ARB;
453 break;
454 case SDL_GL_ACCUM_RED_SIZE:
455 wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
456 break;
457 case SDL_GL_ACCUM_GREEN_SIZE:
458 wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
459 break;
460 case SDL_GL_ACCUM_BLUE_SIZE:
461 wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
462 break;
463 case SDL_GL_ACCUM_ALPHA_SIZE:
464 wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
465 break;
466 case SDL_GL_STEREO:
467 wgl_attrib = WGL_STEREO_ARB;
468 break;
469 case SDL_GL_MULTISAMPLEBUFFERS:
470 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
471 break;
472 case SDL_GL_MULTISAMPLESAMPLES:
473 wgl_attrib = WGL_SAMPLES_ARB;
474 break;
475 case SDL_GL_ACCELERATED_VISUAL:
476 wgl_attrib = WGL_ACCELERATION_ARB;
477 _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0,
478 1, &wgl_attrib,
479 value);
480 if (*value == WGL_NO_ACCELERATION_ARB) {
481 *value = SDL_FALSE;
482 } else {
483 *value = SDL_TRUE;
484 }
485 return 0;
486 break;
487 default:
488 return (-1);
489 }
490 _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1,
491 &wgl_attrib, value);
492 return 0;
493 } else {
494 PIXELFORMATDESCRIPTOR pfd;
495 int retval;
496
497 if (!DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd)) {
498 WIN_SetError("DescribePixelFormat()");
499 return -1;
500 }
501 retval = 0;
502 switch (attrib) {
503 case SDL_GL_RED_SIZE:
504 *value = pfd.cRedBits;
505 break;
506 case SDL_GL_GREEN_SIZE:
507 *value = pfd.cGreenBits;
508 break;
509 case SDL_GL_BLUE_SIZE:
510 *value = pfd.cBlueBits;
511 break;
512 case SDL_GL_ALPHA_SIZE:
513 *value = pfd.cAlphaBits;
514 break;
515 case SDL_GL_DOUBLEBUFFER:
516 if (pfd.dwFlags & PFD_DOUBLEBUFFER) {
517 *value = 1;
518 } else {
519 *value = 0;
520 }
521 break;
522 case SDL_GL_BUFFER_SIZE:
523 *value = pfd.cColorBits;
524 break;
525 case SDL_GL_DEPTH_SIZE:
526 *value = pfd.cDepthBits;
527 break;
528 case SDL_GL_STENCIL_SIZE:
529 *value = pfd.cStencilBits;
530 break;
531 case SDL_GL_ACCUM_RED_SIZE:
532 *value = pfd.cAccumRedBits;
533 break;
534 case SDL_GL_ACCUM_GREEN_SIZE:
535 *value = pfd.cAccumGreenBits;
536 break;
537 case SDL_GL_ACCUM_BLUE_SIZE:
538 *value = pfd.cAccumBlueBits;
539 break;
540 case SDL_GL_ACCUM_ALPHA_SIZE:
541 *value = pfd.cAccumAlphaBits;
542 break;
543 case SDL_GL_STEREO:
544 if (pfd.dwFlags & PFD_STEREO) {
545 *value = 1;
546 } else {
547 *value = 0;
548 }
549 break;
550 case SDL_GL_MULTISAMPLEBUFFERS:
551 *value = 0;
552 break;
553 case SDL_GL_MULTISAMPLESAMPLES:
554 *value = 1;
555 break;
556 default:
557 retval = -1;
558 break;
559 }
560 return retval;
561 }
562 }
563
564 SDL_GLContext 417 SDL_GLContext
565 WIN_GL_CreateContext(_THIS, SDL_Window * window) 418 WIN_GL_CreateContext(_THIS, SDL_Window * window)
566 { 419 {
567 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; 420 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
568 421
621 } 474 }
622 475
623 void 476 void
624 WIN_GL_DeleteContext(_THIS, SDL_GLContext context) 477 WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
625 { 478 {
626 if (context) { 479 _this->gl_data->wglDeleteContext((HGLRC) context);
627 _this->gl_data->wglDeleteContext((HGLRC) context);
628 }
629 } 480 }
630 481
631 #endif /* SDL_VIDEO_OPENGL */ 482 #endif /* SDL_VIDEO_OPENGL */
632 483
633 484