diff --git a/README.QNX b/README.QNX index c6173ea7c..56c035a2d 100644 --- a/README.QNX +++ b/README.QNX @@ -7,10 +7,11 @@ new Photon3D runtime from http://developers.qnx.com. The versions of OS before 6.1.0 are not supported. Problems: -1. While creating OpenGL context artificially selected software - renderer mode (QSSL made acceleration only for Voodoo boards - in fullscreen mode, sorry but I don't have this board, if you - want acceleration - you may remove some line in source). +1. While creating OpenGL context software renderer mode is + artificially selected (QSSL made acceleration only for Voodoo + boards in fullscreen mode, sorry but I don't have this board, + if you want acceleration - you may remove some line in source + code). 2. Photon has some errors in detecting how much bits per pixel videomode has. 3. No shared libraries yet. We need manually set flag to @@ -31,7 +32,8 @@ Some building issues: --disable-shared \ --disable-video-opengl - In test directory also run ./configure script without x11 support, e.g.: + In test directory also run ./configure script without x11 +support, e.g.: ./configure --with-sdl-prefix=/usr/local \ --with-sdl-exec-prefix=/usr/local \ diff --git a/src/video/photon/SDL_ph_events.c b/src/video/photon/SDL_ph_events.c index 3375d8bd3..aec51a5e5 100644 --- a/src/video/photon/SDL_ph_events.c +++ b/src/video/photon/SDL_ph_events.c @@ -74,7 +74,7 @@ static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent) (peekevent->timestamp == event->timestamp) ) { repeated = 1; - //PhEventNext( peekevent, EVENT_SIZE ); + /* PhEventNext( peekevent, EVENT_SIZE ); */ } } } @@ -85,7 +85,7 @@ static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent) } break; - default: // no events pending + default: /* no events pending */ } return(repeated); } @@ -93,11 +93,12 @@ static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent) static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) { - PhPointerEvent_t *pointer = PhGetData( winEvent ); +/* PhPointerEvent_t *pointer = PhGetData( winEvent ); */ PhRect_t *rect = PhGetRects( winEvent ); int centre_x, centre_y; - int dx, dy, abs_x, abs_y; + int dx, dy; + short abs_x, abs_y; int posted; centre_x = SDL_VideoSurface->w / 2; @@ -155,177 +156,168 @@ static Uint8 ph2sdl_mousebutton( unsigned short button_state ) static int ph_DispatchEvent(_THIS) { - int posted; - PhRect_t* rect; - PhPointerEvent_t* pointerEvent; - PhKeyEvent_t* keyEvent; - PhWindowEvent_t* winEvent; - int i, buttons; - SDL_Rect sdlrects[50]; + int posted; + PhRect_t* rect; + PhPointerEvent_t* pointerEvent; + PhKeyEvent_t* keyEvent; + PhWindowEvent_t* winEvent; + int i, buttons; + SDL_Rect sdlrects[50]; - posted = 0; + posted = 0; - switch (event->type) { - case Ph_EV_BOUNDARY: + switch (event->type) + { + case Ph_EV_BOUNDARY: + { + if (event->subtype == Ph_EV_PTR_ENTER) + { + posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); + } + else if (event->subtype ==Ph_EV_PTR_LEAVE) + { + posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); + } + } + break; + + case Ph_EV_PTR_MOTION_BUTTON: + case Ph_EV_PTR_MOTION_NOBUTTON: + { + if (SDL_VideoSurface) + { + pointerEvent = PhGetData(event); + rect = PhGetRects(event); + + if (mouse_relative) + { + posted = ph_WarpedMotion(this, event); + } + else + { + posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y); + } + } + } + break; + + case Ph_EV_BUT_PRESS: + { + pointerEvent = PhGetData( event ); + buttons = ph2sdl_mousebutton( pointerEvent->buttons ); + if (buttons != 0) + { + posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0); + } + } + break; + + case Ph_EV_BUT_RELEASE: + { + pointerEvent = PhGetData(event); + buttons = ph2sdl_mousebutton(pointerEvent->buttons); + if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0) + { + posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); + } + else if(event->subtype == Ph_EV_RELEASE_PHANTOM) + { + /* If the mouse is outside the window, + * only a phantom release event is sent, so + * check if the window doesn't have mouse focus. + * Not perfect, maybe checking the mouse button + * state for Ph_EV_BOUNDARY events would be + * better. */ + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) { - if (event->subtype == Ph_EV_PTR_ENTER) - posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); - else if (event->subtype ==Ph_EV_PTR_LEAVE) - posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); - } - break; + posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); + } + } + } + break; - case Ph_EV_PTR_MOTION_BUTTON: - case Ph_EV_PTR_MOTION_NOBUTTON: - { - if ( SDL_VideoSurface ) { - pointerEvent = PhGetData( event ); - rect = PhGetRects( event ); - if( mouse_relative ) - { - posted = ph_WarpedMotion(this, event); - } - else - posted = SDL_PrivateMouseMotion(0, 0, - rect->ul.x, rect->ul.y); - } - } - break; + case Ph_EV_WM: + { + winEvent = PhGetData(event); - case Ph_EV_BUT_PRESS: - { - pointerEvent = PhGetData( event ); - buttons = ph2sdl_mousebutton( pointerEvent->buttons ); - if( buttons != 0 ) - posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons, - 0, 0 ); - } - break; + /* losing focus */ + if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) + { + set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); + posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); - case Ph_EV_BUT_RELEASE: - { - pointerEvent = PhGetData(event); - buttons = ph2sdl_mousebutton(pointerEvent->buttons); - if( event->subtype == Ph_EV_RELEASE_REAL && - buttons != 0 ) - { - posted = SDL_PrivateMouseButton( SDL_RELEASED, - buttons, 0, 0 ); - } - else if( event->subtype == Ph_EV_RELEASE_PHANTOM ) - { - /* If the mouse is outside the window, - * only a phantom release event is sent, so - * check if the window doesn't have mouse focus. - * Not perfect, maybe checking the mouse button - * state for Ph_EV_BOUNDARY events would be - * better. */ - if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 ) - { - posted = SDL_PrivateMouseButton( SDL_RELEASED, - buttons, 0, 0 ); - } - } - } - break; + /* Queue leaving fullscreen mode */ + switch_waiting = 0x01; + switch_time = SDL_GetTicks() + 200; + } + /* gaining focus */ + else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) + { + set_motion_sensitivity(this, -1); + posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); + } + /* request to quit */ + else if (winEvent->event_f==Ph_WM_CLOSE) + { + posted = SDL_PrivateQuit(); + } + /* request to resize */ + else if (winEvent->event_f==Ph_WM_RESIZE) + { + SDL_PrivateResize(winEvent->size.w, winEvent->size.h); + } + /* request to maximize */ + else if (winEvent->event_f==Ph_WM_MAX) + { + /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */ + } + } + break; - case Ph_EV_WM: - { - winEvent = PhGetData( event ); - - /* losing focus */ - if ((winEvent->event_f==Ph_WM_FOCUS)&& - (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) - { - set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); - posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); + /* window has been resized, moved or removed */ + case Ph_EV_EXPOSE: + { + if (SDL_VideoSurface) + { + rect = PhGetRects(event); - /* Queue leaving fullscreen mode */ - switch_waiting = 0x01; - switch_time = SDL_GetTicks() + 200; - } + for(i=0;inum_rects;i++) + { + sdlrects[i].x = rect[i].ul.x; + sdlrects[i].y = rect[i].ul.y; + sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; + sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; + } - /* gaining focus */ - else if ((winEvent->event_f==Ph_WM_FOCUS)&& - (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) - { - set_motion_sensitivity(this, -1); - posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); -#if 0 - /* Queue entry into fullscreen mode */ - switch_waiting = 0x01 | SDL_FULLSCREEN; - switch_time = SDL_GetTicks() + 1500; -#endif - } + this->UpdateRects(this, event->num_rects, sdlrects); + } + } + break; - /* request to quit */ - else if (winEvent->event_f==Ph_WM_CLOSE) - { - posted = SDL_PrivateQuit(); - } - else if (winEvent->event_f==Ph_WM_RESIZE) - { - PhDim_t *size; + case Ph_EV_KEY: + { + SDL_keysym keysym; - PtGetResource( window, Pt_ARG_DIM, &size, 0 ); - SDL_PrivateResize(size->w,size->h); - } - } - break; - - /* window has been resized, moved or removed */ - case Ph_EV_EXPOSE: - { - if (SDL_VideoSurface) - { - rect = PhGetRects( event ); + posted = 0; - //PgSetClipping(1, rect ); - for(i=0;inum_rects;i++) - { - sdlrects[i].x = rect[i].ul.x; - sdlrects[i].y = rect[i].ul.y; - sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; - sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; - } + keyEvent = PhGetData( event ); - this->UpdateRects(this, event->num_rects, sdlrects); + if (Pk_KF_Key_Down & keyEvent->key_flags) + { + posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym)); + } + else /* must be key release */ + { + /* Ignore repeated key release events */ + /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */ - } - } - break; + posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym)); + } + } + break; + } - case Ph_EV_KEY: - { - - SDL_keysym keysym; - - posted = 0; - - keyEvent = PhGetData( event ); - - if (Pk_KF_Key_Down & keyEvent->key_flags) - { - - posted = SDL_PrivateKeyboard(SDL_PRESSED, - ph_TranslateKey( keyEvent, &keysym)); - } - else /* must be key release */ - { - /* Ignore repeated key release events */ - /*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/ - - posted = SDL_PrivateKeyboard(SDL_RELEASED, - ph_TranslateKey( keyEvent, &keysym)); - /*}*/ - } - } - break; - } - - - - return(posted); + return(posted); } /* perform a blocking read if no events available */ diff --git a/src/video/photon/SDL_ph_video.c b/src/video/photon/SDL_ph_video.c index db9e708a5..76c89f118 100644 --- a/src/video/photon/SDL_ph_video.c +++ b/src/video/photon/SDL_ph_video.c @@ -175,15 +175,14 @@ static void ph_DeleteDevice(SDL_VideoDevice *device) static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) { - int i; - unsigned long *tempptr; - int rtnval; PgVideoModeInfo_t my_mode_info; PgHWCaps_t my_hwcaps; window=NULL; - oglctx=NULL; desktoppal=SDLPH_PAL_NONE; +#ifdef HAVE_OPENGL + oglctx=NULL; +#endif /* HAVE_OPENGL */ captionflag=0; old_video_mode=-1; @@ -218,31 +217,13 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) vformat->BitsPerPixel = my_mode_info.bits_per_pixel; vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; desktopbpp = my_mode_info.bits_per_pixel; - - /* return a palette if we are in 256 color mode */ - if (vformat->BitsPerPixel == 8) + + /* save current palette */ + if (desktopbpp==8) { - vformat->palette = malloc(sizeof(SDL_Palette)); - memset(vformat->palette, 0, sizeof(SDL_Palette)); - vformat->palette->ncolors = 256; - vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); - - /* fill the palette */ - rtnval = PgGetPalette(ph_palette); - if (rtnval < 0) - { - fprintf(stderr, "ph_VideoInit: PgGetPalette failed\n"); - } - - tempptr = (unsigned long *)vformat->palette->colors; - - for(i=0;i<256; i++) - { - *tempptr = (((unsigned long)ph_palette[i]) << 8); - tempptr++; - } + PgGetPalette(ph_palette); } - + currently_fullscreen = 0; this->info.wm_available = 1; @@ -268,6 +249,8 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); + current->flags = flags; + /* create window if no OpenGL support selected */ if ((flags & SDL_OPENGL)!=SDL_OPENGL) { @@ -276,6 +259,34 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0); PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED); + /* enable window minimizing */ + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE); + + /* remove border and caption if no frame flag selected */ + if ((flags & SDL_NOFRAME) == SDL_NOFRAME) + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + else + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + + /* if window is not resizable then remove resize handles and maximize button */ + if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + } + else + { + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX); + /* it is need to be Pt_FALSE to allow the application to process the resize callback */ + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX); + PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX); + } + if (window!=NULL) { PtUnrealizeWidget(window); @@ -283,7 +294,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, window=NULL; } - window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); + window=PtCreateWidget(PtWindow, NULL, pargc, arg); PtRealizeWidget(window); PtFlush(); @@ -295,7 +306,6 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, /* ph_SetupOpenGLContext creates also window as need */ if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0) { - current->flags=flags; /* setup OGL update function ... ugly method */ ph_ResizeImage(this, current, flags); } @@ -363,15 +373,13 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, } /* end fullscreen flag */ else { - if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ + /* Use offscreen memory iff SDL_HWSURFACE flag is set */ + if (flags & SDL_HWSURFACE) { - /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */ - current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ - } - else /* must be SDL_SWSURFACE */ - { - current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */ + /* no stretch blit in offscreen context */ + current->flags = (flags & (~SDL_RESIZABLE)); } + /* using palette emulation code in window mode */ if (bpp==8) { @@ -425,6 +433,9 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, ph_SetCaption(this, this->wm_title, NULL); } + /* finish window drawing */ + PtFlush(); + SDL_Unlock_EventThread(); /* We're done! */ @@ -433,7 +444,9 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, static void ph_VideoQuit(_THIS) { +#ifdef HAVE_OPENGL PhRegion_t region_info; +#endif /* HAVE_OPENGL */ ph_DestroyImage(this, SDL_VideoSurface); @@ -443,7 +456,7 @@ static void ph_VideoQuit(_THIS) } #ifdef HAVE_OPENGL - /* prevent double SEGFAULT with parachute mode */ + /* prevent double SEGFAULT during parachute mode */ if (this->screen) { if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && @@ -518,14 +531,14 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { /* window mode must use soft palette */ - PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); + PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0); /* image needs to be redrawed, very slow method */ PgDrawPhImage(&point, SDL_Image, 0); } else { /* fullscreen mode must use hardware palette */ - PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); + PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); } } else @@ -586,9 +599,10 @@ int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) { oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); } + if (oglctx==NULL) { - fprintf(stderr,"error: cannot create OpenGL context.\n"); + fprintf(stderr,"ph_SetupOpenGLContext: cannot create OpenGL context.\n"); return (-1); } @@ -608,10 +622,26 @@ int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) pos.y=0; PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0); - PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH); PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS); PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0); } + else + { + /* remove border and caption if no frame flag selected */ + if ((flags & SDL_NOFRAME) == SDL_NOFRAME) + { + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER); + } + else + { + /* if window is not resizable then remove resize handles */ + if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE) + { + PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE); + } + } + } if (window!=NULL) { @@ -620,7 +650,7 @@ int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) window=NULL; } - window=PtCreateWidget(PtWindow, NULL, pargc-1, args); + window=PtCreateWidget(PtWindow, NULL, pargc, args); PtRealizeWidget(window); /* disable mouse for fullscreen */ diff --git a/test/testgl.c b/test/testgl.c index d046e22c8..cedd43220 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -393,7 +393,7 @@ void DrawLogoBlit(void) } int RunGLTest( int argc, char* argv[], - int logo, int slowly, int bpp, float gamma ) + int logo, int slowly, int bpp, float gamma, int noframe ) { int i; int rgb_size[3]; @@ -447,6 +447,10 @@ int RunGLTest( int argc, char* argv[], } } + if (noframe) { + video_flags |= SDL_NOFRAME; + } + /* Initialize the display */ switch (bpp) { case 8: @@ -686,6 +690,7 @@ int main(int argc, char *argv[]) int bpp = 0; int slowly; float gamma = 0.0; + int noframe = 0; logo = 0; slowly = 0; @@ -711,15 +716,18 @@ int main(int argc, char *argv[]) if ( strcmp(argv[i], "-gamma") == 0 ) { gamma = (float)atof(argv[++i]); } + if ( strcmp(argv[i], "-noframe") == 0 ) { + noframe = 1; + } if ( strncmp(argv[i], "-h", 2) == 0 ) { printf( -"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n", +"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe]\n", argv[0]); exit(0); } } for ( i=0; i