diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java index 4bc34b4f..61763fe0 100644 --- a/src/java/org/lwjgl/Display.java +++ b/src/java/org/lwjgl/Display.java @@ -110,13 +110,19 @@ public final class Display { * destroyed. * * @param displayMode A display mode to choose + * @param alpha Minimun number of alpha bits on the display + * @param depth Minimun number of depth bits on the display + * @param stencil Minimun number of stencil bits on the display * @param fullscreen Whether to create the display fullscreen * @param title The title for the application * @throws Exception if the display mode could not be set * @see #destroy() */ public static void create( - DisplayMode displayMode, + DisplayMode displayMode, + int alpha, + int depth, + int stencil, boolean fullscreen, String title) throws Exception { @@ -129,9 +135,9 @@ public final class Display { displayMode.height, displayMode.bpp, displayMode.freq, - displayMode.alpha, - displayMode.depth, - displayMode.stencil, + alpha, + depth, + stencil, fullscreen, title)) { throw new Exception("Failed to set display mode to " + displayMode); @@ -274,4 +280,4 @@ public final class Display { public static boolean isCloseRequested() { return closeRequested; } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/DisplayMode.java b/src/java/org/lwjgl/DisplayMode.java index e924252b..4051c1a6 100644 --- a/src/java/org/lwjgl/DisplayMode.java +++ b/src/java/org/lwjgl/DisplayMode.java @@ -46,21 +46,18 @@ package org.lwjgl; public final class DisplayMode { /** properties of the display mode */ - public final int width, height, bpp, freq, alpha, depth, stencil; + public final int width, height, bpp, freq; /** * Construct a display mode. * * @see Display */ - private DisplayMode(int width, int height, int bpp, int freq, int alpha, int depth, int stencil) { + private DisplayMode(int width, int height, int bpp, int freq) { this.width = width; this.height = height; this.bpp = bpp; this.freq = freq; - this.alpha = alpha; - this.depth = depth; - this.stencil = stencil; } /** @@ -77,10 +74,7 @@ public final class DisplayMode { return dm.width == width && dm.height == dm.height && dm.bpp == bpp - && dm.freq == freq - && dm.alpha == alpha - && dm.depth == depth - && dm.stencil == stencil; + && dm.freq == freq; } /** @@ -89,7 +83,7 @@ public final class DisplayMode { * @see java.lang.Object#hashCode() */ public int hashCode() { - return width ^ height ^ freq ^ bpp ^ alpha ^ (depth << 8) ^ (stencil << 24); + return width ^ height ^ freq ^ bpp; } /** @@ -106,13 +100,7 @@ public final class DisplayMode { sb.append(bpp); sb.append(" @"); sb.append(freq); - sb.append("Hz "); - sb.append(alpha); - sb.append("bit alpha, "); - sb.append(depth); - sb.append("bit depth, "); - sb.append(stencil); - sb.append("bit stencil"); + sb.append("Hz"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/test/input/ControllerCreationTest.java b/src/java/org/lwjgl/test/input/ControllerCreationTest.java index a3fc19e3..4af967d4 100644 --- a/src/java/org/lwjgl/test/input/ControllerCreationTest.java +++ b/src/java/org/lwjgl/test/input/ControllerCreationTest.java @@ -83,7 +83,7 @@ public class ControllerCreationTest { private void setupDisplay(boolean fullscreen) { try { - Display.create(displayMode, fullscreen, "MouseTest"); + Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest"); gl = new GL(); gl.create(); @@ -223,4 +223,4 @@ public class ControllerCreationTest { ControllerCreationTest cct = new ControllerCreationTest(); cct.executeTest(); } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/test/input/MouseCreationTest.java b/src/java/org/lwjgl/test/input/MouseCreationTest.java index 51f754db..60c91d1e 100644 --- a/src/java/org/lwjgl/test/input/MouseCreationTest.java +++ b/src/java/org/lwjgl/test/input/MouseCreationTest.java @@ -83,7 +83,7 @@ public class MouseCreationTest { private void setupDisplay(boolean fullscreen) { try { - Display.create(displayMode, fullscreen, "MouseTest"); + Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest"); gl = new GL(); gl.create(); @@ -226,4 +226,4 @@ public class MouseCreationTest { MouseCreationTest mt = new MouseCreationTest(); mt.executeTest(); } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/test/input/MouseTest.java b/src/java/org/lwjgl/test/input/MouseTest.java index 02182f20..6aba7c5a 100644 --- a/src/java/org/lwjgl/test/input/MouseTest.java +++ b/src/java/org/lwjgl/test/input/MouseTest.java @@ -90,7 +90,7 @@ public class MouseTest { private void setupDisplay(boolean fullscreen) { try { - Display.create(displayMode, fullscreen, "MouseTest"); + Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest"); gl = new GL(); gl.create(); @@ -193,4 +193,4 @@ public class MouseTest { MouseTest mt = new MouseTest(); mt.executeTest(); } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/test/openal/MovingSoundTest.java b/src/java/org/lwjgl/test/openal/MovingSoundTest.java index 228a356a..8341f2fa 100644 --- a/src/java/org/lwjgl/test/openal/MovingSoundTest.java +++ b/src/java/org/lwjgl/test/openal/MovingSoundTest.java @@ -92,7 +92,7 @@ public class MovingSoundTest extends BasicTest { break; } } - Display.create(modes[mode], false, "MovingSoundTest"); + Display.create(modes[mode], 0, 0, 0, false, "MovingSoundTest"); } catch (Exception e) { e.printStackTrace(); exit(-1); @@ -256,4 +256,4 @@ public class MovingSoundTest extends BasicTest { MovingSoundTest movingSoundTest = new MovingSoundTest(); movingSoundTest.execute(args); } -} \ No newline at end of file +} diff --git a/src/java/org/lwjgl/test/opengl/Game.java b/src/java/org/lwjgl/test/opengl/Game.java index 3cdbdfa1..b97ca899 100644 --- a/src/java/org/lwjgl/test/opengl/Game.java +++ b/src/java/org/lwjgl/test/opengl/Game.java @@ -63,7 +63,7 @@ public final class Game { } //select above found displaymode - Display.create(modes[mode], false, "LWJGL Game Example"); + Display.create(modes[mode], 0, 16, 0, false, "LWJGL Game Example"); System.out.println("Created display."); } catch (Exception e) { System.err.println("Failed to create display due to " + e); diff --git a/src/java/org/lwjgl/test/opengl/Grass.java b/src/java/org/lwjgl/test/opengl/Grass.java index 707d5a19..d1a21fea 100644 --- a/src/java/org/lwjgl/test/opengl/Grass.java +++ b/src/java/org/lwjgl/test/opengl/Grass.java @@ -81,7 +81,7 @@ public class Grass { } // For now let's just pick a mode we're certain to have - Display.create(modes[mode], false, "Grass"); + Display.create(modes[mode], 0, 16, 0, false, "Grass"); System.out.println("Created display."); } catch (Exception e) { e.printStackTrace(); diff --git a/src/native/common/org_lwjgl_Display.h b/src/native/common/org_lwjgl_Display.h index fc994e88..8fd828d0 100644 --- a/src/native/common/org_lwjgl_Display.h +++ b/src/native/common/org_lwjgl_Display.h @@ -12,7 +12,7 @@ extern "C" { /* Inaccessible static: mode */ /* Inaccessible static: handle */ /* Inaccessible static: closeRequested */ -/* Inaccessible static: class_000240 */ +/* Inaccessible static: class_00024org_00024lwjgl_00024Display */ /* * Class: org_lwjgl_Display * Method: nGetAvailableDisplayModes diff --git a/src/native/linux/org_lwjgl_Display.cpp b/src/native/linux/org_lwjgl_Display.cpp index 4afeafed..a185090e 100644 --- a/src/native/linux/org_lwjgl_Display.cpp +++ b/src/native/linux/org_lwjgl_Display.cpp @@ -84,7 +84,7 @@ struct pixelformat { int stencil; }; -static int fillFormat(struct pixelformat *formats, int index, int bpp, int depth, int alpha, int stencil) { +/*static int fillFormat(struct pixelformat *formats, int index, int bpp, int depth, int alpha, int stencil) { for (int i = 0; i < index; i++) if (formats[i].bpp == bpp && formats[i].depth == depth && @@ -114,7 +114,7 @@ static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen int bpp, depth, alpha, stencil; int val; if (glXGetFBConfigAttrib(disp, configs[i], GLX_RED_SIZE, &val) != 0) { - free(formats); + ree(formats); return NULL; } bpp = val; @@ -147,7 +147,7 @@ static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen } return NULL; } - +*/ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { int bpe; switch (bpp) { @@ -174,7 +174,7 @@ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, return glXChooseVisual(disp, screen, attriblist); } -static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, int *length) { +/*static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, int *length) { struct pixelformat *formats = getGLXAvailablePixelFormats(disp, screen, length); if (formats != NULL) return formats; @@ -194,6 +194,7 @@ static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, i } return formats; } +*/ static void waitMapped(Display *disp, Window win) { XEvent event; @@ -470,6 +471,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes } screen = DefaultScreen(disp); + int bpp = XDefaultDepth(disp, screen); if (!loadGL(disp, screen)) { #ifdef _DEBUG @@ -486,19 +488,21 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes return NULL; } int num_pixelformats; - struct pixelformat *formats = getAvailablePixelFormats(disp, screen, &num_pixelformats); +// struct pixelformat *formats = getAvailablePixelFormats(disp, screen, &num_pixelformats); // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); - jobjectArray ret = env->NewObjectArray(num_modes*num_pixelformats, displayModeClass, NULL); - jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIIIIII)V"); + jobjectArray ret = env->NewObjectArray(num_modes/**num_pixelformats*/, displayModeClass, NULL); + jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIII)V"); for (i = 0; i < num_modes; i++) { - for (int j = 0; j < num_pixelformats; j++) { +/* for (int j = 0; j < num_pixelformats; j++) { jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay, formats[j].bpp, 0, formats[j].alpha, formats[j].depth, formats[j].stencil); env->SetObjectArrayElement(ret, i*num_pixelformats + j, displayMode); - } + }*/ + jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay, bpp, 0); + env->SetObjectArrayElement(ret, i, displayMode); } - free(formats); +// free(formats); XFree(avail_modes); XCloseDisplay(disp); return ret; diff --git a/src/native/win32/org_lwjgl_Display.cpp b/src/native/win32/org_lwjgl_Display.cpp index 89362ab8..54b58939 100644 --- a/src/native/win32/org_lwjgl_Display.cpp +++ b/src/native/win32/org_lwjgl_Display.cpp @@ -288,125 +288,101 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes * Choose displaymodes using NT codepath (multiple displaydevices) */ jobjectArray GetAvailableDisplayModesNT(JNIEnv * env) { - int i = 0, j = 0, n = 0; - int AvailableModes = 0; + int i = 0, j = 0, n = 0; + int AvailableModes = 0; - DISPLAY_DEVICE DisplayDevice; - DEVMODE DevMode; + DISPLAY_DEVICE DisplayDevice; + DEVMODE DevMode; - DevMode.dmSize = sizeof(DEVMODE); - DisplayDevice.cb = sizeof(DISPLAY_DEVICE); + DevMode.dmSize = sizeof(DEVMODE); + DisplayDevice.cb = sizeof(DISPLAY_DEVICE); //enumerate all displays, and all of their displaymodes - while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { - while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { - if (DevMode.dmBitsPerPel <=8) { - continue; - } - AvailableModes++; - } - } + while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { + while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { + if (DevMode.dmBitsPerPel > 8) { + AvailableModes++; + } + } + } #ifdef _DEBUG - printf("Found %d displaymodes\n", AvailableModes); + printf("Found %d displaymodes\n", AvailableModes); #endif - // now that we have the count create the classes, and add 'em all - we'll remove dups in Java - // Allocate an array of DisplayModes big enough + // now that we have the count create the classes, and add 'em all - we'll remove dups in Java + // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); // Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos. - jobjectArray ret = env->NewObjectArray(AvailableModes * 16, displayModeClass, NULL); - jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIIIIII)V"); + jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL); + jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIII)V"); - i = 0, j = 0, n = 0; - while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { - while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { - // Filter out indexed modes - if (DevMode.dmBitsPerPel <= 8) { - continue; - } else { - jobject displayMode; + i = 0, j = 0, n = 0; + while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { + while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { + // Filter out indexed modes + if (DevMode.dmBitsPerPel > 8) { + jobject displayMode; + displayMode = env->NewObject(displayModeClass, displayModeConstructor, + DevMode.dmPelsWidth, DevMode.dmPelsHeight, + DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency); - for (int depthBits = 0; depthBits <= 24; depthBits += 8) { - for (int stencilBits = 0; stencilBits <= 8; stencilBits += 8) { - for (int alphaBits = 0; alphaBits <= 8; alphaBits += 8) { - - displayMode = env->NewObject( displayModeClass, displayModeConstructor, - DevMode.dmPelsWidth, DevMode.dmPelsHeight, - DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency, - alphaBits, depthBits, stencilBits); - - env->SetObjectArrayElement(ret, n++, displayMode); - } - } - } + env->SetObjectArrayElement(ret, n++, displayMode); } - } - } - return ret; + } + } + return ret; } /** * Choose displaymodes using 9x codepath (single displaydevice) */ jobjectArray GetAvailableDisplayModes9x(JNIEnv * env) { - int i = 0, j = 0, n = 0; - int AvailableModes = 0; + int i = 0, j = 0, n = 0; + int AvailableModes = 0; - DEVMODE DevMode; + DEVMODE DevMode; - DevMode.dmSize = sizeof(DEVMODE); + DevMode.dmSize = sizeof(DEVMODE); - //enumerate all displaymodes - while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { - if (DevMode.dmBitsPerPel <=8) { - continue; - } - AvailableModes++; - } + //enumerate all displaymodes + while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { + if (DevMode.dmBitsPerPel > 8) { + AvailableModes++; + } + } #ifdef _DEBUG - printf("Found %d displaymodes\n", AvailableModes); + printf("Found %d displaymodes\n", AvailableModes); #endif - // now that we have the count create the classes, and add 'em all - we'll remove dups in Java - // Allocate an array of DisplayModes big enough + // now that we have the count create the classes, and add 'em all - we'll remove dups in Java + // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); // Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos. jobjectArray ret = env->NewObjectArray(AvailableModes * 16, displayModeClass, NULL); - jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIIIIII)V"); + jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIII)V"); - i = 0, j = 0, n = 0; - while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { - // Filter out indexed modes - if (DevMode.dmBitsPerPel <= 8) { - continue; - } else { - jobject displayMode; - for (int depthBits = 0; depthBits <= 24; depthBits += 8) { - for (int stencilBits = 0; stencilBits <= 8; stencilBits += 8) { - for (int alphaBits = 0; alphaBits <= 8; alphaBits += 8) { - - displayMode = env->NewObject( displayModeClass, displayModeConstructor, - DevMode.dmPelsWidth, DevMode.dmPelsHeight, - DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency, - alphaBits, depthBits, stencilBits); - - env->SetObjectArrayElement(ret, n++, displayMode); - } - } - } - } - } - return ret; + i = 0, j = 0, n = 0; + while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { + // Filter out indexed modes + if (DevMode.dmBitsPerPel > 8) { + jobject displayMode; + displayMode = env->NewObject(displayModeClass, displayModeConstructor, + DevMode.dmPelsWidth, DevMode.dmPelsHeight, + DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency); + env->SetObjectArrayElement(ret, n++, displayMode); + } + } + return ret; } /* * Class: org_lwjgl_Display * Method: nCreate - * Signature: (IIIIZ)Z + * Signature: (IIIIIIIZLjava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq,