Ver código fonte

Add rescaling support

Riccardo Balbo 3 anos atrás
pai
commit
4ed198c7cb

+ 5 - 0
jme3-android/src/main/java/com/jme3/app/AndroidHarness.java

@@ -494,6 +494,11 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
         app.reshape(width, height);
     }
 
+    @Override
+    public void rescale(float x, float y) {
+        app.rescale(x, y);
+    }
+
     @Override
     public void update() {
         app.update();

+ 5 - 0
jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java

@@ -571,6 +571,11 @@ public class AndroidHarnessFragment extends Fragment implements
         app.reshape(width, height);
     }
 
+    @Override
+    public void rescale(float x, float y) {
+        app.rescale(x, y);
+    }
+
     @Override
     public void update() {
         app.update();

+ 11 - 0
jme3-android/src/main/java/com/jme3/app/jmeSurfaceView/JmeSurfaceView.java

@@ -395,6 +395,17 @@ public class JmeSurfaceView extends RelativeLayout implements SystemListener, Di
         jmeSurfaceViewLogger.log(Level.INFO, "Requested reshaping from the system listener");
     }
 
+
+    @Override
+    public void rescale(float x, float y) {
+        if (legacyApplication == null) {
+            return;
+        }
+        legacyApplication.rescale(x, y);
+        jmeSurfaceViewLogger.log(Level.INFO, "Requested rescaling from the system listener");
+    }
+
+
     @Override
     public void update() {
         /*Invoking can be delayed by delaying the draw of GlSurfaceView component on the screen*/

+ 11 - 0
jme3-core/src/main/java/com/jme3/app/LegacyApplication.java

@@ -578,6 +578,17 @@ public class LegacyApplication implements Application, SystemListener {
         }
     }
 
+
+    /**
+     * Internal use only.
+     */
+    @Override
+    public void rescale(float x, float y){
+        if (renderManager != null) {
+            renderManager.notifyRescale(x, y);
+        }
+    }
+
     /**
      * Restarts the context, applying any changed settings.
      * <p>

+ 11 - 0
jme3-core/src/main/java/com/jme3/post/SceneProcessor.java

@@ -62,6 +62,17 @@ public interface SceneProcessor {
      */
     public void reshape(ViewPort vp, int w, int h);
 
+    /**
+     * Called when the scale of the viewport has been changed.
+     *
+     * @param vp the affected ViewPort
+     * @param x the new scale (in pixels)
+     * @param y the new scale (in pixels)
+     */
+    public default void rescale(ViewPort vp, float x, float y){
+
+    }
+
     /**
      * @return True if initialize() has been called on this SceneProcessor,
      * false if otherwise.

+ 23 - 0
jme3-core/src/main/java/com/jme3/renderer/RenderManager.java

@@ -342,6 +342,17 @@ public class RenderManager {
         }
     }
 
+    private void notifyRescale(ViewPort vp, float x, float y) {
+        List<SceneProcessor> processors = vp.getProcessors();
+        for (SceneProcessor proc : processors) {
+            if (!proc.isInitialized()) {
+                proc.initialize(this, vp);
+            } else {
+                proc.rescale(vp, x, y);
+            }
+        }
+    }
+
     /**
      * Internal use only.
      * Updates the resolution of all on-screen cameras to match
@@ -374,6 +385,18 @@ public class RenderManager {
         }
     }
 
+    public void notifyRescale(float x, float y) {
+        for (ViewPort vp : preViewPorts) {
+            notifyRescale(vp, x, y);
+        }
+        for (ViewPort vp : viewPorts) {        
+            notifyRescale(vp, x, y);
+        }
+        for (ViewPort vp : postViewPorts) {
+            notifyRescale(vp, x, y);
+        }
+    }
+
     /**
      * Sets the material to use to render all future objects.
      * This overrides the material set on the geometry and renders

+ 8 - 0
jme3-core/src/main/java/com/jme3/system/SystemListener.java

@@ -51,6 +51,14 @@ public interface SystemListener {
      */
     public void reshape(int width, int height);
 
+    /**
+     * Called to notify the application that the scale has changed.
+     * @param x the new scale of the display (in pixels, &ge;0)
+     * @param y the new scale of the display (in pixels, &ge;0)
+     */
+    public void rescale(float x, float y);
+
+
     /**
      * Callback to update the application state, and render the scene
      * to the back buffer.

+ 5 - 0
jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java

@@ -67,6 +67,11 @@ public class AwtPanelsContext implements JmeContext {
             throw new IllegalStateException();
         }
 
+        @Override
+        public void rescale(float x, float y) {
+            throw new IllegalStateException();
+        }
+
         @Override
         public void update() {
             updateInThread();

+ 6 - 1
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java

@@ -382,11 +382,16 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
         int[] width = new int[1];
         int[] height = new int[1];
         glfwGetFramebufferSize(window, width, height);
+
+        Vector2f scale=new Vector2f();
+        getWindowContentScale(scale);
+
         if (settings.getWidth() != width[0] || settings.getHeight() != height[0]) {
             settings.setResolution(width[0], height[0]);
             // https://www.glfw.org/docs/latest/window_guide.html#window_fbsize
+            listener.rescale(scale.x,scale.y);
             listener.reshape(width[0], height[0]);
-        }
+        }   
     }
 
     private void onWindowSizeChanged(final int width, final int height) {