From b88624e60850fbc58d384eeb86372737fb17ec23 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 9 Aug 2004 11:55:48 +0000 Subject: [PATCH] Add a public DisplayMode constructor --- src/java/org/lwjgl/opengl/Display.java | 20 ++++++++++---- src/java/org/lwjgl/opengl/DisplayMode.java | 27 ++++++++++++++++--- src/native/common/org_lwjgl_opengl_Display.h | 5 ++-- src/native/linux/org_lwjgl_opengl_Display.cpp | 2 +- src/native/win32/org_lwjgl_opengl_Display.cpp | 2 +- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java index 122c558b..91d7388a 100644 --- a/src/java/org/lwjgl/opengl/Display.java +++ b/src/java/org/lwjgl/opengl/Display.java @@ -104,10 +104,12 @@ public final class Display { } /** - * Returns the entire list of display modes as an array, in no + * Returns the entire list of possible fullscreen display modes as an array, in no * particular order. Any given mode is not guaranteed to be available and * the only certain way to check is to call create() and make sure it works. * Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). + * Only DisplayModes from this call can be used when the Display is in fullscreen + * mode. * * @return an array of all display modes the system reckons it can handle. */ @@ -161,7 +163,7 @@ public final class Display { destroyWindow(); try { if (fullscreen) - switchDisplayMode(mode); + switchDisplayMode(); createWindow(); } catch (LWJGLException e) { destroyContext(); @@ -200,7 +202,13 @@ public final class Display { private static native void nDestroyWindow(); - private static native void switchDisplayMode(DisplayMode mode) throws LWJGLException; + private static void switchDisplayMode() throws LWJGLException { + if (!current_mode.isFullscreen()) + throw new LWJGLException("The current DisplayMode instance cannot be used for fullscreen mode"); + nSwitchDisplayMode(current_mode); + } + + private static native void nSwitchDisplayMode(DisplayMode mode) throws LWJGLException; /** * Reset the display mode to whatever it was when LWJGL was initialized. @@ -353,6 +361,8 @@ public final class Display { * mode returned by getDisplayMode(). The native cursor position is also reset. * * @param fullscreen Specify the fullscreen mode of the context. + * @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not + * from getAvailableDisplayModes() or if the mode switch fails. */ public static void setFullscreen(boolean fullscreen) throws LWJGLException { if (Display.fullscreen != fullscreen) { @@ -362,7 +372,7 @@ public final class Display { destroyWindow(); try { if (fullscreen) - switchDisplayMode(current_mode); + switchDisplayMode(); else resetDisplayMode(); createWindow(); @@ -537,7 +547,7 @@ public final class Display { if (isCreated()) throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time."); if (fullscreen) - switchDisplayMode(current_mode); + switchDisplayMode(); try { GLContext.loadOpenGLLibrary(); try { diff --git a/src/java/org/lwjgl/opengl/DisplayMode.java b/src/java/org/lwjgl/opengl/DisplayMode.java index 055ef33a..6f395994 100644 --- a/src/java/org/lwjgl/opengl/DisplayMode.java +++ b/src/java/org/lwjgl/opengl/DisplayMode.java @@ -46,17 +46,38 @@ public final class DisplayMode { /** properties of the display mode */ private final int width, height, bpp, freq; + /** If true, this instance can be used for fullscreen modes */ + private final boolean fullscreen; /** - * Construct a display mode. - * + * Construct a display mode. DisplayModes constructed through the + * public constructor can only be used to specify the dimensions of + * the Display in windowed mode. To get the available DisplayModes for + * fullscreen modes, use Display.getAvailableDisplayModes(). + * + * @param width The Display width. + * @param height The Display height. * @see Display */ - private DisplayMode(int width, int height, int bpp, int freq) { + public DisplayMode(int width, int height) { + this(width, height, 0, 0, false); + } + + DisplayMode(int width, int height, int bpp, int freq) { + this(width, height, bpp, freq, true); + } + + private DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen) { this.width = width; this.height = height; this.bpp = bpp; this.freq = freq; + this.fullscreen = fullscreen; + } + + /** True iff this instance can be used for fullscreen modes */ + boolean isFullscreen() { + return fullscreen; } public int getWidth() { diff --git a/src/native/common/org_lwjgl_opengl_Display.h b/src/native/common/org_lwjgl_opengl_Display.h index c38e4256..92d5fd44 100644 --- a/src/native/common/org_lwjgl_opengl_Display.h +++ b/src/native/common/org_lwjgl_opengl_Display.h @@ -14,7 +14,6 @@ extern "C" { /* Inaccessible static: title */ /* Inaccessible static: fullscreen */ /* Inaccessible static: vsync */ -/* Inaccessible static: vbo_tracker */ /* Inaccessible static: context */ /* Inaccessible static: timeLate */ /* @@ -43,10 +42,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow /* * Class: org_lwjgl_opengl_Display - * Method: switchDisplayMode + * Method: nSwitchDisplayMode * Signature: (Lorg/lwjgl/opengl/DisplayMode;)V */ -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode (JNIEnv *, jclass, jobject); /* diff --git a/src/native/linux/org_lwjgl_opengl_Display.cpp b/src/native/linux/org_lwjgl_opengl_Display.cpp index 6d628f8e..ea64f410 100644 --- a/src/native/linux/org_lwjgl_opengl_Display.cpp +++ b/src/native/linux/org_lwjgl_opengl_Display.cpp @@ -602,7 +602,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDispla return getAvailableDisplayModes(env); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) { switchDisplayMode(env, mode); } diff --git a/src/native/win32/org_lwjgl_opengl_Display.cpp b/src/native/win32/org_lwjgl_opengl_Display.cpp index 447b9b60..60e782fd 100644 --- a/src/native/win32/org_lwjgl_opengl_Display.cpp +++ b/src/native/win32/org_lwjgl_opengl_Display.cpp @@ -615,7 +615,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env, closeWindow(display_hwnd, display_hdc); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) { switchDisplayMode(env, mode); }