Linux part:

Merged Window and Display into org.lwjgl.Display
Added support for persistent context. This will enable LWJGL games
to avoid recreating the context resources like textures and display
lists when switching between windowed and fullscreen and/or context
dimensions.

Added PixelFormat class instead of individual parameters to Display.create
and Pbuffer constructor.
This commit is contained in:
Elias Naur 2004-07-02 19:02:00 +00:00
parent d03916ebec
commit 84110e9c13
25 changed files with 945 additions and 885 deletions

View File

@ -276,7 +276,6 @@
<!-- Generates the native headers from source files -->
<target name="headers" description="invokes javah on java classes, producing the headers needed for native compilation" depends="compile_java">
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
<class name="org.lwjgl.Display"/>
<class name="org.lwjgl.Sys"/>
<class name="org.lwjgl.input.Controller"/>
@ -292,7 +291,7 @@
<class name="org.lwjgl.openal.eax.EAXListenerProperties"/>
<class name="org.lwjgl.opengl.GLContext"/>
<class name="org.lwjgl.opengl.Window"/>
<class name="org.lwjgl.opengl.Display"/>
<class name="org.lwjgl.opengl.Pbuffer"/>
</javah>
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}/fmod3" force="yes">

View File

@ -1,247 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * 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 'LWJGL' 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.
*/
package org.lwjgl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.HashSet;
/**
* $Id$
*
* 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.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
*/
public final class Display {
/** Has the display been created? */
private static boolean created;
/** The current display mode, if created */
private static DisplayMode mode;
/** Whether or not the display has been requested to shutdown by the user */
private static boolean closeRequested = false;
/** Timer for sync() */
private static long timeNow, timeThen;
static {
Sys.initialize();
init();
Sys.log("Adapter: "+getAdapter()+" Version: "+getVersion());
}
/**
* 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();
/**
* 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() {
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);
Sys.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
return filteredModes;
}
/**
* Native method for getting displaymodes
*/
private static native DisplayMode[] nGetAvailableDisplayModes();
/**
* 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().
*
* @param mode The new display mode to set
* @throws LWJGLException if the display mode could not be set
*/
public static native void setDisplayMode(DisplayMode mode) throws LWJGLException;
/**
* Reset the display mode to whatever it was when LWJGL was initialized.
* Fails silently.
*/
public static native void resetDisplayMode();
/**
* Retrieves the width of the created display
*
* @return the current display width.
*/
public static int getWidth() {
return mode.width;
}
/**
* Retrieves the height of the created display
*
* @return the current display height.
*/
public static int getHeight() {
return mode.height;
}
/**
* Retrieves the current display depth of the created display
*
* @return the current display depth.
*/
public static int getDepth() {
return mode.bpp;
}
/**
* Retrieves the current display frequency of the created display
*
* @return the current display frequency.
*/
public static int getFrequency() {
return mode.freq;
}
/**
* Set the display configuration to the specified gamma, brightness and contrast.
* The configuration changes will be reset when resetDisplayMode is called.
*
* @param gamma The gamma value
* @param brightness The brightness value between -1.0 and 1.0, inclusive
* @param contrast The contrast, larger than 0.0.
*/
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
if (brightness < -1.0f || brightness > 1.0f)
throw new IllegalArgumentException("Invalid brightness value");
if (contrast < 0.0f)
throw new IllegalArgumentException("Invalid contrast value");
int rampSize = getGammaRampLength();
if (rampSize == 0) {
throw new LWJGLException("Display configuration not supported");
}
FloatBuffer gammaRamp = ByteBuffer.allocateDirect(rampSize*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
for (int i = 0; i < rampSize; i++) {
float intensity = (float)i/(rampSize - 1);
// apply gamma
float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
// apply brightness
rampEntry += brightness;
// apply contrast
rampEntry = (rampEntry - 0.5f)*contrast + 0.5f;
// Clamp entry to [0, 1]
if (rampEntry > 1.0f)
rampEntry = 1.0f;
else if (rampEntry < 0.0f)
rampEntry = 0.0f;
gammaRamp.put(i, rampEntry);
}
setGammaRamp(gammaRamp);
Sys.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
}
/**
* Return the length of the gamma ramp arrays. Returns 0 if gamma settings are
* unsupported.
*
* @return the length of each gamma ramp array, or 0 if gamma settings are unsupported.
*/
private static native int getGammaRampLength();
/**
* Native method to set the gamma ramp.
*/
private static native void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
/**
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
* "Radeon9700". If the adapter cannot be determined, this function returns null.
* @return a String
*/
public static native String getAdapter();
/**
* Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined,
* this function returns null.
* @return a String
*/
public static native String getVersion();
/**
* Synchronize the display to a capped frame rate.
* @param fps The desired frame rate, in frames per second
*/
public static void sync(int fps) {
float frameTime = 1.0f / (float) fps;
timeNow = Sys.getTime();
while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) {
// This is a system-friendly way of allowing other stuff to use CPU if it wants to
Thread.yield();
timeNow = Sys.getTime();
}
timeThen = timeNow;
}
}

View File

@ -36,6 +36,7 @@ import java.io.IOException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
/**
* $Id$
@ -135,7 +136,7 @@ public final class Sys {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
Display.resetDisplayMode();
Display.destroy();
if (Keyboard.isCreated())
Keyboard.destroy();
if (Mouse.isCreated())

View File

@ -35,7 +35,7 @@ import java.util.HashMap;
import java.util.Map;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.Display;
import org.lwjgl.LWJGLException;
/**
@ -159,8 +159,8 @@ public class Controller {
* @throws LWJGLException if the controller could not be created for any reason
*/
public static void create() throws LWJGLException {
if (!Window.isCreated())
throw new IllegalStateException("Window must be created before you can create Controller");
if (!Display.isCreated())
throw new IllegalStateException("Display must be created before you can create Controller");
initialize();
if (created) {

View File

@ -39,7 +39,7 @@ import java.util.Map;
import org.lwjgl.BufferUtils;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.Display;
import org.lwjgl.LWJGLException;
/**
@ -281,8 +281,8 @@ public class Keyboard {
* @throws LWJGLException if the keyboard could not be created for any reason
*/
public static void create() throws LWJGLException {
if (!Window.isCreated())
throw new IllegalStateException("Window must be created before you can create Keyboard");
if (!Display.isCreated())
throw new IllegalStateException("Display must be created before you can create Keyboard");
if (!initialized)
initialize();
if (created)

View File

@ -39,7 +39,7 @@ import java.util.Map;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.Display;
/**
* $Id$
@ -50,7 +50,7 @@ import org.lwjgl.opengl.Window;
* n buttons supported, n being a native limit. A scrolly wheel is also
* supported, if one such is available. Movement is reported as delta from
* last position or as an absolute position. If the window has been created
* the absolute position will be clamped to 0 - Window (width | height)
* the absolute position will be clamped to 0 - Display (width | height)
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @author elias_naur <elias_naur@users.sourceforge.net>
@ -262,7 +262,7 @@ public class Mouse {
*/
public static void create() throws LWJGLException {
if (!Window.isCreated()) throw new IllegalStateException("Window must be created prior to creating mouse");
if (!Display.isCreated()) throw new IllegalStateException("Display must be created prior to creating mouse");
initialize();
if (created) { return; }
@ -271,8 +271,8 @@ public class Mouse {
created = true;
currentCursor = null;
dx = dy = dwheel = 0;
width = Window.getWidth() << 16;
height = Window.getHeight() << 16;
width = Display.getDisplayMode().getWidth() << 16;
height = Display.getDisplayMode().getHeight() << 16;
x = width / 2;
y = height / 2;
@ -514,7 +514,7 @@ public class Mouse {
}
/**
* Retrieves the absolute position. If the Window has been created
* Retrieves the absolute position. If the Display has been created
* x will be clamped to 0...width-1.
*
* @return Absolute x axis position of mouse
@ -524,7 +524,7 @@ public class Mouse {
}
/**
* Retrieves the absolute position. If the Window has been created
* Retrieves the absolute position. If the Display has been created
* y will be clamped to 0...height-1.
*
* @return Absolute y axis position of mouse

View File

@ -43,33 +43,38 @@ package org.lwjgl.opengl;
* @author foo
*/
import org.lwjgl.Display;
import org.lwjgl.Sys;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.LWJGLException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.HashSet;
public final class Window {
public final class Display {
static {
Sys.initialize();
current_mode = init();
}
/** X coordinate of the window */
private static int x;
/** The current display mode, if created */
private static DisplayMode current_mode;
/** Timer for sync() */
private static long timeNow, timeThen;
// /** X coordinate of the window */
// private static int x;
/**
* Y coordinate of the window. Y in window coordinates is from the top of the display down,
* unlike GL, where it is typically at the bottom of the display.
*/
private static int y;
/** Width of the window */
private static int width;
/** Height of the window */
private static int height;
// private static int y;
/** Title of the window */
private static String title;
@ -81,7 +86,7 @@ public final class Window {
private static VBOTracker vbo_tracker;
/** A unique context object, so we can track different contexts between creates() and destroys() */
private static Window context;
private static Display context;
/** Whether we created the Mouse */
private static boolean createdMouse;
@ -95,45 +100,209 @@ public final class Window {
/**
* Only constructed by ourselves
*/
private Window() {
private Display() {
}
/**
* 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() {
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);
Sys.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
return filteredModes;
}
/**
* Native method for getting displaymodes
*/
private static native DisplayMode[] nGetAvailableDisplayModes();
/**
* Return the current display mode, as set by setDisplayMode().
* @return The current display mode
*/
public static DisplayMode getDisplayMode() {
return current_mode;
}
/**
* Set the current display mode. If no OpenGL context has been created, the given mode will apply to
* the context when create() is called, and no immediate mode switching will happen. If there is a
* context already, it will be resized according to the given mode. If the context is also a
* fullscreen context, the mode will also be switched immediately.
*
* @param mode The new display mode to set
* @throws LWJGLException if the display mode could not be set
*/
public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
current_mode = mode;
if (isCreated()) {
destroyWindow();
if (fullscreen)
switchDisplayMode(current_mode);
createWindow();
}
}
/**
* Create the native window peer from the given mode and fullscreen flag.
* A native context must exist, and it will be attached to the window.
*/
private static void createWindow() throws LWJGLException {
nCreateWindow(current_mode, fullscreen);
initControls();
}
private static native void nCreateWindow(DisplayMode mode, boolean fullscreen) throws LWJGLException;
private static void destroyWindow() {
// Automatically destroy keyboard, mouse, and controller
if (createdMouse && Mouse.isCreated()) {
Mouse.destroy();
createdMouse = false;
}
if (createdKeyboard && Keyboard.isCreated()) {
Keyboard.destroy();
createdKeyboard = false;
}
if (createdController && Controller.isCreated()) {
Controller.destroy();
createdController = false;
}
nDestroyWindow();
}
private static native void nDestroyWindow();
private static native void switchDisplayMode(DisplayMode mode) throws LWJGLException;
/**
* Reset the display mode to whatever it was when LWJGL was initialized.
* Fails silently.
*/
private static native void resetDisplayMode();
/**
* Set the display configuration to the specified gamma, brightness and contrast.
* The configuration changes will be reset when resetDisplayMode is called.
*
* @param gamma The gamma value
* @param brightness The brightness value between -1.0 and 1.0, inclusive
* @param contrast The contrast, larger than 0.0.
*/
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
if (brightness < -1.0f || brightness > 1.0f)
throw new IllegalArgumentException("Invalid brightness value");
if (contrast < 0.0f)
throw new IllegalArgumentException("Invalid contrast value");
int rampSize = getGammaRampLength();
if (rampSize == 0) {
throw new LWJGLException("Display configuration not supported");
}
FloatBuffer gammaRamp = ByteBuffer.allocateDirect(rampSize*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
for (int i = 0; i < rampSize; i++) {
float intensity = (float)i/(rampSize - 1);
// apply gamma
float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
// apply brightness
rampEntry += brightness;
// apply contrast
rampEntry = (rampEntry - 0.5f)*contrast + 0.5f;
// Clamp entry to [0, 1]
if (rampEntry > 1.0f)
rampEntry = 1.0f;
else if (rampEntry < 0.0f)
rampEntry = 0.0f;
gammaRamp.put(i, rampEntry);
}
setGammaRamp(gammaRamp);
Sys.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
}
/**
* Return the length of the gamma ramp arrays. Returns 0 if gamma settings are
* unsupported.
*
* @return the length of each gamma ramp array, or 0 if gamma settings are unsupported.
*/
private static native int getGammaRampLength();
/**
* Native method to set the gamma ramp.
*/
private static native void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
/**
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
* "Radeon9700". If the adapter cannot be determined, this function returns null.
* @return a String
*/
public static native String getAdapter();
/**
* Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined,
* this function returns null.
* @return a String
*/
public static native String getVersion();
/**
* Synchronize the display to a capped frame rate.
* @param fps The desired frame rate, in frames per second
*/
public static void sync(int fps) {
float frameTime = 1.0f / (float) fps;
timeNow = Sys.getTime();
while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) {
// This is a system-friendly way of allowing other stuff to use CPU if it wants to
Thread.yield();
timeNow = Sys.getTime();
}
timeThen = timeNow;
}
/**
* Initialize and return the current display mode.
*/
private static native DisplayMode init();
/**
* @return the X coordinate of the window (always 0 for fullscreen)
*/
public static int getX() {
/* public static int getX() {
if (!isCreated())
throw new IllegalStateException("Cannot get X on uncreated window");
return x;
}
*/
/**
* @return the Y coordinate of the window (always 0 for fullscreen)
*/
public static int getY() {
/* public static int getY() {
if (!isCreated())
throw new IllegalStateException("Cannot get Y on uncreated window");
return y;
}
/**
* @return the width of the window
*/
public static int getWidth() {
if (!isCreated())
throw new IllegalStateException("Cannot get width on uncreated window");
return width;
}
/**
* @return the height of the window
*/
public static int getHeight() {
if (!isCreated())
throw new IllegalStateException("Cannot get height on uncreated window");
return height;
}
*/
/**
* @return the title of the window
*/
@ -142,13 +311,47 @@ public final class Window {
throw new IllegalStateException("Cannot get title on uncreated window");
return title;
}
/**
* @return whether this window is in fullscreen mode
* Set the fullscreen mode of the context. If no context has been created through create(),
* the mode will apply when create() is called. If fullscreen is true, the context will become
* a fullscreen context and the display mode is switched to the mode given by getDisplayMode(). If
* fullscreen is false, the context will become a windowed context with the dimensions given in the
* mode returned by getDisplayMode().
*
* @param fullscreen Specify the fullscreen mode of the context.
*/
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
if (Display.fullscreen != fullscreen) {
Display.fullscreen = fullscreen;
if (!isCreated())
return;
destroyWindow();
if (fullscreen) {
try {
switchDisplayMode(current_mode);
} catch (LWJGLException e) {
destroyContext();
throw e;
}
} else {
resetDisplayMode();
}
try {
createWindow();
} catch (LWJGLException e) {
destroyContext();
if (fullscreen)
resetDisplayMode();
throw e;
}
}
}
/**
* @return whether the Display is in fullscreen mode
*/
public static boolean isFullscreen() {
if (!isCreated())
throw new IllegalStateException("Cannot determine fullscreen state of uncreated window");
return fullscreen;
}
@ -256,7 +459,7 @@ public final class Window {
private static native void swapBuffers();
/**
* Make the Window the current rendering context for GL calls.
* Make the Display the current rendering context for GL calls.
*/
public static synchronized void makeCurrent() {
if (!isCreated())
@ -269,152 +472,77 @@ public final class Window {
* Make the window the current rendering context for GL calls.
*/
private static native void nMakeCurrent();
/**
* Create a fullscreen window that matches the current display depth. Default common values are chosen
* for common OpenGL rendering operations: you will get at least a 16-bit depth buffer, an 8 bit stencil
* buffer, probably no alpha buffer, and probably no multisampling.
* Create the OpenGL context. If isFullscreen() is true or if windowed
* context are not supported on the platform, the display mode will be switched to the mode returned by
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
* created with the given parameters, a LWJGLException will be thrown.
*
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
* @param title
*
* @param pixel_format Describes the minimum specifications the context must fulfill.
* @throws LWJGLException
*/
public static void create(String title) throws LWJGLException {
create(title, Display.getDepth(), 0, 16, 8, 0);
public static void create() throws LWJGLException {
create(new PixelFormat());
}
/**
* Create a fullscreen window. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this
* fails too then an LWJGLException will be thrown.
* Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed
* context are not supported on the platform, the display mode will be switched to the mode returned by
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
* created with the given parameters, a LWJGLException will be thrown.
*
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
* @param title The title of the window
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
* @throws LWJGLException if the window could not be created for any reason; typically because
* the minimum requirements could not be met satisfactorily
*/
public static void create(String title, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
create(title, bpp, alpha, depth, stencil, 0);
}
/**
* Create a fullscreen window. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this
* fails too then an LWJGLException will be thrown.
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
* @param title The title of the window
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
* @throws LWJGLException if the window could not be created for any reason; typically because
* the minimum requirements could not be met satisfactorily
*/
public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws LWJGLException {
if (isCreated())
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = true;
Window.x = 0;
Window.y = 0;
Window.width = Display.getWidth();
Window.height = Display.getHeight();
Window.title = title;
createWindow(bpp, alpha, depth, stencil, samples);
}
/**
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
* display will be created instead. If this fails too then an LWJGLException will be thrown.
* If the window is created fullscreen, then its size may not match the specified size
* here.
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
* @param title The title of the window
* @param x The position of the window on the x axis. May be ignored.
* @param y The position of the window on the y axis. May be ignored.
* @param width The width of the window's client area
* @param height The height of the window's client area
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @throws LWJGLException if the window could not be created for any reason; typically because
* the minimum requirements could not be met satisfactorily
*/
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
create(title, x, y, width, height, bpp, alpha, depth, stencil, 0);
}
/**
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
* display will be created instead. If this fails too then an LWJGLException will be thrown.
* If the window is created fullscreen, then its size may not match the specified size
* here.
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
* @param title The title of the window
* @param x The position of the window on the x axis. May be ignored.
* @param y The position of the window on the y axis. May be ignored.
* @param width The width of the window's client area
* @param height The height of the window's client area
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
* @throws LWJGLException if the window could not be created for any reason; typically because
* the minimum requirements could not be met satisfactorily
*/
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples)
throws LWJGLException {
if (isCreated())
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = false;
Window.x = x;
Window.y = y;
Window.width = width;
Window.height = height;
Window.title = title;
createWindow(bpp, alpha, depth, stencil, samples);
}
/**
* Create the native window peer.
*
* @param pixel_format Describes the minimum specifications the context must fulfill.
* @throws LWJGLException
*/
private static native void nCreate(
String title,
int x,
int y,
int width,
int height,
boolean fullscreen,
int bpp,
int alpha,
int depth,
int stencil,
int samples)
throws LWJGLException;
private static void createWindow(int bpp, int alpha, int depth, int stencil, int samples) throws LWJGLException {
nCreate(title, x, y, width, height, fullscreen, bpp, alpha, depth, stencil, samples);
context = new Window();
public static void create(PixelFormat pixel_format) throws LWJGLException {
if (isCreated())
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
if (fullscreen)
switchDisplayMode(current_mode);
createContext(pixel_format);
context = new Display();
try {
createWindow();
} catch (LWJGLException e) {
destroyContext();
context = null;
if (fullscreen)
resetDisplayMode();
}
makeCurrent();
initContext();
}
/**
* Create the native OpenGL context.
* @throws LWJGLException
*/
private static native void createContext(PixelFormat pixel_format) throws LWJGLException;
private static native void destroyContext();
private static void initContext() {
// Put the window into orthographic projection mode with 1:1 pixel ratio.
// We haven't used GLU here to do this to avoid an unnecessary dependency.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0.0, (double) width, 0.0, (double) height, -1.0, 1.0);
GL11.glOrtho(0.0, (double) current_mode.getWidth(), 0.0, (double) current_mode.getHeight(), -1.0, 1.0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, width, height);
GL11.glViewport(0, 0, current_mode.getWidth(), current_mode.getHeight());
}
private static void initControls() {
// Automatically create mouse, keyboard and controller
if (!Boolean.getBoolean("org.lwjgl.opengl.Window.noinput")) {
if (!Mouse.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nomouse")) {
if (!Boolean.getBoolean("org.lwjgl.opengl.DIsplay.noinput")) {
if (!Mouse.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Display.nomouse")) {
try {
Mouse.create();
createdMouse = true;
@ -427,7 +555,7 @@ public final class Window {
}
}
}
if (!Keyboard.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nokeyboard")) {
if (!Keyboard.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Display.nokeyboard")) {
try {
Keyboard.create();
createdKeyboard = true;
@ -441,7 +569,7 @@ public final class Window {
}
}
}
if (!Controller.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nocontroller")) {
if (!Controller.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Display.nocontroller")) {
try {
Controller.create();
createdController = true;
@ -457,35 +585,23 @@ public final class Window {
}
/**
* Destroy the Window. After this call, there will be no current GL rendering context,
* regardless of whether the Window was the current rendering context.
* Destroy the Display. After this call, there will be no current GL rendering context,
* regardless of whether the Display was the current rendering context.
*/
public static synchronized void destroy() {
if (context == null) {
if (!isCreated()) {
return;
}
// Automatically destroy keyboard, mouse, and controller
if (createdMouse && Mouse.isCreated()) {
Mouse.destroy();
createdMouse = false;
}
if (createdKeyboard && Keyboard.isCreated()) {
Keyboard.destroy();
createdKeyboard = false;
}
if (createdController && Controller.isCreated()) {
Controller.destroy();
createdController = false;
}
makeCurrent();
nDestroy();
destroyWindow();
destroyContext();
context = null;
if (fullscreen)
resetDisplayMode();
}
/**
* @return the unique Window context (or null, if the Window has not been created)
* @return the unique DIsplay context (or null, if the Display has not been created)
*/
public static Object getContext() {
return context;
@ -535,49 +651,11 @@ public final class Window {
// if (fullscreen) {
// return;
// }
// Window.x = Math.max(0, Math.min(Display.getWidth() - Window.width, x));
// Window.y = Math.max(0, Math.min(Display.getHeight() - Window.height, y));
// nReshape(Window.x, Window.y, Window.width, Window.height);
// Display.x = Math.max(0, Math.min(Display.getWidth() - Display.width, x));
// Display.y = Math.max(0, Math.min(Display.getHeight() - Display.height, y));
// nReshape(Display.x, Display.y, Display.width, Display.height);
// }
//
// /**
// * Set the window's size. This is a no-op on fullscreen windows.
// * The window is clamped to remain entirely on the screen. If you attempt
// * to position the window such that it would extend off the screen, the window
// * is simply placed as close to the edge as possible.
// * @param width, height The new window dimensions
// */
// public static void setSize(int width, int height) {
// if (!isCreated())
// throw new IllegalStateException("Cannot resize uncreated window");
// if (fullscreen) {
// return;
// }
// Window.width = Math.max(0, Math.min(Display.getWidth() - Window.x, width));
// Window.height = Math.max(0, Math.min(Display.getHeight() - Window.y, height));
// nReshape(Window.x, Window.y, Window.width, Window.height);
// }
//
// /**
// * Set the window's bounds. This is a no-op on fullscreen windows.
// * The window is clamped to remain entirely on the screen.
// * @param x, y The new window location
// * @param width, height The new window dimensions
// */
// public static void setBounds(int x, int y, int width, int height) {
// if (!isCreated())
// throw new IllegalStateException("Cannot reshape uncreated window");
// if (fullscreen) {
// return;
// }
// width = Math.max(0, Math.min(Display.getWidth(), width));
// height = Math.max(0, Math.min(Display.getHeight(), height));
// Window.x = Math.max(0, Math.min(Display.getWidth() - width, x));
// Window.y = Math.max(0, Math.min(Display.getHeight() - height, y));
// Window.width = Math.max(0, Math.min(Display.getWidth() - Window.x, width));
// Window.height = Math.max(0, Math.min(Display.getHeight() - Window.y, height));
// nReshape(Window.x, Window.y, Window.width, Window.height);
// }
//
// /**
// * Native method to reshape the window

View File

@ -29,7 +29,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl;
package org.lwjgl.opengl;
/**
* $Id$
@ -45,7 +45,7 @@ package org.lwjgl;
public final class DisplayMode {
/** properties of the display mode */
public final int width, height, bpp, freq;
private final int width, height, bpp, freq;
/**
* Construct a display mode.
@ -59,6 +59,22 @@ public final class DisplayMode {
this.freq = freq;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getBitsPerPixel() {
return bpp;
}
public int getFrequency() {
return freq;
}
/**
* Tests for <code>DisplayMode</code> equality
*

View File

@ -180,7 +180,7 @@ public final class GLContext {
/**
* Determine which extensions are available. Use this to initialize capability fields. Can only be
* called _after_ a GLWindow or Pbuffer has been created (or a context from some other GL library).
* called _after_ the Display context or a Pbuffer has been created (or a context from some other GL library).
* Using LWJGL, this method is called automatically for you when the LWJGL Window is created and there
* is no need to call it yourself.
*
@ -237,5 +237,4 @@ public final class GLContext {
* @param exts An empty Set of Strings that will be filled with the names of enabled extensions
*/
private static native void init(Set exts);
}

View File

@ -174,24 +174,17 @@ public final class Pbuffer {
*
* @param width Pbuffer width
* @param height Pbuffer height
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec). Pass
* 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
* @param pixel_format Minimum Pbuffer context properties
* @param renderTexture
*/
public Pbuffer(int width, int height, int bpp, int alpha, int depth, int stencil, int samples, RenderTexture renderTexture) throws LWJGLException {
public Pbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
this.width = width;
this.height = height;
if ( renderTexture == null )
handle = nCreate(width, height, bpp, alpha, depth, stencil, samples, null, 0, null, 0);
handle = nCreate(width, height, pixel_format, null, 0, null, 0);
else
handle = nCreate(width, height,
bpp, alpha, depth, stencil,
samples,
handle = nCreate(width, height, pixel_format,
renderTexture.pixelFormatCaps, renderTexture.pixelFormatCaps.limit(),
renderTexture.pBufferAttribs, renderTexture.pBufferAttribs.limit());
}
@ -236,9 +229,7 @@ public final class Pbuffer {
/**
* Native method to create a Pbuffer
*/
private static native int nCreate(int width, int height,
int bpp, int alpha, int depth, int stencil,
int samples,
private static native int nCreate(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps, int pixelFormatCapsSize,
IntBuffer pBufferAttribs, int pBufferAttribsSize) throws LWJGLException;

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * 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 'LWJGL' 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.
*/
package org.lwjgl.opengl;
/**
* This class describes pixel format properties for an OpenGL context. Instances
* of this class is used as arguments to Display.create() and Pbuffer.create(), to
* indicate minimum required properties.
*
* @author elias_naur@sourceforge.net
* @version $Revision$
*/
public final class PixelFormat {
/**
* The number of bits per pixel, exluding alpha.
* This parameter is ignored in Display.create().
*/
private final int bpp;
/** The number of alpha bits. */
private final int alpha;
/** The number of depth buffer bits*/
private final int depth;
/** The number of stencil bits */
private final int stencil;
/**
* The number of samples to use in anti-aliasing.
* 0 means that anti-aliasing is disabled.
*/
private final int samples;
/** The number of auxilliary buffers */
private final int num_aux_buffers;
/** The number of bits per pixel in the accumulation buffer */
private final int accum_bpp;
/** The number of alpha bits in the accumulation buffer */
private final int accum_alpha;
/** Whether this format represents a stereo buffer or not */
private final boolean stereo;
public PixelFormat() {
this(0, 0, 0);
}
public PixelFormat(int alpha, int depth, int stencil) {
this(alpha, depth, stencil, 0);
}
public PixelFormat(int alpha, int depth, int stencil, int samples) {
this(0, alpha, depth, stencil, samples);
}
public PixelFormat(int bpp, int alpha, int depth, int stencil, int samples) {
this(bpp, alpha, depth, stencil, samples, 0, 0, 0, false);
}
public PixelFormat(int bpp, int alpha, int depth, int stencil, int samples, int num_aux_buffers, int accum_bpp, int accum_alpha, boolean stereo) {
this.bpp = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.samples = samples;
this.num_aux_buffers = num_aux_buffers;
this.accum_bpp = accum_bpp;
this.accum_alpha = accum_alpha;
this.stereo = stereo;
}
public int getBitsPerPixel() {
return bpp;
}
public int getAlphaBits() {
return alpha;
}
public int getDepthBits() {
return depth;
}
public int getStencilBits() {
return stencil;
}
public int getSamples() {
return samples;
}
public int getAuxBuffers() {
return num_aux_buffers;
}
public int getAccumulationBitsPerPixel() {
return accum_bpp;
}
public int getAccumulationAlpha() {
return accum_alpha;
}
public boolean isStereo() {
return stereo;
}
}

View File

@ -44,6 +44,19 @@ static bool debug = false;
static const char* VERSION = "0.9pre";
JavaVM *jvm;
void initAttribList(attrib_list_t *list) {
list->current_index = 0;
}
void putAttrib(attrib_list_t *list, int attrib) {
if (list->current_index == ATTRIB_LIST_SIZE) {
printfDebug("Ignoring attrib %d: attrib list size too small", attrib);
return;
}
list->attribs[list->current_index] = attrib;
list->current_index++;
}
jstring getVersionString(JNIEnv *env) {
return env->NewStringUTF(VERSION);
}
@ -214,4 +227,4 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_4;
}
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
}
}

View File

@ -48,6 +48,7 @@ extern JavaVM *jvm;
// Must be x * max_event_size + 1
#define EVENT_BUFFER_SIZE (25 * 4 + 1)
#define ATTRIB_LIST_SIZE (256)
typedef struct {
unsigned char input_event_buffer[EVENT_BUFFER_SIZE];
@ -56,6 +57,14 @@ typedef struct {
int list_end;
} event_queue_t;
typedef struct {
int current_index;
int attribs[ATTRIB_LIST_SIZE];
} attrib_list_t;
extern void initAttribList(attrib_list_t *list);
extern void putAttrib(attrib_list_t *list, int attrib);
extern bool isDebugEnabled(void);
extern jstring getVersionString(JNIEnv *env);
extern void initEventQueue(event_queue_t *event_queue);

View File

@ -1,7 +1,7 @@
lib_LTLIBRARIES = liblwjgl-fmod3.la
liblwjgl_fmod_la_SOURCES = $(FMOD_SOURCE)
liblwjgl_fmod_la_LIBADD = $(DEP_LIBS)
liblwjgl_fmod_la_DEPENDENCIES = $(DEP_LIBS)
liblwjgl_fmod3_la_SOURCES = $(FMOD_SOURCE)
liblwjgl_fmod3_la_LIBADD = $(DEP_LIBS)
liblwjgl_fmod3_la_DEPENDENCIES = $(DEP_LIBS)
INCLUDES = -I..
DEP_LIBS = ../libtools.la

View File

@ -1,82 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_lwjgl_Display */
#ifndef _Included_org_lwjgl_Display
#define _Included_org_lwjgl_Display
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: created */
/* Inaccessible static: mode */
/* Inaccessible static: closeRequested */
/* Inaccessible static: timeNow */
/* Inaccessible static: timeThen */
/*
* Class: org_lwjgl_Display
* Method: init
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: nGetAvailableDisplayModes
* Signature: ()[Lorg/lwjgl/DisplayMode;
*/
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: setDisplayMode
* Signature: (Lorg/lwjgl/DisplayMode;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode
(JNIEnv *, jclass, jobject);
/*
* Class: org_lwjgl_Display
* Method: resetDisplayMode
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: getGammaRampLength
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: setGammaRamp
* Signature: (Ljava/nio/FloatBuffer;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp
(JNIEnv *, jclass, jobject);
/*
* Class: org_lwjgl_Display
* Method: getAdapter
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_Display
* Method: getVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,199 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_lwjgl_opengl_Display */
#ifndef _Included_org_lwjgl_opengl_Display
#define _Included_org_lwjgl_opengl_Display
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: current_mode */
/* Inaccessible static: timeNow */
/* Inaccessible static: timeThen */
/* Inaccessible static: title */
/* Inaccessible static: fullscreen */
/* Inaccessible static: vbo_tracker */
/* Inaccessible static: context */
/* Inaccessible static: createdMouse */
/* Inaccessible static: createdKeyboard */
/* Inaccessible static: createdController */
/*
* Class: org_lwjgl_opengl_Display
* Method: nGetAvailableDisplayModes
* Signature: ()[Lorg/lwjgl/opengl/DisplayMode;
*/
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDisplayModes
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nCreateWindow
* Signature: (Lorg/lwjgl/opengl/DisplayMode;Z)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nCreateWindow
(JNIEnv *, jclass, jobject, jboolean);
/*
* Class: org_lwjgl_opengl_Display
* Method: nDestroyWindow
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: switchDisplayMode
* Signature: (Lorg/lwjgl/opengl/DisplayMode;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode
(JNIEnv *, jclass, jobject);
/*
* Class: org_lwjgl_opengl_Display
* Method: resetDisplayMode
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_resetDisplayMode
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: getGammaRampLength
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Display_getGammaRampLength
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: setGammaRamp
* Signature: (Ljava/nio/FloatBuffer;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_setGammaRamp
(JNIEnv *, jclass, jobject);
/*
* Class: org_lwjgl_opengl_Display
* Method: getAdapter
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getAdapter
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: getVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getVersion
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: init
* Signature: ()Lorg/lwjgl/opengl/DisplayMode;
*/
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Display_init
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nSetTitle
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetTitle
(JNIEnv *, jclass, jstring);
/*
* Class: org_lwjgl_opengl_Display
* Method: nIsCloseRequested
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsCloseRequested
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nIsVisible
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsVisible
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nIsActive
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsActive
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nIsDirty
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsDirty
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_swapBuffers
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nMakeCurrent
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: createContext
* Signature: (Lorg/lwjgl/opengl/PixelFormat;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext
(JNIEnv *, jclass, jobject);
/*
* Class: org_lwjgl_opengl_Display
* Method: destroyContext
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroy
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nUpdate
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nUpdate
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Display
* Method: nSetVSyncEnabled
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetVSyncEnabled
(JNIEnv *, jclass, jboolean);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -69,10 +69,10 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_getPbufferCaps
/*
* Class: org_lwjgl_opengl_Pbuffer
* Method: nCreate
* Signature: (IIIIIIILjava/nio/IntBuffer;ILjava/nio/IntBuffer;I)I
* Signature: (IILorg/lwjgl/opengl/PixelFormat;Ljava/nio/IntBuffer;ILjava/nio/IntBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
(JNIEnv *, jclass, jint, jint, jint, jint, jint, jint, jint, jobject, jint, jobject, jint);
(JNIEnv *, jclass, jint, jint, jobject, jobject, jint, jobject, jint);
/*
* Class: org_lwjgl_opengl_Pbuffer

View File

@ -1,112 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_lwjgl_opengl_Window */
#ifndef _Included_org_lwjgl_opengl_Window
#define _Included_org_lwjgl_opengl_Window
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: x */
/* Inaccessible static: y */
/* Inaccessible static: width */
/* Inaccessible static: height */
/* Inaccessible static: title */
/* Inaccessible static: fullscreen */
/* Inaccessible static: vbo_tracker */
/* Inaccessible static: context */
/* Inaccessible static: createdMouse */
/* Inaccessible static: createdKeyboard */
/* Inaccessible static: createdController */
/*
* Class: org_lwjgl_opengl_Window
* Method: nSetTitle
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetTitle
(JNIEnv *, jclass, jstring);
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsCloseRequested
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsVisible
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVisible
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsActive
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsActive
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsDirty
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nMakeCurrent
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nCreate
* Signature: (Ljava/lang/String;IIIIZIIIII)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
(JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint);
/*
* Class: org_lwjgl_opengl_Window
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nUpdate
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nUpdate
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_Window
* Method: nSetVSyncEnabled
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
(JNIEnv *, jclass, jboolean);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,14 +4,14 @@ libnative_la_SOURCES = $(NATIVE)
INCLUDES = -I../common
NATIVE = \
org_lwjgl_Display.cpp \
org_lwjgl_Sys.cpp \
org_lwjgl_input_Controller.cpp \
org_lwjgl_input_Keyboard.cpp \
org_lwjgl_input_Mouse.cpp \
org_lwjgl_input_Cursor.cpp \
org_lwjgl_opengl_Window.cpp \
org_lwjgl_opengl_Display.cpp \
org_lwjgl_opengl_Pbuffer.cpp \
display.cpp \
extgl_glx.cpp \
extxcursor.cpp

View File

@ -49,6 +49,7 @@
#include "extgl.h"
#include "extgl_glx.h"
extern GLXFBConfig *chooseVisualGLX13(JNIEnv *env, jobject pixel_format, bool use_display_bpp, int drawable_type, bool double_buffer);
/*
* release input (keyboard, mouse)
*/

View File

@ -46,8 +46,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <jni.h>
#include "org_lwjgl_Display.h"
#include "display.h"
#include "common_tools.h"
#include "Window.h"
@ -129,15 +128,13 @@ static int getGammaRampLength(Display *disp, int screen) {
return ramp_size;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
(JNIEnv * env, jclass clazz)
{
jobject initDisplay(JNIEnv *env) {
int num_modes;
XF86VidModeModeInfo **avail_modes;
int screen;
Display *disp = incDisplay(env);
if (disp == NULL)
return;
return NULL;
screen = DefaultScreen(disp);
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
@ -146,12 +143,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
saved_width = avail_modes[0]->hdisplay;
saved_height = avail_modes[0]->vdisplay;
int bpp = XDefaultDepth(disp, screen);
printfDebug("Saved width, height %d, %d\n", saved_width, saved_height);
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
printfDebug("Original display dimensions: width %d, height %d\n", saved_width, saved_height);
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/opengl/DisplayMode");
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, saved_width, saved_height, bpp, 0);
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
XFree(avail_modes);
@ -165,14 +160,15 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
freeSavedGammaRamps();
}
decDisplay();
return newMode;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclass clazz, jobject mode) {
void switchDisplayMode(JNIEnv * env, jobject mode) {
if (mode == NULL) {
throwException(env, "mode must be non-null");
return;
}
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
jclass cls_displayMode = env->GetObjectClass(mode);
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
int width = env->GetIntField(mode, fid_width);
@ -183,15 +179,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclas
if (disp == NULL)
return;
screen = DefaultScreen(disp);
if (setMode(disp, screen, width, height, true)) {
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
env->SetStaticObjectField(clazz, fid_initialMode, mode);
} else
if (!setMode(disp, screen, width, height, true))
throwException(env, "Could not switch mode.");
decDisplay();
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jclass clazz) {
void resetDisplayMode(JNIEnv *env) {
int screen;
Display *disp = incDisplay(env);
if (disp == NULL)
@ -205,9 +198,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jcl
decDisplay();
}
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
(JNIEnv * env, jclass clazz)
{
jobjectArray getAvailableDisplayModes(JNIEnv * env) {
int num_modes, i;
int screen;
XF86VidModeModeInfo **avail_modes;
@ -225,7 +216,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
return NULL;
}
// Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
jclass displayModeClass = env->FindClass("org/lwjgl/opengl/DisplayMode");
jobjectArray ret = env->NewObjectArray(num_modes, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
@ -238,11 +229,11 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
return ret;
}
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
int getGammaRampLength(void) {
return gamma_ramp_length;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer) {
void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer) {
if (gamma_ramp_length == 0) {
throwException(env, "gamma ramp length == 0.");
return;
@ -263,15 +254,3 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass c
}
decDisplay();
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
(JNIEnv * env, jclass clazz)
{
return NULL;
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
(JNIEnv * env, jclass clazz)
{
return NULL;
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * 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 'LWJGL' 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.
*/
/**
* $Id$
*
* Linux specific library for display handling.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#include <jni.h>
extern jobject initDisplay(JNIEnv *env);
extern void switchDisplayMode(JNIEnv * env, jobject mode);
extern void resetDisplayMode(JNIEnv * env);
extern jobjectArray getAvailableDisplayModes(JNIEnv * env);
extern int getGammaRampLength(void);
extern void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer);

View File

@ -33,7 +33,7 @@
/**
* $Id$
*
* Linux specific window functions.
* Linux specific display functions.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
@ -51,13 +51,16 @@
#include "extgl.h"
#include "extgl_glx.h"
#include "Window.h"
#include "org_lwjgl_opengl_Window.h"
#include "display.h"
#include "org_lwjgl_opengl_Display.h"
#define USEGLX13 extgl_Extensions.GLX13
#define ERR_MSG_SIZE 1024
static GLXContext context = NULL; // OpenGL rendering context
static GLXWindow glx_window;
static XVisualInfo * vis_info;
static GLXFBConfig *configs;
static Atom delete_atom;
static Colormap cmap;
@ -253,7 +256,7 @@ static void setWindowTitle(const char *title) {
XStoreName(getDisplay(), current_win, title);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetTitle
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetTitle
(JNIEnv * env, jclass clazz, jstring title_obj)
{
const char * title = env->GetStringUTFChars(title_obj, NULL);
@ -266,7 +269,8 @@ static void destroyWindow() {
XFreeColormap(getDisplay(), cmap);
}
static bool createWindow(JNIEnv* env, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen, bool undecorated) {
static bool createWindow(JNIEnv* env, int width, int height) {
bool undecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
dirty = true;
focused = true;
minimized = false;
@ -279,30 +283,27 @@ static bool createWindow(JNIEnv* env, int screen, XVisualInfo *vis_info, jstring
XSetWindowAttributes attribs;
int attribmask;
current_screen = screen;
input_released = false;
current_fullscreen = fullscreen;
current_width = width;
current_height = height;
root_win = RootWindow(getDisplay(), screen);
root_win = RootWindow(getDisplay(), getCurrentScreen());
cmap = XCreateColormap(getDisplay(), root_win, vis_info->visual, AllocNone);
attribs.colormap = cmap;
attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
attribs.background_pixel = 0xFF000000;
attribmask = CWColormap | CWBackPixel | CWEventMask;
if (fullscreen || undecorated) {
if (current_fullscreen || undecorated) {
attribmask |= CWOverrideRedirect;
attribs.override_redirect = True;
}
win = XCreateWindow(getDisplay(), root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
win = XCreateWindow(getDisplay(), root_win, 0, 0, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
if (!checkXError(env)) {
XFreeColormap(getDisplay(), cmap);
return false;
}
printfDebug("Created window\n");
current_win = win;
Java_org_lwjgl_opengl_Window_nSetTitle(env, NULL, title);
XSizeHints * size_hints = XAllocSizeHints();
size_hints->flags = PMinSize | PMaxSize;
size_hints->min_width = width;
@ -345,7 +346,7 @@ int getWindowHeight(void) {
* Method: nUpdate
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nUpdate
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nUpdate
(JNIEnv *env, jclass clazz)
{
handleMessages();
@ -356,7 +357,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nUpdate
* Method: nMakeCurrent
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
(JNIEnv *env, jclass clazz)
{
makeCurrent();
@ -395,57 +396,94 @@ GLXContext getCurrentContext(void) {
return context;
}
static GLXFBConfig *chooseVisualGLX13(int screen, int bpp, int depth, int alpha, int stencil, int samples) {
GLXFBConfig *chooseVisualGLX13(JNIEnv *env, jobject pixel_format, bool use_display_bpp, int drawable_type, bool double_buffer) {
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int bpp;
if (use_display_bpp)
bpp = XDefaultDepthOfScreen(XScreenOfDisplay(getDisplay(), getCurrentScreen()));
else
bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "bpp", "I"));
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
bool stereo = (bool)env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
int bpe = convertToBPE(bpp);
int attriblist[] = {GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, True,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
None, None, /* For ARB_multisample */
None, None, /* */
None};
int num_formats = 0;
int accum_bpe = convertToBPE(accum_bpp);
attrib_list_t attrib_list;
initAttribList(&attrib_list);
putAttrib(&attrib_list, GLX_RENDER_TYPE); putAttrib(&attrib_list, GLX_RGBA_BIT);
putAttrib(&attrib_list, GLX_DOUBLEBUFFER); putAttrib(&attrib_list, double_buffer ? True : False);
putAttrib(&attrib_list, GLX_DRAWABLE_TYPE); putAttrib(&attrib_list, drawable_type);
putAttrib(&attrib_list, GLX_DEPTH_SIZE); putAttrib(&attrib_list, depth);
putAttrib(&attrib_list, GLX_RED_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_GREEN_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_BLUE_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_ALPHA_SIZE); putAttrib(&attrib_list, alpha);
putAttrib(&attrib_list, GLX_STENCIL_SIZE); putAttrib(&attrib_list, stencil);
putAttrib(&attrib_list, GLX_AUX_BUFFERS); putAttrib(&attrib_list, num_aux_buffers);
putAttrib(&attrib_list, GLX_ACCUM_RED_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_GREEN_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_BLUE_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_ALPHA_SIZE); putAttrib(&attrib_list, accum_alpha);
putAttrib(&attrib_list, GLX_STEREO); putAttrib(&attrib_list, stereo ? True : False);
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
attriblist[18] = GLX_SAMPLE_BUFFERS_ARB;
attriblist[19] = 1;
attriblist[20] = GLX_SAMPLES_ARB;
attriblist[21] = samples;
putAttrib(&attrib_list, GLX_SAMPLE_BUFFERS_ARB); putAttrib(&attrib_list, 1);
putAttrib(&attrib_list, GLX_SAMPLES_ARB); putAttrib(&attrib_list, samples);
}
GLXFBConfig* configs = glXChooseFBConfig(getDisplay(), screen, attriblist, &num_formats);
if (num_formats > 0)
putAttrib(&attrib_list, None); putAttrib(&attrib_list, None);
int num_formats = 0;
GLXFBConfig* configs = glXChooseFBConfig(getDisplay(), getCurrentScreen(), attrib_list.attribs, &num_formats);
if (num_formats > 0) {
return configs;
else {
} else {
if (configs != NULL)
XFree(configs);
return NULL;
}
}
static XVisualInfo *chooseVisual(int screen, int bpp, int depth, int alpha, int stencil, int samples) {
static XVisualInfo *chooseVisualGLX(JNIEnv *env, jobject pixel_format) {
int bpp = XDefaultDepthOfScreen(XScreenOfDisplay(getDisplay(), getCurrentScreen()));
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
bool stereo = (bool)env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
int bpe = convertToBPE(bpp);
int attriblist[] = {GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
None, None, /* For ARB_multisample */
None, None, /* */
None};
int accum_bpe = convertToBPE(accum_bpp);
attrib_list_t attrib_list;
initAttribList(&attrib_list);
putAttrib(&attrib_list, GLX_RGBA);
putAttrib(&attrib_list, GLX_DOUBLEBUFFER);
putAttrib(&attrib_list, GLX_DEPTH_SIZE); putAttrib(&attrib_list, depth);
putAttrib(&attrib_list, GLX_RED_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_GREEN_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_BLUE_SIZE); putAttrib(&attrib_list, bpe);
putAttrib(&attrib_list, GLX_ALPHA_SIZE); putAttrib(&attrib_list, alpha);
putAttrib(&attrib_list, GLX_STENCIL_SIZE); putAttrib(&attrib_list, stencil);
putAttrib(&attrib_list, GLX_AUX_BUFFERS); putAttrib(&attrib_list, num_aux_buffers);
putAttrib(&attrib_list, GLX_ACCUM_RED_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_GREEN_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_BLUE_SIZE); putAttrib(&attrib_list, accum_bpe);
putAttrib(&attrib_list, GLX_ACCUM_ALPHA_SIZE); putAttrib(&attrib_list, accum_alpha);
if (stereo)
putAttrib(&attrib_list, GLX_STEREO);
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
attriblist[14] = GLX_SAMPLE_BUFFERS_ARB;
attriblist[15] = 1;
attriblist[16] = GLX_SAMPLES_ARB;
attriblist[17] = samples;
putAttrib(&attrib_list, GLX_SAMPLE_BUFFERS_ARB); putAttrib(&attrib_list, 1);
putAttrib(&attrib_list, GLX_SAMPLES_ARB); putAttrib(&attrib_list, samples);
}
return glXChooseVisual(getDisplay(), screen, attriblist);
putAttrib(&attrib_list, None);
return glXChooseVisual(getDisplay(), getCurrentScreen(), attrib_list.attribs);
}
static void dumpVisualInfo(XVisualInfo *vis_info) {
@ -465,20 +503,22 @@ static void dumpVisualInfo(XVisualInfo *vis_info) {
printfDebug("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples);
}
static void destroy(void) {
static void destroyContext(void) {
releaseContext();
if (USEGLX13)
if (USEGLX13) {
glXDestroyWindow(getDisplay(), glx_window);
XFree(configs);
}
XFree(vis_info);
glXDestroyContext(getDisplay(), context);
context = NULL;
destroyWindow();
setRepeatMode(AutoRepeatModeDefault);
decDisplay();
extgl_Close();
}
static bool initWindowGLX13(JNIEnv *env, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen, bool undecorated) {
GLXFBConfig *configs = chooseVisualGLX13(screen, bpp, depth, alpha, stencil, samples);
static bool initWindowGLX13(JNIEnv *env, jobject pixel_format) {
configs = chooseVisualGLX13(env, pixel_format, true, GLX_WINDOW_BIT, true);
if (configs == NULL) {
throwException(env, "Could not find a matching pixel format");
return false;
@ -496,35 +536,23 @@ static bool initWindowGLX13(JNIEnv *env, int screen, jstring title, int x, int y
throwException(env, "Could not create a direct GLX context");
return false;
}
XVisualInfo * vis_info = glXGetVisualFromFBConfig(getDisplay(), configs[0]);
vis_info = glXGetVisualFromFBConfig(getDisplay(), configs[0]);
if (vis_info == NULL) {
glXDestroyContext(getDisplay(), context);
XFree(configs);
throwException(env, "Could not create visual info from FB config");
throwException(env, "Could not get visual from FB config");
return false;
}
bool window_created = createWindow(env, screen, vis_info, title, x, y, width, height, fscreen, undecorated);
if (isDebugEnabled())
dumpVisualInfo(vis_info);
XFree(vis_info);
if (!window_created) {
if (!checkXError(env)) {
glXDestroyContext(getDisplay(), context);
XFree(configs);
return false;
}
glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL);
makeCurrent();
XFree(configs);
if (!checkXError(env)) {
glXDestroyWindow(getDisplay(), glx_window);
glXDestroyContext(getDisplay(), context);
return false;
}
return true;
}
static bool initWindowGLX(JNIEnv *env, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen, bool undecorated) {
XVisualInfo *vis_info = chooseVisual(screen, bpp, depth, alpha, stencil, samples);
static bool initWindowGLX(JNIEnv *env, jobject pixel_format) {
vis_info = chooseVisualGLX(env, pixel_format);
if (vis_info == NULL) {
throwException(env, "Could not find a matching pixel format");
return false;
@ -544,30 +572,46 @@ static bool initWindowGLX(JNIEnv *env, int screen, jstring title, int x, int y,
throwException(env, "Could not create a direct GLX context");
return false;
}
bool window_created = createWindow(env, screen, vis_info, title, x, y, width, height, fscreen, undecorated);
XFree(vis_info);
if (!window_created) {
glXDestroyContext(getDisplay(), context);
return false;
}
makeCurrent();
if (!checkXError(env)) {
glXDestroyContext(getDisplay(), context);
destroyWindow();
return false;
}
return true;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
(JNIEnv * env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jint samples)
{
int screen;
bool fscreen = false;
if (fullscreen == JNI_TRUE)
fscreen = true;
bool isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz) {
return getAvailableDisplayModes(env);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
switchDisplayMode(env, mode);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
resetDisplayMode(env);
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
return (jint)getGammaRampLength();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
setGammaRamp(env, gamma_buffer);
}
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Display_init(JNIEnv *env, jclass clazz) {
return initDisplay(env);
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getAdapter(JNIEnv *env , jclass clazz) {
return NULL;
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getVersion(JNIEnv *env, jclass clazz) {
return NULL;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env, jclass clazz, jobject pixel_format) {
if (!extgl_Open()) {
throwException(env, "Could not load gl libs");
return;
@ -575,8 +619,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
Display *disp = incDisplay(env);
if (disp == NULL)
return;
screen = XDefaultScreen(disp);
if (!extgl_InitGLX(env, disp, screen)) {
current_screen = XDefaultScreen(disp);
if (!extgl_InitGLX(env, disp, current_screen)) {
decDisplay();
extgl_Close();
throwException(env, "Could not init GLX");
@ -584,9 +628,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
}
bool create_success;
if (USEGLX13) {
create_success = initWindowGLX13(env, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen, isUndecorated);
create_success = initWindowGLX13(env, pixel_format);
} else {
create_success = initWindowGLX(env, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen, isUndecorated);
create_success = initWindowGLX(env, pixel_format);
}
if (!create_success) {
decDisplay();
@ -595,15 +639,34 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
}
}
/*
* Class: org_lwjgl_opengl_GLWindow
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
(JNIEnv *env, jclass clazz)
{
destroy();
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
destroyContext();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nCreateWindow(JNIEnv *env, jclass clazz, jobject mode, jboolean fullscreen) {
current_fullscreen = fullscreen == JNI_TRUE;
jclass cls_displayMode = env->GetObjectClass(mode);
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
int width = env->GetIntField(mode, fid_width);
int height = env->GetIntField(mode, fid_height);
bool window_created = createWindow(env, width, height);
if (!window_created) {
return;
}
if (isDebugEnabled())
dumpVisualInfo(vis_info);
if (USEGLX13)
glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL);
makeCurrent();
if (!checkXError(env)) {
glXDestroyWindow(getDisplay(), glx_window);
destroyWindow();
}
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env, jclass clazz) {
destroyWindow();
}
/*
@ -611,7 +674,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz)
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_swapBuffers(JNIEnv * env, jclass clazz)
{
dirty = false;
if (USEGLX13)
@ -626,7 +689,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jc
* Method: nIsDirty
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsDirty
(JNIEnv *env, jclass clazz) {
bool result = dirty;
dirty = false;
@ -638,7 +701,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty
* Method: nIsVisible
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVisible
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsVisible
(JNIEnv *env, jclass clazz) {
return minimized ? JNI_FALSE : JNI_TRUE;
}
@ -648,7 +711,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVisible
* Method: nIsCloseRequested
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsCloseRequested
(JNIEnv *, jclass) {
bool saved = closerequested;
closerequested = false;
@ -660,12 +723,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested
* Method: nIsActive
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsActive
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsActive
(JNIEnv *env, jclass clazz) {
return focused ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetVSyncEnabled
(JNIEnv * env, jclass clazz, jboolean sync)
{
if (extgl_Extensions.GLX_SGI_swap_control) {

View File

@ -87,38 +87,14 @@ static void destroyPbuffer(PbufferInfo *buffer_info) {
* Class: org_lwjgl_opengl_Pbuffer
* Method: nCreate
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
(JNIEnv *env, jclass clazz,
jint width, jint height,
jint bpp, jint alpha, jint depth, jint stencil,
jint samples,
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jint width, jint height, jobject pixel_format,
jobject pixelFormatCaps, jint pixelFormatCapsSize, jobject pBufferAttribs, jint pBufferAttribsSize)
{
Display *disp = incDisplay(env);
if (disp == NULL)
return 0;
int bpe = convertToBPE(bpp);
int attrib_list[] = {GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, False,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_DEPTH_SIZE, depth,
GLX_STENCIL_SIZE, stencil,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
None, None, /* for ARB_multisample */
None, None, /* */
None};
int num_configs;
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
attrib_list[18] = GLX_SAMPLE_BUFFERS_ARB;
attrib_list[19] = 1;
attrib_list[20] = GLX_SAMPLES_ARB;
attrib_list[21] = samples;
}
GLXFBConfig *configs = glXChooseFBConfig(disp, getCurrentScreen(), attrib_list, &num_configs);
if (num_configs == 0) {
GLXFBConfig *configs = chooseVisualGLX13(env, pixel_format, false, GLX_PBUFFER_BIT, false);
if (configs == 0) {
XFree(configs);
throwException(env, "No matching pixel format");
return -1;

View File

@ -60,10 +60,6 @@ RECT clientSize;
static bool closerequested;
static jboolean allowSoftwareOpenGL; // Whether to allow software opengl
//CAS: commented these out as no longer used
//extern void tempRestoreDisplayMode();
//extern void tempResetDisplayMode();
#define WINDOWCLASSNAME "LWJGL"
static bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {