New getPlatform() method added

This commit is contained in:
Caspian Rychlik-Prince 2003-03-21 17:08:26 +00:00
parent 8575ae0496
commit c6a231cf43
8 changed files with 113 additions and 92 deletions

View File

@ -63,6 +63,20 @@ public final class Display {
/** Whether or not the display has been requested to shutdown by the user */
private static boolean closeRequested = false;
/*
* Platforms. This will let you determine which platform you are running
* on, which is handy to know for some GL context calls.
*/
/** Windows platform */
public static final int PLATFORM_WGL = 0;
/** GLX (Linux/Unix) platform */
public static final int PLATFORM_GLX = 1;
/** MacOSX platform */
public static final int PLATFORM_AGL = 2;
/**
* No construction allowed.
*/
@ -79,30 +93,30 @@ public final class Display {
* @return an array of all display modes the system reckons it can handle.
*/
public static DisplayMode[] getAvailableDisplayModes() {
DisplayMode[] unfilteredModes = nGetAvailableDisplayModes();
DisplayMode[] unfilteredModes = nGetAvailableDisplayModes();
if (unfilteredModes == null) {
return new DisplayMode[0];
}
// We'll use a HashSet to filter out the duplicated modes
HashSet modes = new HashSet(unfilteredModes.length);
modes.addAll(Arrays.asList(unfilteredModes));
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
modes.toArray(filteredModes);
if(Sys.DEBUG) {
System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
}
return filteredModes;
if (unfilteredModes == null) {
return new DisplayMode[0];
}
// We'll use a HashSet to filter out the duplicated modes
HashSet modes = new HashSet(unfilteredModes.length);
modes.addAll(Arrays.asList(unfilteredModes));
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
modes.toArray(filteredModes);
if (Sys.DEBUG) {
System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
}
return filteredModes;
}
/**
* Native method for getting displaymodes
*/
public static native DisplayMode[] nGetAvailableDisplayModes();
/**
* Native method for getting displaymodes
*/
public static native DisplayMode[] nGetAvailableDisplayModes();
/**
* Create a display with the specified display mode. If the display is
@ -118,13 +132,7 @@ public final class Display {
* @throws Exception if the display mode could not be set
* @see #destroy()
*/
public static void create(
DisplayMode displayMode,
int alpha,
int depth,
int stencil,
boolean fullscreen,
String title)
public static void create(DisplayMode displayMode, int alpha, int depth, int stencil, boolean fullscreen, String title)
throws Exception {
if (created) {
@ -280,4 +288,16 @@ public final class Display {
public static boolean isCloseRequested() {
return closeRequested;
}
/**
* Returns the operating system windowing platform. This will be one of the
* constants defined above. There is no "unknown" platform; a native library port
* has to provide a unique platform number for this mechanism to work. If the LWJGL
* is ported to, say, QNX, we will have a PLATFORM_QNX at the ready.
*
* @return the windowing system
*/
public static native int getPlatform();
}

View File

@ -32,6 +32,10 @@
package org.lwjgl;
import java.nio.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* $Id$
*
@ -790,13 +794,36 @@ public final class Math {
return (float) java.lang.Math.toDegrees(java.lang.Math.atan(theta));
}
/* We use NIO to do our bit fiddling */
private static final ByteBuffer sqrtByteBuf = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder());
private static final IntBuffer sqrtIntBuf = sqrtByteBuf.asIntBuffer();
private static final FloatBuffer sqrtFloatBuf = sqrtByteBuf.asFloatBuffer();
/**
* Return the square root of a value
* @param n the number for which you want the square root
* @return sqrt(n)
* Approximate inverse square root function (Newton-Raphson?). This is a very approximate
* root, accurate to maybe 1 or 2 dp.
* @param x
* @return ~x^0.5
*/
public static float sqrt(float n) {
return (float) java.lang.Math.sqrt(n);
public static float invsqrt(float x) {
float xhalf = 0.5f * x;
sqrtFloatBuf.put(0, x);
int i = sqrtIntBuf.get(0);
i = 0x5f375a86 - (i >> 1);
sqrtIntBuf.put(0, i);
x = sqrtFloatBuf.get(0);
x *= (1.5f - xhalf * x * x); // This line may be duplicated for more accuracy.
return x;
}
/**
* Approximate square root function (Newton-Raphson?). This is a very approximate
* root, accurate to maybe 1 or 2 dp.
* @param x
* @return ~x^0.5
*/
public static float sqrt(float x) {
return 1.0f / invsqrt(x);
}
/*
@ -1100,5 +1127,6 @@ public final class Math {
);
}
}

View File

@ -101,20 +101,7 @@ public final class Sys {
}
}
/*
* Platforms. This will let you determine which platform you are running
* on, which is handy to know for some GL calls.
*/
/** Windows platform */
public static final int PLATFORM_WGL = 0;
/** GLX (Linux/Unix) platform */
public static final int PLATFORM_GLX = 1;
/** MacOSX platform */
public static final int PLATFORM_AGL = 2;
/**
* @return the name of the native library to load
*/
@ -223,14 +210,4 @@ public final class Sys {
*/
public static native void alert(String title, String message);
/**
* Returns the operating system windowing platform. This will be one of the
* constants defined above. There is no "unknown" platform; a native library port
* has to provide a unique platform number for this mechanism to work. If the LWJGL
* is ported to, say, QNX, we will have a PLATFORM_QNX at the ready.
*
* @return the windowing system
*/
public static native int getPlatform();
}

View File

@ -189,4 +189,5 @@ abstract class BaseGL {
&& currentContext == this
&& Thread.currentThread() == renderThread;
}
}

View File

@ -12,7 +12,13 @@ extern "C" {
/* Inaccessible static: mode */
/* Inaccessible static: handle */
/* Inaccessible static: closeRequested */
/* Inaccessible static: class_00024org_00024lwjgl_00024Display */
#undef org_lwjgl_Display_PLATFORM_WGL
#define org_lwjgl_Display_PLATFORM_WGL 0L
#undef org_lwjgl_Display_PLATFORM_GLX
#define org_lwjgl_Display_PLATFORM_GLX 1L
#undef org_lwjgl_Display_PLATFORM_AGL
#define org_lwjgl_Display_PLATFORM_AGL 2L
/* Inaccessible static: class_000240 */
/*
* Class: org_lwjgl_Display
* Method: nGetAvailableDisplayModes
@ -45,6 +51,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: getPlatform
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif

View File

@ -19,12 +19,6 @@ extern "C" {
/* Inaccessible static: LIBRARY_NAME */
/* Inaccessible static: DEBUG */
/* Inaccessible static: _debug */
#undef org_lwjgl_Sys_PLATFORM_WGL
#define org_lwjgl_Sys_PLATFORM_WGL 0L
#undef org_lwjgl_Sys_PLATFORM_GLX
#define org_lwjgl_Sys_PLATFORM_GLX 1L
#undef org_lwjgl_Sys_PLATFORM_AGL
#define org_lwjgl_Sys_PLATFORM_AGL 2L
/* Inaccessible static: class_000240 */
/*
* Class: org_lwjgl_Sys
@ -82,14 +76,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
(JNIEnv *, jclass, jstring, jstring);
/*
* Class: org_lwjgl_Sys
* Method: getPlatform
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_Sys_getPlatform
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif

View File

@ -536,14 +536,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
0, 0, 0 // layer masks ignored
};
// Ensure desktop color depth is adequate
int availableBitDepth = GetDeviceCaps(hdc, BITSPIXEL);
if (availableBitDepth < bpp) {
printf("This application requires a greater colour depth.\n");
destroyAll();
return JNI_FALSE;
};
int iPixelFormat;
// get the best available match of pixel format for the device context
@ -561,11 +553,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
return JNI_FALSE;
}
/*
if (desc.cColorBits < bpp) {
printf("This application requires a greater colour depth.\n");
destroyAll();
return JNI_FALSE;
}
*/
if (desc.cAlphaBits < alphaBits) {
printf("This application requires a greater alpha depth.\n");
@ -643,3 +637,16 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized
return isMinimized ? JNI_TRUE : JNI_FALSE;
}
/*
* Class: org_lwjgl_Display
* Method: getPlatform
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
(JNIEnv * env, jclass clazz)
{
return org_lwjgl_Display_PLATFORM_WGL;
}

View File

@ -163,15 +163,3 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
env->ReleaseStringUTFChars(message, eMessageText);
env->ReleaseStringUTFChars(title, cTitleBarText);
}
/*
* Class: org_lwjgl_Sys
* Method: getPlatform
* Signature: ()I
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_getPlatform
(JNIEnv * env, jclass clazz)
{
return org_lwjgl_Sys_PLATFORM_WGL;
}