From 9b943faa4f374b5a37b1bf6d544f826078cd361b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 27 Jun 2003 15:10:06 +0000 Subject: [PATCH] XF86 game mode fixes, context sharing option. (John Fay) git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@108 7f0cb862-5218-0410-a997-914c9d46530a --- include/GL/freeglut_ext.h | 8 ++++++++ src/freeglut_init.c | 17 ++++++++++------- src/freeglut_internal.h | 6 ++++++ src/freeglut_main.c | 21 ++++++++++++++++++--- src/freeglut_state.c | 23 ++++++++++++++--------- src/freeglut_stroke_mono_roman.c | 4 +--- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/include/GL/freeglut_ext.h b/include/GL/freeglut_ext.h index 2f7c922..7369f0f 100644 --- a/include/GL/freeglut_ext.h +++ b/include/GL/freeglut_ext.h @@ -40,6 +40,12 @@ #define GLUT_ACTION_CONTINUE_EXECUTION 2 /* + * Create a new rendering context when the user opens a new window? + */ +#define GLUT_CREATE_NEW_CONTEXT 0 +#define GLUT_USE_CURRENT_CONTEXT 1 + +/* * GLUT API Extension macro definitions -- the glutGet parameters */ #define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9 @@ -49,6 +55,8 @@ #define GLUT_VERSION 0x01FC +#define GLUT_RENDERING_CONTEXT 0x01FD + /* * Process loop function, see freeglut_main.c */ diff --git a/src/freeglut_init.c b/src/freeglut_init.c index a1367b8..eb0935b 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -61,6 +61,7 @@ SFG_State fgState = { { -1, -1, FALSE }, /* Position */ FALSE, /* ForceDirectContext */ TRUE, /* TryDirectContext */ FALSE, /* ForceIconic */ + FALSE, /* UseCurrentContext */ FALSE, /* GLDebugSwitch */ FALSE, /* XSyncSwitch */ TRUE, /* IgnoreKeyRepeat */ @@ -81,7 +82,7 @@ SFG_State fgState = { { -1, -1, FALSE }, /* Position */ 72, /* GameModeRefresh */ GLUT_ACTION_EXIT, /* ActionOnWindowClose */ GLUT_EXEC_STATE_INIT /* ExecState */ -}; +} ; /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ @@ -306,6 +307,7 @@ void fgDeinitialize( void ) fgState.ForceDirectContext = FALSE; fgState.TryDirectContext = TRUE; fgState.ForceIconic = FALSE; + fgState.UseCurrentContext = FALSE; fgState.GLDebugSwitch = FALSE; fgState.XSyncSwitch = FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT ; @@ -394,12 +396,13 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) /* check if GLUT_FPS env var is set */ { - const char *fps = getenv("GLUT_FPS"); - if (fps) { - sscanf(fps, "%d", &fgState.FPSInterval); - if (fgState.FPSInterval <= 0) - fgState.FPSInterval = 5000; /* 5000 milliseconds */ - } + const char *fps = getenv ( "GLUT_FPS" ); + if ( fps ) + { + sscanf ( fps, "%d", &fgState.FPSInterval ) ; + if ( fgState.FPSInterval <= 0 ) + fgState.FPSInterval = 5000 ; /* 5000 milliseconds */ + } } /* diff --git a/src/freeglut_internal.h b/src/freeglut_internal.h index 203ece1..4564157 100644 --- a/src/freeglut_internal.h +++ b/src/freeglut_internal.h @@ -219,6 +219,7 @@ struct tagSFG_State GLboolean TryDirectContext; /* What about giving a try to? */ GLboolean ForceIconic; /* All new top windows are iconified */ + GLboolean UseCurrentContext; /* New windows use current window's rendering context */ GLboolean GLDebugSwitch; /* OpenGL state debugging switch */ GLboolean XSyncSwitch; /* X11 sync protocol switch */ @@ -260,6 +261,11 @@ struct tagSFG_Display Atom DeleteWindow; /* The window deletion atom */ #ifdef X_XF86VidModeGetModeLine + /* + * XF86VidMode may be compilable even if it fails at runtime. Therefore, + * the validity of the VidMode has to be tracked + */ + int DisplayModeValid; /* Flag that indicates runtime status*/ XF86VidModeModeLine DisplayMode; /* Current screen's display settings */ int DisplayModeClock; /* The display mode's refresh rate */ #endif diff --git a/src/freeglut_main.c b/src/freeglut_main.c index 1c11f0d..7984f58 100644 --- a/src/freeglut_main.c +++ b/src/freeglut_main.c @@ -1175,9 +1175,12 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE ); /* - * Create the OpenGL rendering context now + * Create or get the OpenGL rendering context now */ - window->Window.Context = wglCreateContext( window->Window.Device ); + if ( fgState.UseCurrentContext == TRUE ) + window->Window.Context = wglGetCurrentContext(); + else + window->Window.Context = wglCreateContext( window->Window.Device ); /* * Still, we'll be needing to explicitly resize the window @@ -1287,8 +1290,20 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara */ if( fgStructure.Window == window ) { + int used = FALSE ; + SFG_Window *iter ; + wglMakeCurrent( NULL, NULL ); - wglDeleteContext( window->Window.Context ); + /* Step through the list of windows. If the rendering context is notbeing used + * by another window, then we delete it. + */ + for ( iter = fgStructure.Windows.First; iter; iter = iter->Node.Next ) + { + if ( ( iter->Window.Context == window->Window.Context ) && ( iter != window ) ) + used = TRUE ; + } + + if ( used == FALSE ) wglDeleteContext( window->Window.Context ); } /* diff --git a/src/freeglut_state.c b/src/freeglut_state.c index cb40f05..84b261e 100644 --- a/src/freeglut_state.c +++ b/src/freeglut_state.c @@ -104,6 +104,9 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value ) case GLUT_ACTION_ON_WINDOW_CLOSE: fgState.ActionOnWindowClose = value ; break ; + case GLUT_RENDERING_CONTEXT: fgState.UseCurrentContext = ( value == GLUT_USE_CURRENT_CONTEXT ) ? TRUE : FALSE ; + break ; + case GLUT_WINDOW_CURSOR: if( fgStructure.Window != NULL ) fgStructure.Window->State.Cursor = value ; break ; @@ -122,11 +125,11 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value ) */ int FGAPIENTRY glutGet( GLenum eWhat ) { - int returnValue ; - GLboolean boolValue ; + int returnValue ; + GLboolean boolValue ; - if ( eWhat == GLUT_INIT_STATE ) - return ( fgState.Time.Set ) ; + if ( eWhat == GLUT_INIT_STATE ) + return ( fgState.Time.Set ) ; freeglut_assert_ready; @@ -364,8 +367,7 @@ int FGAPIENTRY glutGet( GLenum eWhat ) /* * ...then we've got to correct the results we've just received... */ - if (fgStructure.GameMode != fgStructure.Window && - fgStructure.Window->Parent == NULL ) + if ( ( fgStructure.GameMode != fgStructure.Window ) && ( fgStructure.Window->Parent == NULL ) ) { winRect.left += GetSystemMetrics( SM_CXSIZEFRAME ); winRect.right -= GetSystemMetrics( SM_CXSIZEFRAME ); @@ -452,10 +454,13 @@ int FGAPIENTRY glutGet( GLenum eWhat ) return( fgListLength( &fgStructure.Menu->Entries ) ); case GLUT_ACTION_ON_WINDOW_CLOSE: - return fgState.ActionOnWindowClose; + return fgState.ActionOnWindowClose ; + + case GLUT_VERSION : + return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH ; - case GLUT_VERSION: - return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH; + case GLUT_RENDERING_CONTEXT: + return ( fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT : GLUT_CREATE_NEW_CONTEXT ) ; default: /* diff --git a/src/freeglut_stroke_mono_roman.c b/src/freeglut_stroke_mono_roman.c index e709532..46ef9b2 100644 --- a/src/freeglut_stroke_mono_roman.c +++ b/src/freeglut_stroke_mono_roman.c @@ -2,9 +2,7 @@ /* This file has been automatically generated by the genstroke utility. */ #include "freeglut_internal.h" -//#ifdef TARGET_HOST_WIN32 -//#pragma warning ( once:4305 ) -//#endif + /* char: 0x20 */ static const SFG_StrokeStrip ch32st[] = -- 1.7.10.4