* @author cix_foo
* @author elias_naur
- * @version $Revision: 3419 $
- * $Id: BufferChecks.java 3419 2010-09-30 17:21:50Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public class BufferChecks {
/** Static methods only! */
@@ -159,7 +159,7 @@
* This is a separate call to help inline checkBufferSize.
*/
private static void throwBufferSizeException(Buffer buf, int size) {
- throw new IllegalArgumentException("Number of remaining buffer elements is " + buf.remaining() + ", must be at least " + size);
+ throw new IllegalArgumentException("Number of remaining buffer elements is " + buf.remaining() + ", must be at least " + size + ". Because at most " + size + " elements can be returned, a buffer with at least " + size + " elements is required, regardless of actual returned element count");
}
private static void throwBufferSizeException(PointerBuffer buf, int size) {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/BufferUtils.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/BufferUtils.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/BufferUtils.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/BufferUtils.java 2016-04-09 16:26:56.000000000 +0000
@@ -44,9 +44,9 @@
/**
* Some often-used Buffer code for creating native buffers of the appropriate size.
*
- * @author $Author: matzon $
- * @version $Revision: 3456 $
- * $Id: BufferUtils.java 3456 2010-11-24 21:48:23Z matzon $
+ * @author $Author$
+ * @version $Revision$
+ * $Id$
*/
public final class BufferUtils {
@@ -192,4 +192,14 @@
/** Fill buffer with zeros from position to remaining */
private static native void zeroBuffer0(Buffer b, long off, long size);
+
+ /**
+ * Returns the memory address of the specified buffer.
+ *
+ * @param buffer the buffer
+ *
+ * @return the memory address
+ */
+ static native long getBufferAddress(Buffer buffer);
+
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/DefaultSysImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/DefaultSysImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/DefaultSysImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/DefaultSysImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -35,8 +35,8 @@
/**
*
* @author elias_naur
- * @version $Revision: 3426 $
- * $Id: DefaultSysImplementation.java 3426 2010-10-01 22:20:14Z spasi $
+ * @version $Revision$
+ * $Id$
*/
abstract class DefaultSysImplementation implements SysImplementation {
public native int getJNIVersion();
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/examples/Game.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/examples/Game.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/examples/Game.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/examples/Game.java 2016-04-09 16:26:56.000000000 +0000
@@ -42,9 +42,9 @@
*
* This is a very basic skeleton to init a game and run it.
*
- * @author $Author: spasi $
- * @version $Revision: 3418 $
- * $Id: Game.java 3418 2010-09-28 21:11:35Z spasi $
+ * @author $Author$
+ * @version $Revision$
+ * $Id$
*/
public class Game {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java 2016-04-09 16:26:56.000000000 +0000
@@ -47,8 +47,8 @@
* whether it's playing.
*
* @author Brian Matzon
- * @version $Revision: 3418 $
- * $Id: SoundManager.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public class SoundManager {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/ControllerEvent.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/ControllerEvent.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/ControllerEvent.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/ControllerEvent.java 2016-04-09 16:26:56.000000000 +0000
@@ -52,12 +52,18 @@
private int index;
/** Type of control that generated the event */
private int type;
+ /** True when a button is pressed, if this event was caused by the button */
+ private boolean buttonState;
/** True if this event was caused by the x axis */
private boolean xaxis;
/** True if this event was caused by the y axis */
private boolean yaxis;
/** The time stamp of this event */
private long timeStamp;
+ /** The value on a specified axis, if this event was caused by the x-axis */
+ private float xaxisValue;
+ /** The value on a specified axis, if this event was caused by the y-axis */
+ private float yaxisValue;
/**
* Create a new event
@@ -70,12 +76,32 @@
* @param yaxis True if this event was caused by the y-axis
*/
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
+ this(source, timeStamp, type, index, false, xaxis, yaxis, 0, 0);
+ }
+
+ /**
+ * Create a new event
+ *
+ * @param source The source of the event
+ * @param timeStamp The time stamp given for this event
+ * @param type The type of control generating this event
+ * @param index The index of the input that generated the event
+ * @param buttonState True when a button is pressed, if this event was caused by the button
+ * @param xaxis True if this event was caused by the x-axis
+ * @param yaxis True if this event was caused by the y-axis
+ * @param xaxisValue The value on a specified axis, if this event was caused by the x-axis
+ * @param yaxisValue The value on a specified axis, if this event was caused by the y-axis
+ */
+ ControllerEvent(Controller source,long timeStamp, int type,int index,boolean buttonState,boolean xaxis,boolean yaxis,float xaxisValue,float yaxisValue) {
this.source = source;
this.timeStamp = timeStamp;
this.type = type;
this.index = index;
+ this.buttonState = buttonState;
this.xaxis = xaxis;
this.yaxis = yaxis;
+ this.xaxisValue = xaxisValue;
+ this.yaxisValue = yaxisValue;
}
/**
@@ -116,6 +142,15 @@
}
/**
+ * Check the button is pressed or not, when this event was caused
+ *
+ * @return True when a button is pressed, if this event was caused by the button
+ */
+ public boolean getButtonState() {
+ return buttonState;
+ }
+
+ /**
* Check if this event was generated by a axis
*
* @return True if this event was generated by a axis
@@ -159,6 +194,24 @@
public boolean isYAxis() {
return yaxis;
}
+
+ /**
+ * Get the value on an X axis when this event was caused
+ *
+ * @return The value on a specified axis, if this event was caused by the x-axis
+ */
+ public float getXAxisValue() {
+ return xaxisValue;
+ }
+
+ /**
+ * Get the value on an Y axis when this event was caused
+ *
+ * @return The value on a specified axis, if this event was caused by the y-axis
+ */
+ public float getYAxisValue() {
+ return yaxisValue;
+ }
/*
* @see java.lang.Object#toString()
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Controller.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Controller.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Controller.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Controller.java 2016-04-09 16:26:56.000000000 +0000
@@ -270,4 +270,21 @@
* @param zone The dead zone to use for the RZ axis
*/
void setRZAxisDeadZone(float zone);
+
+
+ /** Returns the number of rumblers this controller supports */
+ int getRumblerCount();
+
+ /** Returns the name of the specified rumbler
+ *
+ * @param index The rumbler index
+ */
+ String getRumblerName(int index);
+
+ /** Sets the vibration strength of the specified rumbler
+ *
+ * @param index The index of the rumbler
+ * @param strength The strength to vibrate at
+ */
+ void setRumblerStrength(int index, float strength);
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Controllers.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Controllers.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Controllers.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Controllers.java 2016-04-09 16:26:56.000000000 +0000
@@ -262,13 +262,40 @@
/**
* Get the timestamp assigned to the current event
*
- * @return The timestamp assigned ot the current event
+ * @return The timestamp assigned to the current event
*/
public static long getEventNanoseconds() {
return event.getTimeStamp();
}
/**
+ * Gets the state of the button that generated the current event
+ *
+ * @return True if button was down, or false if released
+ */
+ public static boolean getEventButtonState() {
+ return event.getButtonState();
+ }
+
+ /**
+ * Get the value on an X axis of the current event
+ *
+ * @return The value on a x axis of the current event
+ */
+ public static float getEventXAxisValue() {
+ return event.getXAxisValue();
+ }
+
+ /**
+ * Get the value on an Y axis of the current event
+ *
+ * @return The value on a y axis of the current event
+ */
+ public static float getEventYAxisValue() {
+ return event.getYAxisValue();
+ }
+
+ /**
* Add an event to the stack of events that have been caused
*
* @param event The event to add to the list
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Cursor.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Cursor.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Cursor.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Cursor.java 2016-04-09 16:26:56.000000000 +0000
@@ -33,10 +33,10 @@
import java.nio.IntBuffer;
+import org.lwjgl.BufferChecks;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
-import org.lwjgl.NondirectBufferWrapper;
import org.lwjgl.Sys;
/**
@@ -45,8 +45,8 @@
* class can be used with Mouse.setCursor(), if available.
*
* @author elias_naur
- * @version $Revision: 3418 $
- * $Id: Cursor.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public class Cursor {
@@ -86,9 +86,9 @@
synchronized (OpenGLPackageAccess.global_lock) {
if ((getCapabilities() & CURSOR_ONE_BIT_TRANSPARENCY) == 0)
throw new LWJGLException("Native cursors not supported");
- images = NondirectBufferWrapper.wrapBuffer(images, width*height*numImages);
+ BufferChecks.checkBufferSize(images, width*height*numImages);
if (delays != null)
- delays = NondirectBufferWrapper.wrapBuffer(delays, numImages);
+ BufferChecks.checkBufferSize(delays, numImages);
if (!Mouse.isCreated())
throw new IllegalStateException("Mouse must be created before creating cursor objects");
if (width*height*numImages > images.remaining())
@@ -163,17 +163,32 @@
IntBuffer images_copy = BufferUtils.createIntBuffer(images.remaining());
flipImages(width, height, numImages, images, images_copy);
- // Win32 doesn't (afaik) allow for animation based cursors, except when they're
- // in the .ani format, which we don't support.
+ // Mac and Windows doesn't (afaik) allow for animation based cursors, except in the .ani
+ // format on Windows, which we don't support.
// The cursor animation was therefor developed using java side time tracking.
// unfortunately X flickers when changing cursor. We therefore check for either
- // Win32 or X and do accordingly. This hasn't been implemented on Mac, but we
- // might want to split it into a X/Win/Mac cursor if it gets too cluttered
+ // Windows, Mac or X and do accordingly.
+ // we might want to split it into a X/Win/Mac cursor if it gets too cluttered
CursorElement[] cursors;
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_MACOSX:
- /* Fall through */
+
+ // OS X requires the image format to be in ABGR format
+ convertARGBtoABGR(images_copy);
+
+ // create our cursor elements
+ cursors = new CursorElement[numImages];
+ for(int i=0; i>> 24);
+ byte blue = (byte)(argbColor >>> 16);
+ byte green = (byte)(argbColor >>> 8);
+ byte red = (byte)argbColor;
+
+ int abgrColor = ((alpha & 0xff) << 24 ) + ((red & 0xff) << 16 ) + ((green & 0xff) << 8 ) + ((blue & 0xff) );
+
+ imageBuffer.put(i, abgrColor);
+ }
+ }
/**
* Flips the images so they're oriented according to opengl
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/JInputController.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/JInputController.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/JInputController.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/JInputController.java 2016-04-09 16:26:56.000000000 +0000
@@ -38,6 +38,7 @@
import net.java.games.input.Component.Identifier.Button;
import net.java.games.input.Event;
import net.java.games.input.EventQueue;
+import net.java.games.input.Rumbler;
/**
* A wrapper round a JInput controller that attempts to make the interface
@@ -56,6 +57,8 @@
private ArrayList axes = new ArrayList();
/** The POVs that have been detected on the JInput controller */
private ArrayList pov = new ArrayList();
+ /** The rumblers exposed by the controller */
+ private Rumbler[] rumblers;
/** The state of the buttons last check */
private boolean[] buttonState;
/** The values that were read from the pov last check */
@@ -86,7 +89,7 @@
* @param index The index this controller has been assigned to
* @param target The target JInput controller this class is wrapping
*/
- JInputController(int index,net.java.games.input.Controller target) {
+ JInputController(int index, net.java.games.input.Controller target) {
this.target = target;
this.index = index;
@@ -148,6 +151,8 @@
axesMax[i] = 1.0f;
deadZones[i] = 0.05f;
}
+
+ rumblers = target.getRumblers();
}
/*
@@ -203,7 +208,8 @@
buttonState[buttonIndex] = event.getValue() != 0;
// fire button pressed event
- Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,false,false));
+ Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,
+ buttonState[buttonIndex],false,false,0,0));
}
// handle pov events
@@ -227,6 +233,8 @@
Component axis = event.getComponent();
int axisIndex = axes.indexOf(axis);
float value = axis.getPollData();
+ float xaxisValue = 0;
+ float yaxisValue = 0;
// fixed dead zone since most axis don't report it :(
if (Math.abs(value) < deadZones[axisIndex]) {
@@ -241,9 +249,17 @@
// normalize the value based on maximum value read in the past
value /= axesMax[axisIndex];
+
+ if (axisIndex == xaxis) {
+ xaxisValue = value;
+ }
+ if (axisIndex == yaxis) {
+ yaxisValue = value;
+ }
+
// fire event
- Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,
- axisIndex == xaxis,axisIndex == yaxis));
+ Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,false,
+ axisIndex == xaxis,axisIndex == yaxis,xaxisValue,yaxisValue));
axesValue[axisIndex] = value;
}
}
@@ -506,5 +522,16 @@
return 0;
}
+ public int getRumblerCount() {
+ return rumblers.length;
+ }
+
+ public String getRumblerName(int index) {
+ return rumblers[index].getAxisName();
+ }
+
+ public void setRumblerStrength(int index, float strength) {
+ rumblers[index].rumble(strength);
+ }
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Keyboard.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Keyboard.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Keyboard.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Keyboard.java 2016-04-09 16:26:56.000000000 +0000
@@ -51,8 +51,8 @@
* @author cix_foo
* @author elias_naur
* @author Brian Matzon
- * @version $Revision: 3463 $
- * $Id: Keyboard.java 3463 2010-12-15 18:48:56Z kappa1 $
+ * @version $Revision$
+ * $Id$
*/
public class Keyboard {
/** Internal use - event size in bytes */
@@ -158,7 +158,11 @@
public static final int KEY_F13 = 0x64; /* (NEC PC98) */
public static final int KEY_F14 = 0x65; /* (NEC PC98) */
public static final int KEY_F15 = 0x66; /* (NEC PC98) */
+ public static final int KEY_F16 = 0x67; /* Extended Function keys - (Mac) */
+ public static final int KEY_F17 = 0x68;
+ public static final int KEY_F18 = 0x69;
public static final int KEY_KANA = 0x70; /* (Japanese keyboard) */
+ public static final int KEY_F19 = 0x71; /* Extended Function keys - (Mac) */
public static final int KEY_CONVERT = 0x79; /* (Japanese keyboard) */
public static final int KEY_NOCONVERT = 0x7B; /* (Japanese keyboard) */
public static final int KEY_YEN = 0x7D; /* (Japanese keyboard) */
@@ -173,10 +177,12 @@
public static final int KEY_UNLABELED = 0x97; /* (J3100) */
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
public static final int KEY_RCONTROL = 0x9D;
+ public static final int KEY_SECTION = 0xA7; /* Section symbol (Mac) */
public static final int KEY_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
public static final int KEY_SYSRQ = 0xB7;
public static final int KEY_RMENU = 0xB8; /* right Alt */
+ public static final int KEY_FUNCTION = 0xC4; /* Function (Mac) */
public static final int KEY_PAUSE = 0xC5; /* Pause */
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
@@ -188,7 +194,8 @@
public static final int KEY_NEXT = 0xD1; /* PgDn on arrow keypad */
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
- public static final int KEY_LMETA = 0xDB; /* Left Windows/Option key */
+ public static final int KEY_CLEAR = 0xDA; /* Clear key (Mac) */
+ public static final int KEY_LMETA = 0xDB; /* Left Windows/Option key */
/**
* The left windows key, mapped to KEY_LMETA
*
@@ -216,7 +223,7 @@
private static final int BUFFER_SIZE = 50;
/** Key names */
- private static final String[] keyName = new String[255];
+ private static final String[] keyName = new String[KEYBOARD_SIZE];
private static final Map keyMap = new HashMap(253);
private static int counter;
@@ -229,7 +236,8 @@
&& Modifier.isPublic(field.getModifiers())
&& Modifier.isFinal(field.getModifiers())
&& field.getType().equals(int.class)
- && field.getName().startsWith("KEY_") ) {
+ && field.getName().startsWith("KEY_")
+ && !field.getName().endsWith("WIN") ) { /* Don't use deprecated names */
int key = field.getInt(null);
String name = field.getName().substring(4);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Mouse.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Mouse.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/input/Mouse.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/input/Mouse.java 2016-04-09 16:26:56.000000000 +0000
@@ -59,8 +59,8 @@
* @author cix_foo
* @author elias_naur
* @author Brian Matzon
- * @version $Revision: 3418 $
- * $Id: Mouse.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public class Mouse {
/** Internal use - event size in bytes */
@@ -77,6 +77,12 @@
/** Mouse absolute Y position in pixels */
private static int y;
+
+ /** Mouse absolute X position in pixels without any clipping */
+ private static int absolute_x;
+
+ /** Mouse absolute Y position in pixels without any clipping */
+ private static int absolute_y;
/** Buffer to hold the deltas dx, dy and dwheel */
private static IntBuffer coord_buffer;
@@ -128,6 +134,9 @@
/** The position of the mouse it was grabbed at */
private static int grab_x;
private static int grab_y;
+ /** The last absolute mouse event position (before clipping) for delta computation */
+ private static int last_event_raw_x;
+ private static int last_event_raw_y;
/** Buffer size in events */
private static final int BUFFER_SIZE = 50;
@@ -140,7 +149,7 @@
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS ||
LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX;
- private static final boolean allowNegativeMouseCoords = getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords");
+ private static boolean clipMouseCoordinatesToWindow = !getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords");
/**
* Mouse cannot be constructed.
@@ -189,6 +198,14 @@
}
}
+ public static boolean isClipMouseCoordinatesToWindow() {
+ return clipMouseCoordinatesToWindow;
+ }
+
+ public static void setClipMouseCoordinatesToWindow(boolean clip) {
+ clipMouseCoordinatesToWindow = clip;
+ }
+
/**
* Set the position of the cursor. If the cursor is not grabbed,
* the native cursor is moved to the new position.
@@ -344,17 +361,21 @@
dy += poll_coord2;
x += poll_coord1;
y += poll_coord2;
+ absolute_x += poll_coord1;
+ absolute_y += poll_coord2;
} else {
- dx = poll_coord1 - x;
- dy = poll_coord2 - y;
- x = poll_coord1;
- y = poll_coord2;
+ dx = poll_coord1 - absolute_x;
+ dy = poll_coord2 - absolute_y;
+ absolute_x = x = poll_coord1;
+ absolute_y = y = poll_coord2;
+ }
+
+ if(clipMouseCoordinatesToWindow) {
+ x = Math.min(Display.getWidth() - 1, Math.max(0, x));
+ y = Math.min(Display.getHeight() - 1, Math.max(0, y));
}
- if(!allowNegativeMouseCoords) {
- x = Math.min(implementation.getWidth() - 1, Math.max(0, x));
- y = Math.min(implementation.getHeight() - 1, Math.max(0, y));
- }
- dwheel += poll_dwheel;
+
+ dwheel += poll_dwheel;
read();
}
}
@@ -412,8 +433,8 @@
/**
* Gets the next mouse event. You can query which button caused the event by using
* getEventButton() (if any). To get the state of that key, for that event, use
- * getEventButtonState. To get the current mouse delta values use getEventDX(),
- * getEventDY() and getEventDZ().
+ * getEventButtonState. To get the current mouse delta values use getEventDX()
+ * and getEventDY().
* @see org.lwjgl.input.Mouse#getEventButton()
* @see org.lwjgl.input.Mouse#getEventButtonState()
* @return true if a mouse event was read, false otherwise
@@ -429,16 +450,22 @@
event_dy = readBuffer.getInt();
event_x += event_dx;
event_y += event_dy;
+ last_event_raw_x = event_x;
+ last_event_raw_y = event_y;
} else {
int new_event_x = readBuffer.getInt();
int new_event_y = readBuffer.getInt();
- event_dx = new_event_x - event_x;
- event_dy = new_event_y - event_y;
+ event_dx = new_event_x - last_event_raw_x;
+ event_dy = new_event_y - last_event_raw_y;
event_x = new_event_x;
event_y = new_event_y;
+ last_event_raw_x = new_event_x;
+ last_event_raw_y = new_event_y;
+ }
+ if(clipMouseCoordinatesToWindow) {
+ event_x = Math.min(Display.getWidth() - 1, Math.max(0, event_x));
+ event_y = Math.min(Display.getHeight() - 1, Math.max(0, event_y));
}
- event_x = Math.min(implementation.getWidth() - 1, Math.max(0, event_x));
- event_y = Math.min(implementation.getHeight() - 1, Math.max(0, event_y));
event_dwheel = readBuffer.getInt();
event_nanos = readBuffer.getLong();
return true;
@@ -638,6 +665,8 @@
poll();
event_x = x;
event_y = y;
+ last_event_raw_x = x;
+ last_event_raw_y = y;
resetMouse();
}
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/J2SESysImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/J2SESysImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/J2SESysImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/J2SESysImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -37,9 +37,9 @@
/**
* A SysImplementation which delegates as much as it can to J2SE.
*
@@ -92,7 +92,8 @@
* @return ALCdevice if it was possible to open a device
*/
public static ALCdevice alcCaptureOpenDevice(String devicename, int frequency, int format, int buffersize) {
- long device_address = nalcCaptureOpenDevice(devicename, frequency, format, buffersize);
+ ByteBuffer buffer = MemoryUtil.encodeASCII(devicename);
+ long device_address = nalcCaptureOpenDevice(MemoryUtil.getAddressSafe(buffer), frequency, format, buffersize);
if(device_address != 0) {
ALCdevice device = new ALCdevice(device_address);
synchronized (ALC10.devices) {
@@ -102,7 +103,7 @@
}
return null;
}
- static native long nalcCaptureOpenDevice( String devicename, int frequency, int format, int buffersize);
+ private static native long nalcCaptureOpenDevice(long devicename, int frequency, int format, int buffersize);
/**
* The alcCaptureCloseDevice function allows the application to disconnect from a capture
@@ -162,9 +163,9 @@
* @param samples Number of samples to request
*/
public static void alcCaptureSamples(ALCdevice device, ByteBuffer buffer, int samples ) {
- nalcCaptureSamples(ALC10.getDevice(device), buffer, buffer.position(), samples);
+ nalcCaptureSamples(ALC10.getDevice(device), MemoryUtil.getAddress(buffer), samples);
}
- static native void nalcCaptureSamples(long device, ByteBuffer buffer, int position, int samples );
+ static native void nalcCaptureSamples(long device, long buffer, int samples );
static native void initNativeStubs() throws LWJGLException;
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/ALCcontext.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/ALCcontext.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/ALCcontext.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/ALCcontext.java 2016-04-09 16:26:56.000000000 +0000
@@ -46,8 +46,8 @@
* AL and ALC are threadsafe.
*
* @author Brian Matzon
- * @version $Revision: 3418 $
- * $Id: ALCcontext.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public final class ALCcontext {
@@ -82,7 +82,7 @@
* @param contextFrequency Frequency to add
* @param contextRefresh Refresh rate to add
* @param contextSynchronized Whether to synchronize the context
- * @return
+ * @return attribute list
*/
static IntBuffer createAttributeList(int contextFrequency, int contextRefresh, int contextSynchronized) {
IntBuffer attribList = BufferUtils.createIntBuffer(7);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/ALCdevice.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/ALCdevice.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/ALCdevice.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/ALCdevice.java 2016-04-09 16:26:56.000000000 +0000
@@ -45,8 +45,8 @@
* which has to map the available backends to unique device specifiers.
*
* @author Brian Matzon
- * @version $Revision: 3418 $
- * $Id: ALCdevice.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public final class ALCdevice {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/AL.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/AL.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/AL.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/AL.java 2016-04-09 16:26:56.000000000 +0000
@@ -42,8 +42,8 @@
*
*
* @author Brian Matzon
- * @version $Revision: 3418 $
- * $Id: AL.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public final class AL {
/** ALCdevice instance. */
@@ -115,8 +115,13 @@
String[] library_names;
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_WINDOWS:
- libname = "OpenAL32";
- library_names = new String[]{"OpenAL64.dll", "OpenAL32.dll"};
+ if ( Sys.is64Bit() ) {
+ libname = "OpenAL64";
+ library_names = new String[]{"OpenAL64.dll"};
+ } else {
+ libname = "OpenAL32";
+ library_names = new String[]{"OpenAL32.dll"};
+ }
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "openal";
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/OpenALException.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/OpenALException.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/OpenALException.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/OpenALException.java 2016-04-09 16:26:56.000000000 +0000
@@ -37,8 +37,8 @@
* causes an error.
*
* @author Brian Matzon
- * @version $Revision: 2983 $
- * $Id: OpenALException.java 2983 2008-04-07 18:36:09Z matzon $
+ * @version $Revision$
+ * $Id$
*/
public class OpenALException extends RuntimeException {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/Util.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/Util.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/openal/Util.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/openal/Util.java 2016-04-09 16:26:56.000000000 +0000
@@ -37,7 +37,7 @@
*
* @author cix_foo
* @author Brian Matzon
- * @version $Revision: 2983 $
+ * @version $Revision$
*/
public final class Util {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/APIUtil.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/APIUtil.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/APIUtil.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/APIUtil.java 2016-04-09 16:26:56.000000000 +0000
@@ -31,9 +31,7 @@
*/
package org.lwjgl.opencl;
-import org.lwjgl.BufferUtils;
-import org.lwjgl.LWJGLUtil;
-import org.lwjgl.PointerBuffer;
+import org.lwjgl.*;
import org.lwjgl.opencl.FastLongMap.Entry;
import java.nio.*;
@@ -53,7 +51,7 @@
*/
final class APIUtil {
- private static final int INITIAL_BUFFER_SIZE = 256;
+ private static final int INITIAL_BUFFER_SIZE = 256;
private static final int INITIAL_LENGTHS_SIZE = 4;
private static final int BUFFERS_SIZE = 32;
@@ -223,10 +221,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string) {
+ static long getBuffer(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -236,10 +234,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string, final int offset) {
+ static long getBuffer(final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress(buffer);
}
/**
@@ -249,11 +247,11 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence string) {
+ static long getBufferNT(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
buffer.put((byte)0);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
static int getTotalLength(final CharSequence[] strings) {
@@ -271,14 +269,14 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence[] strings) {
+ static long getBuffer(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
for ( CharSequence string : strings )
encode(buffer, string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -288,7 +286,7 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence[] strings) {
+ static long getBufferNT(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
for ( CharSequence string : strings ) {
@@ -297,7 +295,7 @@
}
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -307,14 +305,14 @@
*
* @return the String lengths in a PointerBuffer
*/
- static PointerBuffer getLengths(final CharSequence[] strings) {
+ static long getLengths(final CharSequence[] strings) {
PointerBuffer buffer = getLengths(strings.length);
for ( CharSequence string : strings )
buffer.put(string.length());
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -324,14 +322,14 @@
*
* @return the buffer lengths in a PointerBuffer
*/
- static PointerBuffer getLengths(final ByteBuffer[] buffers) {
+ static long getLengths(final ByteBuffer[] buffers) {
PointerBuffer lengths = getLengths(buffers.length);
for ( ByteBuffer buffer : buffers )
lengths.put(buffer.remaining());
lengths.flip();
- return lengths;
+ return MemoryUtil.getAddress0(lengths);
}
static int getSize(final PointerBuffer lengths) {
@@ -342,14 +340,22 @@
return (int)size;
}
+ static long getPointer(final PointerWrapper pointer) {
+ return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer));
+ }
+
+ static long getPointerSafe(final PointerWrapper pointer) {
+ return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer == null ? 0L : pointer.getPointer()));
+ }
+
private static class Buffers {
final ShortBuffer shorts;
- final IntBuffer ints;
- final IntBuffer intsDebug;
- final LongBuffer longs;
+ final IntBuffer ints;
+ final IntBuffer intsDebug;
+ final LongBuffer longs;
- final FloatBuffer floats;
+ final FloatBuffer floats;
final DoubleBuffer doubles;
final PointerBuffer pointers;
@@ -453,7 +459,7 @@
*/
static void releaseObjects(final CLDevice device) {
// Release objects only if we're about to hit 0.
- if ( device.getReferenceCount() > 1 )
+ if ( !device.isValid() || device.getReferenceCount() > 1 )
return;
releaseObjects(device.getSubCLDeviceRegistry(), DESTRUCTOR_CLSubDevice);
@@ -466,7 +472,7 @@
*/
static void releaseObjects(final CLContext context) {
// Release objects only if we're about to hit 0.
- if ( context.getReferenceCount() > 1 )
+ if ( !context.isValid() || context.getReferenceCount() > 1 )
return;
releaseObjects(context.getCLEventRegistry(), DESTRUCTOR_CLEvent);
@@ -483,7 +489,7 @@
*/
static void releaseObjects(final CLProgram program) {
// Release objects only if we're about to hit 0.
- if ( program.getReferenceCount() > 1 )
+ if ( !program.isValid() || program.getReferenceCount() > 1 )
return;
releaseObjects(program.getCLKernelRegistry(), DESTRUCTOR_CLKernel);
@@ -496,7 +502,7 @@
*/
static void releaseObjects(final CLCommandQueue queue) {
// Release objects only if we're about to hit 0.
- if ( queue.getReferenceCount() > 1 )
+ if ( !queue.isValid() || queue.getReferenceCount() > 1 )
return;
releaseObjects(queue.getCLEventRegistry(), DESTRUCTOR_CLEvent);
@@ -513,25 +519,25 @@
}
}
- private static final ObjectDestructor DESTRUCTOR_CLSubDevice = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLSubDevice = new ObjectDestructor() {
public void release(final CLDevice object) { clReleaseDeviceEXT(object); }
};
- private static final ObjectDestructor DESTRUCTOR_CLMem = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLMem = new ObjectDestructor() {
public void release(final CLMem object) { clReleaseMemObject(object); }
};
private static final ObjectDestructor DESTRUCTOR_CLCommandQueue = new ObjectDestructor() {
public void release(final CLCommandQueue object) { clReleaseCommandQueue(object); }
};
- private static final ObjectDestructor DESTRUCTOR_CLSampler = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLSampler = new ObjectDestructor() {
public void release(final CLSampler object) { clReleaseSampler(object); }
};
- private static final ObjectDestructor DESTRUCTOR_CLProgram = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLProgram = new ObjectDestructor() {
public void release(final CLProgram object) { clReleaseProgram(object); }
};
- private static final ObjectDestructor DESTRUCTOR_CLKernel = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLKernel = new ObjectDestructor() {
public void release(final CLKernel object) { clReleaseKernel(object); }
};
- private static final ObjectDestructor DESTRUCTOR_CLEvent = new ObjectDestructor() {
+ private static final ObjectDestructor DESTRUCTOR_CLEvent = new ObjectDestructor() {
public void release(final CLEvent object) { clReleaseEvent(object); }
};
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CallbackUtil.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CallbackUtil.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CallbackUtil.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CallbackUtil.java 2016-04-09 16:26:56.000000000 +0000
@@ -70,7 +70,7 @@
*
* @param ref the GlobalRef memory address.
*/
- private static native void deleteGlobalRef(long ref);
+ static native void deleteGlobalRef(long ref);
/**
* Deletes the global reference represented by user_data if an OpenCL error occured.
@@ -99,41 +99,6 @@
*/
static native long getContextCallback();
- /**
- * Associates the specified CLContext with the specified global reference. If the context
- * is invalid, the global reference is deleted. NO-OP if user_data is 0.
- *
- * @param context the CLContext to register
- * @param user_data the global reference pointer
- */
- static void registerCallback(final CLContext context, final long user_data) {
- if ( context.getPointerUnsafe() == 0 ) {
- if ( user_data != 0 )
- deleteGlobalRef(user_data);
- return;
- }
-
- if ( user_data != 0 )
- contextUserData.put(context, user_data);
- }
-
- /**
- * Decrements the specified context's reference count, clears its association
- * with a CLContextCallback object if it exists and deletes the corresponding
- * global reference.
- *
- * @param context the CLContext to unregister
- */
- static void unregisterCallback(final CLContext context) {
- if ( context.release() > 0 )
- return;
-
- final Long user_data = contextUserData.remove(context);
-
- if ( user_data != null )
- deleteGlobalRef(user_data);
- }
-
/* [ Other callback functionality ]
The other callbacks are simpler. We create the GlobalRef before passing the callback,
we delete it when we receive the callback call.
@@ -151,7 +116,7 @@
*
* @return the callback function address
*/
- static native long getBuildProgramCallback();
+ static native long getProgramCallback();
/**
* Returns the memory address of the native function we pass to clEnqueueNativeKernel.
@@ -168,6 +133,13 @@
static native long getEventCallback();
/**
+ * Returns the memory address of the native function we pass to clSetPrintfCallback.
+ *
+ * @return the callback function address
+ */
+ static native long getPrintfCallback();
+
+ /**
* Returns the memory address of the native function we pass to clCreateContext(FromType),
* when APPLEContextLoggingUtil.SYSTEM_LOG_CALLBACK is used.
*
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2010 LWJGL Project
+ * Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,29 +33,11 @@
/**
* Instances of this class can be used to receive OpenCL program build notifications.
+ * A single CLBuildProgramCallback instance should only be used with programs created
+ * in the same CLContext.
*
* @author Spasi
*/
-public abstract class CLBuildProgramCallback extends CLCallback {
-
- protected CLBuildProgramCallback() {
- super(CallbackUtil.getBuildProgramCallback());
- }
-
- /**
- * Called from native code.
- *
- * @param program_address the CLProgram object pointer
- */
- private void handleMessage(long program_address) {
- handleMessage(CLContext.getCLProgramGlobal(program_address));
- }
-
- /**
- * The callback method.
- *
- * @param program the CLProgram object that was built
- */
- protected abstract void handleMessage(CLProgram program);
+public abstract class CLBuildProgramCallback extends CLProgramCallback {
}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCallback.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2002-2010 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.opencl;
-
-import org.lwjgl.PointerWrapperAbstract;
-
-/**
- * Base class for OpenCL callback objects.
- *
- * @author Spasi
- */
-abstract class CLCallback extends PointerWrapperAbstract {
-
- private final boolean custom;
-
- protected CLCallback(final long pointer) {
- this(pointer, false);
- }
-
- protected CLCallback(final long pointer, final boolean custom) {
- super(pointer);
-
- this.custom = custom;
- }
-
- final boolean isCustom() {
- return custom;
- }
-
-}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLChecks.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLChecks.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLChecks.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLChecks.java 2016-04-09 16:26:56.000000000 +0000
@@ -53,23 +53,23 @@
/**
* Calculates the number of bytes in the specified cl_mem buffer rectangle region.
*
- * @param origin the host origin
+ * @param offset the host offset
* @param region the rectangle region
* @param row_pitch the host row pitch
* @param slice_pitch the host slice pitch
*
* @return the region size in bytes
*/
- static int calculateBufferRectSize(final PointerBuffer origin, final PointerBuffer region, long row_pitch, long slice_pitch) {
+ static int calculateBufferRectSize(final PointerBuffer offset, final PointerBuffer region, long row_pitch, long slice_pitch) {
if ( !LWJGLUtil.CHECKS )
return 0;
- final long x = origin.get(0);
- final long y = origin.get(1);
- final long z = origin.get(2);
+ final long x = offset.get(0);
+ final long y = offset.get(1);
+ final long z = offset.get(2);
if ( LWJGLUtil.DEBUG && (x < 0 || y < 0 || z < 0) )
- throw new IllegalArgumentException("Invalid cl_mem host origin: " + x + ", " + y + ", " + z);
+ throw new IllegalArgumentException("Invalid cl_mem host offset: " + x + ", " + y + ", " + z);
final long w = region.get(0);
final long h = region.get(1);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCommandQueue.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCommandQueue.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCommandQueue.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCommandQueue.java 2016-04-09 16:26:56.000000000 +0000
@@ -50,7 +50,7 @@
super(pointer, context);
if ( isValid() ) {
this.device = device;
- this.clEvents = new CLObjectRegistryGlobal(CLContext.clEventsGlobal);
+ this.clEvents = new CLObjectRegistry();
context.getCLCommandQueueRegistry().registerObject(this);
} else {
this.device = null;
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCompileProgramCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCompileProgramCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLCompileProgramCallback.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLCompileProgramCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2011 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.opencl;
+
+/**
+ * Instances of this class can be used to receive OpenCL program compilation notifications.
+ * A single CLCompileProgramCallback instance should only be used with programs created
+ * in the same CLContext.
+ *
+ * @author Spasi
+ */
+public abstract class CLCompileProgramCallback extends CLProgramCallback {
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLContext.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLContext.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLContext.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLContext.java 2016-04-09 16:26:56.000000000 +0000
@@ -49,16 +49,14 @@
private static final CLContextUtil util = (CLContextUtil)CLPlatform.getInfoUtilInstance(CLContext.class, "CL_CONTEXT_UTIL");
private final CLObjectRegistry clCommandQueues;
- private final CLObjectRegistry clMems;
- private final CLObjectRegistry clSamplers;
- private final CLObjectRegistry clPrograms;
- private final CLObjectRegistry clEvents;
-
- /** Global registry for build callbacks. */
- static final FastLongMap clProgramsGlobal = new FastLongMap();
-
- /** Global registry for event callbacks. */
- static final FastLongMap clEventsGlobal = new FastLongMap();
+ private final CLObjectRegistry clMems;
+ private final CLObjectRegistry clSamplers;
+ private final CLObjectRegistry clPrograms;
+ private final CLObjectRegistry clEvents;
+
+ private long
+ contextCallback,
+ printfCallback;
CLContext(final long pointer, final CLPlatform platform) {
super(pointer, platform);
@@ -70,8 +68,8 @@
clCommandQueues = new CLObjectRegistry();
clMems = new CLObjectRegistry();
clSamplers = new CLObjectRegistry();
- clPrograms = new CLObjectRegistryGlobal(clProgramsGlobal);
- clEvents = new CLObjectRegistryGlobal(clEventsGlobal);
+ clPrograms = new CLObjectRegistry();
+ clEvents = new CLObjectRegistry();
} else {
clCommandQueues = null;
clMems = null;
@@ -275,8 +273,50 @@
CLObjectRegistry getCLEventRegistry() { return clEvents; }
- static CLProgram getCLProgramGlobal(final long id) { return clProgramsGlobal.get(id); }
+ private boolean checkCallback(final long callback, final int result) {
+ if ( result == 0 && (callback == 0 || isValid()) )
+ return true;
+
+ if ( callback != 0 )
+ CallbackUtil.deleteGlobalRef(callback);
+ return false;
+ }
+
+ /**
+ * Associates this context with the specified context callback reference. If the context
+ * is invalid, the callback reference is deleted. NO-OP if user_data is 0.
+ *
+ * @param callback the context callback pointer
+ */
+ void setContextCallback(final long callback) {
+ if ( checkCallback(callback, 0) )
+ this.contextCallback = callback;
+ }
+
+ /**
+ * Associates this context with the specified printf callback reference. If the context
+ * is invalid, the callback reference is deleted. NO-OP if user_data is 0.
+ *
+ * @param callback the printf callback pointer
+ */
+ void setPrintfCallback(final long callback, final int result) {
+ if ( checkCallback(callback, result) )
+ this.printfCallback = callback;
+ }
- static CLEvent getCLEventGlobal(final long id) { return clEventsGlobal.get(id); }
+ /**
+ * Decrements the context's reference count. If the reference
+ * count hits zero, it also deletes
+ * any callback objects associated with it.
+ */
+ void releaseImpl() {
+ if ( release() > 0 )
+ return;
+
+ if ( contextCallback != 0 )
+ CallbackUtil.deleteGlobalRef(contextCallback);
+ if ( printfCallback != 0 )
+ CallbackUtil.deleteGlobalRef(printfCallback);
+ }
}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLEventCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLEventCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLEventCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLEventCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -31,30 +31,46 @@
*/
package org.lwjgl.opencl;
+import org.lwjgl.PointerWrapperAbstract;
+
/**
- * Instances of this class can be used to receive OpenCL memory object destruction notifications.
+ * Instances of this class can be used to handle OpenCL event callbacks. A single
+ * CLEventCallback instance should only be used on events generated from the same
+ * CLCommandQueue or on user events associated with the same CLContext.
*
* @author Spasi
*/
-public abstract class CLEventCallback extends CLCallback {
+public abstract class CLEventCallback extends PointerWrapperAbstract {
+
+ private CLObjectRegistry eventRegistry;
protected CLEventCallback() {
super(CallbackUtil.getEventCallback());
}
/**
+ * Sets the eventRegistry that contains the CLEvents to which we're registered.
+ *
+ * @param eventRegistry the CLEvent object registry
+ */
+ void setRegistry(final CLObjectRegistry eventRegistry) {
+ this.eventRegistry = eventRegistry;
+ }
+
+ /**
* Called from native code.
*
* @param event_address the CLEvent object pointer
*/
private void handleMessage(long event_address, int event_command_exec_status) {
- handleMessage(CLContext.getCLEventGlobal(event_address), event_command_exec_status);
+ handleMessage(eventRegistry.getObject(event_address), event_command_exec_status);
}
/**
* The callback method.
*
- * @param event the CLEvent object
+ * @param event the CLEvent object
+ * @param event_command_exec_status the execution status
*/
protected abstract void handleMessage(CLEvent event, int event_command_exec_status);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLEvent.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLEvent.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLEvent.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLEvent.java 2016-04-09 16:26:56.000000000 +0000
@@ -108,6 +108,13 @@
// -------[ IMPLEMENTATION STUFF BELOW ]-------
+ CLObjectRegistry getParentRegistry() {
+ if ( queue == null )
+ return getParent().getCLEventRegistry();
+ else
+ return queue.getCLEventRegistry();
+ }
+
int release() {
try {
return super.release();
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CL.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CL.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CL.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CL.java 2016-04-09 16:26:56.000000000 +0000
@@ -33,6 +33,7 @@
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import org.lwjgl.Sys;
import java.nio.ByteBuffer;
@@ -143,7 +144,12 @@
return 0;
}
- static native long getFunctionAddress(String name);
+ /** Helper method to get a pointer to a named function in the OpenCL library. */
+ static long getFunctionAddress(String name) {
+ ByteBuffer buffer = MemoryUtil.encodeASCII(name);
+ return ngetFunctionAddress(MemoryUtil.getAddress(buffer));
+ }
+ private static native long ngetFunctionAddress(long name);
static native ByteBuffer getHostBuffer(final long address, final int size);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLLinkProgramCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLLinkProgramCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLLinkProgramCallback.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLLinkProgramCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2011 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.opencl;
+
+/**
+ * Instances of this class can be used to receive OpenCL program linkage notifications.
+ * A single CLLinkProgramCallback instance should only be used with programs created
+ * in the same CLContext.
+ *
+ * @author Spasi
+ */
+public abstract class CLLinkProgramCallback extends CLProgramCallback {
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -31,12 +31,14 @@
*/
package org.lwjgl.opencl;
+import org.lwjgl.PointerWrapperAbstract;
+
/**
* Instances of this class can be used to receive OpenCL memory object destruction notifications.
*
* @author Spasi
*/
-public abstract class CLMemObjectDestructorCallback extends CLCallback {
+public abstract class CLMemObjectDestructorCallback extends PointerWrapperAbstract {
protected CLMemObjectDestructorCallback() {
super(CallbackUtil.getMemObjectDestructorCallback());
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLNativeKernel.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLNativeKernel.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLNativeKernel.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLNativeKernel.java 2016-04-09 16:26:56.000000000 +0000
@@ -31,6 +31,8 @@
*/
package org.lwjgl.opencl;
+import org.lwjgl.PointerWrapperAbstract;
+
import java.nio.ByteBuffer;
/**
@@ -43,7 +45,7 @@
* @see CL10#clEnqueueNativeKernel
* @see #execute(java.nio.ByteBuffer[])
*/
-public abstract class CLNativeKernel extends CLCallback {
+public abstract class CLNativeKernel extends PointerWrapperAbstract {
protected CLNativeKernel() {
super(CallbackUtil.getNativeKernelCallback());
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2002-2010 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.opencl;
-
-/**
- * A CLObject registry that also registers/unregisters objects to/from a global registry.
- *
- * @author Spasi
- */
-final class CLObjectRegistryGlobal extends CLObjectRegistry {
-
- private final FastLongMap globalRegistry;
-
- CLObjectRegistryGlobal(final FastLongMap globalRegistry) {
- this.globalRegistry = globalRegistry;
- }
-
- void registerObject(final T object) {
- super.registerObject(object);
- globalRegistry.put(object.getPointer(), object);
- }
-
- void unregisterObject(final T object) {
- super.unregisterObject(object);
- globalRegistry.remove(object.getPointerUnsafe());
- }
-
-}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLPlatform.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLPlatform.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLPlatform.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLPlatform.java 2016-04-09 16:26:56.000000000 +0000
@@ -53,9 +53,6 @@
private final CLObjectRegistry clDevices;
- /** Global registry for build callbacks. */
- static final FastLongMap clDevicesGlobal = new FastLongMap();
-
private Object caps;
CLPlatform(final long pointer) {
@@ -63,7 +60,7 @@
if ( isValid() ) {
clPlatforms.put(pointer, this);
- clDevices = new CLObjectRegistryGlobal(clDevicesGlobal);
+ clDevices = new CLObjectRegistry();
} else
clDevices = null;
}
@@ -195,8 +192,6 @@
CLObjectRegistry getCLDeviceRegistry() { return clDevices; }
- static CLDevice getCLDeviceGlobal(final long id) { return clDevicesGlobal.get(id); }
-
/**
* Called from clGetDeviceIDs to register new devices.
*
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLPrintfCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLPrintfCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLPrintfCallback.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLPrintfCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002-2011 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.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Instances of this class can be used to receive OpenCL printf messages.
+ * Different CLContexts should use different CLPrintfCallback instances.
+ *
+ * @author Spasi
+ */
+public abstract class CLPrintfCallback extends PointerWrapperAbstract {
+
+ protected CLPrintfCallback() {
+ super(CallbackUtil.getPrintfCallback());
+ }
+
+ /** The callback method. */
+ protected abstract void handleMessage(String data);
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLProgramCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLProgramCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/CLProgramCallback.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/CLProgramCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2002-2011 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.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Base class for OpenCL program action notifications.
+ *
+ * @author Spasi
+ */
+abstract class CLProgramCallback extends PointerWrapperAbstract {
+
+ private CLContext context;
+
+ protected CLProgramCallback() {
+ super(CallbackUtil.getProgramCallback());
+ }
+
+ /**
+ * Sets the context that contains the CLPrograms to which we're registered.
+ *
+ * @param context the CLContext object
+ */
+ final void setContext(final CLContext context) {
+ this.context = context;
+ }
+
+ /**
+ * Called from native code.
+ *
+ * @param program_address the CLProgram object pointer
+ */
+ private void handleMessage(long program_address) {
+ handleMessage(context.getCLProgram(program_address));
+ }
+
+ /**
+ * The callback method.
+ *
+ * @param program the CLProgram object affected
+ */
+ protected abstract void handleMessage(CLProgram program);
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/InfoUtilFactory.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/InfoUtilFactory.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2016-04-09 16:26:56.000000000 +0000
@@ -118,12 +118,12 @@
final long user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify);
CLContext __result = null;
try {
- __result = new CLContext(nclCreateContext(properties.getBuffer(), 0, devices.size(), properties.getBuffer(), propertyCount * PointerBuffer.getPointerSize(), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), platform);
+ __result = new CLContext(nclCreateContext(MemoryUtil.getAddress0(properties.getBuffer()), devices.size(), MemoryUtil.getAddress(properties, propertyCount), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), platform);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
} finally {
- CallbackUtil.registerCallback(__result, user_data);
+ if ( __result != null ) __result.setContextCallback(user_data);
}
}
@@ -256,7 +256,7 @@
final int size;
switch ( param_name ) {
- case CL_KERNEL_WORK_GROUP_SIZE:
+ case CL_KERNEL_COMPILE_WORK_GROUP_SIZE:
size = 3;
break;
default:
@@ -304,9 +304,9 @@
else if ( LWJGLUtil.DEBUG )
errcode_ret = APIUtil.getBufferInt();
- CLMem __result = new CLMem(nclCreateImage2D(context.getPointer(), flags, formatBuffer, 0, image_width, image_height, image_row_pitch, host_ptr,
- host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(formatBuffer, image_width, image_height, image_row_pitch)) : 0,
- errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), context);
+ CLMem __result = new CLMem(nclCreateImage2D(context.getPointer(), flags, MemoryUtil.getAddress(formatBuffer, 0), image_width, image_height, image_row_pitch, MemoryUtil.getAddress0Safe(host_ptr) +
+ (host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(formatBuffer, image_width, image_height, image_row_pitch)) : 0),
+ MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
@@ -324,9 +324,9 @@
else if ( LWJGLUtil.DEBUG )
errcode_ret = APIUtil.getBufferInt();
- CLMem __result = new CLMem(nclCreateImage3D(context.getPointer(), flags, formatBuffer, 0, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr,
- host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage3DSize(formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0,
- errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), context);
+ CLMem __result = new CLMem(nclCreateImage3D(context.getPointer(), flags, MemoryUtil.getAddress(formatBuffer, 0), image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, MemoryUtil.getAddress0Safe(host_ptr) +
+ (host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage3DSize(formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0),
+ MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
@@ -547,7 +547,7 @@
target = new ByteBuffer[sizes.remaining()];
for ( int i = 0; i < sizes.remaining(); i++ )
- target[i] = BufferUtils.createByteBuffer((int)sizes.get(0));
+ target[i] = BufferUtils.createByteBuffer((int)sizes.get(i));
} else if ( LWJGLUtil.DEBUG ) {
final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AbstractDrawable.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AbstractDrawable.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AbstractDrawable.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AbstractDrawable.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,89 +0,0 @@
-package org.lwjgl.opengl;
-
-import org.lwjgl.LWJGLException;
-import org.lwjgl.LWJGLUtil;
-import org.lwjgl.PointerBuffer;
-
-/**
- * @author Spasi
- */
-abstract class AbstractDrawable implements DrawableLWJGL {
-
- /** Handle to the native GL rendering context */
- protected PeerInfo peer_info;
-
- /** The OpenGL Context. */
- protected Context context;
-
- protected AbstractDrawable() {
- }
-
- public Context getContext() {
- synchronized ( GlobalLock.lock ) {
- return context;
- }
- }
-
- public Context createSharedContext() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- checkDestroyed();
- return new Context(peer_info, context.getContextAttribs(), context);
- }
- }
-
- public boolean isCurrent() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- checkDestroyed();
- return context.isCurrent();
- }
- }
-
- public void makeCurrent() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- checkDestroyed();
- context.makeCurrent();
- }
- }
-
- public void releaseContext() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- checkDestroyed();
- if ( context.isCurrent() )
- Context.releaseCurrentContext();
- }
- }
-
- public void destroy() {
- synchronized ( GlobalLock.lock ) {
- if ( context == null )
- return;
-
- try {
- releaseContext();
-
- context.forceDestroy();
- context = null;
-
- if ( peer_info != null ) {
- peer_info.destroy();
- peer_info = null;
- }
- } catch (LWJGLException e) {
- LWJGLUtil.log("Exception occurred while destroying Drawable: " + e);
- }
- }
- }
-
- public void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- checkDestroyed();
- context.setCLSharingProperties(properties);
- }
- }
-
- protected final void checkDestroyed() {
- if ( context == null )
- throw new IllegalStateException("The Drawable has no context available.");
- }
-
-}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -110,7 +110,7 @@
description = "OTHER";
break;
default:
- description = "Unknown (" + Integer.toHexString(category) + ")";
+ description = printUnknownToken(category);
}
System.err.println("\tCategory: " + description);
@@ -125,12 +125,16 @@
description = "LOW";
break;
default:
- description = "Unknown (" + Integer.toHexString(category) + ")";
+ description = printUnknownToken(severity);
}
System.err.println("\tSeverity: " + description);
System.err.println("\tMessage: " + message);
}
+
+ private String printUnknownToken(final int token) {
+ return "Unknown (0x" + Integer.toHexString(token).toUpperCase() + ")";
+ }
});
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/APIUtil.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/APIUtil.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/APIUtil.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/APIUtil.java 2016-04-09 16:26:56.000000000 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2008 LWJGL Project
+ * Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,38 +33,46 @@
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import java.nio.*;
-/** @author spasi */
+/**
+ * Utility class for OpenGL API calls. Instances of APIUtil are created in ContextCapabilities,
+ * so we have an instance per OpenGL context.
+ *
+ * @author spasi
+ */
final class APIUtil {
- private static final int INITIAL_BUFFER_SIZE = 256;
+ private static final int INITIAL_BUFFER_SIZE = 256;
private static final int INITIAL_LENGTHS_SIZE = 4;
private static final int BUFFERS_SIZE = 32;
- private static final ThreadLocal arrayTL = new ThreadLocal() {
- protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
- };
+ private char[] array;
+ private ByteBuffer buffer;
+ private IntBuffer lengths;
- private static final ThreadLocal bufferTL = new ThreadLocal() {
- protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
- };
+ private final IntBuffer ints;
+ private final LongBuffer longs;
+ private final FloatBuffer floats;
+ private final DoubleBuffer doubles;
- private static final ThreadLocal lengthsTL = new ThreadLocal() {
- protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
- };
+ APIUtil() {
+ array = new char[INITIAL_BUFFER_SIZE];
+ buffer = BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE);
+ lengths = BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE);
- private static final ThreadLocal buffersTL = new ThreadLocal() {
- protected Buffers initialValue() { return new Buffers(); }
- };
+ ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
+ longs = BufferUtils.createLongBuffer(BUFFERS_SIZE);
- private APIUtil() {
+ floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
+ doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE);
}
- private static char[] getArray(final int size) {
- char[] array = arrayTL.get();
+ private static char[] getArray(final ContextCapabilities caps, final int size) {
+ char[] array = caps.util.array;
if ( array.length < size ) {
int sizeNew = array.length << 1;
@@ -72,14 +80,14 @@
sizeNew <<= 1;
array = new char[size];
- arrayTL.set(array);
+ caps.util.array = array;
}
return array;
}
- static ByteBuffer getBufferByte(final int size) {
- ByteBuffer buffer = bufferTL.get();
+ static ByteBuffer getBufferByte(final ContextCapabilities caps, final int size) {
+ ByteBuffer buffer = caps.util.buffer;
if ( buffer.capacity() < size ) {
int sizeNew = buffer.capacity() << 1;
@@ -87,15 +95,15 @@
sizeNew <<= 1;
buffer = BufferUtils.createByteBuffer(size);
- bufferTL.set(buffer);
+ caps.util.buffer = buffer;
} else
buffer.clear();
return buffer;
}
- private static ByteBuffer getBufferByteOffset(final int size) {
- ByteBuffer buffer = bufferTL.get();
+ private static ByteBuffer getBufferByteOffset(final ContextCapabilities caps, final int size) {
+ ByteBuffer buffer = caps.util.buffer;
if ( buffer.capacity() < size ) {
int sizeNew = buffer.capacity() << 1;
@@ -104,7 +112,7 @@
final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size);
bufferNew.put(buffer);
- bufferTL.set(buffer = bufferNew);
+ caps.util.buffer = (buffer = bufferNew);
} else {
buffer.position(buffer.limit());
buffer.limit(buffer.capacity());
@@ -113,22 +121,20 @@
return buffer;
}
- static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
+ static IntBuffer getBufferInt(final ContextCapabilities caps) { return caps.util.ints; }
- static IntBuffer getBufferInt() { return buffersTL.get().ints; }
+ static LongBuffer getBufferLong(final ContextCapabilities caps) { return caps.util.longs; }
- static LongBuffer getBufferLong() { return buffersTL.get().longs; }
+ static FloatBuffer getBufferFloat(final ContextCapabilities caps) { return caps.util.floats; }
- static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
+ static DoubleBuffer getBufferDouble(final ContextCapabilities caps) { return caps.util.doubles; }
- static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; }
-
- static IntBuffer getLengths() {
- return getLengths(1);
+ static IntBuffer getLengths(final ContextCapabilities caps) {
+ return getLengths(caps, 1);
}
- static IntBuffer getLengths(final int size) {
- IntBuffer lengths = lengthsTL.get();
+ static IntBuffer getLengths(final ContextCapabilities caps, final int size) {
+ IntBuffer lengths = caps.util.lengths;
if ( lengths.capacity() < size ) {
int sizeNew = lengths.capacity();
@@ -136,7 +142,7 @@
sizeNew <<= 1;
lengths = BufferUtils.createIntBuffer(size);
- lengthsTL.set(lengths);
+ caps.util.lengths = lengths;
} else
lengths.clear();
@@ -168,9 +174,9 @@
*
* @return the buffer as a String.
*/
- static String getString(final ByteBuffer buffer) {
+ static String getString(final ContextCapabilities caps, final ByteBuffer buffer) {
final int length = buffer.remaining();
- final char[] charArray = getArray(length);
+ final char[] charArray = getArray(caps, length);
for ( int i = buffer.position(); i < buffer.limit(); i++ )
charArray[i - buffer.position()] = (char)buffer.get(i);
@@ -185,10 +191,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string) {
- final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
+ static long getBuffer(final ContextCapabilities caps, final CharSequence string) {
+ final ByteBuffer buffer = encode(getBufferByte(caps, string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -198,10 +204,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string, final int offset) {
- final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
+ static long getBuffer(final ContextCapabilities caps, final CharSequence string, final int offset) {
+ final ByteBuffer buffer = encode(getBufferByteOffset(caps, offset + string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress(buffer);
}
/**
@@ -211,11 +217,11 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence string) {
- final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
+ static long getBufferNT(final ContextCapabilities caps, final CharSequence string) {
+ final ByteBuffer buffer = encode(getBufferByte(caps, string.length() + 1), string);
buffer.put((byte)0);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
static int getTotalLength(final CharSequence[] strings) {
@@ -233,14 +239,14 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence[] strings) {
- final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
+ static long getBuffer(final ContextCapabilities caps, final CharSequence[] strings) {
+ final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings));
for ( CharSequence string : strings )
encode(buffer, string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -250,8 +256,8 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence[] strings) {
- final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
+ static long getBufferNT(final ContextCapabilities caps, final CharSequence[] strings) {
+ final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings) + strings.length);
for ( CharSequence string : strings ) {
encode(buffer, string);
@@ -259,7 +265,7 @@
}
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -269,34 +275,22 @@
*
* @return the String lengths in an IntBuffer
*/
- static IntBuffer getLengths(final CharSequence[] strings) {
- IntBuffer buffer = getLengths(strings.length);
+ static long getLengths(final ContextCapabilities caps, final CharSequence[] strings) {
+ IntBuffer buffer = getLengths(caps, strings.length);
for ( CharSequence string : strings )
buffer.put(string.length());
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
- private static class Buffers {
-
- final ShortBuffer shorts;
- final IntBuffer ints;
- final LongBuffer longs;
-
- final FloatBuffer floats;
- final DoubleBuffer doubles;
-
- Buffers() {
- shorts = BufferUtils.createShortBuffer(BUFFERS_SIZE);
- ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
- longs = BufferUtils.createLongBuffer(BUFFERS_SIZE);
-
- floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
- doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE);
- }
+ static long getInt(final ContextCapabilities caps, final int value) {
+ return MemoryUtil.getAddress0(getBufferInt(caps).put(0, value));
+ }
+ static long getBufferByte0(final ContextCapabilities caps) {
+ return MemoryUtil.getAddress0(getBufferByte(caps, 0));
}
}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -113,7 +113,7 @@
description = "OTHER";
break;
default:
- description = "Unknown (" + Integer.toHexString(source) + ")";
+ description = printUnknownToken(source);
}
System.err.println("\tSource: " + description);
@@ -137,7 +137,7 @@
description = "OTHER";
break;
default:
- description = "Unknown (" + Integer.toHexString(source) + ")";
+ description = printUnknownToken(type);
}
System.err.println("\tType: " + description);
@@ -152,12 +152,16 @@
description = "LOW";
break;
default:
- description = "Unknown (" + Integer.toHexString(source) + ")";
+ description = printUnknownToken(severity);
}
System.err.println("\tSeverity: " + description);
System.err.println("\tMessage: " + message);
}
+
+ private String printUnknownToken(final int token) {
+ return "Unknown (0x" + Integer.toHexString(token).toUpperCase() + ")";
+ }
});
}
@@ -184,9 +188,9 @@
/**
* This method will be called when an ARB_debug_output message is generated.
*
- * @param id the message ID
* @param source the message source
* @param type the message type
+ * @param id the message ID
* @param severity the message severity
* @param message the string representation of the message.
*/
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTCanvasImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTCanvasImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTCanvasImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTCanvasImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -40,14 +40,14 @@
/**
*
* @author elias_naur
- * @version $Revision: 3002 $
- * $Id: AWTCanvasImplementation.java 3002 2008-04-10 20:25:54Z elias_naur $
+ * @version $Revision$
+ * $Id$
*/
interface AWTCanvasImplementation {
/**
* Return an opaque handle to the canvas peer information required to create a context from it.
*/
- PeerInfo createPeerInfo(Canvas component, PixelFormat pixel_format) throws LWJGLException;
+ PeerInfo createPeerInfo(Canvas component, PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException;
/**
* Find a proper GraphicsConfiguration from the given GraphicsDevice and PixelFormat.
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTGLCanvas.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTGLCanvas.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2016-04-09 16:26:56.000000000 +0000
@@ -42,21 +42,23 @@
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
+import static org.lwjgl.opengl.GL11.*;
+
/**
*
* An AWT rendering context.
*
*
- * @author $Author: spasi $
- * $Id: AWTGLCanvas.java 3418 2010-09-28 21:11:35Z spasi $
- * @version $Revision: 3418 $
+ * @author $Author$
+ * $Id$
+ * @version $Revision$
*/
public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListener, HierarchyListener {
private static final long serialVersionUID = 1L;
private static final AWTCanvasImplementation implementation;
- private boolean update_context;
+ private boolean update_context;
private Object SYNC_LOCK = new Object();
/** The requested pixel format */
@@ -69,8 +71,8 @@
private final ContextAttribs attribs;
/** Context handle */
- private PeerInfo peer_info;
- private Context context;
+ private PeerInfo peer_info;
+ private ContextGL context;
/**
* re-entry counter for support for re-entrant
@@ -105,20 +107,43 @@
}
}
+ public void setPixelFormat(final PixelFormatLWJGL pf) throws LWJGLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs) throws LWJGLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public PixelFormatLWJGL getPixelFormat() {
+ return pixel_format;
+ }
+
/** This method should only be called internally. */
- public Context getContext() {
+ public ContextGL getContext() {
return context;
}
/** This method should only be called internally. */
- public Context createSharedContext() throws LWJGLException {
+ public ContextGL createSharedContext() throws LWJGLException {
synchronized ( SYNC_LOCK ) {
if ( context == null ) throw new IllegalStateException("Canvas not yet displayable");
- return new Context(peer_info, context.getContextAttribs(), context);
+ return new ContextGL(peer_info, context.getContextAttribs(), context);
}
}
+ public void checkGLError() {
+ Util.checkGLError();
+ }
+
+ public void initContext(final float r, final float g, final float b) {
+ // set background clear color
+ glClearColor(r, g, b, 0.0f);
+ // Clear window to avoid the desktop "showing through"
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
/** Constructor using the default PixelFormat. */
public AWTGLCanvas() throws LWJGLException {
this(new PixelFormat());
@@ -195,7 +220,7 @@
synchronized ( SYNC_LOCK ) {
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
- Context.setSwapInterval(swap_interval);
+ ContextGL.setSwapInterval(swap_interval);
}
}
@@ -209,7 +234,7 @@
synchronized ( SYNC_LOCK ) {
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
- Context.swapBuffers();
+ ContextGL.swapBuffers();
}
}
@@ -238,7 +263,7 @@
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
if ( context.isCurrent() )
- Context.releaseCurrentContext();
+ context.releaseCurrent();
}
}
@@ -290,12 +315,12 @@
return;
try {
if ( peer_info == null ) {
- this.peer_info = implementation.createPeerInfo(this, pixel_format);
+ this.peer_info = implementation.createPeerInfo(this, pixel_format, attribs);
}
peer_info.lockAndGetHandle();
try {
if ( context == null ) {
- this.context = new Context(peer_info, attribs, drawable != null ? ((DrawableLWJGL)drawable).getContext() : null);
+ this.context = new ContextGL(peer_info, attribs, drawable != null ? (ContextGL)((DrawableLWJGL)drawable).getContext() : null);
first_run = true;
}
@@ -315,7 +340,7 @@
} finally {
reentry_count--;
if ( reentry_count == 0 )
- Context.releaseCurrentContext();
+ context.releaseCurrent();
}
} finally {
peer_info.unlock();
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTSurfaceLock.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/AWTSurfaceLock.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/AWTSurfaceLock.java 2016-04-09 16:26:56.000000000 +0000
@@ -32,6 +32,8 @@
package org.lwjgl.opengl;
import java.awt.Canvas;
+import java.awt.Component;
+import java.applet.Applet;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedActionException;
@@ -43,8 +45,8 @@
/**
*
* @author elias_naur
- * @version $Revision: 3418 $
- * $Id: AWTSurfaceLock.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
final class AWTSurfaceLock {
@@ -78,7 +80,8 @@
// We need to elevate privileges because of an AWT bug. Please see
// http://192.18.37.44/forums/index.php?topic=10572 for a discussion.
// It is only needed on first call, so we avoid it on all subsequent calls
- // due to performance.
+ // due to performance..
+
if (firstLockSucceeded)
return lockAndInitHandle(lock_buffer, component);
else
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/CallbackUtil.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/CallbackUtil.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/CallbackUtil.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/CallbackUtil.java 2016-04-09 16:26:56.000000000 +0000
@@ -42,9 +42,11 @@
final class CallbackUtil {
/** Context -> Long */
- private static final Map contextUserParamsARB = new HashMap();
+ private static final Map contextUserParamsARB = new HashMap();
/** Context -> Long */
- private static final Map contextUserParamsAMD = new HashMap();
+ private static final Map contextUserParamsAMD = new HashMap();
+ /** Context -> Long */
+ private static final Map contextUserParamsKHR = new HashMap();
private CallbackUtil() {}
@@ -84,19 +86,19 @@
*
* @param userParam the global reference pointer
*/
- private static void registerContextCallback(final long userParam, final Map contextUserData) {
- Context context = Context.getCurrentContext();
- if ( context == null ) {
+ private static void registerContextCallback(final long userParam, final Map contextUserData) {
+ ContextCapabilities caps = GLContext.getCapabilities();
+ if ( caps == null ) {
deleteGlobalRef(userParam);
throw new IllegalStateException("No context is current.");
}
- final Long userParam_old = contextUserData.remove(context);
+ final Long userParam_old = contextUserData.remove(caps);
if ( userParam_old != null )
deleteGlobalRef(userParam_old);
if ( userParam != 0 )
- contextUserData.put(context, userParam);
+ contextUserData.put(caps, userParam);
}
/**
@@ -104,12 +106,19 @@
*
* @param context the Context to unregister
*/
- static void unregisterCallbacks(final Context context) {
- Long userParam = contextUserParamsARB.remove(context);
+ static void unregisterCallbacks(final Object context) {
+ // TODO: This is never called for custom contexts. Need to fix for LWJGL 3.0
+ final ContextCapabilities caps = GLContext.getCapabilities(context);
+
+ Long userParam = contextUserParamsARB.remove(caps);
+ if ( userParam != null )
+ deleteGlobalRef(userParam);
+
+ userParam = contextUserParamsAMD.remove(caps);
if ( userParam != null )
deleteGlobalRef(userParam);
- userParam = contextUserParamsAMD.remove(context);
+ userParam = contextUserParamsKHR.remove(caps);
if ( userParam != null )
deleteGlobalRef(userParam);
}
@@ -154,4 +163,24 @@
registerContextCallback(userParam, contextUserParamsAMD);
}
+ // --------- [ KHR_debug ] ---------
+
+ /**
+ * Returns the memory address of the native function we pass to glDebugMessageCallback.
+ *
+ * @return the callback function address
+ */
+ static native long getDebugCallbackKHR();
+
+ /**
+ * Associates the current OpenGL context with the specified global reference. If there
+ * is no context current, the global reference is deleted and an exception is thrown.
+ * Any previous callback registrations will be cleared.
+ *
+ * @param userParam the global reference pointer
+ */
+ static void registerContextCallbackKHR(final long userParam) {
+ registerContextCallback(userParam, contextUserParamsKHR);
+ }
+
}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextAttribsImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextAttribsImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextAttribsImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextAttribsImplementation.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2002-2008 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;
-
-/** @author spasi */
-interface ContextAttribsImplementation {
-
- int getMajorVersionAttrib();
-
- int getMinorVersionAttrib();
-
- int getLayerPlaneAttrib();
-
- int getFlagsAttrib();
-
- int getDebugBit();
-
- int getForwardCompatibleBit();
-
- int getProfileMaskAttrib();
-
- int getProfileCoreBit();
-
- int getProfileCompatibilityBit();
-
-}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextAttribs.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextAttribs.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextAttribs.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextAttribs.java 2016-04-09 16:26:56.000000000 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2008 LWJGL Project
+ * Copyright (c) 2002-2014 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,269 +35,399 @@
import org.lwjgl.LWJGLUtil;
import java.nio.IntBuffer;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
/**
- * This class represents the context attributes passed to CreateContextAttribs of the ARB_create_context and
- * ARB_create_context_profile extensions.
- * These attributes can be used to indicate at context creation which OpenGL interface will be used. This includes the
- * OpenGL version, the layer plane on which rendering takes place and also optional debug and forward combatibility modes.
- * (read the ARB_create_context spec for details)
+ * This class represents the context attributes passed to CreateContextAttribs of the ARB_create_context extension.
+ *
+ * The attributes supported are described in the following extensions:
+ *
*
* Use of this class is optional. If an OpenGL context is created without passing an instance of this class
* (or ARB_create_context is not supported), the old context creation code will be used. Support for debug and forward
* compatible mobes is not guaranteed by the OpenGL implementation. Developers may encounter debug contexts being the same
* as non-debug contexts or forward compatible contexts having support for deprecated functionality.
*
- * If the forwardCompatible
- * attribute is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0 specification). This
- * means that developers can start working on cleaning up their applications without an OpenGL 3.0 complaint driver.
+ * If the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} flag is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0
+ * specification), even if the driver exposes the corresponding entry points.
+ *
+ * This extension is not supported on MacOS X. However, in order to enable the GL 3.2 context on MacOS X 10.7 or newer, an instance of this class must be passed
+ * to LWJGL. The only valid configuration is ContextAttribs(3, 2, CONTEXT_CORE_PROFILE_BIT_ARB), anything else will be ignored.
*
* @author spasi
*/
public final class ContextAttribs {
- // Same values for GLX & WGL
- private static final int CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
+ // ATTRIBUTES
+
+ public static final int CONTEXT_MAJOR_VERSION_ARB = 0x2091;
+ public static final int CONTEXT_MINOR_VERSION_ARB = 0x2092;
+
+ public static final int CONTEXT_PROFILE_MASK_ARB = 0x9126,
+ CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001,
+ CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002,
+ CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
+
+ public static final int CONTEXT_FLAGS_ARB = 0x2094,
+ CONTEXT_DEBUG_BIT_ARB = 0x0001,
+ CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002,
+ CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004,
+ CONTEXT_RESET_ISOLATION_BIT_ARB = 0x00000008;
+
+ public static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256,
+ NO_RESET_NOTIFICATION_ARB = 0x8261,
+ LOSE_CONTEXT_ON_RESET_ARB = 0x8252;
+
+ public static final int CONTEXT_RELEASE_BEHABIOR_ARB = 0x2097,
+ CONTEXT_RELEASE_BEHAVIOR_NONE_ARB = 0x0000,
+ CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB = 0x2098;
+
+ public static final int CONTEXT_LAYER_PLANE_ARB = 0x2093; // WGL-only
- private static final int CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004;
- private static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256;
- private static final int
- NO_RESET_NOTIFICATION_ARB = 0x8261,
- LOSE_CONTEXT_ON_RESET_ARB = 0x8252;
+ // STATE
private int majorVersion;
private int minorVersion;
- private int layerPlane;
+ private int profileMask;
+ private int contextFlags;
+
+ private int contextResetNotificationStrategy = NO_RESET_NOTIFICATION_ARB;
+ private int contextReleaseBehavior = CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB;
- private boolean debug;
- private boolean forwardCompatible;
- private boolean robustAccess;
-
- private boolean profileCore;
- private boolean profileCompatibility;
- private boolean profileES;
+ private int layerPlane;
- private boolean loseContextOnReset;
+ // CONSTRUCTORS
+ /** Creates the default ContextAttribs instance. No special attributes will be used when creating the OpenGL context. */
public ContextAttribs() {
this(1, 0);
}
- public ContextAttribs(final int majorVersion, final int minorVersion) {
+ /** Creates a ContextAttribs instance for the given OpenGL version. */
+ public ContextAttribs(int majorVersion, int minorVersion) {
+ this(majorVersion, minorVersion, 0, 0);
+ }
+
+ /**
+ * Creates a new ContextAttribs instance with the given attributes.
+ *
+ * @param majorVersion the major OpenGL version
+ * @param minorVersion the minor OpenGL version
+ * @param profileMask the context profile mask. One of: {@link #CONTEXT_CORE_PROFILE_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ES2_PROFILE_BIT_EXT}
+ */
+ public ContextAttribs(int majorVersion, int minorVersion, int profileMask) {
+ this(majorVersion, minorVersion, 0, profileMask);
+ }
+
+ /**
+ * Creates a new ContextAttribs instance with the given attributes.
+ *
+ * @param majorVersion the major OpenGL version
+ * @param minorVersion the minor OpenGL version
+ * @param profileMask the context profile mask. One of: {@link #CONTEXT_CORE_PROFILE_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ES2_PROFILE_BIT_EXT}
+ * @param contextFlags the context flags, a bitfield value. One or more of: {@link #CONTEXT_DEBUG_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB}, {@link #CONTEXT_RESET_ISOLATION_BIT_ARB}
+ */
+ public ContextAttribs(int majorVersion, int minorVersion, int profileMask, int contextFlags) {
if ( majorVersion < 0 || 4 < majorVersion ||
minorVersion < 0 ||
- (majorVersion == 4 && 0 < minorVersion) ||
+ (majorVersion == 4 && 5 < minorVersion) ||
(majorVersion == 3 && 3 < minorVersion) ||
(majorVersion == 2 && 1 < minorVersion) ||
(majorVersion == 1 && 5 < minorVersion) )
throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);
+ if ( LWJGLUtil.CHECKS ) {
+ if ( 1 < Integer.bitCount(profileMask) || CONTEXT_ES2_PROFILE_BIT_EXT < profileMask )
+ throw new IllegalArgumentException("Invalid profile mask specified: " + Integer.toBinaryString(profileMask));
+
+ if ( 0xF < contextFlags )
+ throw new IllegalArgumentException("Invalid context flags specified: " + Integer.toBinaryString(profileMask));
+ }
+
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
- }
- private ContextAttribs(final ContextAttribs attribs) {
- this.majorVersion = attribs.majorVersion;
- this.minorVersion = attribs.minorVersion;
+ this.profileMask = profileMask;
+ this.contextFlags = contextFlags;
+ }
- this.layerPlane = attribs.layerPlane;
+ // Copy constructor
+ private ContextAttribs(ContextAttribs other) {
+ this.majorVersion = other.majorVersion;
+ this.minorVersion = other.minorVersion;
- this.debug = attribs.debug;
- this.forwardCompatible = attribs.forwardCompatible;
- this.robustAccess = attribs.robustAccess;
+ this.profileMask = other.profileMask;
+ this.contextFlags = other.contextFlags;
- this.profileCore = attribs.profileCore;
- this.profileCompatibility = attribs.profileCompatibility;
- this.profileES = attribs.profileES;
+ this.contextResetNotificationStrategy = other.contextResetNotificationStrategy;
+ this.contextReleaseBehavior = other.contextReleaseBehavior;
- this.loseContextOnReset = attribs.loseContextOnReset;
+ this.layerPlane = other.layerPlane;
}
+ // GETTERS
+
+ /** Returns the {@link #CONTEXT_MAJOR_VERSION_ARB} value. */
public int getMajorVersion() {
return majorVersion;
}
+ /** Returns the {@link #CONTEXT_MINOR_VERSION_ARB} value. */
public int getMinorVersion() {
return minorVersion;
}
- public int getLayerPlane() {
- return layerPlane;
- }
-
- public boolean isDebug() {
- return debug;
+ /** Returns the {@link #CONTEXT_PROFILE_MASK_ARB} value. */
+ public int getProfileMask() {
+ return profileMask;
}
- public boolean isForwardCompatible() {
- return forwardCompatible;
+ private boolean hasMask(int mask) {
+ return profileMask == mask;
}
+ /** Returns true if the {@link #CONTEXT_CORE_PROFILE_BIT_ARB} has been set. */
public boolean isProfileCore() {
- return profileCore;
+ return hasMask(CONTEXT_CORE_PROFILE_BIT_ARB);
}
+ /** Returns true if the {@link #CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB} has been set. */
public boolean isProfileCompatibility() {
- return profileCompatibility;
+ return hasMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
}
+ /** Returns true if the {@link #CONTEXT_ES2_PROFILE_BIT_EXT} has been set. */
public boolean isProfileES() {
- return profileES;
+ return hasMask(CONTEXT_ES2_PROFILE_BIT_EXT);
}
- public ContextAttribs withLayer(final int layerPlane) {
- if ( layerPlane < 0 )
- throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
+ /** Returns the {@link #CONTEXT_FLAGS_ARB} value. */
+ public int getContextFlags() {
+ return contextFlags;
+ }
- if ( layerPlane == this.layerPlane )
- return this;
+ private boolean hasFlag(int flag) {
+ return (contextFlags & flag) != 0;
+ }
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.layerPlane = layerPlane;
- return attribs;
+ /** Returns true if the {@link #CONTEXT_DEBUG_BIT_ARB} has been set. */
+ public boolean isDebug() {
+ return hasFlag(CONTEXT_DEBUG_BIT_ARB);
}
- public ContextAttribs withDebug(final boolean debug) {
- if ( debug == this.debug )
- return this;
+ /** Returns true if the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} has been set. */
+ public boolean isForwardCompatible() {
+ return hasFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
+ }
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.debug = debug;
- return attribs;
+ /** Returns true if the {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB} has been set. */
+ public boolean isRobustAccess() { return hasFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB); }
+
+ /** Returns true if the {@link #CONTEXT_RESET_ISOLATION_BIT_ARB} has been set. */
+ public boolean isContextResetIsolation() {
+ return hasFlag(CONTEXT_RESET_ISOLATION_BIT_ARB);
+ }
+
+ /** Returns the {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} value. */
+ public int getContextResetNotificationStrategy() {
+ return contextResetNotificationStrategy;
}
- public ContextAttribs withForwardCompatible(final boolean forwardCompatible) {
- if ( forwardCompatible == this.forwardCompatible )
+ /**
+ * Returns true if the {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} has been set to {@link #LOSE_CONTEXT_ON_RESET_ARB}.
+ *
+ * @deprecated use {@link #getContextResetNotificationStrategy} instead
+ */
+ public boolean isLoseContextOnReset() { return contextResetNotificationStrategy == LOSE_CONTEXT_ON_RESET_ARB; }
+
+ /** Returns the {@link #CONTEXT_RELEASE_BEHABIOR_ARB} value. */
+ public int getContextReleaseBehavior() {
+ return contextReleaseBehavior;
+ }
+
+ /** Returns the {@link #CONTEXT_LAYER_PLANE_ARB} value. */
+ public int getLayerPlane() {
+ return layerPlane;
+ }
+
+ // CHAIN CONFIGURATION PATTERN
+
+ private ContextAttribs toggleMask(int mask, boolean value) {
+ if ( value == hasMask(mask) )
return this;
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.forwardCompatible = forwardCompatible;
+ ContextAttribs attribs = new ContextAttribs(this);
+ attribs.profileMask = value ? mask : 0;
return attribs;
}
- public ContextAttribs withProfileCore(final boolean profileCore) {
+ /**
+ * Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_CORE_PROFILE_BIT_ARB} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
+ * If {@code profileCore} is true, all other bits in the mask are cleared.
+ */
+ public ContextAttribs withProfileCore(boolean profileCore) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
- if ( profileCore == this.profileCore )
- return this;
-
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.profileCore = profileCore;
- if ( profileCore )
- attribs.profileCompatibility = false;
-
- return attribs;
+ return toggleMask(CONTEXT_CORE_PROFILE_BIT_ARB, profileCore);
}
- public ContextAttribs withProfileCompatibility(final boolean profileCompatibility) {
+ /**
+ * Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
+ * If {@code profileCompatibility} is true, all other bits in the mask are cleared.
+ */
+ public ContextAttribs withProfileCompatibility(boolean profileCompatibility) {
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
- if ( profileCompatibility == this.profileCompatibility )
- return this;
+ return toggleMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, profileCompatibility);
+ }
+
+ /**
+ * Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_ES2_PROFILE_BIT_EXT} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
+ * If {@code profileES} is true, all other bits in the mask are cleared.
+ */
+ public ContextAttribs withProfileES(boolean profileES) {
+ if ( !(majorVersion == 2 && minorVersion == 0) )
+ throw new IllegalArgumentException("The OpenGL ES profile is only supported on OpenGL version 2.0.");
+
+ return toggleMask(CONTEXT_ES2_PROFILE_BIT_EXT, profileES);
+ }
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.profileCompatibility = profileCompatibility;
- if ( profileCompatibility )
- attribs.profileCore = false;
+ private ContextAttribs toggleFlag(int flag, boolean value) {
+ if ( value == hasFlag(flag) )
+ return this;
+ ContextAttribs attribs = new ContextAttribs(this);
+ attribs.contextFlags ^= flag; // toggle bit
return attribs;
}
- public ContextAttribs withProfileES(final boolean profileES) {
- if ( !(majorVersion == 2 && minorVersion == 0) )
- throw new IllegalArgumentException("The OpenGL ES profiles is only supported for OpenGL version 2.0.");
+ /** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_DEBUG_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
+ public ContextAttribs withDebug(boolean debug) { return toggleFlag(CONTEXT_DEBUG_BIT_ARB, debug); }
+
+ /** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
+ public ContextAttribs withForwardCompatible(boolean forwardCompatible) { return toggleFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, forwardCompatible); }
- if ( profileES == this.profileES )
+ /** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
+ public ContextAttribs withRobustAccess(boolean robustAccess) { return toggleFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB, robustAccess); }
+
+ /** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_RESET_ISOLATION_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
+ public ContextAttribs withContextResetIsolation(boolean contextResetIsolation) { return toggleFlag(CONTEXT_RESET_ISOLATION_BIT_ARB, contextResetIsolation); }
+
+ /**
+ * Returns a ContextAttribs instance with {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} set to the given strategy. The default context reset notification
+ * strategy is {@link #NO_RESET_NOTIFICATION_ARB}.
+ *
+ * @param strategy the context reset notification strategy. One of: {@link #NO_RESET_NOTIFICATION_ARB}, {@link #LOSE_CONTEXT_ON_RESET_ARB}
+ *
+ * @return the new ContextAttribs
+ */
+ public ContextAttribs withResetNotificationStrategy(int strategy) {
+ if ( strategy == contextResetNotificationStrategy )
return this;
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.profileES = profileES;
+ if ( LWJGLUtil.CHECKS && !(strategy == NO_RESET_NOTIFICATION_ARB || strategy == LOSE_CONTEXT_ON_RESET_ARB) )
+ throw new IllegalArgumentException("Invalid context reset notification strategy specified: 0x" + LWJGLUtil.toHexString(strategy));
+ ContextAttribs attribs = new ContextAttribs(this);
+ attribs.contextResetNotificationStrategy = strategy;
return attribs;
}
/**
- * Returns a ContextAttribs instance with CONTEXT_RESET_NOTIFICATION_STRATEGY set
- * to LOSE_CONTEXT_ON_RESET if the parameter is true or to NO_RESET_NOTIFICATION
- * if the parameter is false.
+ * Returns a ContextAttribs instance with {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} set to {@link #LOSE_CONTEXT_ON_RESET_ARB} if the parameter is
+ * true or to {@link #NO_RESET_NOTIFICATION_ARB} if the parameter is false.
+ *
+ * @param loseContextOnReset the context reset notification strategy
+ *
+ * @return the new ContextAttribs
+ *
+ * @deprecated use {@link #withResetNotificationStrategy} instead
+ */
+ public ContextAttribs withLoseContextOnReset(boolean loseContextOnReset) {
+ return withResetNotificationStrategy(loseContextOnReset ? LOSE_CONTEXT_ON_RESET_ARB : NO_RESET_NOTIFICATION_ARB);
+ }
+
+ /**
+ * Returns a ContextAttribs instance with {@link #CONTEXT_RELEASE_BEHABIOR_ARB} set to the given behavior. The default context release behavior is
+ * {@link #CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB}.
*
- * @param loseContextOnReset
+ * @param behavior the context release behavior. One of: {@link #CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB}, {@link #CONTEXT_RELEASE_BEHAVIOR_NONE_ARB}
*
* @return the new ContextAttribs
*/
- public ContextAttribs withLoseContextOnReset(final boolean loseContextOnReset) {
- if ( loseContextOnReset == this.loseContextOnReset )
+ public ContextAttribs withContextReleaseBehavior(int behavior) {
+ if ( behavior == contextReleaseBehavior )
return this;
- final ContextAttribs attribs = new ContextAttribs(this);
- attribs.loseContextOnReset = loseContextOnReset;
+ if ( LWJGLUtil.CHECKS && !(behavior == CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB || behavior == CONTEXT_RELEASE_BEHAVIOR_NONE_ARB) )
+ throw new IllegalArgumentException("Invalid context release behavior specified: 0x" + LWJGLUtil.toHexString(behavior));
+
+ ContextAttribs attribs = new ContextAttribs(this);
+ attribs.contextReleaseBehavior = behavior;
return attribs;
}
- private static ContextAttribsImplementation getImplementation() {
- switch ( LWJGLUtil.getPlatform() ) {
- case LWJGLUtil.PLATFORM_LINUX:
- return new LinuxContextAttribs();
- case LWJGLUtil.PLATFORM_WINDOWS:
- return new WindowsContextAttribs();
- case LWJGLUtil.PLATFORM_MACOSX:
- return new MacOSXContextAttribs();
- default:
- throw new IllegalStateException("Unsupported platform");
- }
- }
+ /** Returns a new {@code ContextAttribs} instance with {@link #CONTEXT_LAYER_PLANE_ARB} set to the given value. */
+ public ContextAttribs withLayer(int layerPlane) {
+ if ( LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS )
+ throw new IllegalArgumentException("The CONTEXT_LAYER_PLANE_ARB attribute is supported only on the Windows platform.");
- IntBuffer getAttribList() {
- ContextAttribsImplementation implementation = getImplementation();
+ if ( layerPlane == this.layerPlane )
+ return this;
- int attribCount = 0;
+ if ( layerPlane < 0 )
+ throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
- if ( !(majorVersion == 1 && minorVersion == 0) )
- attribCount += 2;
- if ( 0 < layerPlane )
- attribCount++;
-
- int flags = 0;
- if ( debug )
- flags |= implementation.getDebugBit();
- if ( forwardCompatible )
- flags |= implementation.getForwardCompatibleBit();
- if ( robustAccess )
- flags |= CONTEXT_ROBUST_ACCESS_BIT_ARB;
- if ( 0 < flags )
- attribCount++;
-
- int profileMask = 0;
- if ( profileCore )
- profileMask |= implementation.getProfileCoreBit();
- else if ( profileCompatibility )
- profileMask |= implementation.getProfileCompatibilityBit();
- else if ( profileES )
- profileMask |= CONTEXT_ES2_PROFILE_BIT_EXT;
- if ( 0 < profileMask )
- attribCount++;
+ ContextAttribs attribs = new ContextAttribs(this);
+ attribs.layerPlane = layerPlane;
+ return attribs;
+ }
- if ( attribCount == 0 )
+ IntBuffer getAttribList() {
+ if ( LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX )
return null;
- final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);
+ LinkedHashMap map = new LinkedHashMap(8);
if ( !(majorVersion == 1 && minorVersion == 0) ) {
- attribs.put(implementation.getMajorVersionAttrib()).put(majorVersion);
- attribs.put(implementation.getMinorVersionAttrib()).put(minorVersion);
+ map.put(CONTEXT_MAJOR_VERSION_ARB, majorVersion);
+ map.put(CONTEXT_MINOR_VERSION_ARB, minorVersion);
}
- if ( 0 < layerPlane )
- attribs.put(implementation.getLayerPlaneAttrib()).put(layerPlane);
- if ( 0 < flags )
- attribs.put(implementation.getFlagsAttrib()).put(flags);
- if ( 0 < profileMask )
- attribs.put(implementation.getProfileMaskAttrib()).put(profileMask);
- if ( loseContextOnReset )
- attribs.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB).put(LOSE_CONTEXT_ON_RESET_ARB);
+ if ( contextFlags != 0 )
+ map.put(CONTEXT_FLAGS_ARB, contextFlags);
+
+ if ( profileMask != 0 )
+ map.put(CONTEXT_PROFILE_MASK_ARB, profileMask);
+
+ if ( contextResetNotificationStrategy != NO_RESET_NOTIFICATION_ARB )
+ map.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, contextResetNotificationStrategy);
+
+ if ( contextReleaseBehavior != CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB )
+ map.put(CONTEXT_RELEASE_BEHABIOR_ARB, contextReleaseBehavior);
+
+ if ( layerPlane != 0 )
+ map.put(CONTEXT_LAYER_PLANE_ARB, layerPlane);
+
+ if ( map.isEmpty() )
+ return null;
+
+ IntBuffer attribs = BufferUtils.createIntBuffer((map.size() * 2) + 1);
+ for ( Entry attrib : map.entrySet() ) {
+ attribs
+ .put(attrib.getKey())
+ .put(attrib.getValue());
+ }
attribs.put(0);
attribs.rewind();
return attribs;
@@ -308,19 +438,37 @@
sb.append("ContextAttribs:");
sb.append(" Version=").append(majorVersion).append('.').append(minorVersion);
- sb.append(" - Layer=").append(layerPlane);
- sb.append(" - Debug=").append(debug);
- sb.append(" - ForwardCompatible=").append(forwardCompatible);
- sb.append(" - RobustAccess=").append(robustAccess);
- if ( robustAccess )
- sb.append(" (").append(loseContextOnReset ? "LOSE_CONTEXT_ON_RESET" : "NO_RESET_NOTIFICATION");
- sb.append(" - Profile=");
- if ( profileCore )
- sb.append("Core");
- else if ( profileCompatibility )
- sb.append("Compatibility");
- else
- sb.append("None");
+
+ if ( profileMask != 0 ) {
+ sb.append(", Profile=");
+ if ( hasMask(CONTEXT_CORE_PROFILE_BIT_ARB) )
+ sb.append("CORE");
+ else if ( hasMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) )
+ sb.append("COMPATIBLITY");
+ else if ( hasMask(CONTEXT_ES2_PROFILE_BIT_EXT) )
+ sb.append("ES2");
+ else
+ sb.append("*unknown*");
+ }
+
+ if ( contextFlags != 0 ) {
+ if ( hasFlag(CONTEXT_DEBUG_BIT_ARB) )
+ sb.append(", DEBUG");
+ if ( hasFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) )
+ sb.append(", FORWARD_COMPATIBLE");
+ if ( hasFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB) )
+ sb.append(", ROBUST_ACCESS");
+ if ( hasFlag(CONTEXT_RESET_ISOLATION_BIT_ARB) )
+ sb.append(", RESET_ISOLATION");
+ }
+
+ if ( contextResetNotificationStrategy != NO_RESET_NOTIFICATION_ARB )
+ sb.append(", LOSE_CONTEXT_ON_RESET");
+ if ( contextReleaseBehavior != CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB )
+ sb.append(", RELEASE_BEHAVIOR_NONE");
+
+ if ( layerPlane != 0 )
+ sb.append(", Layer=").append(layerPlane);
return sb.toString();
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextGLES.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextGLES.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextGLES.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextGLES.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2002-2008 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;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.Sys;
+import org.lwjgl.opengles.EGLContext;
+import org.lwjgl.opengles.GLContext;
+import org.lwjgl.opengles.GLES20;
+import org.lwjgl.opengles.PowerManagementEventException;
+
+import static org.lwjgl.opengles.EGL.*;
+
+/**
+ *
+ * Context encapsulates an OpenGL ES context.
+ *
+ *
+ * This class is thread-safe.
+ *
+ * @author elias_naur
+ * @version $Revision: 3332 $
+ * $Id: Context.java 3332 2010-04-20 18:21:05Z spasi $
+ */
+final class ContextGLES implements org.lwjgl.opengl.Context {
+
+ /** The current Context */
+ private static final ThreadLocal current_context_local = new ThreadLocal();
+
+ /** Handle to the native GL rendering context */
+ private final DrawableGLES drawable;
+ private final EGLContext eglContext;
+
+ private final org.lwjgl.opengles.ContextAttribs contextAttribs;
+
+ /** Whether the context has been destroyed */
+ private boolean destroyed;
+
+ private boolean destroy_requested;
+
+ /** The thread that has this context current, or null. */
+ private Thread thread;
+
+ static {
+ Sys.initialize();
+ }
+
+ public EGLContext getEGLContext() {
+ return eglContext;
+ }
+
+ org.lwjgl.opengles.ContextAttribs getContextAttribs() {
+ return contextAttribs;
+ }
+
+ static ContextGLES getCurrentContext() {
+ return current_context_local.get();
+ }
+
+ /** Create a context with the specified peer info and shared context */
+ ContextGLES(DrawableGLES drawable, org.lwjgl.opengles.ContextAttribs attribs, ContextGLES shared_context) throws LWJGLException {
+ if ( drawable == null )
+ throw new IllegalArgumentException();
+
+ ContextGLES context_lock = shared_context != null ? shared_context : this;
+ // If shared_context is not null, synchronize on it to make sure it is not deleted
+ // while this context is created. Otherwise, simply synchronize on ourself to avoid NPE
+ synchronized ( context_lock ) {
+ if ( shared_context != null && shared_context.destroyed )
+ throw new IllegalArgumentException("Shared context is destroyed");
+
+ this.drawable = drawable;
+ this.contextAttribs = attribs;
+ this.eglContext = drawable.getEGLDisplay().createContext(drawable.getEGLConfig(),
+ shared_context == null ? null : shared_context.eglContext,
+ attribs == null ? new org.lwjgl.opengles.ContextAttribs(2).getAttribList() : attribs.getAttribList());
+ }
+ }
+
+ /** Release the current context (if any). After this call, no context is current. */
+ public void releaseCurrent() throws LWJGLException, PowerManagementEventException {
+ eglReleaseCurrent(drawable.getEGLDisplay());
+ org.lwjgl.opengles.GLContext.useContext(null);
+ current_context_local.set(null);
+
+ synchronized ( this ) {
+ thread = null;
+ checkDestroy();
+ }
+ }
+
+ /** Swap the buffers on the current context. Only valid for double-buffered contexts */
+ public static void swapBuffers() throws LWJGLException, PowerManagementEventException {
+ ContextGLES current_context = getCurrentContext();
+ if ( current_context != null )
+ current_context.drawable.getEGLSurface().swapBuffers();
+ }
+
+ private boolean canAccess() {
+ return thread == null || Thread.currentThread() == thread;
+ }
+
+ private void checkAccess() {
+ if ( !canAccess() )
+ throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current");
+ }
+
+ /** Make the context current */
+ public synchronized void makeCurrent() throws LWJGLException, PowerManagementEventException {
+ checkAccess();
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ thread = Thread.currentThread();
+ current_context_local.set(this);
+ eglContext.makeCurrent(drawable.getEGLSurface());
+ org.lwjgl.opengles.GLContext.useContext(this);
+ }
+
+ /** Query whether the context is current */
+ public synchronized boolean isCurrent() throws LWJGLException {
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ return eglIsCurrentContext(eglContext);
+ }
+
+ private void checkDestroy() {
+ if ( !destroyed && destroy_requested ) {
+ try {
+ eglContext.destroy();
+ destroyed = true;
+ thread = null;
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Exception occurred while destroying context: " + e);
+ }
+ }
+ }
+
+ /**
+ * Set the buffer swap interval. This call is a best-attempt at changing
+ * the monitor swap interval, which is the minimum periodicity of color buffer swaps,
+ * measured in video frame periods, and is not guaranteed to be successful.
+ *
+ * A video frame period is the time required to display a full frame of video data.
+ */
+ public static void setSwapInterval(int value) {
+ ContextGLES current_context = getCurrentContext();
+ if ( current_context != null ) {
+ try {
+ current_context.drawable.getEGLDisplay().setSwapInterval(value);
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to set swap interval. Reason: " + e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Destroy the context. This method behaves the same as destroy() with the extra
+ * requirement that the context must be either current to the current thread or not
+ * current at all.
+ */
+ public synchronized void forceDestroy() throws LWJGLException {
+ checkAccess();
+ destroy();
+ }
+
+ /**
+ * Request destruction of the Context. If the context is current, no context will be current after this call.
+ * The context is destroyed when no thread has it current.
+ */
+ public synchronized void destroy() throws LWJGLException {
+ if ( destroyed )
+ return;
+ destroy_requested = true;
+ boolean was_current = isCurrent();
+ int error = GLES20.GL_NO_ERROR;
+ if ( was_current ) {
+ if ( org.lwjgl.opengles.GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGLES20 )
+ error = GLES20.glGetError();
+
+ try {
+ releaseCurrent();
+ } catch (PowerManagementEventException e) {
+ // Ignore
+ }
+ }
+ checkDestroy();
+ if ( was_current && error != GLES20.GL_NO_ERROR )
+ throw new OpenGLException(error);
+ }
+
+ public void releaseDrawable() throws LWJGLException {
+ }
+
+}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextGL.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextGL.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextGL.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextGL.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,299 @@
+/*
+ * Copyright (c) 2002-2008 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;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.Sys;
+import org.lwjgl.opencl.KHRGLSharing;
+import org.lwjgl.opencl.APPLEGLSharing;
+
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+
+import static org.lwjgl.opengl.GL11.*;
+
+/**
+ *
+ * Context encapsulates an OpenGL context.
+ *
+ *
+ * This class is thread-safe.
+ *
+ * @author elias_naur
+ * @version $Revision$
+ * $Id$
+ */
+final class ContextGL implements Context {
+
+ /** The platform specific implementation of context methods */
+ private static final ContextImplementation implementation;
+
+ /** The current Context */
+ private static final ThreadLocal current_context_local = new ThreadLocal();
+
+ /** Handle to the native GL rendering context */
+ private final ByteBuffer handle;
+ private final PeerInfo peer_info;
+
+ private final ContextAttribs contextAttribs;
+ private final boolean forwardCompatible;
+
+ /** Whether the context has been destroyed */
+ private boolean destroyed;
+
+ private boolean destroy_requested;
+
+ /** The thread that has this context current, or null. */
+ private Thread thread;
+
+ static {
+ Sys.initialize();
+ implementation = createImplementation();
+ }
+
+ private static ContextImplementation createImplementation() {
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_LINUX:
+ return new LinuxContextImplementation();
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ return new WindowsContextImplementation();
+ case LWJGLUtil.PLATFORM_MACOSX:
+ return new MacOSXContextImplementation();
+ default:
+ throw new IllegalStateException("Unsupported platform");
+ }
+ }
+
+ PeerInfo getPeerInfo() {
+ return peer_info;
+ }
+
+ ContextAttribs getContextAttribs() {
+ return contextAttribs;
+ }
+
+ static ContextGL getCurrentContext() {
+ return current_context_local.get();
+ }
+
+ /** Create a context with the specified peer info and shared context */
+ ContextGL(PeerInfo peer_info, ContextAttribs attribs, ContextGL shared_context) throws LWJGLException {
+ ContextGL context_lock = shared_context != null ? shared_context : this;
+ // If shared_context is not null, synchronize on it to make sure it is not deleted
+ // while this context is created. Otherwise, simply synchronize on ourself to avoid NPE
+ synchronized ( context_lock ) {
+ if ( shared_context != null && shared_context.destroyed )
+ throw new IllegalArgumentException("Shared context is destroyed");
+ GLContext.loadOpenGLLibrary();
+ try {
+ this.peer_info = peer_info;
+ this.contextAttribs = attribs;
+
+ IntBuffer attribList;
+ if ( attribs != null ) {
+ attribList = attribs.getAttribList();
+ forwardCompatible = attribs.isForwardCompatible();
+ } else {
+ attribList = null;
+ forwardCompatible = false;
+ }
+
+ this.handle = implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null);
+ } catch (LWJGLException e) {
+ GLContext.unloadOpenGLLibrary();
+ throw e;
+ }
+ }
+ }
+
+ /** Release the current context (if any). After this call, no context is current. */
+ public void releaseCurrent() throws LWJGLException {
+ ContextGL current_context = getCurrentContext();
+ if ( current_context != null ) {
+ implementation.releaseCurrentContext();
+ GLContext.useContext(null);
+ current_context_local.set(null);
+ synchronized ( current_context ) {
+ current_context.thread = null;
+ current_context.checkDestroy();
+ }
+ }
+ }
+
+ /**
+ * Release the context from its drawable. This is necessary on some platforms,
+ * like Mac OS X, where binding the context to a drawable and binding the context
+ * for rendering are two distinct actions and where calling releaseDrawable
+ * on every releaseCurrentContext results in artifacts.
+ */
+ public synchronized void releaseDrawable() throws LWJGLException {
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ implementation.releaseDrawable(getHandle());
+ }
+
+ /** Update the context. Should be called whenever it's drawable is moved or resized */
+ public synchronized void update() {
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ implementation.update(getHandle());
+ }
+
+ /** Swap the buffers on the current context. Only valid for double-buffered contexts */
+ public static void swapBuffers() throws LWJGLException {
+ implementation.swapBuffers();
+ }
+
+ private boolean canAccess() {
+ return thread == null || Thread.currentThread() == thread;
+ }
+
+ private void checkAccess() {
+ if ( !canAccess() )
+ throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current");
+ }
+
+ /** Make the context current */
+ public synchronized void makeCurrent() throws LWJGLException {
+ checkAccess();
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ thread = Thread.currentThread();
+ current_context_local.set(this);
+ implementation.makeCurrent(peer_info, handle);
+ GLContext.useContext(this, forwardCompatible);
+ }
+
+ ByteBuffer getHandle() {
+ return handle;
+ }
+
+ /** Query whether the context is current */
+ public synchronized boolean isCurrent() throws LWJGLException {
+ if ( destroyed )
+ throw new IllegalStateException("Context is destroyed");
+ return implementation.isCurrent(handle);
+ }
+
+ private void checkDestroy() {
+ if ( !destroyed && destroy_requested ) {
+ try {
+ releaseDrawable();
+ implementation.destroy(peer_info, handle);
+ CallbackUtil.unregisterCallbacks(this);
+ destroyed = true;
+ thread = null;
+ GLContext.unloadOpenGLLibrary();
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Exception occurred while destroying context: " + e);
+ }
+ }
+ }
+
+ /**
+ * Set the buffer swap interval. This call is a best-attempt at changing
+ * the monitor swap interval, which is the minimum periodicity of color buffer swaps,
+ * measured in video frame periods, and is not guaranteed to be successful.
+ *
+ * A video frame period is the time required to display a full frame of video data.
+ */
+ public static void setSwapInterval(int value) {
+ implementation.setSwapInterval(value);
+ }
+
+ /**
+ * Destroy the context. This method behaves the same as destroy() with the extra
+ * requirement that the context must be either current to the current thread or not
+ * current at all.
+ */
+ public synchronized void forceDestroy() throws LWJGLException {
+ checkAccess();
+ destroy();
+ }
+
+ /**
+ * Request destruction of the Context. If the context is current, no context will be current after this call.
+ * The context is destroyed when no thread has it current.
+ */
+ public synchronized void destroy() throws LWJGLException {
+ if ( destroyed )
+ return;
+ destroy_requested = true;
+ boolean was_current = isCurrent();
+ int error = GL_NO_ERROR;
+ if ( was_current ) {
+ try {
+ // May fail on GLContext.getCapabilities()
+ error = glGetError();
+ } catch (Exception e) {
+ // ignore
+ }
+ releaseCurrent();
+ }
+ checkDestroy();
+ if ( was_current && error != GL_NO_ERROR )
+ throw new OpenGLException(error);
+ }
+
+ public synchronized void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ final ByteBuffer peer_handle = peer_info.lockAndGetHandle();
+ try {
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ final WindowsContextImplementation implWindows = (WindowsContextImplementation)implementation;
+ properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implWindows.getHGLRC(handle));
+ properties.put(KHRGLSharing.CL_WGL_HDC_KHR).put(implWindows.getHDC(peer_handle));
+ break;
+ case LWJGLUtil.PLATFORM_LINUX:
+ final LinuxContextImplementation implLinux = (LinuxContextImplementation)implementation;
+ properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implLinux.getGLXContext(handle));
+ properties.put(KHRGLSharing.CL_GLX_DISPLAY_KHR).put(implLinux.getDisplay(peer_handle));
+ break;
+ case LWJGLUtil.PLATFORM_MACOSX:
+ if (LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6)) { // only supported on OS X 10.6+
+ // http://oscarbg.blogspot.com/2009/10/about-opencl-opengl-interop.html
+ final MacOSXContextImplementation implMacOSX = (MacOSXContextImplementation)implementation;
+ final long CGLShareGroup = implMacOSX.getCGLShareGroup(handle);
+ properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE).put(CGLShareGroup);
+ break;
+ }
+ default:
+ throw new UnsupportedOperationException("CL/GL context sharing is not supported on this platform.");
+ }
+ } finally {
+ peer_info.unlock();
+ }
+ }
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/ContextImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/ContextImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -42,8 +42,8 @@
*
*
* @author elias_naur
- * @version $Revision: 3116 $
- * $Id: ContextImplementation.java 3116 2008-08-19 16:46:03Z spasi $
+ * @version $Revision$
+ * $Id$
*/
interface ContextImplementation {
/**
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/Context.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/Context.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/Context.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/Context.java 2016-04-09 16:26:56.000000000 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2008 LWJGL Project
+ * Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,255 +32,19 @@
package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
-import org.lwjgl.LWJGLUtil;
-import org.lwjgl.PointerBuffer;
-import org.lwjgl.Sys;
-import org.lwjgl.opencl.KHRGLSharing;
-
-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-
-import static org.lwjgl.opengl.GL11.*;
/**
- *
- * Context encapsulates an OpenGL context.
- *
- *
- * This class is thread-safe.
- *
- * @author elias_naur
- * @version $Revision: 3418 $
- * $Id: Context.java 3418 2010-09-28 21:11:35Z spasi $
+ * @author Spasi
+ * @since 14/5/2011
*/
-final class Context {
-
- /** The platform specific implementation of context methods */
- private static final ContextImplementation implementation;
-
- /** The current Context */
- private static final ThreadLocal current_context_local = new ThreadLocal();
-
- /** Handle to the native GL rendering context */
- private final ByteBuffer handle;
- private final PeerInfo peer_info;
-
- private final ContextAttribs contextAttribs;
- private final boolean forwardCompatible;
-
- /** Whether the context has been destroyed */
- private boolean destroyed;
-
- private boolean destroy_requested;
-
- /** The thread that has this context current, or null. */
- private Thread thread;
-
- static {
- Sys.initialize();
- implementation = createImplementation();
- }
-
- private static ContextImplementation createImplementation() {
- switch ( LWJGLUtil.getPlatform() ) {
- case LWJGLUtil.PLATFORM_LINUX:
- return new LinuxContextImplementation();
- case LWJGLUtil.PLATFORM_WINDOWS:
- return new WindowsContextImplementation();
- case LWJGLUtil.PLATFORM_MACOSX:
- return new MacOSXContextImplementation();
- default:
- throw new IllegalStateException("Unsupported platform");
- }
- }
-
- PeerInfo getPeerInfo() {
- return peer_info;
- }
-
- ContextAttribs getContextAttribs() {
- return contextAttribs;
- }
-
- static Context getCurrentContext() {
- return current_context_local.get();
- }
-
- /** Create a context with the specified peer info and shared context */
- Context(PeerInfo peer_info, ContextAttribs attribs, Context shared_context) throws LWJGLException {
- Context context_lock = shared_context != null ? shared_context : this;
- // If shared_context is not null, synchronize on it to make sure it is not deleted
- // while this context is created. Otherwise, simply synchronize on ourself to avoid NPE
- synchronized ( context_lock ) {
- if ( shared_context != null && shared_context.destroyed )
- throw new IllegalArgumentException("Shared context is destroyed");
- GLContext.loadOpenGLLibrary();
- try {
- this.peer_info = peer_info;
- this.contextAttribs = attribs;
-
- IntBuffer attribList;
- if ( attribs != null ) {
- attribList = attribs.getAttribList();
- forwardCompatible = attribs.isForwardCompatible();
- } else {
- attribList = null;
- forwardCompatible = false;
- }
-
- this.handle = implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null);
- } catch (LWJGLException e) {
- GLContext.unloadOpenGLLibrary();
- throw e;
- }
- }
- }
-
- /** Release the current context (if any). After this call, no context is current. */
- public static void releaseCurrentContext() throws LWJGLException {
- Context current_context = getCurrentContext();
- if ( current_context != null ) {
- implementation.releaseCurrentContext();
- GLContext.useContext(null);
- current_context_local.set(null);
- synchronized ( current_context ) {
- current_context.thread = null;
- current_context.checkDestroy();
- }
- }
- }
-
- /**
- * Release the context from its drawable. This is necessary on some platforms,
- * like Mac OS X, where binding the context to a drawable and binding the context
- * for rendering are two distinct actions and where calling releaseDrawable
- * on every releaseCurrentContext results in artifacts.
- */
- public synchronized void releaseDrawable() throws LWJGLException {
- if ( destroyed )
- throw new IllegalStateException("Context is destroyed");
- implementation.releaseDrawable(getHandle());
- }
-
- /** Update the context. Should be called whenever it's drawable is moved or resized */
- public synchronized void update() {
- if ( destroyed )
- throw new IllegalStateException("Context is destroyed");
- implementation.update(getHandle());
- }
-
- /** Swap the buffers on the current context. Only valid for double-buffered contexts */
- public static void swapBuffers() throws LWJGLException {
- implementation.swapBuffers();
- }
-
- private boolean canAccess() {
- return thread == null || Thread.currentThread() == thread;
- }
-
- private void checkAccess() {
- if ( !canAccess() )
- throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current");
- }
-
- /** Make the context current */
- public synchronized void makeCurrent() throws LWJGLException {
- checkAccess();
- if ( destroyed )
- throw new IllegalStateException("Context is destroyed");
- thread = Thread.currentThread();
- current_context_local.set(this);
- implementation.makeCurrent(peer_info, handle);
- GLContext.useContext(this, forwardCompatible);
- }
-
- ByteBuffer getHandle() {
- return handle;
- }
-
- /** Query whether the context is current */
- public synchronized boolean isCurrent() throws LWJGLException {
- if ( destroyed )
- throw new IllegalStateException("Context is destroyed");
- return implementation.isCurrent(handle);
- }
-
- private void checkDestroy() {
- if ( !destroyed && destroy_requested ) {
- try {
- releaseDrawable();
- implementation.destroy(peer_info, handle);
- CallbackUtil.unregisterCallbacks(this);
- destroyed = true;
- thread = null;
- GLContext.unloadOpenGLLibrary();
- } catch (LWJGLException e) {
- LWJGLUtil.log("Exception occurred while destroying context: " + e);
- }
- }
- }
+interface Context {
- /**
- * Set the buffer swap interval. This call is a best-attempt at changing
- * the monitor swap interval, which is the minimum periodicity of color buffer swaps,
- * measured in video frame periods, and is not guaranteed to be successful.
- *
- * A video frame period is the time required to display a full frame of video data.
- */
- public static void setSwapInterval(int value) {
- implementation.setSwapInterval(value);
- }
+ boolean isCurrent() throws LWJGLException;
- /**
- * Destroy the context. This method behaves the same as destroy() with the extra
- * requirement that the context must be either current to the current thread or not
- * current at all.
- */
- public synchronized void forceDestroy() throws LWJGLException {
- checkAccess();
- destroy();
- }
+ void makeCurrent() throws LWJGLException;
- /**
- * Request destruction of the Context. If the context is current, no context will be current after this call.
- * The context is destroyed when no thread has it current.
- */
- public synchronized void destroy() throws LWJGLException {
- if ( destroyed )
- return;
- destroy_requested = true;
- boolean was_current = isCurrent();
- int error = GL_NO_ERROR;
- if ( was_current ) {
- if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
- error = glGetError();
- releaseCurrentContext();
- }
- checkDestroy();
- if ( was_current && error != GL_NO_ERROR )
- throw new OpenGLException(error);
- }
+ void releaseCurrent() throws LWJGLException;
- public synchronized void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
- final ByteBuffer peer_handle = peer_info.lockAndGetHandle();
- try {
- switch ( LWJGLUtil.getPlatform() ) {
- case LWJGLUtil.PLATFORM_WINDOWS:
- final WindowsContextImplementation implWindows = (WindowsContextImplementation)implementation;
- properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implWindows.getHGLRC(handle));
- properties.put(KHRGLSharing.CL_WGL_HDC_KHR).put(implWindows.getHDC(peer_handle));
- break;
- case LWJGLUtil.PLATFORM_LINUX:
- final LinuxContextImplementation implLinux = (LinuxContextImplementation)implementation;
- properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implLinux.getGLXContext(handle));
- properties.put(KHRGLSharing.CL_GLX_DISPLAY_KHR).put(implLinux.getDisplay(peer_handle));
- break;
- default:
- throw new UnsupportedOperationException("CL/GL context sharing is not supposed on this platform.");
- }
- } finally {
- peer_info.unlock();
- }
- }
+ void releaseDrawable() throws LWJGLException;
}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DisplayImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DisplayImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DisplayImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DisplayImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -47,7 +47,7 @@
interface DisplayImplementation extends InputImplementation {
- void createWindow(DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException;
+ void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException;
void destroyWindow();
@@ -108,7 +108,7 @@
* Create the native PeerInfo.
* @throws LWJGLException
*/
- PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException;
+ PeerInfo createPeerInfo(PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException;
// void destroyPeerInfo();
@@ -136,7 +136,7 @@
/**
* Method to create a Pbuffer
*/
- PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
+ PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format, ContextAttribs attribs,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException;
@@ -159,4 +159,42 @@
* @return number of icons used.
*/
int setIcon(ByteBuffer[] icons);
+
+ /**
+ * Enable or disable the Display window to be resized.
+ *
+ * @param resizable set to true to make the Display window resizable;
+ * false to disable resizing on the Display window.
+ */
+ void setResizable(boolean resizable);
+
+ /**
+ * @return true if the Display window has been resized since this method was last called.
+ */
+ boolean wasResized();
+
+ /**
+ * @return this method will return the width of the Display window.
+ */
+ int getWidth();
+
+ /**
+ * @return this method will return the height of the Display window.
+ */
+ int getHeight();
+
+ /**
+ * @return this method will return the top-left x position of the Display window.
+ */
+ int getX();
+
+ /**
+ * @return this method will return the top-left y position of the Display window.
+ */
+ int getY();
+
+ /**
+ * @return this method will return the pixel scale factor of the Display window useful for high resolution modes.
+ */
+ float getPixelScaleFactor();
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/Display.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/Display.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/Display.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/Display.java 2016-04-09 16:26:56.000000000 +0000
@@ -62,8 +62,6 @@
import java.util.Arrays;
import java.util.HashSet;
-import static org.lwjgl.opengl.GL11.*;
-
public final class Display {
private static final Thread shutdown_hook = new Thread() {
@@ -84,9 +82,6 @@
/** The current display mode, if created */
private static DisplayMode current_mode;
- /** Timer for sync() */
- private static long timeThen;
-
/** X coordinate of the window */
private static int x = -1;
@@ -99,6 +94,12 @@
*/
private static int y = -1;
+ /** the width of the Display window */
+ private static int width = 0;
+
+ /** the height of the Display window */
+ private static int height = 0;
+
/** Title of the window (never null) */
private static String title = "Game";
@@ -109,12 +110,16 @@
private static int swap_interval;
/** The Drawable instance that tracks the current Display context */
- private static final AbstractDrawable drawable;
+ private static DrawableLWJGL drawable;
private static boolean window_created;
private static boolean parent_resized;
+ private static boolean window_resized;
+
+ private static boolean window_resizable;
+
/** Initial Background Color of Display */
private static float r, g, b;
@@ -134,22 +139,6 @@
LWJGLUtil.log("Initial mode: " + initial_mode);
} catch (LWJGLException e) {
throw new RuntimeException(e);
- }
- drawable = new AbstractDrawable() {
- public void destroy() {
- synchronized ( GlobalLock.lock ) {
- if ( !isCreated() )
- return;
-
- releaseDrawable();
- super.destroy();
- destroyWindow();
- x = y = -1;
- cached_icons = null;
- reset();
- removeShutdownHook();
- }
- }
};
}
@@ -256,7 +245,7 @@
try {
if ( was_fullscreen && !isFullscreen() )
display_impl.resetDisplayMode();
- else if ( isFullscreen() )
+ else if ( isFullscreen() )
switchDisplayMode();
createWindow();
makeCurrentAndSetSwapInterval();
@@ -314,9 +303,12 @@
tmp_parent.addComponentListener(component_listener);
}
DisplayMode mode = getEffectiveMode();
- display_impl.createWindow(mode, tmp_parent, getWindowX(), getWindowY());
+ display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
window_created = true;
+ width = Display.getDisplayMode().getWidth();
+ height = Display.getDisplayMode().getHeight();
+
setTitle(title);
initControls();
@@ -330,9 +322,9 @@
private static void releaseDrawable() {
try {
- Context context = drawable.context;
+ Context context = drawable.getContext();
if ( context != null && context.isCurrent() ) {
- Context.releaseCurrentContext();
+ context.releaseCurrent();
context.releaseDrawable();
}
} catch (LWJGLException e) {
@@ -409,40 +401,14 @@
}
}
- private static long timeLate;
-
/**
- * Best sync method that works reliably.
+ * An accurate sync method that will attempt to run at a constant frame rate.
+ * It should be called once every frame.
*
- * @param fps The desired frame rate, in frames per second
+ * @param fps - the desired frame rate, in frames per second
*/
public static void sync(int fps) {
- long timeNow;
- long gapTo;
- long savedTimeLate;
- synchronized ( GlobalLock.lock ) {
- gapTo = Sys.getTimerResolution() / fps + timeThen;
- timeNow = Sys.getTime();
- savedTimeLate = timeLate;
- }
-
- try {
- while ( gapTo > timeNow + savedTimeLate ) {
- Thread.sleep(1);
- timeNow = Sys.getTime();
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
-
- synchronized ( GlobalLock.lock ) {
- if ( gapTo < timeNow )
- timeLate = timeNow - gapTo;
- else
- timeLate = 0;
-
- timeThen = timeNow;
- }
+ Sync.sync(fps);
}
/** @return the title of the window */
@@ -648,8 +614,8 @@
throw new IllegalStateException("Display not created");
if ( LWJGLUtil.DEBUG )
- Util.checkGLError();
- Context.swapBuffers();
+ drawable.checkGLError();
+ drawable.swapBuffers();
}
}
@@ -683,9 +649,17 @@
}
}
+ window_resized = !isFullscreen() && parent == null && display_impl.wasResized();
+
+ if ( window_resized ) {
+ width = display_impl.getWidth();
+ height = display_impl.getHeight();
+ }
+
if ( parent_resized ) {
reshape();
parent_resized = false;
+ window_resized = true;
}
if ( processMessages )
@@ -762,9 +736,7 @@
* @throws LWJGLException
*/
public static void create() throws LWJGLException {
- synchronized ( GlobalLock.lock ) {
- create(new PixelFormat());
- }
+ create(new PixelFormat());
}
/**
@@ -782,7 +754,7 @@
*/
public static void create(PixelFormat pixel_format) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
- create(pixel_format, null, null);
+ create(pixel_format, null, (ContextAttribs)null);
}
}
@@ -802,7 +774,7 @@
*/
public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
- create(pixel_format, shared_drawable, null);
+ create(pixel_format, shared_drawable, (ContextAttribs)null);
}
}
@@ -851,12 +823,168 @@
registerShutdownHook();
if ( isFullscreen() )
switchDisplayMode();
+
+ final DrawableGL drawable = new DrawableGL() {
+ public void destroy() {
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
+ return;
+
+ releaseDrawable();
+ super.destroy();
+ destroyWindow();
+ x = y = -1;
+ cached_icons = null;
+ reset();
+ removeShutdownHook();
+ }
+ }
+ };
+ Display.drawable = drawable;
+
try {
- drawable.peer_info = display_impl.createPeerInfo(pixel_format);
+ drawable.setPixelFormat(pixel_format, attribs);
try {
createWindow();
try {
- drawable.context = new Context(drawable.peer_info, attribs, shared_drawable != null ? ((AbstractDrawable)shared_drawable).getContext() : null);
+ drawable.context = new ContextGL(drawable.peer_info, attribs, shared_drawable != null ? ((DrawableGL)shared_drawable).getContext() : null);
+ try {
+ makeCurrentAndSetSwapInterval();
+ initContext();
+ } catch (LWJGLException e) {
+ drawable.destroy();
+ throw e;
+ }
+ } catch (LWJGLException e) {
+ destroyWindow();
+ throw e;
+ }
+ } catch (LWJGLException e) {
+ drawable.destroy();
+ throw e;
+ }
+ } catch (LWJGLException e) {
+ display_impl.resetDisplayMode();
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Create the OpenGL ES 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.
+ *
+ *
The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
+ *
+ * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
+ *
+ * @throws LWJGLException
+ */
+
+ public static void create(PixelFormatLWJGL pixel_format) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, null, null);
+ }
+ }
+
+ /**
+ * Create the OpenGL ES 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.
+ *
+ *
The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
+ *
+ * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
+ * @param shared_drawable The Drawable to share context with. (optional, may be null)
+ *
+ * @throws LWJGLException
+ */
+ public static void create(PixelFormatLWJGL pixel_format, Drawable shared_drawable) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, shared_drawable, null);
+ }
+ }
+
+ /**
+ * Create the OpenGL ES 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.
+ *
+ *
The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
+ *
+ * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
+ * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
+ *
+ * @throws LWJGLException
+ */
+ public static void create(PixelFormatLWJGL pixel_format, org.lwjgl.opengles.ContextAttribs attribs) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, null, attribs);
+ }
+ }
+
+ /**
+ * Create the OpenGL ES 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.
+ *
+ *
The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
+ *
+ * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
+ * @param shared_drawable The Drawable to share context with. (optional, may be null)
+ * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
+ *
+ * @throws LWJGLException
+ */
+ public static void create(PixelFormatLWJGL pixel_format, Drawable shared_drawable, org.lwjgl.opengles.ContextAttribs attribs) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ if ( isCreated() )
+ throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
+ if ( pixel_format == null )
+ throw new NullPointerException("pixel_format cannot be null");
+ removeShutdownHook();
+ registerShutdownHook();
+ if ( isFullscreen() )
+ switchDisplayMode();
+
+ final DrawableGLES drawable = new DrawableGLES() {
+
+ public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs) throws LWJGLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void destroy() {
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
+ return;
+
+ releaseDrawable();
+ super.destroy();
+ destroyWindow();
+ x = y = -1;
+ cached_icons = null;
+ reset();
+ removeShutdownHook();
+ }
+ }
+ };
+ Display.drawable = drawable;
+
+ try {
+ drawable.setPixelFormat(pixel_format);
+ try {
+ createWindow();
+ try {
+ drawable.createContext(attribs, shared_drawable);
try {
makeCurrentAndSetSwapInterval();
initContext();
@@ -896,7 +1024,7 @@
private static void makeCurrentAndSetSwapInterval() throws LWJGLException {
makeCurrent();
try {
- Util.checkGLError();
+ drawable.checkGLError();
} catch (OpenGLException e) {
LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage());
}
@@ -904,10 +1032,7 @@
}
private static void initContext() {
- // set background clear color
- glClearColor(r, g, b, 0.0f);
- // Clear window to avoid the desktop "showing through"
- glClear(GL_COLOR_BUFFER_BIT);
+ drawable.initContext(r, g, b);
update();
}
@@ -923,6 +1048,15 @@
}
});
}
+
+ /** Gets a string property as a privileged action. */
+ static String getPrivilegedString(final String property_name) {
+ return AccessController.doPrivileged(new PrivilegedAction() {
+ public String run() {
+ return System.getProperty(property_name);
+ }
+ });
+ }
private static void initControls() {
// Automatically create mouse, keyboard and controller
@@ -957,7 +1091,9 @@
* regardless of whether the Display was the current rendering context.
*/
public static void destroy() {
- drawable.destroy();
+ if(isCreated()) {
+ drawable.destroy();
+ }
}
/*
@@ -990,7 +1126,8 @@
synchronized ( GlobalLock.lock ) {
swap_interval = value;
if ( isCreated() )
- Context.setSwapInterval(swap_interval);
+ drawable.setSwapInterval(swap_interval);
+
}
}
@@ -1065,7 +1202,7 @@
*
Linux (and similar platforms) expect one 32x32 icon.
*
Mac OS X should be supplied one 128x128 icon
*
- * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform.
+ * The implementation will use the supplied ByteBuffers with image data in RGBA (size must be a power of two) and perform any conversions nescesarry for the specific platform.
*
* NOTE: The display will make a deep copy of the supplied byte buffer array, for the purpose
* of recreating the icons when you go back and forth fullscreen mode. You therefore only need to
@@ -1097,4 +1234,142 @@
}
}
}
+
+ /**
+ * Enable or disable the Display window to be resized.
+ *
+ * @param resizable set to true to make the Display window resizable;
+ * false to disable resizing on the Display window.
+ */
+ public static void setResizable(boolean resizable) {
+ window_resizable = resizable;
+ if ( isCreated() ) {
+ display_impl.setResizable(resizable);
+ }
+ }
+
+ /**
+ * @return true if the Display window is resizable.
+ */
+ public static boolean isResizable() {
+ return window_resizable;
+ }
+
+ /**
+ * @return true if the Display window has been resized.
+ * This value will be updated after a call to Display.update().
+ *
+ * This will return false if running in fullscreen or with Display.setParent(Canvas parent)
+ */
+ public static boolean wasResized() {
+ return window_resized;
+ }
+
+ /**
+ * @return this method will return the x position (top-left) of the Display window.
+ *
+ * If running in fullscreen mode it will return 0.
+ * If Display.setParent(Canvas parent) is being used, the x position of
+ * the parent will be returned.
+ */
+ public static int getX() {
+
+ if (Display.isFullscreen()) {
+ return 0;
+ }
+
+ if (parent != null) {
+ return parent.getX();
+ }
+
+ return display_impl.getX();
+ }
+
+ /**
+ * @return this method will return the y position (top-left) of the Display window.
+ *
+ * If running in fullscreen mode it will return 0.
+ * If Display.setParent(Canvas parent) is being used, the y position of
+ * the parent will be returned.
+ */
+ public static int getY() {
+
+ if (Display.isFullscreen()) {
+ return 0;
+ }
+
+ if (parent != null) {
+ return parent.getY();
+ }
+
+ return display_impl.getY();
+ }
+
+ /**
+ * @return this method will return the width of the Display window.
+ *
+ * If running in fullscreen mode it will return the width of the current set DisplayMode.
+ * If Display.setParent(Canvas parent) is being used, the width of the parent
+ * will be returned.
+ *
+ * This value will be updated after a call to Display.update().
+ */
+ public static int getWidth() {
+
+ if (Display.isFullscreen()) {
+ return Display.getDisplayMode().getWidth();
+ }
+
+ if (parent != null) {
+ return parent.getWidth();
+ }
+
+ return width;
+ }
+
+ /**
+ * @return this method will return the height of the Display window.
+ *
+ * If running in fullscreen mode it will return the height of the current set DisplayMode.
+ * If Display.setParent(Canvas parent) is being used, the height of the parent
+ * will be returned.
+ *
+ * This value will be updated after a call to Display.update().
+ */
+ public static int getHeight() {
+
+ if (Display.isFullscreen()) {
+ return Display.getDisplayMode().getHeight();
+ }
+
+ if (parent != null) {
+ return parent.getHeight();
+ }
+
+ return height;
+ }
+
+ /**
+ * @return this method will return the pixel scale factor of the Display window.
+ *
+ * This method should be used when running in high DPI mode. In such modes Operating
+ * Systems will scale the Display window to avoid the window shrinking due to high
+ * resolutions. The OpenGL frame buffer will however use the higher resolution and
+ * not be scaled to match the Display window size.
+ *
+ * OpenGL methods that require pixel dependent values e.g. glViewport, glTexImage2D,
+ * glReadPixels, glScissor, glLineWidth, glRenderbufferStorage, etc can convert the
+ * scaled Display and Mouse coordinates to the correct high resolution value by
+ * multiplying them by the pixel scale factor.
+ *
+ * e.g. Display.getWidth() * Display.getPixelScaleFactor() will return the high DPI
+ * width of the OpenGL frame buffer. Whereas Display.getWidth() will be the same as
+ * the OpenGL frame buffer in non high DPI mode.
+ *
+ * Where high DPI mode is not available this method will just return 1.0f therefore
+ * not have any effect on values that are multiplied by it.
+ */
+ public static float getPixelScaleFactor() {
+ return display_impl.getPixelScaleFactor();
+ }
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DisplayMode.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DisplayMode.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DisplayMode.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DisplayMode.java 2016-04-09 16:26:56.000000000 +0000
@@ -38,8 +38,8 @@
* getAvailableDisplayModes() method.
*
* @author cix_foo
- * @version $Revision: 3418 $
- * $Id: DisplayMode.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public final class DisplayMode {
@@ -75,7 +75,7 @@
this.fullscreen = fullscreen;
}
- /** True iff this instance can be used for fullscreen modes */
+ /** True if this instance can be used for fullscreen modes */
public boolean isFullscreenCapable() {
return fullscreen;
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableGLES.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableGLES.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableGLES.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableGLES.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2002-2011 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;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.opengles.ContextAttribs;
+import org.lwjgl.opengles.*;
+import org.lwjgl.opengles.Util;
+
+import static org.lwjgl.opengles.EGL.*;
+import static org.lwjgl.opengles.GLES20.*;
+
+/**
+ * @author Spasi
+ * @since 14/5/2011
+ */
+abstract class DrawableGLES implements DrawableLWJGL {
+
+ /** The PixelFormat used to create the EGLDisplay. */
+ protected org.lwjgl.opengles.PixelFormat pixel_format;
+
+ protected EGLDisplay eglDisplay;
+ protected EGLConfig eglConfig;
+ protected EGLSurface eglSurface;
+
+ /** The OpenGL Context. */
+ protected ContextGLES context;
+
+ /** The Drawable that shares objects with this Drawable. */
+ protected Drawable shared_drawable;
+
+ protected DrawableGLES() {
+ }
+
+ public void setPixelFormat(final PixelFormatLWJGL pf) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ this.pixel_format = (org.lwjgl.opengles.PixelFormat)pf;
+ }
+ }
+
+ public PixelFormatLWJGL getPixelFormat() {
+ synchronized ( GlobalLock.lock ) {
+ return pixel_format;
+ }
+ }
+
+ public void initialize(final long window, final long display_id, final int eglSurfaceType, final org.lwjgl.opengles.PixelFormat pf) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ if ( eglSurface != null ) {
+ eglSurface.destroy();
+ eglSurface = null;
+ }
+
+ if ( eglDisplay != null ) {
+ eglDisplay.terminate();
+ eglDisplay = null;
+ }
+
+ final EGLDisplay eglDisplay = eglGetDisplay((int)display_id);
+
+ int[] attribs = {
+ EGL_LEVEL, 0,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NATIVE_RENDERABLE, EGL_FALSE,
+ };
+
+ final EGLConfig[] configs = eglDisplay.chooseConfig(pf.getAttribBuffer(eglDisplay, eglSurfaceType, attribs), null, BufferUtils.createIntBuffer(1));
+ if ( configs.length == 0 )
+ throw new LWJGLException("No EGLConfigs found for the specified PixelFormat.");
+
+ final EGLConfig eglConfig = pf.getBestMatch(configs);
+ final EGLSurface eglSurface = eglDisplay.createWindowSurface(eglConfig, window, null);
+ pf.setSurfaceAttribs(eglSurface);
+
+ this.eglDisplay = eglDisplay;
+ this.eglConfig = eglConfig;
+ this.eglSurface = eglSurface;
+
+ // This can happen when switching in and out of full-screen mode.
+ if ( context != null )
+ context.getEGLContext().setDisplay(eglDisplay);
+ }
+ }
+
+ public void createContext(final ContextAttribs attribs, final Drawable shared_drawable) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ this.context = new ContextGLES(this, attribs, shared_drawable != null ? ((DrawableGLES)shared_drawable).getContext() : null);
+ this.shared_drawable = shared_drawable;
+ }
+ }
+
+ Drawable getSharedDrawable() {
+ synchronized ( GlobalLock.lock ) {
+ return shared_drawable;
+ }
+ }
+
+ public EGLDisplay getEGLDisplay() {
+ synchronized ( GlobalLock.lock ) {
+ return eglDisplay;
+ }
+ }
+
+ public EGLConfig getEGLConfig() {
+ synchronized ( GlobalLock.lock ) {
+ return eglConfig;
+ }
+ }
+
+ public EGLSurface getEGLSurface() {
+ synchronized ( GlobalLock.lock ) {
+ return eglSurface;
+ }
+ }
+
+ public ContextGLES getContext() {
+ synchronized ( GlobalLock.lock ) {
+ return context;
+ }
+ }
+
+ public org.lwjgl.opengl.Context createSharedContext() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ return new ContextGLES(this, context.getContextAttribs(), context);
+ }
+ }
+
+ public void checkGLError() {
+ Util.checkGLError();
+ }
+
+ public void setSwapInterval(final int swap_interval) {
+ ContextGLES.setSwapInterval(swap_interval);
+ }
+
+ public void swapBuffers() throws LWJGLException {
+ ContextGLES.swapBuffers();
+ }
+
+ public void initContext(final float r, final float g, final float b) {
+ // set background clear color
+ glClearColor(r, g, b, 0.0f);
+ // Clear window to avoid the desktop "showing through"
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
+ public boolean isCurrent() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ return context.isCurrent();
+ }
+ }
+
+ public void makeCurrent() throws LWJGLException, PowerManagementEventException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ context.makeCurrent();
+ }
+ }
+
+ public void releaseContext() throws LWJGLException, PowerManagementEventException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ if ( context.isCurrent() )
+ context.releaseCurrent();
+ }
+ }
+
+ public void destroy() {
+ synchronized ( GlobalLock.lock ) {
+ try {
+ if ( context != null ) {
+ try {
+ releaseContext();
+ } catch (PowerManagementEventException e) {
+ // Ignore
+ }
+
+ context.forceDestroy();
+ context = null;
+ }
+
+ if ( eglSurface != null ) {
+ eglSurface.destroy();
+ eglSurface = null;
+ }
+
+ if ( eglDisplay != null ) {
+ eglDisplay.terminate();
+ eglDisplay = null;
+ }
+
+ pixel_format = null;
+ shared_drawable = null;
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Exception occurred while destroying Drawable: " + e);
+ }
+ }
+ }
+
+ protected void checkDestroyed() {
+ if ( context == null )
+ throw new IllegalStateException("The Drawable has no context available.");
+ }
+
+ public void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableGL.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableGL.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableGL.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableGL.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2002-2011 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;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
+
+import static org.lwjgl.opengl.GL11.*;
+
+/** @author Spasi */
+abstract class DrawableGL implements DrawableLWJGL {
+
+ /** The PixelFormat used to create the drawable. */
+ protected PixelFormat pixel_format;
+
+ /** Handle to the native GL rendering context */
+ protected PeerInfo peer_info;
+
+ /** The OpenGL Context. */
+ protected ContextGL context;
+
+ protected DrawableGL() {
+ }
+
+ public void setPixelFormat(final PixelFormatLWJGL pf) throws LWJGLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs) throws LWJGLException {
+ this.pixel_format = (PixelFormat)pf;
+ this.peer_info = Display.getImplementation().createPeerInfo(pixel_format, attribs);
+ }
+
+ public PixelFormatLWJGL getPixelFormat() {
+ return pixel_format;
+ }
+
+ public ContextGL getContext() {
+ synchronized ( GlobalLock.lock ) {
+ return context;
+ }
+ }
+
+ public ContextGL createSharedContext() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ return new ContextGL(peer_info, context.getContextAttribs(), context);
+ }
+ }
+
+ public void checkGLError() {
+ Util.checkGLError();
+ }
+
+ public void setSwapInterval(final int swap_interval) {
+ ContextGL.setSwapInterval(swap_interval);
+ }
+
+ public void swapBuffers() throws LWJGLException {
+ ContextGL.swapBuffers();
+ }
+
+ public void initContext(final float r, final float g, final float b) {
+ // set background clear color
+ glClearColor(r, g, b, 0.0f);
+ // Clear window to avoid the desktop "showing through"
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
+ public boolean isCurrent() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ return context.isCurrent();
+ }
+ }
+
+ public void makeCurrent() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ context.makeCurrent();
+ }
+ }
+
+ public void releaseContext() throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ if ( context.isCurrent() )
+ context.releaseCurrent();
+ }
+ }
+
+ public void destroy() {
+ synchronized ( GlobalLock.lock ) {
+ if ( context == null )
+ return;
+
+ try {
+ releaseContext();
+
+ context.forceDestroy();
+ context = null;
+
+ if ( peer_info != null ) {
+ peer_info.destroy();
+ peer_info = null;
+ }
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Exception occurred while destroying Drawable: " + e);
+ }
+ }
+ }
+
+ public void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ context.setCLSharingProperties(properties);
+ }
+ }
+
+ protected final void checkDestroyed() {
+ if ( context == null )
+ throw new IllegalStateException("The Drawable has no context available.");
+ }
+
+}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableLWJGL.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableLWJGL.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/DrawableLWJGL.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/DrawableLWJGL.java 2016-04-09 16:26:56.000000000 +0000
@@ -1,12 +1,51 @@
+/*
+ * Copyright (c) 2002-2011 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;
import org.lwjgl.LWJGLException;
/**
+ * [INTERNAL USE ONLY]
+ *
* @author Spasi
*/
interface DrawableLWJGL extends Drawable {
+ void setPixelFormat(PixelFormatLWJGL pf) throws LWJGLException;
+
+ void setPixelFormat(PixelFormatLWJGL pf, ContextAttribs attribs) throws LWJGLException;
+
+ PixelFormatLWJGL getPixelFormat();
+
/**
* [INTERNAL USE ONLY] Returns the Drawable's Context.
*
@@ -21,4 +60,12 @@
*/
Context createSharedContext() throws LWJGLException;
-}
+ void checkGLError();
+
+ void setSwapInterval(int swap_interval);
+
+ void swapBuffers() throws LWJGLException;
+
+ void initContext(final float r, final float g, final float b);
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLChecks.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLChecks.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLChecks.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLChecks.java 2016-04-09 16:26:56.000000000 +0000
@@ -31,11 +31,12 @@
*/
package org.lwjgl.opengl;
-import java.nio.Buffer;
-
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
+import java.nio.Buffer;
+import java.nio.FloatBuffer;
+
import static org.lwjgl.opengl.ARBBufferObject.*;
import static org.lwjgl.opengl.ATIVertexArrayObject.*;
import static org.lwjgl.opengl.EXTAbgr.*;
@@ -43,6 +44,7 @@
import static org.lwjgl.opengl.EXTDirectStateAccess.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.NVPathRendering.*;
/**
* A class to check buffer boundaries in GL methods. Many GL
@@ -54,8 +56,8 @@
* Thrown by the debug build library of the LWJGL if any OpenGL operation causes an error.
*
* @author cix_foo
- * @version $Revision: 3459 $
- * $Id: GLChecks.java 3459 2010-11-29 17:21:05Z spasi $
+ * @version $Revision$
+ * $Id$
*/
class GLChecks {
@@ -63,43 +65,27 @@
private GLChecks() {
}
- static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) {
- return glGetBufferParameter(buffer_enum, GL_BUFFER_SIZE);
- }
-
- static int getBufferObjectSizeARB(ContextCapabilities caps, int buffer_enum) {
- return glGetBufferParameterARB(buffer_enum, GL_BUFFER_SIZE_ARB);
- }
-
- static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) {
- return glGetObjectBufferATI(buffer, GL_OBJECT_BUFFER_SIZE_ATI);
- }
-
- static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) {
- return glGetNamedBufferParameterEXT(buffer, GL_BUFFER_SIZE);
- }
-
/** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
static void ensureArrayVBOdisabled(ContextCapabilities caps) {
- if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer != 0 )
+ if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer != 0 )
throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled");
}
/** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
static void ensureArrayVBOenabled(ContextCapabilities caps) {
- if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer == 0 )
+ if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer == 0 )
throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled");
}
/** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
static void ensureElementVBOdisabled(ContextCapabilities caps) {
- if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) != 0 )
+ if ( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) != 0 )
throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled");
}
/** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
static void ensureElementVBOenabled(ContextCapabilities caps) {
- if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) == 0 )
+ if ( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) == 0 )
throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled");
}
@@ -209,10 +195,10 @@
case GL_FLOAT:
bpe = 4;
break;
- default :
+ default:
// TODO: Add more types (like the GL12 types GL_UNSIGNED_INT_8_8_8_8
return 0;
- // throw new IllegalArgumentException("Unknown type " + type);
+ // throw new IllegalArgumentException("Unknown type " + type);
}
int epp;
switch ( format ) {
@@ -233,7 +219,7 @@
case GL_BGRA_EXT:
epp = 4;
break;
- default :
+ default:
// TODO: Add more formats. Assuming 4 is too wasteful on buffer sizes where e.g. 1 is enough (like GL_DEPTH_COMPONENT)
return 0;
/* // Assume 4 elements per pixel
@@ -242,4 +228,116 @@
return bpe * epp;
}
-}
+
+ // NV_path_rendering checks
+
+ static int calculateBytesPerCharCode(int type) {
+ switch ( type ) {
+ case GL_UNSIGNED_BYTE:
+ case GL_UTF8_NV:
+ return 1;
+ case GL_UNSIGNED_SHORT:
+ case GL_2_BYTES:
+ case GL_UTF16_NV:
+ return 2;
+ case GL_3_BYTES:
+ return 3;
+ case GL_4_BYTES:
+ return 4;
+ default:
+ throw new IllegalArgumentException("Unsupported charcode type: " + type);
+ }
+ }
+
+ static int calculateBytesPerPathName(int pathNameType) {
+ switch ( pathNameType ) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_UTF8_NV:
+ return 1;
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_2_BYTES:
+ case GL_UTF16_NV:
+ return 2;
+ case GL_3_BYTES:
+ return 3;
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ case GL_FLOAT:
+ case GL_4_BYTES:
+ return 4;
+ default:
+ throw new IllegalArgumentException("Unsupported path name type: " + pathNameType);
+ }
+ }
+
+ static int calculateTransformPathValues(int transformType) {
+ switch ( transformType ) {
+ case GL_NONE:
+ return 0;
+ case GL_TRANSLATE_X_NV:
+ case GL_TRANSLATE_Y_NV:
+ return 1;
+ case GL_TRANSLATE_2D_NV:
+ return 2;
+ case GL_TRANSLATE_3D_NV:
+ return 3;
+ case GL_AFFINE_2D_NV:
+ case GL_TRANSPOSE_AFFINE_2D_NV:
+ return 6;
+ case GL_AFFINE_3D_NV:
+ case GL_TRANSPOSE_AFFINE_3D_NV:
+ return 12;
+ default:
+ throw new IllegalArgumentException("Unsupported transform type: " + transformType);
+ }
+ }
+
+ static int calculatePathColorGenCoeffsCount(int genMode, int colorFormat) {
+ final int coeffsPerComponent = calculatePathGenCoeffsPerComponent(genMode);
+
+ switch ( colorFormat ) {
+ case GL_RGB:
+ return 3 * coeffsPerComponent;
+ case GL_RGBA:
+ return 4 * coeffsPerComponent;
+ default:
+ return coeffsPerComponent;
+ }
+ }
+
+ static int calculatePathTextGenCoeffsPerComponent(FloatBuffer coeffs, int genMode) {
+ if ( genMode == GL_NONE )
+ return 0;
+
+ return coeffs.remaining() / calculatePathGenCoeffsPerComponent(genMode);
+ }
+
+ private static int calculatePathGenCoeffsPerComponent(int genMode) {
+ switch ( genMode ) {
+ case GL_NONE:
+ return 0;
+ case GL_OBJECT_LINEAR:
+ case GL_PATH_OBJECT_BOUNDING_BOX_NV:
+ return 3;
+ case GL_EYE_LINEAR:
+ return 4;
+ default:
+ throw new IllegalArgumentException("Unsupported gen mode: " + genMode);
+ }
+ }
+
+ static int calculateMetricsSize(int metricQueryMask, int stride) {
+ if ( LWJGLUtil.DEBUG && (stride < 0 || (stride % 4) != 0) )
+ throw new IllegalArgumentException("Invalid stride value: " + stride);
+
+ final int metrics = Integer.bitCount(metricQueryMask);
+
+ if ( LWJGLUtil.DEBUG && (stride >> 2) < metrics )
+ throw new IllegalArgumentException("The queried metrics do not fit in the specified stride: " + stride);
+
+ return stride == 0 ? metrics : (stride >> 2);
+ }
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLContext.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLContext.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLContext.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLContext.java 2016-04-09 16:26:56.000000000 +0000
@@ -33,9 +33,11 @@
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import org.lwjgl.Sys;
import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
@@ -56,8 +58,8 @@
* That way, multiple threads can have multiple contexts current and render to them concurrently.
*
* @author elias_naur
- * @version $Revision: 3418 $
- * $Id: GLContext.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public final class GLContext {
@@ -117,6 +119,14 @@
* @return The current capabilities instance.
*/
public static ContextCapabilities getCapabilities() {
+ ContextCapabilities caps = getCapabilitiesImpl();
+ if ( caps == null )
+ throw new RuntimeException("No OpenGL context found in the current thread.");
+
+ return caps;
+ }
+
+ private static ContextCapabilities getCapabilitiesImpl() {
CapabilitiesCacheEntry recent_cache_entry = fast_path_cache;
// Check owner of cache entry
if ( recent_cache_entry.owner == Thread.currentThread() ) {
@@ -128,6 +138,17 @@
return getThreadLocalCapabilities();
}
+ /**
+ * Returns the capabilities instance associated with the specified context object.
+ *
+ * @param context the context object
+ *
+ * @return the capabilities instance
+ */
+ static ContextCapabilities getCapabilities(Object context) {
+ return capability_cache.get(context);
+ }
+
private static ContextCapabilities getThreadLocalCapabilities() {
return current_capabilities.get();
}
@@ -187,8 +208,12 @@
return 0;
}
- /** Helper method to get a pointer to a named function in the OpenGL library */
- static native long getFunctionAddress(String name);
+ /** Helper method to get a pointer to a named function in the OpenGL library. */
+ static long getFunctionAddress(String name) {
+ ByteBuffer buffer = MemoryUtil.encodeASCII(name);
+ return ngetFunctionAddress(MemoryUtil.getAddress(buffer));
+ }
+ private static native long ngetFunctionAddress(long name);
/**
* Determine which extensions are available and returns the context profile mask. Helper method to ContextCapabilities.
@@ -218,10 +243,10 @@
}
final int[][] GL_VERSIONS = {
- { 1, 2, 3, 4, 5 }, // OpenGL 1
- { 0, 1 }, // OpenGL 2
- { 0, 1, 2, 3 }, // OpenGL 3
- { 0, 1 }, // OpenGL 4
+ { 1, 2, 3, 4, 5 }, // OpenGL 1
+ { 0, 1 }, // OpenGL 2
+ { 0, 1, 2, 3 }, // OpenGL 3
+ { 0, 1, 2, 3, 4, 5 }, // OpenGL 4
};
for ( int major = 1; major <= GL_VERSIONS.length; major++ ) {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLUConstants.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLUConstants.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/GLUConstants.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/GLUConstants.java 2016-04-09 16:26:56.000000000 +0000
@@ -38,8 +38,8 @@
* GLU constants.
*
* @author cix_foo
- * @version $Revision: 3418 $
- * $Id: GLUConstants.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
public interface GLUConstants {
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/InputImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/InputImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/InputImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/InputImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -69,7 +69,7 @@
void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
/**
- * Method to read the keyboard buffer
+ * Method to read the mouse buffer
*/
void readMouse(ByteBuffer buffer);
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/KHRDebugCallback.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/KHRDebugCallback.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/KHRDebugCallback.java 1970-01-01 00:00:00.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/KHRDebugCallback.java 2016-04-09 16:26:56.000000000 +0000
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2002-2008 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;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Instances of this class are needed to use the callback functionality of the KHR_debug extension.
+ * Users of this class may provide implementations of the {@code Handler} interface to receive notifications.
+ * The same {@code Handler} instance may be used by different contexts but it is not recommended.
+ * Handler notifications are synchronized.
+ *
+ * @author Spasi
+ */
+public final class KHRDebugCallback extends PointerWrapperAbstract {
+
+ /** Severity levels. */
+ private static final int
+ GL_DEBUG_SEVERITY_HIGH = 0x9146,
+ GL_DEBUG_SEVERITY_MEDIUM = 0x9147,
+ GL_DEBUG_SEVERITY_LOW = 0x9148,
+ GL_DEBUG_SEVERITY_NOTIFICATION = 0x826B;
+
+ /** Sources. */
+ private static final int
+ GL_DEBUG_SOURCE_API = 0x8246,
+ GL_DEBUG_SOURCE_WINDOW_SYSTEM = 0x8247,
+ GL_DEBUG_SOURCE_SHADER_COMPILER = 0x8248,
+ GL_DEBUG_SOURCE_THIRD_PARTY = 0x8249,
+ GL_DEBUG_SOURCE_APPLICATION = 0x824A,
+ GL_DEBUG_SOURCE_OTHER = 0x824B;
+
+ /** Types. */
+ private static final int
+ GL_DEBUG_TYPE_ERROR = 0x824C,
+ GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR = 0x824D,
+ GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR = 0x824E,
+ GL_DEBUG_TYPE_PORTABILITY = 0x824F,
+ GL_DEBUG_TYPE_PERFORMANCE = 0x8250,
+ GL_DEBUG_TYPE_OTHER = 0x8251,
+ GL_DEBUG_TYPE_MARKER = 0x8268;
+
+ private static final long CALLBACK_POINTER;
+
+ static {
+ long pointer = 0;
+ try {
+ // Call reflectively so that we can compile this class for the Generator.
+ pointer = (Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugCallbackKHR").invoke(null);
+ } catch (Exception e) {
+ // ignore
+ }
+ CALLBACK_POINTER = pointer;
+ }
+
+ private final Handler handler;
+
+ /**
+ * Creates an KHRebugCallback with a default callback handler.
+ * The default handler will simply print the message on System.err.
+ */
+ public KHRDebugCallback() {
+ this(new Handler() {
+ public void handleMessage(final int source, final int type, final int id, final int severity, final String message) {
+ System.err.println("[LWJGL] KHR_debug message");
+ System.err.println("\tID: " + id);
+
+ String description;
+ switch ( source ) {
+ case GL_DEBUG_SOURCE_API:
+ description = "API";
+ break;
+ case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
+ description = "WINDOW SYSTEM";
+ break;
+ case GL_DEBUG_SOURCE_SHADER_COMPILER:
+ description = "SHADER COMPILER";
+ break;
+ case GL_DEBUG_SOURCE_THIRD_PARTY:
+ description = "THIRD PARTY";
+ break;
+ case GL_DEBUG_SOURCE_APPLICATION:
+ description = "APPLICATION";
+ break;
+ case GL_DEBUG_SOURCE_OTHER:
+ description = "OTHER";
+ break;
+ default:
+ description = printUnknownToken(source);
+ }
+ System.err.println("\tSource: " + description);
+
+ switch ( type ) {
+ case GL_DEBUG_TYPE_ERROR:
+ description = "ERROR";
+ break;
+ case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
+ description = "DEPRECATED BEHAVIOR";
+ break;
+ case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
+ description = "UNDEFINED BEHAVIOR";
+ break;
+ case GL_DEBUG_TYPE_PORTABILITY:
+ description = "PORTABILITY";
+ break;
+ case GL_DEBUG_TYPE_PERFORMANCE:
+ description = "PERFORMANCE";
+ break;
+ case GL_DEBUG_TYPE_OTHER:
+ description = "OTHER";
+ break;
+ case GL_DEBUG_TYPE_MARKER:
+ description = "MARKER";
+ break;
+ default:
+ description = printUnknownToken(type);
+ }
+ System.err.println("\tType: " + description);
+
+ switch ( severity ) {
+ case GL_DEBUG_SEVERITY_HIGH:
+ description = "HIGH";
+ break;
+ case GL_DEBUG_SEVERITY_MEDIUM:
+ description = "MEDIUM";
+ break;
+ case GL_DEBUG_SEVERITY_LOW:
+ description = "LOW";
+ break;
+ case GL_DEBUG_SEVERITY_NOTIFICATION:
+ description = "NOTIFICATION";
+ break;
+ default:
+ description = printUnknownToken(severity);
+ }
+ System.err.println("\tSeverity: " + description);
+
+ System.err.println("\tMessage: " + message);
+ }
+
+ private String printUnknownToken(final int token) {
+ return "Unknown (0x" + Integer.toHexString(token).toUpperCase() + ")";
+ }
+ });
+ }
+
+ /**
+ * Creates an ARBDebugOutputCallback with the specified callback handler.
+ * The handler's {@code handleMessage} method will be called whenever
+ * debug output is generated by the GL.
+ *
+ * @param handler the callback handler
+ */
+ public KHRDebugCallback(final Handler handler) {
+ super(CALLBACK_POINTER);
+
+ this.handler = handler;
+ }
+
+ Handler getHandler() {
+ return handler;
+ }
+
+ /** Implementations of this interface can be used to receive ARB_debug_output notifications. */
+ public interface Handler {
+
+ /**
+ * This method will be called when an ARB_debug_output message is generated.
+ *
+ * @param source the message source
+ * @param type the message type
+ * @param id the message ID
+ * @param severity the message severity
+ * @param message the string representation of the message.
+ */
+ void handleMessage(int source, int type, int id, int severity, String message);
+
+ }
+
+}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java 2016-04-09 16:26:56.000000000 +0000
@@ -40,8 +40,8 @@
/**
*
* @author elias_naur
- * @version $Revision: 3116 $
- * $Id: LinuxAWTGLCanvasPeerInfo.java 3116 2008-08-19 16:46:03Z spasi $
+ * @version $Revision$
+ * $Id$
*/
final class LinuxAWTGLCanvasPeerInfo extends LinuxPeerInfo {
private final Canvas component;
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -44,8 +44,8 @@
/**
*
* @author elias_naur
- * @version $Revision: 3418 $
- * $Id: LinuxCanvasImplementation.java 3418 2010-09-28 21:11:35Z spasi $
+ * @version $Revision$
+ * $Id$
*/
final class LinuxCanvasImplementation implements AWTCanvasImplementation {
static int getScreenFromDevice(final GraphicsDevice device) throws LWJGLException {
@@ -76,7 +76,7 @@
}
}
- public PeerInfo createPeerInfo(Canvas component, PixelFormat pixel_format) throws LWJGLException {
+ public PeerInfo createPeerInfo(Canvas component, PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
return new LinuxAWTGLCanvasPeerInfo(component);
}
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxContextAttribs.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxContextAttribs.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxContextAttribs.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxContextAttribs.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2002-2008 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;
-
-/**
- * An implementation of ContextAttribs using GLX_create_context.
- *
- * ---- WIP - GLX_create_context has not been defined yet ----
- *
- * @author spasi
- */
-final class LinuxContextAttribs implements ContextAttribsImplementation {
-
- private static final int GLX_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
- private static final int GLX_CONTEXT_MINOR_VERSION_ARB = 0x2092;
- private static final int GLX_CONTEXT_LAYER_PLANE_ARB = 0x2093;
- private static final int GLX_CONTEXT_FLAGS_ARB = 0x2094;
- private static final int GLX_CONTEXT_PROFILE_MASK_ARB = 0x9126;
-
- private static final int GLX_CONTEXT_DEBUG_BIT_ARB = 0x0001;
- private static final int GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
-
- private static final int GLX_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
- private static final int GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
-
- LinuxContextAttribs() {
- }
-
- public int getMajorVersionAttrib() {
- return GLX_CONTEXT_MAJOR_VERSION_ARB;
- }
-
- public int getMinorVersionAttrib() {
- return GLX_CONTEXT_MINOR_VERSION_ARB;
- }
-
- public int getLayerPlaneAttrib() {
- return GLX_CONTEXT_LAYER_PLANE_ARB;
- }
-
- public int getFlagsAttrib() {
- return GLX_CONTEXT_FLAGS_ARB;
- }
-
- public int getDebugBit() {
- return GLX_CONTEXT_DEBUG_BIT_ARB;
- }
-
- public int getForwardCompatibleBit() {
- return GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
- }
-
- public int getProfileMaskAttrib() {
- return GLX_CONTEXT_PROFILE_MASK_ARB;
- }
-
- public int getProfileCoreBit() {
- return GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
- }
-
- public int getProfileCompatibilityBit() {
- return GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
- }
-
-}
\ No newline at end of file
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxContextImplementation.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxContextImplementation.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxContextImplementation.java 2016-04-09 16:26:56.000000000 +0000
@@ -38,8 +38,8 @@
/**
* @author elias_naur
- * @version $Revision: 3412 $
- * $Id: LinuxContextImplementation.java 3412 2010-09-26 23:43:24Z spasi $
+ * @version $Revision$
+ * $Id$
*/
final class LinuxContextImplementation implements ContextImplementation {
@@ -67,7 +67,7 @@
}
public void swapBuffers() throws LWJGLException {
- Context current_context = Context.getCurrentContext();
+ ContextGL current_context = ContextGL.getCurrentContext();
if ( current_context == null )
throw new IllegalStateException("No context is current");
synchronized ( current_context ) {
@@ -89,7 +89,7 @@
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
public void releaseCurrentContext() throws LWJGLException {
- Context current_context = Context.getCurrentContext();
+ ContextGL current_context = ContextGL.getCurrentContext();
if ( current_context == null )
throw new IllegalStateException("No context is current");
synchronized ( current_context ) {
@@ -142,17 +142,30 @@
private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException;
public void setSwapInterval(int value) {
- Context current_context = Context.getCurrentContext();
+ ContextGL current_context = ContextGL.getCurrentContext();
+ PeerInfo peer_info = current_context.getPeerInfo();
+
if ( current_context == null )
throw new IllegalStateException("No context is current");
synchronized ( current_context ) {
LinuxDisplay.lockAWT();
- nSetSwapInterval(current_context.getHandle(), value);
- LinuxDisplay.unlockAWT();
+ try {
+ ByteBuffer peer_handle = peer_info.lockAndGetHandle();
+ try {
+ nSetSwapInterval(peer_handle, current_context.getHandle(), value);
+ } finally {
+ peer_info.unlock();
+ }
+ } catch (LWJGLException e) {
+ // API CHANGE - this methods should throw LWJGLException
+ e.printStackTrace();
+ } finally {
+ LinuxDisplay.unlockAWT();
+ }
}
}
- private static native void nSetSwapInterval(ByteBuffer context_handle, int value);
+ private static native void nSetSwapInterval(ByteBuffer peer_handle, ByteBuffer context_handle, int value);
public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
LinuxDisplay.lockAWT();
diff -Nru lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxDisplay.java lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxDisplay.java
--- lwjgl-2.7.1+dfsg/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-03-26 18:15:36.000000000 +0000
+++ lwjgl-2.9.3+dfsg/src/java/org/lwjgl/opengl/LinuxDisplay.java 2016-04-09 16:26:56.000000000 +0000
@@ -39,17 +39,24 @@
*/
import java.awt.Canvas;
+import java.awt.event.FocusListener;
+import java.awt.event.FocusEvent;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.ByteOrder;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+import java.lang.reflect.InvocationTargetException;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import org.lwjgl.opengl.XRandR.Screen;
+import org.lwjgl.opengles.EGL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -79,6 +86,8 @@
private static final int SetModeInsert = 0;
private static final int SaveSetRoot = 1;
private static final int SaveSetUnmap = 1;
+
+ private static final int X_SetInputFocus = 42;
/** Window mode enum */
private static final int FULLSCREEN_LEGACY = 1;
@@ -120,7 +129,6 @@
private DisplayMode saved_mode;
private DisplayMode current_mode;
- private Screen[] savedXrandrConfig;
private boolean keyboard_grabbed;
private boolean pointer_grabbed;
@@ -132,14 +140,42 @@
private boolean close_requested;
private long current_cursor;
private long blank_cursor;
- private Canvas parent;
- private long parent_window;
- private boolean xembedded;
- private boolean parent_focus;
private boolean mouseInside = true;
+ private boolean resizable;
+ private boolean resized;
+ private int window_x;
+ private int window_y;
+ private int window_width;
+ private int window_height;
+
+ private Canvas parent;
+ private long parent_window;
+ private static boolean xembedded;
+ private long parent_proxy_focus_window;
+ private boolean parent_focused;
+ private boolean parent_focus_changed;
+ private long last_window_focus = 0;
+
private LinuxKeyboard keyboard;
private LinuxMouse mouse;
+
+ private String wm_class;
+
+ private final FocusListener focus_listener = new FocusListener() {
+ public void focusGained(FocusEvent e) {
+ synchronized (GlobalLock.lock) {
+ parent_focused = true;
+ parent_focus_changed = true;
+ }
+ }
+ public void focusLost(FocusEvent e) {
+ synchronized (GlobalLock.lock) {
+ parent_focused = false;
+ parent_focus_changed = true;
+ }
+ }
+ };
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
lockAWT();
@@ -259,7 +295,12 @@
*/
static void incDisplay() throws LWJGLException {
if (display_connection_usage_count == 0) {
- GLContext.loadOpenGLLibrary();
+ try {
+ // TODO: Can we know if we're on desktop or ES?
+ GLContext.loadOpenGLLibrary();
+ org.lwjgl.opengles.GLContext.loadOpenGLLibrary();
+ } catch (Throwable t) {
+ }
saved_error_handler = setErrorHandler();
display = openDisplay();
// synchronize(display, true);
@@ -272,6 +313,8 @@
private static native void synchronize(long display, boolean synchronize);
private static int globalErrorHandler(long display, long event_ptr, long error_display, long serial, long error_code, long request_code, long minor_code) throws LWJGLException {
+ if (xembedded && request_code == X_SetInputFocus) return 0; // ignore X error in xembeded mode to fix a browser issue when dragging or switching tabs
+
if (display == getDisplay()) {
String error_msg = getErrorText(display, error_code);
throw new LWJGLException("X Error - disp: 0x" + Long.toHexString(error_display) + " serial: " + serial + " error: " + error_msg + " request_code: " + request_code + " minor_code: " + minor_code);
@@ -408,26 +451,54 @@
ungrabKeyboard();
}
- public void createWindow(DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
+ public void createWindow(final DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
lockAWT();
try {
incDisplay();
try {
+ if ( drawable instanceof DrawableGLES )
+ peer_info = new LinuxDisplayPeerInfo();
+
ByteBuffer handle = peer_info.lockAndGetHandle();
try {
current_window_mode = getWindowMode(Display.isFullscreen());
+
// Try to enable Lecagy FullScreen Support in Compiz, else
// we may have trouble with stuff overlapping our fullscreen window.
if ( current_window_mode != WINDOWED )
Compiz.setLegacyFullscreenSupport(true);
+
// Setting _MOTIF_WM_HINTS in fullscreen mode is problematic for certain window
// managers. We do not set MWM_HINTS_DECORATIONS in fullscreen mode anymore,
// unless org.lwjgl.opengl.Window.undecorated_fs has been specified.
// See native/linux/org_lwjgl_opengl_Display.c, createWindow function.
boolean undecorated = Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated") || (current_window_mode != WINDOWED && Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated_fs"));
+
this.parent = parent;
parent_window = parent != null ? getHandle(parent) : getRootWindow(getDisplay(), getDefaultScreen());
- current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window);
+ resizable = Display.isResizable();
+ resized = false;
+ window_x = x;
+ window_y = y;
+ window_width = mode.getWidth();
+ window_height = mode.getHeight();
+
+ // overwrite arguments x and y - superclass always uses 0,0 for fullscreen windows
+ // use the coordinates of XRandRs primary screen instead
+ // this is required to let the fullscreen window appear on the primary screen
+ if (mode.isFullscreenCapable() && current_displaymode_extension == XRANDR) {
+ Screen primaryScreen = XRandR.DisplayModetoScreen(Display.getDisplayMode());
+ x = primaryScreen.xPos;
+ y = primaryScreen.yPos;
+ }
+
+ current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window, resizable);
+
+ // Set the WM_CLASS hint which is needed by some WM's e.g. Gnome Shell
+ wm_class = Display.getPrivilegedString("LWJGL_WM_CLASS");
+ if (wm_class == null) wm_class = Display.getTitle();
+ setClassHint(Display.getTitle(), wm_class);
+
mapRaised(getDisplay(), current_window);
xembedded = parent != null && isAncestorXEmbedded(parent_window);
blank_cursor = createBlankCursor();
@@ -440,6 +511,15 @@
grab = false;
minimized = false;
dirty = true;
+
+ if ( drawable instanceof DrawableGLES )
+ ((DrawableGLES)drawable).initialize(current_window, getDisplay(), EGL.EGL_WINDOW_BIT, (org.lwjgl.opengles.PixelFormat)drawable.getPixelFormat());
+
+ if (parent != null) {
+ parent.addFocusListener(focus_listener);
+ parent_focused = parent.isFocusOwner();
+ parent_focus_changed = true;
+ }
} finally {
peer_info.unlock();
}
@@ -451,12 +531,20 @@
unlockAWT();
}
}
- private static native long nCreateWindow(long display, int screen, ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y, boolean undecorated, long parent_handle) throws LWJGLException;
+ private static native long nCreateWindow(long display, int screen, ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y, boolean undecorated, long parent_handle, boolean resizable) throws LWJGLException;
private static native long getRootWindow(long display, int screen);
private static native boolean hasProperty(long display, long window, long property);
private static native long getParentWindow(long display, long window) throws LWJGLException;
+ private static native int getChildCount(long display, long window) throws LWJGLException;
private static native void mapRaised(long display, long window);
private static native void reparentWindow(long display, long window, long parent, int x, int y);
+ private static native long nGetInputFocus(long display) throws LWJGLException;
+ private static native void nSetInputFocus(long display, long window, long time);
+ private static native void nSetWindowSize(long display, long window, int width, int height, boolean resizable);
+ private static native int nGetX(long display, long window);
+ private static native int nGetY(long display, long window);
+ private static native int nGetWidth(long display, long window);
+ private static native int nGetHeight(long display, long window);
private static boolean isAncestorXEmbedded(long window) throws LWJGLException {
long xembed_atom = internAtom("_XEMBED_INFO", true);
@@ -473,7 +561,7 @@
private static long getHandle(Canvas parent) throws LWJGLException {
AWTCanvasImplementation awt_impl = AWTGLCanvas.createImplementation();
- LinuxPeerInfo parent_peer_info = (LinuxPeerInfo)awt_impl.createPeerInfo(parent, null);
+ LinuxPeerInfo parent_peer_info = (LinuxPeerInfo)awt_impl.createPeerInfo(parent, null, null);
ByteBuffer parent_peer_info_handle = parent_peer_info.lockAndGetHandle();
try {
return parent_peer_info.getDrawable();
@@ -490,6 +578,9 @@
public void destroyWindow() {
lockAWT();
try {
+ if (parent != null) {
+ parent.removeFocusListener(focus_listener);
+ }
try {
setNativeCursor(null);
} catch (LWJGLException e) {
@@ -520,12 +611,17 @@
}
private void switchDisplayModeOnTmpDisplay(DisplayMode mode) throws LWJGLException {
- incDisplay();
- try {
- nSwitchDisplayMode(getDisplay(), getDefaultScreen(), current_displaymode_extension, mode);
- } finally {
- decDisplay();
- }
+ if (current_displaymode_extension == XRANDR) {
+ // let Xrandr set the display mode
+ XRandR.setConfiguration(false, XRandR.DisplayModetoScreen(mode));
+ } else {
+ incDisplay();
+ try {
+ nSwitchDisplayMode(getDisplay(), getDefaultScreen(), current_displaymode_extension, mode);
+ } finally {
+ decDisplay();
+ }
+ }
}
private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException;
@@ -542,11 +638,11 @@
public void resetDisplayMode() {
lockAWT();
try {
- if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
+ if( current_displaymode_extension == XRANDR )
{
AccessController.doPrivileged(new PrivilegedAction