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: https://svn.code.sf.net/p/freeglut/code/trunk@1673 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2014-01-24 10:34:49 +00:00
parent c5201e73ef
commit e8cc20621f
5 changed files with 50 additions and 22 deletions

View File

@ -32,7 +32,11 @@
#include "egl/fg_window_egl.h" #include "egl/fg_window_egl.h"
#include <slog2.h> #include <slog2.h>
#ifdef NDEBUG
#define LOGI(...)
#else
#define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) #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)) #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END))
#include <sys/keycodes.h> #include <sys/keycodes.h>
#include <input/screen_helpers.h> #include <input/screen_helpers.h>
@ -165,7 +169,8 @@ fg_time_t fgPlatformSystemTime ( void )
*/ */
void fgPlatformSleepForEvents( fg_time_t msec ) 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"); LOGW("BPS couldn't get event");
} }
} }

View File

@ -182,7 +182,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
/* Create context */ /* Create context */
fghChooseConfig(&window->Window.pContext.egl.Config); 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 */ /* Create EGL window */
fghPlatformOpenWindowEGL(window); fghPlatformOpenWindowEGL(window);

View File

@ -41,8 +41,8 @@ int fghChooseConfig(EGLConfig* config) {
http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp 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 */ 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_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8, EGL_RED_SIZE, 8,
#else #else
EGL_BLUE_SIZE, 1, EGL_BLUE_SIZE, 1,
EGL_GREEN_SIZE, 1, EGL_GREEN_SIZE, 1,
@ -58,7 +58,7 @@ int fghChooseConfig(EGLConfig* config) {
EGLint num_config; EGLint num_config;
if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display,
attribs, config, 1, &num_config)) { attribs, config, 1, &num_config)) {
fgWarning("eglChooseConfig: error %x\n", eglGetError()); fgWarning("eglChooseConfig: error %x\n", eglGetError());
return 0; return 0;
} }
@ -105,9 +105,9 @@ void fgPlatformSetWindow ( SFG_Window *window )
{ {
if ( window != fgStructure.CurrentWindow && window) { if ( window != fgStructure.CurrentWindow && window) {
if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display,
window->Window.pContext.egl.Surface, window->Window.pContext.egl.Surface,
window->Window.pContext.egl.Surface, window->Window.pContext.egl.Surface,
window->Window.Context) == EGL_FALSE) window->Window.Context) == EGL_FALSE)
fgError("eglMakeCurrent: err=%x\n", eglGetError()); fgError("eglMakeCurrent: err=%x\n", eglGetError());
} }
} }
@ -138,9 +138,28 @@ void fghPlatformOpenWindowEGL( SFG_Window* window )
*/ */
void fghPlatformCloseWindowEGL( 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) { 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; window->Window.Context = EGL_NO_CONTEXT;
} }

View File

@ -110,7 +110,7 @@ void fghParseCommandLineArguments ( int* pargc, char** argv, char **pDisplayName
int i, j, argc = *pargc; 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" ); const char *fps = getenv( "GLUT_FPS" );
if( fps ) if( fps )
@ -229,7 +229,7 @@ void fgDeinitialize( void )
return; 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 ) { if( fgStructure.GameModeWindow ) {
glutLeaveGameMode(); glutLeaveGameMode();
} }
@ -237,7 +237,7 @@ void fgDeinitialize( void )
/* If there was a menu created, destroy the rendering context */ /* If there was a menu created, destroy the rendering context */
if( fgStructure.MenuContext ) if( fgStructure.MenuContext )
{ {
fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext );
free( fgStructure.MenuContext ); free( fgStructure.MenuContext );
fgStructure.MenuContext = NULL; fgStructure.MenuContext = NULL;
} }
@ -256,9 +256,9 @@ void fgDeinitialize( void )
free( timer ); free( timer );
} }
fgPlatformDeinitialiseInputDevices (); fgPlatformDeinitialiseInputDevices ();
fgState.MouseWheelTicks = 0; fgState.MouseWheelTicks = 0;
fgState.MajorVersion = 1; fgState.MajorVersion = 1;
fgState.MinorVersion = 0; fgState.MinorVersion = 0;
@ -310,7 +310,7 @@ void fgDeinitialize( void )
fgState.ProgramName = NULL; fgState.ProgramName = NULL;
} }
fgPlatformCloseDisplay (); fgPlatformCloseDisplay ();
fgState.Initialised = GL_FALSE; fgState.Initialised = GL_FALSE;
} }
@ -342,7 +342,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
fgCreateStructure( ); fgCreateStructure( );
fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry ); fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry );
/* /*
* Have the display created now. If there wasn't a "-display" * Have the display created now. If there wasn't a "-display"

View File

@ -106,7 +106,7 @@ void fghContextCreationError( void )
*/ */
void fgSetWindow ( SFG_Window *window ) void fgSetWindow ( SFG_Window *window )
{ {
fgPlatformSetWindow ( window ); fgPlatformSetWindow ( window );
fgStructure.CurrentWindow = window; fgStructure.CurrentWindow = window;
} }
@ -158,7 +158,7 @@ void fgCloseWindow( SFG_Window* window )
if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID) if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID)
glutLeaveGameMode(); glutLeaveGameMode();
fgPlatformCloseWindow ( window ); fgPlatformCloseWindow ( window );
} }
@ -335,7 +335,7 @@ void FGAPIENTRY glutSetWindowTitle( const char* title )
FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" );
if( ! fgStructure.CurrentWindow->Parent ) if( ! fgStructure.CurrentWindow->Parent )
{ {
fgPlatformGlutSetWindowTitle ( title ); fgPlatformGlutSetWindowTitle ( title );
} }
} }
@ -349,7 +349,7 @@ void FGAPIENTRY glutSetIconTitle( const char* title )
if( ! fgStructure.CurrentWindow->Parent ) if( ! fgStructure.CurrentWindow->Parent )
{ {
fgPlatformGlutSetIconTitle ( title ); fgPlatformGlutSetIconTitle ( title );
} }
} }
@ -445,7 +445,7 @@ void FGAPIENTRY glutFullScreen( void )
} }
if (!win->State.IsFullscreen) if (!win->State.IsFullscreen)
win->State.WorkMask |= GLUT_FULL_SCREEN_WORK; win->State.WorkMask |= GLUT_FULL_SCREEN_WORK;
} }
/* /*