Explorar o código

Android: Move application initialization to the first onDrawFrame. Resolves issues where simpleInitApp gets called without the correct appsettings width and height.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10917 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
iwg..ic %!s(int64=11) %!d(string=hai) anos
pai
achega
4f75cb688f
Modificáronse 1 ficheiros con 18 adicións e 5 borrados
  1. 18 5
      engine/src/android/com/jme3/system/android/OGLESContext.java

+ 18 - 5
engine/src/android/com/jme3/system/android/OGLESContext.java

@@ -176,7 +176,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
             renderer.resetGLObjects();
         } else {
             if (!created.get()) {
-                logger.fine("GL Surface created, doing JME3 init");
+                logger.fine("GL Surface created, initializing JME3 renderer");
                 initInThread();
             } else {
                 logger.warning("GL Surface already created");
@@ -201,12 +201,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
         renderer = new OGLESShaderRenderer();
 
         renderer.initialize();
-        listener.initialize();
 
         JmeSystem.setSoftTextDialogInput(this);
 
         needClose.set(false);
-        renderable.set(true);
     }
 
     /**
@@ -302,8 +300,17 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
     @Override
     public void onSurfaceChanged(GL10 gl, int width, int height) {
         logger.log(Level.FINE, "GL Surface changed, width: {0} height: {1}", new Object[]{width, height});
+        // update the application settings with the new resolution
         settings.setResolution(width, height);
-        listener.reshape(width, height);
+        // reload settings in androidInput so the correct touch event scaling can be
+        // calculated in case the surface resolution is different than the view
+        androidInput.loadSettings(settings);
+        // if the application has already been initialized (ie renderable is set)
+        // then call reshape so the app can adjust to the new resolution.
+        if (renderable.get()) {
+            logger.log(Level.FINE, "App already initialized, calling reshape");
+            listener.reshape(width, height);
+        }
     }
 
     // SystemListener:update
@@ -314,7 +321,13 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
             return;
         }
 
-        if (renderable.get()) {
+        if (!renderable.get()) {
+            if (created.get()) {
+                logger.fine("GL Surface is setup, initializing application");
+                listener.initialize();
+                renderable.set(true);
+            }
+        } else {
             if (!created.get()) {
                 throw new IllegalStateException("onDrawFrame without create");
             }