Skip to content

Commit a0021da

Browse files
committed
Add rescaling support
1 parent ffaed08 commit a0021da

9 files changed

Lines changed: 88 additions & 3 deletions

File tree

jme3-android/src/main/java/com/jme3/app/AndroidHarness.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ public void reshape(int width, int height) {
494494
app.reshape(width, height);
495495
}
496496

497+
@Override
498+
public void rescale(float x, float y) {
499+
app.rescale(x, y);
500+
}
501+
497502
@Override
498503
public void update() {
499504
app.update();

jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ public void reshape(int width, int height) {
571571
app.reshape(width, height);
572572
}
573573

574+
@Override
575+
public void rescale(float x, float y) {
576+
app.rescale(x, y);
577+
}
578+
574579
@Override
575580
public void update() {
576581
app.update();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,17 @@ public void reshape(int width, int height) {
395395
jmeSurfaceViewLogger.log(Level.INFO, "Requested reshaping from the system listener");
396396
}
397397

398+
399+
@Override
400+
public void rescale(float x, float y) {
401+
if (legacyApplication == null) {
402+
return;
403+
}
404+
legacyApplication.rescale(x, y);
405+
jmeSurfaceViewLogger.log(Level.INFO, "Requested rescaling from the system listener");
406+
}
407+
408+
398409
@Override
399410
public void update() {
400411
/*Invoking can be delayed by delaying the draw of GlSurfaceView component on the screen*/

jme3-core/src/main/java/com/jme3/app/LegacyApplication.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ public void reshape(int w, int h){
578578
}
579579
}
580580

581+
582+
/**
583+
* Internal use only.
584+
*/
585+
@Override
586+
public void rescale(float x, float y){
587+
if (renderManager != null) {
588+
renderManager.notifyRescale(x, y);
589+
}
590+
}
591+
581592
/**
582593
* Restarts the context, applying any changed settings.
583594
* <p>

jme3-core/src/main/java/com/jme3/post/SceneProcessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ public interface SceneProcessor {
6262
*/
6363
public void reshape(ViewPort vp, int w, int h);
6464

65+
/**
66+
* Called when the scale of the viewport has been changed.
67+
*
68+
* @param vp the affected ViewPort
69+
* @param x the new scale (in pixels)
70+
* @param y the new scale (in pixels)
71+
*/
72+
public default void rescale(ViewPort vp, float x, float y){
73+
74+
}
75+
6576
/**
6677
* @return True if initialize() has been called on this SceneProcessor,
6778
* false if otherwise.

jme3-core/src/main/java/com/jme3/renderer/RenderManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@ private void notifyReshape(ViewPort vp, int w, int h) {
342342
}
343343
}
344344

345+
private void notifyRescale(ViewPort vp, float x, float y) {
346+
List<SceneProcessor> processors = vp.getProcessors();
347+
for (SceneProcessor proc : processors) {
348+
if (!proc.isInitialized()) {
349+
proc.initialize(this, vp);
350+
} else {
351+
proc.rescale(vp, x, y);
352+
}
353+
}
354+
}
355+
345356
/**
346357
* Internal use only.
347358
* Updates the resolution of all on-screen cameras to match
@@ -374,6 +385,18 @@ public void notifyReshape(int w, int h) {
374385
}
375386
}
376387

388+
public void notifyRescale(float x, float y) {
389+
for (ViewPort vp : preViewPorts) {
390+
notifyRescale(vp, x, y);
391+
}
392+
for (ViewPort vp : viewPorts) {
393+
notifyRescale(vp, x, y);
394+
}
395+
for (ViewPort vp : postViewPorts) {
396+
notifyRescale(vp, x, y);
397+
}
398+
}
399+
377400
/**
378401
* Sets the material to use to render all future objects.
379402
* This overrides the material set on the geometry and renders

jme3-core/src/main/java/com/jme3/system/SystemListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public interface SystemListener {
5151
*/
5252
public void reshape(int width, int height);
5353

54+
/**
55+
* Called to notify the application that the scale has changed.
56+
* @param x the new scale of the display (in pixels, &ge;0)
57+
* @param y the new scale of the display (in pixels, &ge;0)
58+
*/
59+
public void rescale(float x, float y);
60+
61+
5462
/**
5563
* Callback to update the application state, and render the scene
5664
* to the back buffer.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public void reshape(int width, int height) {
6767
throw new IllegalStateException();
6868
}
6969

70+
@Override
71+
public void rescale(float x, float y) {
72+
throw new IllegalStateException();
73+
}
74+
7075
@Override
7176
public void update() {
7277
updateInThread();

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ public void invoke(int error, long description) {
279279

280280
if (settings.getWindowWidth() <= 0 || settings.getWindowHeight() <= 0) {
281281
settings.setWindowSize(videoMode.width(), videoMode.height());
282+
}else{
283+
settings.setWindowSize(settings.getWindowWidth(), settings.getWindowHeight());
282284
}
283285

284286
settings.setResolution(settings.getWindowWidth(), settings.getWindowHeight());// Assume default framebuffer size == window size
@@ -367,19 +369,24 @@ public void invoke(final long window, final int width, final int height) {
367369

368370
updateDefaultFramebufferSize();
369371

370-
framesAfterContextStarted = 0;
371372
}
372373

373374
private void updateDefaultFramebufferSize() {
374375
// If default framebuffer size is different than window size (eg. HiDPI)
375376
int[] width = new int[1];
376377
int[] height = new int[1];
377378
glfwGetFramebufferSize(window, width, height);
379+
380+
float[] xScale = new float[1];
381+
float[] yScale = new float[1];
382+
glfwGetWindowContentScale(window, xScale, yScale);
383+
378384
if (settings.getWidth() != width[0] || settings.getHeight() != height[0]) {
379385
settings.setResolution(width[0], height[0]);
380386
// https://www.glfw.org/docs/latest/window_guide.html#window_fbsize
387+
listener.rescale(xScale[0],yScale[0]);
381388
listener.reshape(width[0], height[0]);
382-
}
389+
}
383390
}
384391

385392
private void onWindowSizeChanged(final int width, final int height) {
@@ -583,7 +590,6 @@ protected boolean initInThread() {
583590
return true;
584591
}
585592

586-
private int framesAfterContextStarted = 0;
587593

588594
/**
589595
* execute one iteration of the render loop in the OpenGL thread

0 commit comments

Comments
 (0)