X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fblackberry%2Ffg_window_blackberry.c;h=86668af1d865911a95ebaf44d3d24635acbb7355;hb=421588fbbc5a989c5722a0eae212917cb86e8f26;hp=08f66432649d7f472ecf1ed48b6590b3afa78ee4;hpb=1182304c390146ff4663bdfb410cf8cf9a4c600d;p=freeglut diff --git a/src/blackberry/fg_window_blackberry.c b/src/blackberry/fg_window_blackberry.c index 08f6643..86668af 100644 --- a/src/blackberry/fg_window_blackberry.c +++ b/src/blackberry/fg_window_blackberry.c @@ -31,8 +31,7 @@ #include #include "fg_internal.h" #include "egl/fg_window_egl.h" -#include -#include +#include /* * Opens a window. Requires a SFG_Window object created and attached @@ -43,83 +42,184 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ) { - /* TODO: only one full-screen window possible? */ - if (fgDisplay.pDisplay.single_native_window != NULL) { - fgWarning("You can't have more than one window on BlackBerry"); - return; - } - window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment - - /* Create window */ - if (screen_create_context(&window->Window.pContext.screenContext, 0)) { - fgError("Could not create screen context"); - return; - } - screen_window_t sWindow; - if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) { - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not create window"); - return; - } - fgDisplay.pDisplay.single_native_window = sWindow; - - /* Set window properties */ - int screenFormat = SCREEN_FORMAT_RGBA8888; -#ifdef GL_ES_VERSION_2_0 - int screenUsage = SCREEN_USAGE_OPENGL_ES2; -#elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 - int screenUsage = SCREEN_USAGE_OPENGL_ES1; + /* TODO: only one full-screen window possible? */ + if (fgDisplay.pDisplay.single_native_window != NULL) { + fgWarning("You can't have more than one window on BlackBerry"); + return; + } + + /* Create window */ + screen_window_t sWindow; + if (screen_create_window(&sWindow, fgDisplay.pDisplay.screenContext)) { + fgError("Could not create window"); + return; + } + fgDisplay.pDisplay.single_native_window = sWindow; + + /* Choose config and screen format */ + fghChooseConfig(&window->Window.pContext.egl.Config); + int screenFormat = SCREEN_FORMAT_RGBA8888; //Only SCREEN_FORMAT_RGBA8888 and SCREEN_FORMAT_RGB565 are supported. See fg_window_egl for more info + int configAttri; +#define EGL_QUERY_COMP(att, comp) (eglGetConfigAttrib(fgDisplay.pDisplay.egl.Display, window->Window.pContext.egl.Config, att, &configAttri) == GL_TRUE && (configAttri comp)) + if (EGL_QUERY_COMP(EGL_ALPHA_SIZE, <= 0) && EGL_QUERY_COMP(EGL_RED_SIZE, <= 5) && + EGL_QUERY_COMP(EGL_GREEN_SIZE, <= 6) && EGL_QUERY_COMP(EGL_BLUE_SIZE, <= 5)) { + screenFormat = SCREEN_FORMAT_RGB565; + } +#undef EGL_QUERY_COMP + + /* Set window properties */ + int orientation = atoi(getenv("ORIENTATION")); + int screenUsage = SCREEN_USAGE_ROTATION; +#ifdef SCREEN_USAGE_OPENGL_ES3 + if (fgState.MajorVersion >= 3) { + screenUsage |= SCREEN_USAGE_OPENGL_ES3; + } else #endif -#ifndef __X86__ - screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display + if (fgState.MajorVersion >= 2) { + screenUsage |= SCREEN_USAGE_OPENGL_ES2; + } else { + screenUsage |= SCREEN_USAGE_OPENGL_ES1; + } +#if !defined(__X86__) && !defined(__PLAYBOOK__) + screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display #endif - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window format"); - return; - } - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window usage"); - return; - } - - /* Could set size based on what is specified for window. Work on another time - int size[2]; - size[0] = w; - size[1] = h; - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window buffer size"); - return; - }*/ - - /* Create window buffers */ - if (screen_create_window_buffers(sWindow, 2)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not create window buffers"); - return; - } - - /* Request window events */ - screen_request_events(window->Window.pContext.screenContext); - - /* Save window */ - window->Window.Handle = fgDisplay.pDisplay.single_native_window; - window->State.WorkMask |= GLUT_INIT_WORK; - - /* Create context */ - fghChooseConfig(&window->Window.pContext.egl.Config); - window->Window.Context = fghCreateNewContextEGL(window); - - /* Create EGL window */ - fghPlatformOpenWindowEGL(window); - - window->State.Visible = GL_TRUE; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { + screen_destroy_window(sWindow); + fgError("Could not set window format"); + return; + } + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { + screen_destroy_window(sWindow); + fgError("Could not set window usage"); + return; + } + + int value[2]; + /* Uncomment when multiple windows are supported + if(positionUse) { + value[0] = x; + value[1] = y; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_POSITION, value)) { + screen_destroy_window(sWindow); + fgError("Could not set window position"); + return; + } + }*/ + + if(sizeUse) { + /* Uncomment when multiple windows are supported + value[0] = w; + value[1] = h; + */ + //TEMP until ^^ is uncommented + if (screen_get_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + screen_destroy_window(sWindow); + fgError("Could not get window mode"); + return; + } + } else { + /* From PlatformBlackBerry in GamePlay3d */ + screen_display_t display; + if (screen_get_window_property_pv(sWindow, SCREEN_PROPERTY_DISPLAY, (void**)&display)) { + screen_destroy_window(sWindow); + fgError("Could not get window display"); + return; + } + + screen_display_mode_t displayMode; + if (screen_get_display_property_pv(display, SCREEN_PROPERTY_MODE, (void**)&displayMode)) { + screen_destroy_window(sWindow); + fgError("Could not get display mode"); + return; + } + + if (screen_get_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + screen_destroy_window(sWindow); + fgError("Could not get window mode"); + return; + } + + /* Adjust buffer sizes based on rotation */ + if ((orientation == 0) || (orientation == 180)) + { + if (((displayMode.width > displayMode.height) && (value[0] < value[1])) || + ((displayMode.width < displayMode.height) && (value[0] > value[1]))) + { + int tmp = value[1]; + value[1] = value[0]; + value[0] = tmp; + } + } + else if ((orientation == 90) || (orientation == 270)) + { + if (((displayMode.width > displayMode.height) && (value[0] > value[1])) || + ((displayMode.width < displayMode.height) && (value[0] < value[1]))) + { + int tmp = value[1]; + value[1] = value[0]; + value[0] = tmp; + } + } + else + { + screen_destroy_window(sWindow); + fgError("Unexpected rotation angle"); + return; + } + } + + /* Set rotation if usage allows it */ + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_ROTATION, &orientation)) { + screen_destroy_window(sWindow); + fgError("Could not set window rotation"); + return; + } + window->State.pWState.originalRotation = orientation; + + /* Set buffer sizes */ + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + screen_destroy_window(sWindow); + fgError("Could not set window buffer size"); + return; + } + + /* Create window buffers */ + if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { + screen_destroy_window(sWindow); + fgError("Could not create window buffers"); + return; + } + + /* Save window and set state */ + window->Window.Handle = sWindow; + window->State.WorkMask |= GLUT_INIT_WORK; + window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now + + /* Create context */ + window->Window.Context = EGL_NO_CONTEXT; + if( fgState.UseCurrentContext == GL_TRUE ) + window->Window.Context = eglGetCurrentContext(); + if( window->Window.Context == EGL_NO_CONTEXT ) + window->Window.Context = fghCreateNewContextEGL(window); + + /* Create EGL window */ + fghPlatformOpenWindowEGL(window); + + window->State.Visible = GL_TRUE; +} + +void fgPlatformFlushCommands() +{ + if(screen_flush_context(fgDisplay.pDisplay.screenContext, 0)) { + fgWarning("Could not flush screen context"); + } +} + +void fgPlatformRotateWindow(SFG_Window* window, int rotation) +{ + if(screen_set_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_ROTATION, &rotation)) { + fgWarning("Could not set window rotation"); + } } /* @@ -127,7 +227,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, */ void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ) { - fprintf(stderr, "fgPlatformReshapeWindow: STUB\n"); + fprintf(stderr, "fgPlatformReshapeWindow: STUB\n"); } /* @@ -135,13 +235,9 @@ void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ) */ void fgPlatformCloseWindow( SFG_Window* window ) { - fghPlatformCloseWindowEGL(window); + fghPlatformCloseWindowEGL(window); - screen_stop_events(window->Window.pContext.screenContext); - - screen_destroy_window((screen_window_t)window->Window.Handle); - - screen_destroy_context(window->Window.pContext.screenContext); + screen_destroy_window((screen_window_t)window->Window.Handle); } /* @@ -149,7 +245,7 @@ void fgPlatformCloseWindow( SFG_Window* window ) */ void fgPlatformShowWindow( void ) { - fprintf(stderr, "fgPlatformShowWindow: STUB\n"); + fprintf(stderr, "fgPlatformShowWindow: STUB\n"); } /* @@ -157,7 +253,7 @@ void fgPlatformShowWindow( void ) */ void fgPlatformHideWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformHideWindow: STUB\n"); + fprintf(stderr, "fgPlatformHideWindow: STUB\n"); } /* @@ -165,7 +261,20 @@ void fgPlatformHideWindow( SFG_Window *window ) */ void fgPlatformIconifyWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); +#ifndef __PLAYBOOK__ + pps_encoder_t encoder; + + pps_encoder_initialize(&encoder, false); + pps_encoder_add_string(&encoder, "msg", "minimizeWindow"); + + if (navigator_raw_write(pps_encoder_buffer(&encoder), pps_encoder_length(&encoder)) != BPS_SUCCESS) { + fgWarning("Could not iconify window on BlackBerry"); + } + + pps_encoder_cleanup(&encoder); +#else + fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); +#endif } /* @@ -173,7 +282,7 @@ void fgPlatformIconifyWindow( SFG_Window *window ) */ void fgPlatformGlutSetWindowTitle( const char* title ) { - fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n"); + fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n"); } /* @@ -181,14 +290,16 @@ void fgPlatformGlutSetWindowTitle( const char* title ) */ void fgPlatformGlutSetIconTitle( const char* title ) { - fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");} + //XXX Possibly a window cover label? + fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n"); +} /* * Change the specified window's position */ void fgPlatformPositionWindow( SFG_Window *window, int x, int y ) { - fprintf(stderr, "fgPlatformPositionWindow: STUB\n"); + fprintf(stderr, "fgPlatformPositionWindow: STUB\n"); } /* @@ -196,7 +307,7 @@ void fgPlatformPositionWindow( SFG_Window *window, int x, int y ) */ void fgPlatformPushWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformPushWindow: STUB\n"); + fprintf(stderr, "fgPlatformPushWindow: STUB\n"); } /* @@ -204,7 +315,7 @@ void fgPlatformPushWindow( SFG_Window *window ) */ void fgPlatformPopWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformPopWindow: STUB\n"); + fprintf(stderr, "fgPlatformPopWindow: STUB\n"); } /* @@ -212,5 +323,5 @@ void fgPlatformPopWindow( SFG_Window *window ) */ void fgPlatformFullScreenToggle( SFG_Window *win ) { - fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n"); + fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n"); }