New getPlatform() method added
This commit is contained in:
parent
8575ae0496
commit
c6a231cf43
|
@ -63,6 +63,20 @@ public final class Display {
|
||||||
/** Whether or not the display has been requested to shutdown by the user */
|
/** Whether or not the display has been requested to shutdown by the user */
|
||||||
private static boolean closeRequested = false;
|
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.
|
* No construction allowed.
|
||||||
*/
|
*/
|
||||||
|
@ -79,30 +93,30 @@ public final class Display {
|
||||||
* @return an array of all display modes the system reckons it can handle.
|
* @return an array of all display modes the system reckons it can handle.
|
||||||
*/
|
*/
|
||||||
public static DisplayMode[] getAvailableDisplayModes() {
|
public static DisplayMode[] getAvailableDisplayModes() {
|
||||||
DisplayMode[] unfilteredModes = nGetAvailableDisplayModes();
|
DisplayMode[] unfilteredModes = nGetAvailableDisplayModes();
|
||||||
|
|
||||||
if (unfilteredModes == null) {
|
if (unfilteredModes == null) {
|
||||||
return new DisplayMode[0];
|
return new DisplayMode[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll use a HashSet to filter out the duplicated modes
|
// We'll use a HashSet to filter out the duplicated modes
|
||||||
HashSet modes = new HashSet(unfilteredModes.length);
|
HashSet modes = new HashSet(unfilteredModes.length);
|
||||||
|
|
||||||
modes.addAll(Arrays.asList(unfilteredModes));
|
modes.addAll(Arrays.asList(unfilteredModes));
|
||||||
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
||||||
modes.toArray(filteredModes);
|
modes.toArray(filteredModes);
|
||||||
|
|
||||||
if(Sys.DEBUG) {
|
if (Sys.DEBUG) {
|
||||||
System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
|
System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredModes;
|
return filteredModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Native method for getting displaymodes
|
* Native method for getting displaymodes
|
||||||
*/
|
*/
|
||||||
public static native DisplayMode[] nGetAvailableDisplayModes();
|
public static native DisplayMode[] nGetAvailableDisplayModes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a display with the specified display mode. If the display is
|
* 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
|
* @throws Exception if the display mode could not be set
|
||||||
* @see #destroy()
|
* @see #destroy()
|
||||||
*/
|
*/
|
||||||
public static void create(
|
public static void create(DisplayMode displayMode, int alpha, int depth, int stencil, boolean fullscreen, String title)
|
||||||
DisplayMode displayMode,
|
|
||||||
int alpha,
|
|
||||||
int depth,
|
|
||||||
int stencil,
|
|
||||||
boolean fullscreen,
|
|
||||||
String title)
|
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (created) {
|
if (created) {
|
||||||
|
@ -280,4 +288,16 @@ public final class Display {
|
||||||
public static boolean isCloseRequested() {
|
public static boolean isCloseRequested() {
|
||||||
return closeRequested;
|
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();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
|
|
||||||
package org.lwjgl;
|
package org.lwjgl;
|
||||||
|
|
||||||
|
import java.nio.*;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
|
@ -790,13 +794,36 @@ public final class Math {
|
||||||
return (float) java.lang.Math.toDegrees(java.lang.Math.atan(theta));
|
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
|
* Approximate inverse square root function (Newton-Raphson?). This is a very approximate
|
||||||
* @param n the number for which you want the square root
|
* root, accurate to maybe 1 or 2 dp.
|
||||||
* @return sqrt(n)
|
* @param x
|
||||||
|
* @return ~x^0.5
|
||||||
*/
|
*/
|
||||||
public static float sqrt(float n) {
|
public static float invsqrt(float x) {
|
||||||
return (float) java.lang.Math.sqrt(n);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1101,4 +1128,5 @@ public final class Math {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,19 +101,6 @@ 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
|
* @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);
|
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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,4 +189,5 @@ abstract class BaseGL {
|
||||||
&& currentContext == this
|
&& currentContext == this
|
||||||
&& Thread.currentThread() == renderThread;
|
&& Thread.currentThread() == renderThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,13 @@ extern "C" {
|
||||||
/* Inaccessible static: mode */
|
/* Inaccessible static: mode */
|
||||||
/* Inaccessible static: handle */
|
/* Inaccessible static: handle */
|
||||||
/* Inaccessible static: closeRequested */
|
/* 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
|
* Class: org_lwjgl_Display
|
||||||
* Method: nGetAvailableDisplayModes
|
* Method: nGetAvailableDisplayModes
|
||||||
|
@ -45,6 +51,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized
|
||||||
(JNIEnv *, jclass);
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: getPlatform
|
||||||
|
* Signature: ()I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
|
||||||
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,12 +19,6 @@ extern "C" {
|
||||||
/* Inaccessible static: LIBRARY_NAME */
|
/* Inaccessible static: LIBRARY_NAME */
|
||||||
/* Inaccessible static: DEBUG */
|
/* Inaccessible static: DEBUG */
|
||||||
/* 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 */
|
/* Inaccessible static: class_000240 */
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_Sys
|
* Class: org_lwjgl_Sys
|
||||||
|
@ -82,14 +76,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
|
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
|
||||||
(JNIEnv *, jclass, jstring, jstring);
|
(JNIEnv *, jclass, jstring, jstring);
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_Sys
|
|
||||||
* Method: getPlatform
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Sys_getPlatform
|
|
||||||
(JNIEnv *, jclass);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -536,14 +536,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
|
||||||
0, 0, 0 // layer masks ignored
|
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;
|
int iPixelFormat;
|
||||||
|
|
||||||
// get the best available match of pixel format for the device context
|
// 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;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (desc.cColorBits < bpp) {
|
if (desc.cColorBits < bpp) {
|
||||||
printf("This application requires a greater colour depth.\n");
|
printf("This application requires a greater colour depth.\n");
|
||||||
destroyAll();
|
destroyAll();
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (desc.cAlphaBits < alphaBits) {
|
if (desc.cAlphaBits < alphaBits) {
|
||||||
printf("This application requires a greater alpha depth.\n");
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,15 +163,3 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
|
||||||
env->ReleaseStringUTFChars(message, eMessageText);
|
env->ReleaseStringUTFChars(message, eMessageText);
|
||||||
env->ReleaseStringUTFChars(title, cTitleBarText);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue