From cc2a530d408fb9781516aeee18523541fea11165 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Fri, 24 Jan 2014 10:34:49 +0000 Subject: [PATCH] Info logging only shows in debug compilation Added support for UseCurrentContext flag Updated fghPlatformCloseWindowEGL for performance so that eglMakeCurrent isn't invoked unless it's the current window and that the EGL context isn't destroyed unless no other windows uses git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1673 7f0cb862-5218-0410-a997-914c9d46530a --- src/blackberry/fg_main_blackberry.c | 7 ++++++- src/blackberry/fg_window_blackberry.c | 6 +++++- src/egl/fg_window_egl.c | 35 +++++++++++++++++++++++++-------- src/fg_init.c | 14 ++++++------- src/fg_window.c | 10 +++++----- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/blackberry/fg_main_blackberry.c b/src/blackberry/fg_main_blackberry.c index 20c3d1b..89474d0 100644 --- a/src/blackberry/fg_main_blackberry.c +++ b/src/blackberry/fg_main_blackberry.c @@ -32,7 +32,11 @@ #include "egl/fg_window_egl.h" #include +#ifdef NDEBUG +#define LOGI(...) +#else #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) +#endif #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) #include #include @@ -165,7 +169,8 @@ fg_time_t fgPlatformSystemTime ( void ) */ void fgPlatformSleepForEvents( fg_time_t msec ) { - if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && + bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } diff --git a/src/blackberry/fg_window_blackberry.c b/src/blackberry/fg_window_blackberry.c index 5689394..0b7d80b 100644 --- a/src/blackberry/fg_window_blackberry.c +++ b/src/blackberry/fg_window_blackberry.c @@ -182,7 +182,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Create context */ fghChooseConfig(&window->Window.pContext.egl.Config); - window->Window.Context = fghCreateNewContextEGL(window); + 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); diff --git a/src/egl/fg_window_egl.c b/src/egl/fg_window_egl.c index 0e06233..2141c5c 100644 --- a/src/egl/fg_window_egl.c +++ b/src/egl/fg_window_egl.c @@ -41,8 +41,8 @@ int fghChooseConfig(EGLConfig* config) { http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp That's all that is used, and that's what BlackBerry uses for their own internal OpenGL setup, so unless something else is determined, use it */ EGL_BLUE_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, #else EGL_BLUE_SIZE, 1, EGL_GREEN_SIZE, 1, @@ -58,7 +58,7 @@ int fghChooseConfig(EGLConfig* config) { EGLint num_config; if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, - attribs, config, 1, &num_config)) { + attribs, config, 1, &num_config)) { fgWarning("eglChooseConfig: error %x\n", eglGetError()); return 0; } @@ -105,9 +105,9 @@ void fgPlatformSetWindow ( SFG_Window *window ) { if ( window != fgStructure.CurrentWindow && window) { if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, - window->Window.pContext.egl.Surface, - window->Window.pContext.egl.Surface, - window->Window.Context) == EGL_FALSE) + window->Window.pContext.egl.Surface, + window->Window.pContext.egl.Surface, + window->Window.Context) == EGL_FALSE) fgError("eglMakeCurrent: err=%x\n", eglGetError()); } } @@ -138,9 +138,28 @@ void fghPlatformOpenWindowEGL( SFG_Window* window ) */ void fghPlatformCloseWindowEGL( SFG_Window* window ) { - eglMakeCurrent(fgDisplay.pDisplay.egl.Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + /* Based on fg_window_mswin fgPlatformCloseWindow */ + if( fgStructure.CurrentWindow == window ) + eglMakeCurrent(fgDisplay.pDisplay.egl.Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (window->Window.Context != EGL_NO_CONTEXT) { - eglDestroyContext(fgDisplay.pDisplay.egl.Display, window->Window.Context); + /* Step through the list of windows. If the rendering context is not being used by another window, then delete it */ + { + GLboolean used = GL_FALSE; + SFG_Window *iter; + + for( iter = (SFG_Window*)fgStructure.Windows.First; + iter && used == GL_FALSE; + iter = (SFG_Window*)iter->Node.Next) + { + if( (iter->Window.Context == window->Window.Context) && + (iter != window) ) + used = GL_TRUE; + } + + if( !used ) + eglDestroyContext(fgDisplay.pDisplay.egl.Display, window->Window.Context); + } window->Window.Context = EGL_NO_CONTEXT; } diff --git a/src/fg_init.c b/src/fg_init.c index 0b6e29d..4061836 100644 --- a/src/fg_init.c +++ b/src/fg_init.c @@ -110,7 +110,7 @@ void fghParseCommandLineArguments ( int* pargc, char** argv, char **pDisplayName int i, j, argc = *pargc; { - /* check if GLUT_FPS env var is set */ + /* check if GLUT_FPS env var is set */ const char *fps = getenv( "GLUT_FPS" ); if( fps ) @@ -229,7 +229,7 @@ void fgDeinitialize( void ) return; } - /* If we're in game mode, we want to leave game mode */ + /* If we're in game mode, we want to leave game mode */ if( fgStructure.GameModeWindow ) { glutLeaveGameMode(); } @@ -237,7 +237,7 @@ void fgDeinitialize( void ) /* If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { - fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); + fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } @@ -256,9 +256,9 @@ void fgDeinitialize( void ) free( timer ); } - fgPlatformDeinitialiseInputDevices (); + fgPlatformDeinitialiseInputDevices (); - fgState.MouseWheelTicks = 0; + fgState.MouseWheelTicks = 0; fgState.MajorVersion = 1; fgState.MinorVersion = 0; @@ -310,7 +310,7 @@ void fgDeinitialize( void ) fgState.ProgramName = NULL; } - fgPlatformCloseDisplay (); + fgPlatformCloseDisplay (); fgState.Initialised = GL_FALSE; } @@ -342,7 +342,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) fgCreateStructure( ); - fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry ); + fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry ); /* * Have the display created now. If there wasn't a "-display" diff --git a/src/fg_window.c b/src/fg_window.c index d61be0d..cf1dff8 100644 --- a/src/fg_window.c +++ b/src/fg_window.c @@ -106,7 +106,7 @@ void fghContextCreationError( void ) */ void fgSetWindow ( SFG_Window *window ) { - fgPlatformSetWindow ( window ); + fgPlatformSetWindow ( window ); fgStructure.CurrentWindow = window; } @@ -158,7 +158,7 @@ void fgCloseWindow( SFG_Window* window ) if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID) glutLeaveGameMode(); - fgPlatformCloseWindow ( window ); + fgPlatformCloseWindow ( window ); } @@ -335,7 +335,7 @@ void FGAPIENTRY glutSetWindowTitle( const char* title ) FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" ); if( ! fgStructure.CurrentWindow->Parent ) { - fgPlatformGlutSetWindowTitle ( title ); + fgPlatformGlutSetWindowTitle ( title ); } } @@ -349,7 +349,7 @@ void FGAPIENTRY glutSetIconTitle( const char* title ) if( ! fgStructure.CurrentWindow->Parent ) { - fgPlatformGlutSetIconTitle ( title ); + fgPlatformGlutSetIconTitle ( title ); } } @@ -445,7 +445,7 @@ void FGAPIENTRY glutFullScreen( void ) } if (!win->State.IsFullscreen) - win->State.WorkMask |= GLUT_FULL_SCREEN_WORK; + win->State.WorkMask |= GLUT_FULL_SCREEN_WORK; } /* -- 1.7.10.4