JNIEXPORT void JNICALL JNIFUNCTION_DEMO(demoSurfaceCreated(JNIEnv* env, jobject object)) { glStateCacheFlush(); // Make sure we don't hold outdated OpenGL state. for (int i = 0; i < NUM_MODELS; i++) { if (models[i].obj) { glmDelete(models[i].obj, 0); models[i].obj = NULL; } } }
// // This is called whenever the OpenGL context has just been created or re-created. // Note that GLSurfaceView is a bit asymmetrical here; we don't get a call when the // OpenGL context is about to be deleted, it's just whipped out from under us. So it's // possible that when we enter this function, we're actually resuming after such an // event. What about resources we allocated previously which we didn't get time to // free? Well, we don't have to worry about the OpenGL resources themselves, they // were deleted along with the context. But, we should clean up any data structures we // allocated with malloc etc. ARGL's settings falls into this category. // JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeSurfaceCreated(JNIEnv * env, jobject object)) { LOGD("nativeSurfaceCreated\n"); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glStateCacheFlush(); // Make sure we don't hold outdated OpenGL state. if (gArglSettings) { arglCleanup(gArglSettings); // Clean up any left-over ARGL data. gArglSettings = NULL; } gARViewInited = false; }
// // This is called whenever the OpenGL context has just been created or re-created. // Note that GLSurfaceView is a bit asymmetrical here; we don't get a call when the // OpenGL context is about to be deleted, it's just whipped out from under us. So it's // possible that when we enter this function, we're actually resuming after such an // event. What about resources we allocated previously which we didn't get time to // de-allocate? Well, we don't have to worry about the OpenGL resources themselves, they // were deleted along with the context. But, we should clean up any data structures we // allocated with malloc etc. ARGL's settings falls into this category. // JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeSurfaceCreated(JNIEnv* env, jobject object)) { #ifdef DEBUG LOGI("nativeSurfaceCreated\n"); #endif glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glStateCacheFlush(); // Make sure we don't hold outdated OpenGL state. if (gArglSettings) { arglCleanup(gArglSettings); // Clean up any left-over ARGL data. gArglSettings = NULL; } VirtualEnvironmentFinal(); // Clean up any left-over OSG data. gARViewInited = false; }
// // This is called whenever the OpenGL context has just been created or re-created. // Note that GLSurfaceView is a bit asymmetrical here; we don't get a call when the // OpenGL context is about to be deleted, it's just whipped out from under us. So it's // possible that when we enter this function, we're actually resuming after such an // event. What about resources we allocated previously which we didn't get time to // de-allocate? Well, we don't have to worry about the OpenGL resources themselves, they // were deleted along with the context. But, we should clean up any data structures we // allocated with malloc etc. ARGL's settings falls into this category. // JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeSurfaceCreated(JNIEnv* env, jobject object)) { #ifdef DEBUG LOGI("nativeSurfaceCreated\n"); #endif glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glStateCacheFlush(); // Make sure we don't hold outdated OpenGL state. if (gArglSettings) { arglCleanup(gArglSettings); // Clean up any left-over ARGL data. gArglSettings = NULL; } program = 0; // The shader program was deleted, so mark it as needing to be recreated. gARViewInited = false; }
void VirtualEnvironmentHandleARViewDrawPreCamera(void) { if (!VirtualEnvironment_AROSG) return; #ifdef USE_OPENGL_ES // Set some state to OSG's expected values. glStateCacheDisableLighting(); glStateCacheDisableTex2D(); glStateCacheDisableBlend(); glStateCacheEnableClientStateVertexArray(); glStateCacheEnableClientStateNormalArray(); glStateCacheEnableClientStateTexCoordArray(); #endif // Save the projection and modelview state. glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Draw the whole scenegraph. arOSGDraw(VirtualEnvironment_AROSG); // OSG modifies the viewport, so restore it. // Also restore projection and modelview. glViewport(viewPort[viewPortIndexLeft], viewPort[viewPortIndexBottom], viewPort[viewPortIndexWidth], viewPort[viewPortIndexHeight]); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); #ifdef USE_OPENGL_ES // Flush the state cache and ensure depth testing is enabled. glStateCacheFlush(); glStateCacheEnableDepthTest(); #else // Ensure depth testing is re-enabled. glEnable(GL_DEPTH_TEST); #endif }