Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_video.c @ 701:aaf3b8af6616
Date: Sat, 30 Aug 2003 16:28:10 +0300
From: "Mike Gorchak"
Subject: Re: SDL 1.2.6
- minor changes about shared library building under QNX6 into README.QNX
- added forgotten libSDLmain.a into distribution, SDL.qpg.in
- added header guards to the all headers.
- fixed fullscreen double buffered mode.
- fixed Photon crashes after/during using fullscreen OpenGL modes.
- added GL_MakeCurrent function.
- added SDL_VIDEOEXPOSE event, when OpenGL window have been resized
- added more HAVE_OPENGL checks to avoid dead code compilation without using OpenGL
- finished code reorganization (began into previous patches).
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 30 Aug 2003 17:07:59 +0000 |
parents | 04dd6c6d7c30 |
children | cbc0f7fabd1c |
comparison
equal
deleted
inserted
replaced
700:c35edafc84d1 | 701:aaf3b8af6616 |
---|---|
48 #include "SDL_ph_mouse_c.h" | 48 #include "SDL_ph_mouse_c.h" |
49 #include "SDL_ph_wm_c.h" | 49 #include "SDL_ph_wm_c.h" |
50 #include "SDL_phyuv_c.h" | 50 #include "SDL_phyuv_c.h" |
51 #include "blank_cursor.h" | 51 #include "blank_cursor.h" |
52 | 52 |
53 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat); | 53 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat); |
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | 54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); |
55 int width, int height, int bpp, Uint32 flags); | 55 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); |
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
57 static void ph_VideoQuit(_THIS); | 56 static void ph_VideoQuit(_THIS); |
58 static void ph_DeleteDevice(SDL_VideoDevice *device); | 57 static void ph_DeleteDevice(SDL_VideoDevice *device); |
59 static void ph_UpdateMouse(_THIS); | |
60 | 58 |
61 #ifdef HAVE_OPENGL | 59 #ifdef HAVE_OPENGL |
62 static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags); | 60 static void ph_GL_SwapBuffers(_THIS); |
63 static void ph_GL_SwapBuffers(_THIS); | 61 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); |
64 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); | 62 static int ph_GL_LoadLibrary(_THIS, const char* path); |
65 static int ph_GL_LoadLibrary(_THIS, const char* path); | |
66 static void* ph_GL_GetProcAddress(_THIS, const char* proc); | 63 static void* ph_GL_GetProcAddress(_THIS, const char* proc); |
67 | 64 static int ph_GL_MakeCurrent(_THIS); |
68 #endif /* HAVE_OPENGL */ | 65 #endif /* HAVE_OPENGL */ |
69 | 66 |
70 static int ph_Available(void) | 67 static int ph_Available(void) |
71 { | 68 { |
72 int phstat=-1; | 69 int phstat=-1; |
130 device->GetWMInfo = ph_GetWMInfo; | 127 device->GetWMInfo = ph_GetWMInfo; |
131 device->FreeWMCursor = ph_FreeWMCursor; | 128 device->FreeWMCursor = ph_FreeWMCursor; |
132 device->CreateWMCursor = ph_CreateWMCursor; | 129 device->CreateWMCursor = ph_CreateWMCursor; |
133 device->ShowWMCursor = ph_ShowWMCursor; | 130 device->ShowWMCursor = ph_ShowWMCursor; |
134 device->WarpWMCursor = ph_WarpWMCursor; | 131 device->WarpWMCursor = ph_WarpWMCursor; |
132 device->MoveWMCursor = NULL; | |
135 device->CheckMouseMode = ph_CheckMouseMode; | 133 device->CheckMouseMode = ph_CheckMouseMode; |
136 device->InitOSKeymap = ph_InitOSKeymap; | 134 device->InitOSKeymap = ph_InitOSKeymap; |
137 device->PumpEvents = ph_PumpEvents; | 135 device->PumpEvents = ph_PumpEvents; |
138 | 136 |
139 /* OpenGL support. */ | 137 /* OpenGL support. */ |
140 device->GL_MakeCurrent = NULL; | |
141 #ifdef HAVE_OPENGL | 138 #ifdef HAVE_OPENGL |
139 device->GL_MakeCurrent = ph_GL_MakeCurrent; | |
142 device->GL_SwapBuffers = ph_GL_SwapBuffers; | 140 device->GL_SwapBuffers = ph_GL_SwapBuffers; |
143 device->GL_GetAttribute = ph_GL_GetAttribute; | 141 device->GL_GetAttribute = ph_GL_GetAttribute; |
144 device->GL_LoadLibrary = ph_GL_LoadLibrary; | 142 device->GL_LoadLibrary = ph_GL_LoadLibrary; |
145 device->GL_GetProcAddress = ph_GL_GetProcAddress; | 143 device->GL_GetProcAddress = ph_GL_GetProcAddress; |
146 #else | 144 #else |
145 device->GL_MakeCurrent = NULL; | |
147 device->GL_SwapBuffers = NULL; | 146 device->GL_SwapBuffers = NULL; |
148 device->GL_GetAttribute = NULL; | 147 device->GL_GetAttribute = NULL; |
149 device->GL_LoadLibrary = NULL; | 148 device->GL_LoadLibrary = NULL; |
150 device->GL_GetProcAddress = NULL; | 149 device->GL_GetProcAddress = NULL; |
151 #endif /* HAVE_OPENGL */ | 150 #endif /* HAVE_OPENGL */ |
311 PgHWCaps_t my_hwcaps; | 310 PgHWCaps_t my_hwcaps; |
312 int i; | 311 int i; |
313 | 312 |
314 window=NULL; | 313 window=NULL; |
315 desktoppal=SDLPH_PAL_NONE; | 314 desktoppal=SDLPH_PAL_NONE; |
315 | |
316 #ifdef HAVE_OPENGL | 316 #ifdef HAVE_OPENGL |
317 oglctx=NULL; | 317 oglctx=NULL; |
318 oglflags=0; | |
319 oglbpp=0; | |
318 #endif /* HAVE_OPENGL */ | 320 #endif /* HAVE_OPENGL */ |
319 | 321 |
320 old_video_mode=-1; | 322 old_video_mode=-1; |
321 old_refresh_rate=-1; | 323 old_refresh_rate=-1; |
322 | 324 |
426 SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); | 428 SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); |
427 return NULL; | 429 return NULL; |
428 } | 430 } |
429 | 431 |
430 #ifdef HAVE_OPENGL | 432 #ifdef HAVE_OPENGL |
431 if (current->flags & SDL_OPENGL) | 433 if ((current->flags & SDL_OPENGL)==SDL_OPENGL) |
432 { | 434 { |
433 /* ph_SetupOpenGLContext creates also window as need */ | |
434 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) | |
435 { | |
436 ph_SetupUpdateFunction(this, current, flags); | |
437 } | |
438 else | |
439 { | |
440 /* if context creation fail, report no OpenGL to high level */ | |
441 current->flags &= ~SDL_OPENGL; | |
442 return NULL; | |
443 } | |
444 #else | 435 #else |
445 if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */ | 436 if ((current->flags & SDL_OPENGL)==SDL_OPENGL) /* if no built-in OpenGL support */ |
446 { | 437 { |
447 SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); | 438 SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); |
448 current->flags &= ~SDL_OPENGL; | 439 current->flags &= ~SDL_OPENGL; |
449 return NULL; | 440 return NULL; |
450 #endif /* HAVE_OPENGL */ | 441 #endif /* HAVE_OPENGL */ |
526 return (current); | 517 return (current); |
527 } | 518 } |
528 | 519 |
529 static void ph_VideoQuit(_THIS) | 520 static void ph_VideoQuit(_THIS) |
530 { | 521 { |
531 #ifdef HAVE_OPENGL | |
532 PhRegion_t region_info; | |
533 #endif /* HAVE_OPENGL */ | |
534 | |
535 /* restore palette */ | 522 /* restore palette */ |
536 if (desktopbpp==8) | 523 if (desktopbpp==8) |
537 { | 524 { |
538 PgSetPalette(syspalph, 0, -1, 0, 0, 0); | 525 PgSetPalette(syspalph, 0, -1, 0, 0, 0); |
539 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); | 526 PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); |
540 PgFlush(); | 527 PgFlush(); |
541 } | 528 } |
542 | 529 |
543 ph_DestroyImage(this, SDL_VideoSurface); | 530 ph_DestroyImage(this, SDL_VideoSurface); |
544 | 531 |
545 #ifdef HAVE_OPENGL | |
546 /* prevent double SEGFAULT during parachute mode */ | |
547 if (this->screen) | |
548 { | |
549 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && | |
550 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) | |
551 { | |
552 region_info.cursor_type=Ph_CURSOR_POINTER; | |
553 region_info.rid=PtWidgetRid(window); | |
554 PhRegionChange(Ph_REGION_CURSOR, 0, ®ion_info, NULL, NULL); | |
555 } | |
556 } | |
557 | |
558 PtFlush(); | |
559 #endif /* HAVE_OPENGL */ | |
560 | |
561 if (window) | 532 if (window) |
562 { | 533 { |
563 PtUnrealizeWidget(window); | 534 PtUnrealizeWidget(window); |
564 PtDestroyWidget(window); | 535 PtDestroyWidget(window); |
565 window=NULL; | 536 window=NULL; |
566 } | 537 } |
567 | |
568 #ifdef HAVE_OPENGL | |
569 if (oglctx) | |
570 { | |
571 PhDCSetCurrent(NULL); | |
572 PhDCRelease(oglctx); | |
573 oglctx=NULL; | |
574 } | |
575 #endif /* HAVE_OPENGL */ | |
576 | 538 |
577 if (event!=NULL) | 539 if (event!=NULL) |
578 { | 540 { |
579 free(event); | 541 free(event); |
580 event=NULL; | 542 event=NULL; |
636 return 1; | 598 return 1; |
637 } | 599 } |
638 | 600 |
639 #ifdef HAVE_OPENGL | 601 #ifdef HAVE_OPENGL |
640 | 602 |
641 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) | 603 static void ph_GL_SwapBuffers(_THIS) |
642 { | |
643 PhDim_t dim; | |
644 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; | |
645 int OGLargc; | |
646 | |
647 dim.w=width; | |
648 dim.h=height; | |
649 | |
650 if (oglctx!=NULL) | |
651 { | |
652 PhDCSetCurrent(NULL); | |
653 PhDCRelease(oglctx); | |
654 oglctx=NULL; | |
655 } | |
656 | |
657 OGLargc=0; | |
658 if (this->gl_config.depth_size) | |
659 { | |
660 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS; | |
661 OGLAttrib[OGLargc++]=this->gl_config.depth_size; | |
662 } | |
663 if (this->gl_config.stencil_size) | |
664 { | |
665 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS; | |
666 OGLAttrib[OGLargc++]=this->gl_config.stencil_size; | |
667 } | |
668 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW; | |
669 if (flags & SDL_FULLSCREEN) | |
670 { | |
671 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN; | |
672 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT; | |
673 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST; | |
674 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER; | |
675 } | |
676 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE; | |
677 | |
678 if (this->gl_config.double_buffer) | |
679 { | |
680 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); | |
681 } | |
682 else | |
683 { | |
684 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); | |
685 } | |
686 | |
687 if (oglctx==NULL) | |
688 { | |
689 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); | |
690 return (-1); | |
691 } | |
692 | |
693 PhDCSetCurrent(oglctx); | |
694 | |
695 /* disable mouse for fullscreen */ | |
696 if (flags & SDL_FULLSCREEN) | |
697 { | |
698 PhRegion_t region_info; | |
699 | |
700 region_info.cursor_type=Ph_CURSOR_NONE; | |
701 region_info.rid=PtWidgetRid(window); | |
702 PhRegionChange(Ph_REGION_CURSOR, 0, ®ion_info, NULL, NULL); | |
703 } | |
704 | |
705 PtFlush(); | |
706 | |
707 return 0; | |
708 } | |
709 | |
710 void ph_GL_SwapBuffers(_THIS) | |
711 { | 604 { |
712 PgSetRegion(PtWidgetRid(window)); | 605 PgSetRegion(PtWidgetRid(window)); |
713 PdOpenGLContextSwapBuffers(oglctx); | 606 PdOpenGLContextSwapBuffers(oglctx); |
714 } | 607 } |
715 | 608 |
716 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | 609 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) |
717 { | 610 { |
718 switch (attrib) | 611 switch (attrib) |
719 { | 612 { |
720 case SDL_GL_DOUBLEBUFFER: | 613 case SDL_GL_DOUBLEBUFFER: |
721 *value=this->gl_config.double_buffer; | 614 *value=this->gl_config.double_buffer; |
731 return(-1); | 624 return(-1); |
732 } | 625 } |
733 return 0; | 626 return 0; |
734 } | 627 } |
735 | 628 |
736 int ph_GL_LoadLibrary(_THIS, const char* path) | 629 static int ph_GL_LoadLibrary(_THIS, const char* path) |
737 { | 630 { |
738 /* if code compiled with HAVE_OPENGL, the library already linked */ | 631 /* if code compiled with HAVE_OPENGL, that mean that library already linked */ |
739 this->gl_config.driver_loaded = 1; | 632 this->gl_config.driver_loaded = 1; |
740 | 633 |
741 return 0; | 634 return 0; |
742 } | 635 } |
743 | 636 |
744 void* ph_GL_GetProcAddress(_THIS, const char* proc) | 637 static void* ph_GL_GetProcAddress(_THIS, const char* proc) |
745 { | 638 { |
746 return NULL; | 639 return NULL; |
747 } | 640 } |
748 | 641 |
642 static int ph_GL_MakeCurrent(_THIS) | |
643 { | |
644 PgSetRegion(PtWidgetRid(window)); | |
645 | |
646 if (oglctx!=NULL) | |
647 { | |
648 PhDCSetCurrent(oglctx); | |
649 } | |
650 | |
651 return 0; | |
652 } | |
653 | |
749 #endif /* HAVE_OPENGL */ | 654 #endif /* HAVE_OPENGL */ |
750 | |
751 static void ph_UpdateMouse(_THIS) | |
752 { | |
753 PhCursorInfo_t phcursor; | |
754 short abs_x; | |
755 short abs_y; | |
756 | |
757 /* Lock the event thread, in multi-threading environments */ | |
758 SDL_Lock_EventThread(); | |
759 | |
760 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */ | |
761 PtGetAbsPosition(window, &abs_x, &abs_y); | |
762 PhQueryCursor(PhInputGroup(NULL), &phcursor); | |
763 if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) && | |
764 ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h))) | |
765 { | |
766 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
767 SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y); | |
768 } | |
769 else | |
770 { | |
771 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
772 } | |
773 | |
774 /* Unlock the event thread, in multi-threading environments */ | |
775 SDL_Unlock_EventThread(); | |
776 } |