Reverted display mode selection

This commit is contained in:
Elias Naur 2003-03-19 12:41:28 +00:00
parent df1d611624
commit 0d620e9125
11 changed files with 100 additions and 126 deletions

View File

@ -110,13 +110,19 @@ public final class Display {
* destroyed. * destroyed.
* *
* @param displayMode A display mode to choose * @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 fullscreen Whether to create the display fullscreen
* @param title The title for the application * @param title The title for the application
* @throws Exception if the display mode could not be set * @throws Exception if the display mode could not be set
* @see #destroy() * @see #destroy()
*/ */
public static void create( public static void create(
DisplayMode displayMode, DisplayMode displayMode,
int alpha,
int depth,
int stencil,
boolean fullscreen, boolean fullscreen,
String title) String title)
throws Exception { throws Exception {
@ -129,9 +135,9 @@ public final class Display {
displayMode.height, displayMode.height,
displayMode.bpp, displayMode.bpp,
displayMode.freq, displayMode.freq,
displayMode.alpha, alpha,
displayMode.depth, depth,
displayMode.stencil, stencil,
fullscreen, fullscreen,
title)) { title)) {
throw new Exception("Failed to set display mode to " + displayMode); throw new Exception("Failed to set display mode to " + displayMode);
@ -274,4 +280,4 @@ public final class Display {
public static boolean isCloseRequested() { public static boolean isCloseRequested() {
return closeRequested; return closeRequested;
} }
} }

View File

@ -46,21 +46,18 @@ package org.lwjgl;
public final class DisplayMode { public final class DisplayMode {
/** properties of the display mode */ /** 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. * Construct a display mode.
* *
* @see Display * @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.width = width;
this.height = height; this.height = height;
this.bpp = bpp; this.bpp = bpp;
this.freq = freq; this.freq = freq;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
} }
/** /**
@ -77,10 +74,7 @@ public final class DisplayMode {
return dm.width == width return dm.width == width
&& dm.height == dm.height && dm.height == dm.height
&& dm.bpp == bpp && dm.bpp == bpp
&& dm.freq == freq && dm.freq == freq;
&& dm.alpha == alpha
&& dm.depth == depth
&& dm.stencil == stencil;
} }
/** /**
@ -89,7 +83,7 @@ public final class DisplayMode {
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
public int 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(bpp);
sb.append(" @"); sb.append(" @");
sb.append(freq); sb.append(freq);
sb.append("Hz "); sb.append("Hz");
sb.append(alpha);
sb.append("bit alpha, ");
sb.append(depth);
sb.append("bit depth, ");
sb.append(stencil);
sb.append("bit stencil");
return sb.toString(); return sb.toString();
} }
} }

View File

@ -83,7 +83,7 @@ public class ControllerCreationTest {
private void setupDisplay(boolean fullscreen) { private void setupDisplay(boolean fullscreen) {
try { try {
Display.create(displayMode, fullscreen, "MouseTest"); Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest");
gl = new GL(); gl = new GL();
gl.create(); gl.create();
@ -223,4 +223,4 @@ public class ControllerCreationTest {
ControllerCreationTest cct = new ControllerCreationTest(); ControllerCreationTest cct = new ControllerCreationTest();
cct.executeTest(); cct.executeTest();
} }
} }

View File

@ -83,7 +83,7 @@ public class MouseCreationTest {
private void setupDisplay(boolean fullscreen) { private void setupDisplay(boolean fullscreen) {
try { try {
Display.create(displayMode, fullscreen, "MouseTest"); Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest");
gl = new GL(); gl = new GL();
gl.create(); gl.create();
@ -226,4 +226,4 @@ public class MouseCreationTest {
MouseCreationTest mt = new MouseCreationTest(); MouseCreationTest mt = new MouseCreationTest();
mt.executeTest(); mt.executeTest();
} }
} }

View File

@ -90,7 +90,7 @@ public class MouseTest {
private void setupDisplay(boolean fullscreen) { private void setupDisplay(boolean fullscreen) {
try { try {
Display.create(displayMode, fullscreen, "MouseTest"); Display.create(displayMode, 0, 0, 0, fullscreen, "MouseTest");
gl = new GL(); gl = new GL();
gl.create(); gl.create();
@ -193,4 +193,4 @@ public class MouseTest {
MouseTest mt = new MouseTest(); MouseTest mt = new MouseTest();
mt.executeTest(); mt.executeTest();
} }
} }

View File

@ -92,7 +92,7 @@ public class MovingSoundTest extends BasicTest {
break; break;
} }
} }
Display.create(modes[mode], false, "MovingSoundTest"); Display.create(modes[mode], 0, 0, 0, false, "MovingSoundTest");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
exit(-1); exit(-1);
@ -256,4 +256,4 @@ public class MovingSoundTest extends BasicTest {
MovingSoundTest movingSoundTest = new MovingSoundTest(); MovingSoundTest movingSoundTest = new MovingSoundTest();
movingSoundTest.execute(args); movingSoundTest.execute(args);
} }
} }

View File

@ -63,7 +63,7 @@ public final class Game {
} }
//select above found displaymode //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."); System.out.println("Created display.");
} catch (Exception e) { } catch (Exception e) {
System.err.println("Failed to create display due to " + e); System.err.println("Failed to create display due to " + e);

View File

@ -81,7 +81,7 @@ public class Grass {
} }
// For now let's just pick a mode we're certain to have // 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."); System.out.println("Created display.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -12,7 +12,7 @@ extern "C" {
/* Inaccessible static: mode */ /* Inaccessible static: mode */
/* Inaccessible static: handle */ /* Inaccessible static: handle */
/* Inaccessible static: closeRequested */ /* Inaccessible static: closeRequested */
/* Inaccessible static: class_000240 */ /* Inaccessible static: class_00024org_00024lwjgl_00024Display */
/* /*
* Class: org_lwjgl_Display * Class: org_lwjgl_Display
* Method: nGetAvailableDisplayModes * Method: nGetAvailableDisplayModes

View File

@ -84,7 +84,7 @@ struct pixelformat {
int stencil; 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++) for (int i = 0; i < index; i++)
if (formats[i].bpp == bpp && if (formats[i].bpp == bpp &&
formats[i].depth == depth && formats[i].depth == depth &&
@ -114,7 +114,7 @@ static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen
int bpp, depth, alpha, stencil; int bpp, depth, alpha, stencil;
int val; int val;
if (glXGetFBConfigAttrib(disp, configs[i], GLX_RED_SIZE, &val) != 0) { if (glXGetFBConfigAttrib(disp, configs[i], GLX_RED_SIZE, &val) != 0) {
free(formats); ree(formats);
return NULL; return NULL;
} }
bpp = val; bpp = val;
@ -147,7 +147,7 @@ static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen
} }
return NULL; return NULL;
} }
*/
static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) {
int bpe; int bpe;
switch (bpp) { switch (bpp) {
@ -174,7 +174,7 @@ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth,
return glXChooseVisual(disp, screen, attriblist); 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); struct pixelformat *formats = getGLXAvailablePixelFormats(disp, screen, length);
if (formats != NULL) if (formats != NULL)
return formats; return formats;
@ -194,6 +194,7 @@ static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, i
} }
return formats; return formats;
} }
*/
static void waitMapped(Display *disp, Window win) { static void waitMapped(Display *disp, Window win) {
XEvent event; XEvent event;
@ -470,6 +471,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
} }
screen = DefaultScreen(disp); screen = DefaultScreen(disp);
int bpp = XDefaultDepth(disp, screen);
if (!loadGL(disp, screen)) { if (!loadGL(disp, screen)) {
#ifdef _DEBUG #ifdef _DEBUG
@ -486,19 +488,21 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
return NULL; return NULL;
} }
int num_pixelformats; 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 // Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
jobjectArray ret = env->NewObjectArray(num_modes*num_pixelformats, displayModeClass, NULL); jobjectArray ret = env->NewObjectArray(num_modes/**num_pixelformats*/, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V"); jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
for (i = 0; i < num_modes; i++) { 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); 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); 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); XFree(avail_modes);
XCloseDisplay(disp); XCloseDisplay(disp);
return ret; return ret;

View File

@ -288,125 +288,101 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
* Choose displaymodes using NT codepath (multiple displaydevices) * Choose displaymodes using NT codepath (multiple displaydevices)
*/ */
jobjectArray GetAvailableDisplayModesNT(JNIEnv * env) { jobjectArray GetAvailableDisplayModesNT(JNIEnv * env) {
int i = 0, j = 0, n = 0; int i = 0, j = 0, n = 0;
int AvailableModes = 0; int AvailableModes = 0;
DISPLAY_DEVICE DisplayDevice; DISPLAY_DEVICE DisplayDevice;
DEVMODE DevMode; DEVMODE DevMode;
DevMode.dmSize = sizeof(DEVMODE); DevMode.dmSize = sizeof(DEVMODE);
DisplayDevice.cb = sizeof(DISPLAY_DEVICE); DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
//enumerate all displays, and all of their displaymodes //enumerate all displays, and all of their displaymodes
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) {
if (DevMode.dmBitsPerPel <=8) { if (DevMode.dmBitsPerPel > 8) {
continue; AvailableModes++;
} }
AvailableModes++; }
} }
}
#ifdef _DEBUG #ifdef _DEBUG
printf("Found %d displaymodes\n", AvailableModes); printf("Found %d displaymodes\n", AvailableModes);
#endif #endif
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java // 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 // Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
// Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos. // Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos.
jobjectArray ret = env->NewObjectArray(AvailableModes * 16, displayModeClass, NULL); jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V"); jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
i = 0, j = 0, n = 0; i = 0, j = 0, n = 0;
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) { while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) { while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) {
// Filter out indexed modes // Filter out indexed modes
if (DevMode.dmBitsPerPel <= 8) { if (DevMode.dmBitsPerPel > 8) {
continue; jobject displayMode;
} else { displayMode = env->NewObject(displayModeClass, displayModeConstructor,
jobject displayMode; DevMode.dmPelsWidth, DevMode.dmPelsHeight,
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
for (int depthBits = 0; depthBits <= 24; depthBits += 8) { env->SetObjectArrayElement(ret, n++, displayMode);
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; return ret;
} }
/** /**
* Choose displaymodes using 9x codepath (single displaydevice) * Choose displaymodes using 9x codepath (single displaydevice)
*/ */
jobjectArray GetAvailableDisplayModes9x(JNIEnv * env) { jobjectArray GetAvailableDisplayModes9x(JNIEnv * env) {
int i = 0, j = 0, n = 0; int i = 0, j = 0, n = 0;
int AvailableModes = 0; int AvailableModes = 0;
DEVMODE DevMode; DEVMODE DevMode;
DevMode.dmSize = sizeof(DEVMODE); DevMode.dmSize = sizeof(DEVMODE);
//enumerate all displaymodes //enumerate all displaymodes
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
if (DevMode.dmBitsPerPel <=8) { if (DevMode.dmBitsPerPel > 8) {
continue; AvailableModes++;
} }
AvailableModes++; }
}
#ifdef _DEBUG #ifdef _DEBUG
printf("Found %d displaymodes\n", AvailableModes); printf("Found %d displaymodes\n", AvailableModes);
#endif #endif
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java // 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 // Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
// Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos. // Note the * 16 - this is because we are manufacturing available alpha/depth/stencil combos.
jobjectArray ret = env->NewObjectArray(AvailableModes * 16, displayModeClass, NULL); jobjectArray ret = env->NewObjectArray(AvailableModes * 16, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V"); jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
i = 0, j = 0, n = 0; i = 0, j = 0, n = 0;
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) { while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
// Filter out indexed modes // Filter out indexed modes
if (DevMode.dmBitsPerPel <= 8) { if (DevMode.dmBitsPerPel > 8) {
continue; jobject displayMode;
} else { displayMode = env->NewObject(displayModeClass, displayModeConstructor,
jobject displayMode; DevMode.dmPelsWidth, DevMode.dmPelsHeight,
for (int depthBits = 0; depthBits <= 24; depthBits += 8) { DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
for (int stencilBits = 0; stencilBits <= 8; stencilBits += 8) { env->SetObjectArrayElement(ret, n++, displayMode);
for (int alphaBits = 0; alphaBits <= 8; alphaBits += 8) { }
}
displayMode = env->NewObject( displayModeClass, displayModeConstructor, return ret;
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency,
alphaBits, depthBits, stencilBits);
env->SetObjectArrayElement(ret, n++, displayMode);
}
}
}
}
}
return ret;
} }
/* /*
* Class: org_lwjgl_Display * Class: org_lwjgl_Display
* Method: nCreate * Method: nCreate
* Signature: (IIIIZ)Z * Signature: (IIIIIIIZLjava/lang/String;)Z
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq,