|
@@ -39,6 +39,7 @@ import com.jme3.input.TouchInput;
|
|
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
|
import com.jme3.input.lwjgl.GlfwJoystickInput;
|
|
import com.jme3.input.lwjgl.GlfwKeyInput;
|
|
import com.jme3.input.lwjgl.GlfwKeyInput;
|
|
import com.jme3.input.lwjgl.GlfwMouseInput;
|
|
import com.jme3.input.lwjgl.GlfwMouseInput;
|
|
|
|
+import com.jme3.math.Vector2f;
|
|
import com.jme3.system.AppSettings;
|
|
import com.jme3.system.AppSettings;
|
|
import com.jme3.system.JmeContext;
|
|
import com.jme3.system.JmeContext;
|
|
import com.jme3.system.JmeSystem;
|
|
import com.jme3.system.JmeSystem;
|
|
@@ -226,6 +227,7 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|
glfwWindowHint(GLFW_SAMPLES, settings.getSamples());
|
|
glfwWindowHint(GLFW_SAMPLES, settings.getSamples());
|
|
glfwWindowHint(GLFW_STEREO, settings.useStereo3D() ? GLFW_TRUE : GLFW_FALSE);
|
|
glfwWindowHint(GLFW_STEREO, settings.useStereo3D() ? GLFW_TRUE : GLFW_FALSE);
|
|
glfwWindowHint(GLFW_REFRESH_RATE, settings.getFrequency()<=0?GLFW_DONT_CARE:settings.getFrequency());
|
|
glfwWindowHint(GLFW_REFRESH_RATE, settings.getFrequency()<=0?GLFW_DONT_CARE:settings.getFrequency());
|
|
|
|
+ glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, settings.isUseRetinaFrameBuffer() ? GLFW_TRUE : GLFW_FALSE);
|
|
|
|
|
|
if (settings.getBitsPerPixel() == 24) {
|
|
if (settings.getBitsPerPixel() == 24) {
|
|
glfwWindowHint(GLFW_RED_BITS, 8);
|
|
glfwWindowHint(GLFW_RED_BITS, 8);
|
|
@@ -330,6 +332,8 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|
if (settings.isOpenCLSupport()) {
|
|
if (settings.isOpenCLSupport()) {
|
|
initOpenCL(window);
|
|
initOpenCL(window);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ framesAfterContextStarted = 0;
|
|
}
|
|
}
|
|
|
|
|
|
private void onWindowSizeChanged(final int width, final int height) {
|
|
private void onWindowSizeChanged(final int width, final int height) {
|
|
@@ -521,6 +525,8 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private int framesAfterContextStarted = 0;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* execute one iteration of the render loop in the OpenGL thread
|
|
* execute one iteration of the render loop in the OpenGL thread
|
|
*/
|
|
*/
|
|
@@ -534,6 +540,21 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|
throw new IllegalStateException();
|
|
throw new IllegalStateException();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Update the frame buffer size from 2nd frame since the initial value
|
|
|
|
+ // of frame buffer size from glfw maybe incorrect when HiDPI display is in use
|
|
|
|
+ if (framesAfterContextStarted < 2) {
|
|
|
|
+ framesAfterContextStarted++;
|
|
|
|
+ if (framesAfterContextStarted == 2) {
|
|
|
|
+ int[] width = new int[1];
|
|
|
|
+ int[] height = new int[1];
|
|
|
|
+ glfwGetFramebufferSize(window, width, height);
|
|
|
|
+
|
|
|
|
+ if (settings.getWidth() != width[0] || settings.getHeight() != height[0]) {
|
|
|
|
+ listener.reshape(width[0], height[0]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
listener.update();
|
|
listener.update();
|
|
|
|
|
|
// All this does is call swap buffers
|
|
// All this does is call swap buffers
|
|
@@ -688,4 +709,28 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
|
|
public long getWindowHandle() {
|
|
public long getWindowHandle() {
|
|
return window;
|
|
return window;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get the window content scale, for HiDPI support.
|
|
|
|
+ *
|
|
|
|
+ * The content scale is the ratio between the current DPI and the platform's default DPI.
|
|
|
|
+ * This is especially important for text and any UI elements. If the pixel dimensions of
|
|
|
|
+ * your UI scaled by this look appropriate on your machine then it should appear at a
|
|
|
|
+ * reasonable size on other machines regardless of their DPI and scaling settings. This
|
|
|
|
+ * relies on the system DPI and scaling settings being somewhat correct.
|
|
|
|
+ *
|
|
|
|
+ * @param store A vector2f to store the result
|
|
|
|
+ * @return The window content scale
|
|
|
|
+ * @see <a href="https://www.glfw.org/docs/latest/window_guide.html#window_scale">Window content scale</a>
|
|
|
|
+ */
|
|
|
|
+ public Vector2f getWindowContentScale(Vector2f store) {
|
|
|
|
+ float[] xScale = new float[1];
|
|
|
|
+ float[] yScale = new float[1];
|
|
|
|
+ glfwGetWindowContentScale(window, xScale, yScale);
|
|
|
|
+
|
|
|
|
+ if (store != null) {
|
|
|
|
+ return store.set(xScale[0], yScale[0]);
|
|
|
|
+ }
|
|
|
|
+ return new Vector2f(xScale[0], yScale[0]);
|
|
|
|
+ }
|
|
}
|
|
}
|