Add new callback to reload context, pending propername
authorSylvain Beucler <beuc@beuc.net>
Fri, 4 May 2012 22:18:54 +0000 (22:18 +0000)
committerSylvain Beucler <beuc@beuc.net>
Fri, 4 May 2012 22:18:54 +0000 (22:18 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1304 7f0cb862-5218-0410-a997-914c9d46530a

include/GL/freeglut_ext.h
progs/test-shapes-gles1/test-shapes-gles1.c
src/android/fg_main_android.c
src/fg_callbacks.c
src/fg_ext.c
src/fg_internal.h
src/fg_main.c
src/fg_window.c

index d6b564d..2c71737 100644 (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
index e4d9122..ab26593 100644 (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
index a989a27..7c11278 100644 (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?); */
     }
   }
index 7e399a9..b3e2917 100644 (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 ***/
index 344fa51..293fa62 100644 (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;
index 1c7429e..dbae676 100644 (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,
index 24de119..33ca857 100644 (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;
index 5c431ea..efbae89 100644 (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;
 }
 
 /*