Add new callback to reload context, pending propername

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1304 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
beuc 2012-05-04 22:18:54 +00:00
parent 5807ec617c
commit e85d2865b2
8 changed files with 58 additions and 3 deletions

View File

@ -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

View File

@ -37,6 +37,7 @@
*/
#include <GL/freeglut.h>
#include <GL/freeglut_ext.h>
#include <stdarg.h>
#include <stdio.h>
@ -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

View File

@ -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?); */
}
}

View File

@ -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 ***/

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -150,6 +150,8 @@ void fgOpenWindow( SFG_Window* window, const char* title,
window->Window.attribute_v_normal = -1;
fgInitGL2();
window->State.NeedToFixMyNameInitContext = GL_TRUE;
}
/*