Add new LWJGL API Display.getPixelScaleFactor() for use in high DPI

modes, like HiDPI retina mode on OS X.
This commit is contained in:
kappaOne 2013-11-11 23:12:51 +00:00
parent 225bd176cb
commit eb2e7176b8
5 changed files with 40 additions and 0 deletions

View File

@ -1348,4 +1348,27 @@ public final class Display {
return height; return height;
} }
/**
* @return this method will return the pixel scale factor of the Display window.
*
* This method should be used when running in high DPI mode. In such modes Operating
* Systems will scale the Display window to avoid the window shrinking due to high
* resolutions. The OpenGL frame buffer will however use the higher resolution and
* not be scaled to match the Display window size.
*
* OpenGL methods that require pixel dependent values e.g. glViewport, glTexImage2D,
* glReadPixels, etc can convert the scaled Display and Mouse coordinates to the
* correct high resolution value by multiplying them by the pixel scale factor.
*
* e.g. Display.getWidth() * Display.getPixelScaleFactor() will return the high DPI
* width of the OpenGL frame buffer. Whereas Display.getWidth() will be the same as
* the OpenGL frame buffer in non high DPI mode.
*
* Where high DPI mode is not available this method will just return 1.0f therefore
* not have any effect on values that are multiplied by it.
*/
public static float getPixelScaleFactor() {
return display_impl.getPixelScaleFactor();
}
} }

View File

@ -192,4 +192,9 @@ interface DisplayImplementation extends InputImplementation {
* @return this method will return the top-left y position of the Display window. * @return this method will return the top-left y position of the Display window.
*/ */
int getY(); int getY();
/**
* @return this method will return the pixel scale factor of the Display window useful for high resolution modes.
*/
float getPixelScaleFactor();
} }

View File

@ -1459,6 +1459,10 @@ final class LinuxDisplay implements DisplayImplementation {
return false; return false;
} }
public float getPixelScaleFactor() {
return 1f;
}
/** /**
* Helper class for managing Compiz's workarounds. We need this to enable Legacy * Helper class for managing Compiz's workarounds. We need this to enable Legacy
* Fullscreen Support in Compiz, else we'll have trouble with fullscreen windows * Fullscreen Support in Compiz, else we'll have trouble with fullscreen windows

View File

@ -622,5 +622,9 @@ final class MacOSXDisplay implements DisplayImplementation {
public boolean wasResized() { public boolean wasResized() {
return nWasResized(window); return nWasResized(window);
} }
public float getPixelScaleFactor() {
return 1f;
}
} }

View File

@ -1191,6 +1191,10 @@ final class WindowsDisplay implements DisplayImplementation {
} }
return false; return false;
} }
public float getPixelScaleFactor() {
return 1f;
}
private static final class Rect { private static final class Rect {
public int top; public int top;