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;
}
}