modes = new HashSet<>(unfilteredModes.length);
+
+ for (DisplayMode mode : unfilteredModes) {
+ modes.add(mode);
+ }
+ DisplayMode[] filteredModes = new DisplayMode[modes.size()];
+ modes.toArray(filteredModes);
+
+ int n = unfilteredModes.length - filteredModes.length;
+ LWJGLUtil.logger().log(() -> "Removed " + n + " duplicate displaymodes");
+
+ return filteredModes;
}
/**
@@ -236,27 +239,29 @@ public final class Display {
* @throws LWJGLException if the display mode could not be set
*/
public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- if ( mode == null )
- throw new NullPointerException("mode must be non-null");
- boolean was_fullscreen = isFullscreen();
- current_mode = mode;
- if ( !isCreated() || parent != null )
- return;
- destroyWindow();
- // If mode is not fullscreen capable, make sure we are in windowed mode
- try {
- if ( was_fullscreen && !isFullscreen() )
- display_impl.resetDisplayMode();
- else if ( isFullscreen() )
- switchDisplayMode();
- createWindow();
- makeCurrentAndSetSwapInterval();
- } catch (LWJGLException e) {
- drawable.destroy();
+ Objects.requireNonNull(mode, "mode must be non-null");
+
+ if (mode == current_mode) return;
+
+ boolean was_fullscreen = isFullscreen();
+ current_mode = mode;
+
+ if (!isCreated() || parent != null) return;
+
+ destroyWindow();
+
+ // If mode is not fullscreen capable, make sure we are in windowed mode
+ try {
+ if ( was_fullscreen && !isFullscreen() )
display_impl.resetDisplayMode();
- throw e;
- }
+ else if ( isFullscreen() )
+ switchDisplayMode();
+ createWindow();
+ makeCurrentAndSetSwapInterval();
+ } catch (LWJGLException e) {
+ drawable.destroy();
+ display_impl.resetDisplayMode();
+ throw e;
}
}
@@ -370,37 +375,35 @@ public final class Display {
* @param contrast The contrast, larger than 0.0.
*/
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() ) {
- throw new LWJGLException("Display not yet created.");
- }
- if ( brightness < -1.0f || brightness > 1.0f )
- throw new IllegalArgumentException("Invalid brightness value");
- if ( contrast < 0.0f )
- throw new IllegalArgumentException("Invalid contrast value");
- int rampSize = display_impl.getGammaRampLength();
- if ( rampSize == 0 ) {
- throw new LWJGLException("Display configuration not supported");
- }
- FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
- for ( int i = 0; i < rampSize; i++ ) {
- float intensity = (float)i / (rampSize - 1);
- // apply gamma
- float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
- // apply brightness
- rampEntry += brightness;
- // apply contrast
- rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
- // Clamp entry to [0, 1]
- if ( rampEntry > 1.0f )
- rampEntry = 1.0f;
- else if ( rampEntry < 0.0f )
- rampEntry = 0.0f;
- gammaRamp.put(i, rampEntry);
- }
- display_impl.setGammaRamp(gammaRamp);
- LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
+ if ( !isCreated() ) {
+ throw new LWJGLException("Display not yet created.");
}
+ if ( brightness < -1.0f || brightness > 1.0f )
+ throw new IllegalArgumentException("Invalid brightness value");
+ if ( contrast < 0.0f )
+ throw new IllegalArgumentException("Invalid contrast value");
+ int rampSize = display_impl.getGammaRampLength();
+ if ( rampSize == 0 ) {
+ throw new LWJGLException("Display configuration not supported");
+ }
+ FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
+ for ( int i = 0; i < rampSize; i++ ) {
+ float intensity = (float)i / (rampSize - 1);
+ // apply gamma
+ float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
+ // apply brightness
+ rampEntry += brightness;
+ // apply contrast
+ rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
+ // Clamp entry to [0, 1]
+ if ( rampEntry > 1.0f )
+ rampEntry = 1.0f;
+ else if ( rampEntry < 0.0f )
+ rampEntry = 0.0f;
+ gammaRamp.put(i, rampEntry);
+ }
+ display_impl.setGammaRamp(gammaRamp);
+ LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
}
/**
@@ -434,25 +437,23 @@ public final class Display {
* the Dispaly will inherit the size of the parent, disregarding the currently set display mode.
*/
public static void setParent(Canvas parent) throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- if ( Display.parent != parent ) {
- Display.parent = parent;
- if ( !isCreated() )
- return;
- destroyWindow();
- try {
- if ( isFullscreen() ) {
- switchDisplayMode();
- } else {
- display_impl.resetDisplayMode();
- }
- createWindow();
- makeCurrentAndSetSwapInterval();
- } catch (LWJGLException e) {
- drawable.destroy();
+ if ( Display.parent != parent ) {
+ Display.parent = parent;
+ if ( !isCreated() )
+ return;
+ destroyWindow();
+ try {
+ if ( isFullscreen() ) {
+ switchDisplayMode();
+ } else {
display_impl.resetDisplayMode();
- throw e;
}
+ createWindow();
+ makeCurrentAndSetSwapInterval();
+ } catch (LWJGLException e) {
+ drawable.destroy();
+ display_impl.resetDisplayMode();
+ throw e;
}
}
}
@@ -489,30 +490,27 @@ public final class Display {
}
private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode) throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- if ( mode == null )
- throw new NullPointerException("mode must be non-null");
- DisplayMode old_mode = current_mode;
- current_mode = mode;
- boolean was_fullscreen = isFullscreen();
- Display.fullscreen = fullscreen;
- if ( was_fullscreen != isFullscreen() || !mode.equals(old_mode) ) {
- if ( !isCreated() )
- return;
- destroyWindow();
- try {
- if ( isFullscreen() ) {
- switchDisplayMode();
- } else {
- display_impl.resetDisplayMode();
- }
- createWindow();
- makeCurrentAndSetSwapInterval();
- } catch (LWJGLException e) {
- drawable.destroy();
+ if ( mode == null )
+ throw new NullPointerException("mode must be non-null");
+ DisplayMode old_mode = current_mode;
+ current_mode = mode;
+ boolean was_fullscreen = isFullscreen();
+ Display.fullscreen = fullscreen;
+ if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) {
+ if (!isCreated()) return;
+ destroyWindow();
+ try {
+ if ( isFullscreen() ) {
+ switchDisplayMode();
+ } else {
display_impl.resetDisplayMode();
- throw e;
}
+ createWindow();
+ makeCurrentAndSetSwapInterval();
+ } catch (LWJGLException e) {
+ drawable.destroy();
+ display_impl.resetDisplayMode();
+ throw e;
}
}
}
@@ -528,41 +526,37 @@ public final class Display {
* @param newTitle The new window title
*/
public static void setTitle(String newTitle) {
- synchronized ( GlobalLock.lock ) {
- if ( newTitle == null ) {
- newTitle = "";
- }
- title = newTitle;
- if ( isCreated() )
- display_impl.setTitle(title);
+ if ( newTitle == null ) {
+ newTitle = "";
+ }
+ title = newTitle;
+ if (isCreated()) {
+ display_impl.setTitle(title);
}
}
/** @return true if the user or operating system has asked the window to close */
public static boolean isCloseRequested() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Cannot determine close requested state of uncreated window");
- return display_impl.isCloseRequested();
+ if (!isCreated()) {
+ throw new IllegalStateException("Cannot determine close requested state of uncreated window");
}
+ return display_impl.isCloseRequested();
}
/** @return true if the window is visible, false if not */
public static boolean isVisible() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Cannot determine minimized state of uncreated window");
- return display_impl.isVisible();
+ if (!isCreated()) {
+ throw new IllegalStateException("Cannot determine minimized state of uncreated window");
}
+ return display_impl.isVisible();
}
/** @return true if window is active, that is, the foreground display of the operating system. */
public static boolean isActive() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Cannot determine focused state of uncreated window");
- return display_impl.isActive();
+ if (!isCreated()) {
+ throw new IllegalStateException("Cannot determine focused state of uncreated window");
}
+ return display_impl.isActive();
}
/**
@@ -576,11 +570,10 @@ public final class Display {
* and needs to repaint itself
*/
public static boolean isDirty() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Cannot determine dirty state of uncreated window");
- return display_impl.isDirty();
+ if (!isCreated()) {
+ throw new IllegalStateException("Cannot determine dirty state of uncreated window");
}
+ return display_impl.isDirty();
}
/**
@@ -589,12 +582,11 @@ public final class Display {
* this method if update() is called periodically.
*/
public static void processMessages() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Display not created");
-
- display_impl.update();
+ if (!isCreated()) {
+ throw new IllegalStateException("Display not created");
}
+
+ display_impl.update();
pollDevices();
}
@@ -605,14 +597,15 @@ public final class Display {
* @throws OpenGLException if an OpenGL error has occured since the last call to glGetError()
*/
public static void swapBuffers() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Display not created");
-
- if ( LWJGLUtil.DEBUG )
- drawable.checkGLError();
- drawable.swapBuffers();
+ if (!isCreated()) {
+ throw new IllegalStateException("Display not created");
}
+
+ if (LWJGLUtil.DEBUG) {
+ drawable.checkGLError();
+ }
+
+ drawable.swapBuffers();
}
/**
@@ -632,49 +625,49 @@ public final class Display {
* @param processMessages Poll input devices if true
*/
public static void update(boolean processMessages) {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- throw new IllegalStateException("Display not created");
+ if (!isCreated()) {
+ throw new IllegalStateException("Display not created");
+ }
- // We paint only when the window is visible or dirty
- if ( display_impl.isVisible() || display_impl.isDirty() ) {
- try {
- swapBuffers();
- } catch (LWJGLException e) {
- throw new RuntimeException(e);
- }
+ // We paint only when the window is visible or dirty
+ if (display_impl.isVisible() || display_impl.isDirty()) {
+ try {
+ swapBuffers();
+ } catch (LWJGLException e) {
+ throw new RuntimeException(e);
}
+ }
- window_resized = !isFullscreen() && parent == null && display_impl.wasResized();
+ window_resized = !isFullscreen() && parent == null && display_impl.wasResized();
- if ( window_resized ) {
- width = display_impl.getWidth();
- height = display_impl.getHeight();
- }
+ if (window_resized) {
+ width = display_impl.getWidth();
+ height = display_impl.getHeight();
+ }
- if ( parent_resized ) {
- reshape();
- parent_resized = false;
- window_resized = true;
- }
+ if (parent_resized) {
+ reshape();
+ parent_resized = false;
+ window_resized = true;
+ }
- if ( processMessages )
- processMessages();
+ if (processMessages) {
+ processMessages();
}
}
static void pollDevices() {
// Poll the input devices while we're here
- if ( Mouse.isCreated() ) {
+ if (Mouse.isCreated()) {
Mouse.poll();
Mouse.updateCursor();
}
- if ( Keyboard.isCreated() ) {
+ if (Keyboard.isCreated()) {
Keyboard.poll();
}
- if ( Controllers.isCreated() ) {
+ if (Controllers.isCreated()) {
Controllers.poll();
}
}
@@ -703,20 +696,16 @@ public final class Display {
}
private static void removeShutdownHook() {
- AccessController.doPrivileged(new PrivilegedAction