comparison src/video/bwindow/SDL_sysvideo.cc @ 906:a48acf6ee48f

Date: Sat, 03 Jul 2004 02:23:48 +0200 From: Marcin Konicki Subject: [PATCH] Add missing functions and bring back OpenGL This patch adds missing functions: IconifyWindow GetWMInfo GL_LoadLibrary GL_GetProcAddress GL_GetAttribute GL_MakeCurrent Adding GL_* functions brings back working OpenGL in SDL for BeOS :). With addd GL_* functions there are few changes in Window class to handle changes better. Patch also fixes bug which freezed window when using MesaGL instead of BeOS r5 GL - it just needed Window->Quit() added into BE_VideoQuit(). THX to Michael Weirauch (a.k.a emwe) who worked on that bug before and found that it freezes because of lock somewhere. THX to Matti "Mictlantecuhtli" Lev��nen for testing, Rod��ric Vicaire (a.k.a. Ingenu) for OpenGL wisdom, and Stefano Ceccherini (a.k.a Jack Burton) for asking me to fix SDL on BeOS :).
author Sam Lantinga <slouken@libsdl.org>
date Sun, 18 Jul 2004 19:14:33 +0000
parents b8d311d90021
children c9b51268668f
comparison
equal deleted inserted replaced
905:e6ceebb0f0eb 906:a48acf6ee48f
69 static int BE_ToggleFullScreen(_THIS, int fullscreen); 69 static int BE_ToggleFullScreen(_THIS, int fullscreen);
70 static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display); 70 static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display);
71 71
72 /* OpenGL functions */ 72 /* OpenGL functions */
73 #ifdef HAVE_OPENGL 73 #ifdef HAVE_OPENGL
74 static int BE_GL_LoadLibrary(_THIS, const char *path);
75 static void* BE_GL_GetProcAddress(_THIS, const char *proc);
76 static int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
77 static int BE_GL_MakeCurrent(_THIS);
74 static void BE_GL_SwapBuffers(_THIS); 78 static void BE_GL_SwapBuffers(_THIS);
75 #endif 79 #endif
76 80
77 /* FB driver bootstrap functions */ 81 /* FB driver bootstrap functions */
78 82
106 return(0); 110 return(0);
107 } 111 }
108 memset(device->hidden, 0, (sizeof *device->hidden)); 112 memset(device->hidden, 0, (sizeof *device->hidden));
109 113
110 /* Set the function pointers */ 114 /* Set the function pointers */
115 /* Initialization/Query functions */
111 device->VideoInit = BE_VideoInit; 116 device->VideoInit = BE_VideoInit;
112 device->ListModes = BE_ListModes; 117 device->ListModes = BE_ListModes;
113 device->SetVideoMode = BE_SetVideoMode; 118 device->SetVideoMode = BE_SetVideoMode;
119 device->ToggleFullScreen = BE_ToggleFullScreen;
114 device->UpdateMouse = BE_UpdateMouse; 120 device->UpdateMouse = BE_UpdateMouse;
121 device->CreateYUVOverlay = BE_CreateYUVOverlay;
115 device->SetColors = BE_SetColors; 122 device->SetColors = BE_SetColors;
116 device->UpdateRects = NULL; 123 device->UpdateRects = NULL;
117 device->VideoQuit = BE_VideoQuit; 124 device->VideoQuit = BE_VideoQuit;
125 /* Hardware acceleration functions */
118 device->AllocHWSurface = BE_AllocHWSurface; 126 device->AllocHWSurface = BE_AllocHWSurface;
119 device->CheckHWBlit = NULL; 127 device->CheckHWBlit = NULL;
120 device->FillHWRect = NULL; 128 device->FillHWRect = NULL;
121 device->SetHWColorKey = NULL; 129 device->SetHWColorKey = NULL;
122 device->SetHWAlpha = NULL; 130 device->SetHWAlpha = NULL;
123 device->LockHWSurface = BE_LockHWSurface; 131 device->LockHWSurface = BE_LockHWSurface;
124 device->UnlockHWSurface = BE_UnlockHWSurface; 132 device->UnlockHWSurface = BE_UnlockHWSurface;
125 device->FlipHWSurface = NULL; 133 device->FlipHWSurface = NULL;
126 device->FreeHWSurface = BE_FreeHWSurface; 134 device->FreeHWSurface = BE_FreeHWSurface;
135 /* Gamma support */
127 #ifdef HAVE_OPENGL 136 #ifdef HAVE_OPENGL
137 /* OpenGL support */
138 device->GL_LoadLibrary = BE_GL_LoadLibrary;
139 device->GL_GetProcAddress = BE_GL_GetProcAddress;
140 device->GL_GetAttribute = BE_GL_GetAttribute;
141 device->GL_MakeCurrent = BE_GL_MakeCurrent;
128 device->GL_SwapBuffers = BE_GL_SwapBuffers; 142 device->GL_SwapBuffers = BE_GL_SwapBuffers;
129 #endif 143 #endif
144 /* Window manager functions */
145 device->SetCaption = BE_SetWMCaption;
130 device->SetIcon = NULL; 146 device->SetIcon = NULL;
131 device->SetCaption = BE_SetWMCaption; 147 device->IconifyWindow = BE_IconifyWindow;
132 device->GetWMInfo = NULL; 148 device->GrabInput = NULL;
149 device->GetWMInfo = BE_GetWMInfo;
150 /* Cursor manager functions */
133 device->FreeWMCursor = BE_FreeWMCursor; 151 device->FreeWMCursor = BE_FreeWMCursor;
134 device->CreateWMCursor = BE_CreateWMCursor; 152 device->CreateWMCursor = BE_CreateWMCursor;
135 device->ShowWMCursor = BE_ShowWMCursor; 153 device->ShowWMCursor = BE_ShowWMCursor;
136 device->WarpWMCursor = BE_WarpWMCursor; 154 device->WarpWMCursor = BE_WarpWMCursor;
155 device->MoveWMCursor = NULL;
156 device->CheckMouseMode = NULL;
157 /* Event manager functions */
137 device->InitOSKeymap = BE_InitOSKeymap; 158 device->InitOSKeymap = BE_InitOSKeymap;
138 device->PumpEvents = BE_PumpEvents; 159 device->PumpEvents = BE_PumpEvents;
139 160
140 device->free = BE_DeleteDevice; 161 device->free = BE_DeleteDevice;
141 device->ToggleFullScreen = BE_ToggleFullScreen;
142 device->CreateYUVOverlay = BE_CreateYUVOverlay;
143 162
144 /* Set the driver flags */ 163 /* Set the driver flags */
145 device->handles_any_size = 1; 164 device->handles_any_size = 1;
146 165
147 return device; 166 return device;
292 bounds.top = 0; bounds.left = 0; 311 bounds.top = 0; bounds.left = 0;
293 bounds.right = BEOS_HIDDEN_SIZE; 312 bounds.right = BEOS_HIDDEN_SIZE;
294 bounds.bottom = BEOS_HIDDEN_SIZE; 313 bounds.bottom = BEOS_HIDDEN_SIZE;
295 SDL_Win = new SDL_BWin(bounds); 314 SDL_Win = new SDL_BWin(bounds);
296 315
316 #ifdef HAVE_OPENGL
317 /* testgl application doesn't load library, just tries to load symbols */
318 /* is it correct? if so we have to load library here */
319 BE_GL_LoadLibrary(_this, NULL);
320 #endif
321
297 /* Create the clear cursor */ 322 /* Create the clear cursor */
298 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask, 323 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask,
299 BLANK_CWIDTH, BLANK_CHEIGHT, BLANK_CHOTX, BLANK_CHOTY); 324 BLANK_CWIDTH, BLANK_CHEIGHT, BLANK_CHOTX, BLANK_CHOTY);
300 325
301 /* Fill in some window manager capabilities */ 326 /* Fill in some window manager capabilities */
473 int width, int height, int bpp, Uint32 flags) 498 int width, int height, int bpp, Uint32 flags)
474 { 499 {
475 BScreen bscreen; 500 BScreen bscreen;
476 BBitmap *bbitmap; 501 BBitmap *bbitmap;
477 BRect bounds; 502 BRect bounds;
478 503 Uint32 gl_flags = 0;
479 /* Create the view for this window */ 504
480 if ( SDL_Win->CreateView(flags) < 0 ) { 505 /* Only RGB works on r5 currently */
506 gl_flags = BGL_RGB;
507 if (_this->gl_config.double_buffer)
508 gl_flags |= BGL_DOUBLE;
509 else
510 gl_flags |= BGL_SINGLE;
511 if (_this->gl_config.alpha_size > 0 || bpp == 32)
512 gl_flags |= BGL_ALPHA;
513 if (_this->gl_config.depth_size > 0)
514 gl_flags |= BGL_DEPTH;
515 if (_this->gl_config.stencil_size > 0)
516 gl_flags |= BGL_STENCIL;
517 if (_this->gl_config.accum_red_size > 0
518 || _this->gl_config.accum_green_size > 0
519 || _this->gl_config.accum_blue_size > 0
520 || _this->gl_config.accum_alpha_size > 0)
521 gl_flags |= BGL_ACCUM;
522
523 /* Create the view for this window, using found flags */
524 if ( SDL_Win->CreateView(flags, gl_flags) < 0 ) {
481 return(NULL); 525 return(NULL);
482 } 526 }
483 527
484 current->flags = 0; /* Clear flags */ 528 current->flags = 0; /* Clear flags */
485 current->w = width; 529 current->w = width;
500 544
501 if ( flags & SDL_OPENGL ) { 545 if ( flags & SDL_OPENGL ) {
502 current->flags |= SDL_OPENGL; 546 current->flags |= SDL_OPENGL;
503 current->pitch = 0; 547 current->pitch = 0;
504 current->pixels = NULL; 548 current->pixels = NULL;
505 _this->UpdateRects = NULL; 549 _this->UpdateRects = NULL;
506 } else { 550 } else {
507 /* Create the BBitmap framebuffer */ 551 /* Create the BBitmap framebuffer */
508 bounds.top = 0; bounds.left = 0; 552 bounds.top = 0; bounds.left = 0;
509 bounds.right = width-1; 553 bounds.right = width-1;
510 bounds.bottom = height-1; 554 bounds.bottom = height-1;
589 SDL_Win->EndDraw(); 633 SDL_Win->EndDraw();
590 } 634 }
591 } 635 }
592 636
593 #ifdef HAVE_OPENGL 637 #ifdef HAVE_OPENGL
638 /* Passing a NULL path means load pointers from the application */
639 int BE_GL_LoadLibrary(_THIS, const char *path)
640 {
641 if (path == NULL) {
642 if (_this->gl_config.dll_handle == NULL) {
643 image_info info;
644 int32 cookie = 0;
645 while (get_next_image_info(0,&cookie,&info) == B_OK) {
646 void *location = NULL;
647 if (get_image_symbol((image_id)cookie,"glBegin",B_SYMBOL_TYPE_ANY,&location) == B_OK) {
648 _this->gl_config.dll_handle = (void*)cookie;
649 _this->gl_config.driver_loaded = 1;
650 strncpy(_this->gl_config.driver_path, "libGL.so", sizeof(_this->gl_config.driver_path)-1);
651 }
652 }
653 }
654 } else {
655 /*
656 FIXME None of BeOS libGL.so implementations have exported functions
657 to load BGLView, which should be reloaded from new lib.
658 So for now just "load" linked libGL.so :(
659 */
660 if (_this->gl_config.dll_handle == NULL) {
661 return BE_GL_LoadLibrary(_this, NULL);
662 }
663
664 /* Unload old first */
665 /*if (_this->gl_config.dll_handle != NULL) {*/
666 /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */
667 /* image_info info;
668 if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) {
669 if (info.type != B_APP_IMAGE) {
670 unload_add_on((image_id)_this->gl_config.dll_handle);
671 }
672 }
673
674 }
675
676 if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
677 _this->gl_config.driver_loaded = 1;
678 strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path)-1);
679 }*/
680 }
681
682 if (_this->gl_config.dll_handle != NULL) {
683 return 0;
684 } else {
685 _this->gl_config.dll_handle = NULL;
686 _this->gl_config.driver_loaded = 0;
687 strcpy(_this->gl_config.driver_path, "");
688 return -1;
689 }
690 }
691
692 void* BE_GL_GetProcAddress(_THIS, const char *proc)
693 {
694 if (_this->gl_config.dll_handle != NULL) {
695 void *location = NULL;
696 status_t err;
697 if ((err = get_image_symbol((image_id)_this->gl_config.dll_handle, proc, B_SYMBOL_TYPE_ANY, &location)) == B_OK) {
698 return location;
699 } else {
700 SDL_SetError("Couldn't find OpenGL symbol");
701 return NULL;
702 }
703 } else {
704 SDL_SetError("OpenGL library not loaded");
705 return NULL;
706 }
707 }
708
709 int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
710 {
711 /*
712 FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
713 */
714 switch (attrib)
715 {
716 case SDL_GL_RED_SIZE:
717 glGetIntegerv(GL_RED_BITS, (GLint*)value);
718 break;
719 case SDL_GL_GREEN_SIZE:
720 glGetIntegerv(GL_GREEN_BITS, (GLint*)value);
721 break;
722 case SDL_GL_BLUE_SIZE:
723 glGetIntegerv(GL_BLUE_BITS, (GLint*)value);
724 break;
725 case SDL_GL_ALPHA_SIZE:
726 glGetIntegerv(GL_ALPHA_BITS, (GLint*)value);
727 break;
728 case SDL_GL_DOUBLEBUFFER:
729 glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean*)value);
730 break;
731 case SDL_GL_BUFFER_SIZE:
732 int v;
733 glGetIntegerv(GL_RED_BITS, (GLint*)&v);
734 *value = v;
735 glGetIntegerv(GL_GREEN_BITS, (GLint*)&v);
736 *value += v;
737 glGetIntegerv(GL_BLUE_BITS, (GLint*)&v);
738 *value += v;
739 glGetIntegerv(GL_ALPHA_BITS, (GLint*)&v);
740 *value += v;
741 break;
742 case SDL_GL_DEPTH_SIZE:
743 glGetIntegerv(GL_DEPTH_BITS, (GLint*)value); /* Mesa creates 16 only? r5 always 32 */
744 break;
745 case SDL_GL_STENCIL_SIZE:
746 glGetIntegerv(GL_STENCIL_BITS, (GLint*)value);
747 break;
748 case SDL_GL_ACCUM_RED_SIZE:
749 glGetIntegerv(GL_ACCUM_RED_BITS, (GLint*)value);
750 break;
751 case SDL_GL_ACCUM_GREEN_SIZE:
752 glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint*)value);
753 break;
754 case SDL_GL_ACCUM_BLUE_SIZE:
755 glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint*)value);
756 break;
757 case SDL_GL_ACCUM_ALPHA_SIZE:
758 glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint*)value);
759 break;
760 case SDL_GL_STEREO:
761 case SDL_GL_MULTISAMPLEBUFFERS:
762 case SDL_GL_MULTISAMPLESAMPLES:
763 default:
764 *value=0;
765 return(-1);
766 }
767 return 0;
768 }
769
770 int BE_GL_MakeCurrent(_THIS)
771 {
772 /* FIXME: should we glview->unlock and then glview->lock()? */
773 return 0;
774 }
775
594 void BE_GL_SwapBuffers(_THIS) 776 void BE_GL_SwapBuffers(_THIS)
595 { 777 {
596 SDL_Win->SwapBuffers(); 778 SDL_Win->SwapBuffers();
597 } 779 }
598 #endif 780 #endif
615 } 797 }
616 798
617 void BE_VideoQuit(_THIS) 799 void BE_VideoQuit(_THIS)
618 { 800 {
619 int i, j; 801 int i, j;
802
803 SDL_Win->Quit();
804 SDL_Win = NULL;
620 805
621 if ( SDL_BlankCursor != NULL ) { 806 if ( SDL_BlankCursor != NULL ) {
622 BE_FreeWMCursor(_this, SDL_BlankCursor); 807 BE_FreeWMCursor(_this, SDL_BlankCursor);
623 SDL_BlankCursor = NULL; 808 SDL_BlankCursor = NULL;
624 } 809 }
637 BScreen bscreen; 822 BScreen bscreen;
638 bscreen.SetMode(&saved_mode); 823 bscreen.SetMode(&saved_mode);
639 } 824 }
640 _this->screen->pixels = NULL; 825 _this->screen->pixels = NULL;
641 } 826 }
827
828 #ifdef HAVE_OPENGL
829 if (_this->gl_config.dll_handle != NULL)
830 unload_add_on((image_id)_this->gl_config.dll_handle);
831 #endif
832
642 SDL_QuitBeApp(); 833 SDL_QuitBeApp();
643 } 834 }
644 835
645 }; /* Extern C */ 836 }; /* Extern C */