From: Sylvain Beucler Date: Fri, 4 May 2012 22:18:54 +0000 (+0000) Subject: Add new callback to reload context, pending propername X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=19242860f0cd6d3f2c3e32e87e15fe5e1151d072;p=freeglut Add new callback to reload context, pending propername git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1304 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/include/GL/freeglut_ext.h b/include/GL/freeglut_ext.h index d6b564d..2c71737 100644 --- a/include/GL/freeglut_ext.h +++ b/include/GL/freeglut_ext.h @@ -227,6 +227,10 @@ FGAPI void FGAPIENTRY glutInitWarningFunc( void (* vWarning)( const char *fmt FGAPI void FGAPIENTRY glutSetVertexAttribCoord3(GLint attrib); FGAPI void FGAPIENTRY glutSetVertexAttribNormal(GLint attrib); +/* Mobile platforms lifecycle */ +FGAPI void FGAPIENTRY glutFixMyNameInitContextFunc(void (* callback)()); +FGAPI void FGAPIENTRY glutFixMyNamePauseFunc(void (* callback)()); +FGAPI void FGAPIENTRY glutFixMyNameResumeFunc(void (* callback)()); /* * GLUT API macro definitions -- the display mode definitions diff --git a/progs/test-shapes-gles1/test-shapes-gles1.c b/progs/test-shapes-gles1/test-shapes-gles1.c index e4d9122..ab26593 100644 --- a/progs/test-shapes-gles1/test-shapes-gles1.c +++ b/progs/test-shapes-gles1/test-shapes-gles1.c @@ -37,6 +37,7 @@ */ #include +#include #include #include @@ -281,7 +282,8 @@ const GLfloat high_shininess[] = { 100.0f }; /* Program entry point */ -void init_resources() { +void init_context() { + printf("init_context\n"); fflush(stdout); glClearColor(1,1,1,1); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); @@ -320,10 +322,10 @@ main(int argc, char *argv[]) glutSpecialFunc(special); glutIdleFunc(idle); glutMouseFunc(onMouseClick); + glutFixMyNameInitContextFunc(init_context); glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ; - init_resources(); glutMainLoop(); #ifdef _MSC_VER diff --git a/src/android/fg_main_android.c b/src/android/fg_main_android.c index a989a27..7c11278 100644 --- a/src/android/fg_main_android.c +++ b/src/android/fg_main_android.c @@ -367,6 +367,7 @@ void handle_cmd(struct android_app* app, int32_t cmd) { /* The application is being hidden, but may be restored */ LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); fghPlatformCloseWindowEGL(window); + window->State.NeedToFixMyNameInitContext = GL_TRUE; fgDisplay.pDisplay.single_native_window = NULL; break; case APP_CMD_STOP: @@ -471,7 +472,6 @@ void fgPlatformProcessSingleEvent ( void ) surface; in which case fgPlatformOpenWindow will no-op. */ fgPlatformOpenWindow(window, "", GL_FALSE, 0, 0, GL_FALSE, 0, 0, GL_FALSE, GL_FALSE); /* TODO: INVOKE_WCB(*window, Pause?); */ - /* TODO: INVOKE_WCB(*window, LoadResources/ContextLost/...?); */ /* TODO: INVOKE_WCB(*window, Resume?); */ } } diff --git a/src/fg_callbacks.c b/src/fg_callbacks.c index 7e399a9..b3e2917 100644 --- a/src/fg_callbacks.c +++ b/src/fg_callbacks.c @@ -409,4 +409,31 @@ void FGAPIENTRY glutMultiPassiveFunc( void (* callback)(int, int, int ) ) SET_CALLBACK( MultiPassive ); } +/* + * Sets the context reload callback for the current window + */ +void FGAPIENTRY glutFixMyNameInitContextFunc( void (* callback)() ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFixMyNameInitContextFunc" ); + SET_CALLBACK( FixMyNameInitContext ); +} + +/* + * Sets the pause callback for the current window + */ +void FGAPIENTRY glutFixMyNamePauseFunc( void (* callback)() ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFixMyNamePauseFunc" ); + SET_CALLBACK( FixMyNamePause ); +} + +/* + * Sets the resume callback for the current window + */ +void FGAPIENTRY glutFixMyNameResumeFunc( void (* callback)() ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutFixMyNameResumeFunc" ); + SET_CALLBACK( FixMyNameResume ); +} + /*** END OF FILE ***/ diff --git a/src/fg_ext.c b/src/fg_ext.c index 344fa51..293fa62 100644 --- a/src/fg_ext.c +++ b/src/fg_ext.c @@ -199,6 +199,9 @@ static GLUTproc fghGetGLUTProcAddress( const char* procName ) CHECK_NAME(glutInitContextProfile); CHECK_NAME(glutInitErrorFunc); CHECK_NAME(glutInitWarningFunc); + CHECK_NAME(glutFixMyNameInitContextFunc) + CHECK_NAME(glutFixMyNamePauseFunc) + CHECK_NAME(glutFixMyNameResumeFunc) #undef CHECK_NAME return NULL; diff --git a/src/fg_internal.h b/src/fg_internal.h index 1c7429e..dbae676 100644 --- a/src/fg_internal.h +++ b/src/fg_internal.h @@ -219,6 +219,10 @@ typedef void (* FGCBMultiButton )( int, int, int, int, int ); typedef void (* FGCBMultiMotion )( int, int, int ); typedef void (* FGCBMultiPassive )( int, int, int ); +typedef void (* FGCBFixMyNameInitContext)(); +typedef void (* FGCBFixMyNamePause)(); +typedef void (* FGCBFixMyNameResume)(); + /* The global callbacks type definitions */ typedef void (* FGCBIdle )( void ); typedef void (* FGCBTimer )( int ); @@ -397,6 +401,8 @@ struct tagSFG_WindowState GLboolean NeedToResize; /* Do we need to resize the window? */ GLboolean IsFullscreen; /* is the window fullscreen? */ + + GLboolean NeedToFixMyNameInitContext; /* are OpenGL context/resources loaded? */ }; @@ -528,6 +534,11 @@ enum CB_MultiMotion, CB_MultiPassive, + /* Mobile platforms LifeCycle */ + CB_FixMyNameInitContext, + CB_FixMyNamePause, + CB_FixMyNameResume, + /* Presently ignored */ CB_Select, CB_OverlayDisplay, diff --git a/src/fg_main.c b/src/fg_main.c index 24de119..33ca857 100644 --- a/src/fg_main.c +++ b/src/fg_main.c @@ -104,6 +104,12 @@ void fghRedrawWindow ( SFG_Window *window ) SFG_Window *current_window = fgStructure.CurrentWindow; freeglut_return_if_fail( window ); + + if( window->State.NeedToFixMyNameInitContext ) { + INVOKE_WCB( *window, FixMyNameInitContext, ()); + window->State.NeedToFixMyNameInitContext = GL_FALSE; + } + freeglut_return_if_fail( FETCH_WCB ( *window, Display ) ); window->State.Redisplay = GL_FALSE; diff --git a/src/fg_window.c b/src/fg_window.c index 5c431ea..efbae89 100644 --- a/src/fg_window.c +++ b/src/fg_window.c @@ -150,6 +150,8 @@ void fgOpenWindow( SFG_Window* window, const char* title, window->Window.attribute_v_normal = -1; fgInitGL2(); + + window->State.NeedToFixMyNameInitContext = GL_TRUE; } /*