lwjgl2-arm64/src/java/org/lwjgl/Display.java

235 lines
7.5 KiB
Java
Raw Normal View History

2002-08-15 17:46:18 +02:00
/*
2002-12-22 20:52:15 +01:00
* Copyright (c) 2002 Light Weight Java Game Library Project
2002-08-15 17:46:18 +02:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
2002-08-09 12:56:30 +02:00
*
2002-08-15 17:46:18 +02:00
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2002-08-09 12:56:30 +02:00
*/
2002-08-15 17:46:18 +02:00
2002-08-09 12:56:30 +02:00
package org.lwjgl;
import java.util.HashSet;
import java.util.Arrays;
2002-08-09 12:56:30 +02:00
/**
2002-08-15 17:46:18 +02:00
* $Id$
*
2002-08-09 12:56:30 +02:00
* Encapsulates everything you need for game display.
* It must be created before any input devices are created.
* The game display has NO mouse cursor or any other window decorations.
2002-08-09 12:56:30 +02:00
*
2002-08-15 17:46:18 +02:00
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
2002-08-09 12:56:30 +02:00
*/
2002-08-15 17:46:18 +02:00
2002-08-09 12:56:30 +02:00
public final class Display {
/** Has the display been created? */
private static boolean created;
/** The current display mode, if created */
private static DisplayMode mode;
2003-02-11 00:09:54 +01:00
2003-02-07 22:54:31 +01:00
/** A pointer to the native display window. On Windows this will be an hWnd. */
2002-08-09 12:56:30 +02:00
private static int handle;
2003-02-11 00:09:54 +01:00
/** Whether or not the display has been requested to shutdown by the user */
private static boolean closeRequested = false;
2003-03-21 18:08:26 +01:00
/*
* 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;
2003-03-28 20:02:24 +01:00
static {
System.loadLibrary(Sys.getLibraryName());
init();
}
2002-08-09 12:56:30 +02:00
/**
* No construction allowed.
*/
private Display() {
super();
}
/**
* Initialize. This determines, natively, the current display mode and stashes
* it back in the mode static member.
*/
private static native void init();
2002-08-09 12:56:30 +02:00
/**
* Returns the entire list of display modes as an array, in no
* particular order. Any given mode is not guaranteed to be available and
* the only certain way to check is to call create() and make sure it works.
* Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32).
*
* @return an array of all display modes the system reckons it can handle.
*/
public static DisplayMode[] getAvailableDisplayModes() {
2003-03-21 18:08:26 +01:00
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;
}
2003-03-21 18:08:26 +01:00
/**
* Native method for getting displaymodes
*/
private static native DisplayMode[] nGetAvailableDisplayModes();
2002-08-09 12:56:30 +02:00
/**
* Set the current display mode. The underlying OS may not use an exact match for
* the specified display mode. After successfully calling setDisplayMode() you will
* still need to query the display's characteristics using getDisplayMode().
2003-05-03 23:20:23 +02:00
*
* @param mode The new display mode to set
2002-08-09 12:56:30 +02:00
* @throws Exception if the display mode could not be set
*/
public static native void setDisplayMode(DisplayMode mode) throws Exception;
2002-08-09 12:56:30 +02:00
/**
* Reset the display mode to whatever it was when LWJGL was initialized.
* Fails silently.
2002-08-09 12:56:30 +02:00
*/
public static native void resetDisplayMode();
2002-08-09 12:56:30 +02:00
/**
2003-02-11 00:09:54 +01:00
* Retrieves the width of the created display
*
2002-08-09 12:56:30 +02:00
* @return the current display width.
*/
public static int getWidth() {
return mode.width;
}
/**
2003-02-11 00:09:54 +01:00
* Retrieves the height of the created display
*
2002-08-09 12:56:30 +02:00
* @return the current display height.
*/
public static int getHeight() {
return mode.height;
}
/**
2003-02-11 00:09:54 +01:00
* Retrieves the current display depth of the created display
*
2002-08-09 12:56:30 +02:00
* @return the current display depth.
*/
public static int getDepth() {
return mode.bpp;
}
/**
2003-02-11 00:09:54 +01:00
* Retrieves the current display frequency of the created display
*
2002-08-09 12:56:30 +02:00
* @return the current display frequency.
*/
public static int getFrequency() {
return mode.freq;
}
2003-02-11 00:09:54 +01:00
2002-08-09 12:56:30 +02:00
/**
* Retrieves the native handle to the created window. The meaning of this value
* is platform specific. Under Win32, it is an HWND.
2003-02-11 00:09:54 +01:00
*
2002-08-09 12:56:30 +02:00
* @return the native handle
* @throws AssertionError if the display has not been created yet.
2002-08-09 12:56:30 +02:00
*/
public static int getHandle() {
assert created : "The display has not been created yet.";
2002-08-09 12:56:30 +02:00
return handle;
}
2003-02-11 00:09:54 +01:00
2003-03-21 18:08:26 +01:00
/**
* 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();
/**
* Obtains the display's gamma ramp. The gamma ramp returned is an array of
* 16:16 fixed point values representing 0.0...1.0. The gamma ramp consists of three
* arrays, one for red, one for green, and one for blue. The array lengths must be 256.
2003-03-29 22:52:14 +01:00
*
* If gamma is not supported by the underlying hardware then false is returned.
*
2003-05-03 23:20:23 +02:00
* @param red An array of ints to store red gamma in. Must be 256 in length.
* @param green An array of ints to store green gamma in. Must be 256 in length.
* @param blue An array of ints to store blue gamma in. Must be 256 in length.
2003-03-29 22:52:14 +01:00
* @return true if it succeeds, false if it fails
*/
2003-03-29 22:52:14 +01:00
public static native boolean getGammaRamp(int[] red, int[] green, int[] blue);
/**
* Sets the display's gamma ramp. The gamma ramp should be an array of ints
2003-03-29 22:52:14 +01:00
* in 16:16 fixed point format, arranged as for getGammaRamp().
* The length of the arrays must be 256.
*
* If the underlying hardware does not support gamma then this command is a no-op.
2003-03-29 22:52:14 +01:00
*
* When resetDisplaMode is called, any gamma changes are automatically undone.
2003-03-29 22:52:14 +01:00
*
2003-05-03 23:20:23 +02:00
* @param red An array of ints to store red gamma in. Must be 256 in length.
* @param green An array of ints to store green gamma in. Must be 256 in length.
* @param blue An array of ints to store blue gamma in. Must be 256 in length.
2003-03-29 22:52:14 +01:00
*
* @return true if it succeeds, false if it fails
*/
2003-03-29 22:52:14 +01:00
public static native boolean setGammaRamp(int[] red, int[] green, int[] blue);
2003-03-21 18:08:26 +01:00
2003-03-19 13:41:28 +01:00
}