|
From: <sp...@us...> - 2008-08-19 16:46:22
|
Revision: 3116
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3116&view=rev
Author: spasi
Date: 2008-08-19 16:46:03 +0000 (Tue, 19 Aug 2008)
Log Message:
-----------
Added support for OpenGL 3.0 functionality
Added support for OpenGL 3.0 context creation (MAJOR/MINOR versions, DEBUG mode, FORWARD_COMBATIBLE mode)
Added support for OpenGL 3.0 context sharing
Added support for OpenGL 3.0 extension detection
Improved support for floating point PixelFormats (ARB_color_buffer_float)
Added support for packed floating point PixelFormats (EXT_packed_float)
Added support for sRGB PixelFormats (ARB_framebuffer_sRGB)
Added support for pseudo-FORWARD_COMBATIBLE mode (deprecated functions not loaded)
Added support for EXT_direct_state_access
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java
trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java
trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java
trunk/LWJGL/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java
trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java
trunk/LWJGL/src/java/org/lwjgl/opengl/ContextImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java
trunk/LWJGL/src/java/org/lwjgl/opengl/GLContext.java
trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplayPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPbufferPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTGLCanvasPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasListener.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplayPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXPbufferPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/Pbuffer.java
trunk/LWJGL/src/java/org/lwjgl/opengl/PeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/PixelFormat.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTGLCanvasPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsContextImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplayPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsFileVersion.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsPbufferPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsPeerInfo.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextCapabilitiesGenerator.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
trunk/LWJGL/src/native/linux/context.c
trunk/LWJGL/src/native/linux/extgl_glx.c
trunk/LWJGL/src/native/linux/extgl_glx.h
trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c
trunk/LWJGL/src/native/macosx/context.m
trunk/LWJGL/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m
trunk/LWJGL/src/native/windows/context.c
trunk/LWJGL/src/native/windows/context.h
trunk/LWJGL/src/native/windows/extgl_wgl.c
trunk/LWJGL/src/native/windows/extgl_wgl.h
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsContextImplementation.c
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_imaging.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_window_pos.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_transform_feedback.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_conditional_render.java
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxContextAttribs.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXContextAttribs.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsContextAttribs.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/Dependent.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/DeprecatedGL.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/GLtime.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java
Modified: trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -57,11 +57,6 @@
}
/**
- * Default buffer size for most buffer checks.
- */
- private static final int DEFAULT_BUFFER_SIZE = 4;
-
- /**
* Helper methods to ensure a function pointer is not-null (0)
*/
public static void checkFunctionAddress(long pointer) {
@@ -129,7 +124,7 @@
private static void throwBufferSizeException(Buffer buf, int size) {
throw new IllegalArgumentException("Number of remaining buffer elements is " + buf.remaining() + ", must be at least " + size);
}
-
+
/**
* Helper method to ensure a buffer is big enough to receive data from a
* glGet* operation.
Modified: trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -52,7 +52,7 @@
private final static int INITIAL_BUFFER_SIZE = 1;
private final static ThreadLocal thread_buffer = new ThreadLocal() {
- protected final Object initialValue() {
+ protected Object initialValue() {
return new CachedBuffers(INITIAL_BUFFER_SIZE);
}
};
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -31,33 +31,29 @@
*/
package org.lwjgl.opengl;
-import java.awt.Canvas;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
-import java.awt.Point;
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.Sys;
+
+import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
-import org.lwjgl.LWJGLException;
-import org.lwjgl.LWJGLUtil;
-import org.lwjgl.Sys;
-
/**
- * <p>
+ * <p/>
* An AWT rendering context.
- * <p>
- * @version $Revision$
+ * <p/>
+ *
* @author $Author$
- * $Id$
+ * $Id$
+ * @version $Revision$
*/
public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener {
private static final long serialVersionUID = 1L;
-
+
private final static AWTCanvasImplementation implementation;
private boolean update_context;
private Object SYNC_LOCK = new Object();
@@ -67,7 +63,10 @@
/** The drawable to share context with */
private final Drawable drawable;
-
+
+ /** The ContextAttribs to use when creating the context */
+ private final ContextAttribs attribs;
+
/** Context handle */
private PeerInfo peer_info;
private Context context;
@@ -87,7 +86,7 @@
}
static AWTCanvasImplementation createImplementation() {
- switch (LWJGLUtil.getPlatform()) {
+ switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxCanvasImplementation();
case LWJGLUtil.PLATFORM_WINDOWS:
@@ -100,25 +99,21 @@
}
private void setUpdate() {
- synchronized(SYNC_LOCK) {
+ synchronized ( SYNC_LOCK ) {
update_context = true;
}
}
- /**
- * This method should only be called internally.
- */
+ /** This method should only be called internally. */
public Context getContext() {
return context;
}
-
- /**
- * Constructor using the default PixelFormat.
- */
+
+ /** Constructor using the default PixelFormat. */
public AWTGLCanvas() throws LWJGLException {
this(new PixelFormat());
}
-
+
/**
* Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.
*
@@ -131,7 +126,7 @@
/**
* Create an AWTGLCanvas with the requested PixelFormat on the default GraphicsDevice.
*
- * @param device the device to create the canvas on.
+ * @param device the device to create the canvas on.
* @param pixel_format The desired pixel format. May not be null
*/
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException {
@@ -141,94 +136,99 @@
/**
* Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.
*
- * @param device the device to create the canvas on.
+ * @param device the device to create the canvas on.
* @param pixel_format The desired pixel format. May not be null
- * @param drawable The Drawable to share context with
+ * @param drawable The Drawable to share context with
*/
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable) throws LWJGLException {
+ this(device, pixel_format, drawable, null);
+ }
+
+ /**
+ * Create an AWTGLCanvas with the requested PixelFormat on the specified GraphicsDevice.
+ *
+ * @param device the device to create the canvas on.
+ * @param pixel_format The desired pixel format. May not be null
+ * @param drawable The Drawable to share context with
+ * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
+ */
+ public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable, ContextAttribs attribs) throws LWJGLException {
super(implementation.findConfiguration(device, pixel_format));
- if (pixel_format == null)
+ if ( pixel_format == null )
throw new NullPointerException("Pixel format must be non-null");
addHierarchyListener(this);
addComponentListener(this);
this.drawable = drawable;
this.pixel_format = pixel_format;
+ this.attribs = attribs;
}
-
+
/* (non-Javadoc)
- * @see java.awt.Canvas#addNotify()
- */
+ * @see java.awt.Canvas#addNotify()
+ */
public void addNotify() {
super.addNotify();
}
-
+
/* (non-Javadoc)
- * @see java.awt.Component#removeNotify()
- */
+ * @see java.awt.Component#removeNotify()
+ */
public void removeNotify() {
- synchronized (SYNC_LOCK) {
+ synchronized ( SYNC_LOCK ) {
destroyContext();
super.removeNotify();
}
- }
-
- /**
- * Set swap interval.
- */
+ }
+
+ /** Set swap interval. */
public void setSwapInterval(int swap_interval) {
- synchronized(SYNC_LOCK) {
- if (context == null)
+ synchronized ( SYNC_LOCK ) {
+ if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
Context.setSwapInterval(swap_interval);
}
}
-
- /**
- * Enable vsync
- */
+
+ /** Enable vsync */
public void setVSyncEnabled(boolean enabled) {
setSwapInterval(enabled ? 1 : 0);
}
-
- /**
- * Swap the canvas' buffer
- */
+
+ /** Swap the canvas' buffer */
public void swapBuffers() throws LWJGLException {
- synchronized(SYNC_LOCK) {
- if (context == null)
+ synchronized ( SYNC_LOCK ) {
+ if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
Context.swapBuffers();
}
}
-
+
public void releaseContext() throws LWJGLException {
- synchronized(SYNC_LOCK) {
- if (context == null)
+ synchronized ( SYNC_LOCK ) {
+ if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
- if (context.isCurrent())
+ if ( context.isCurrent() )
Context.releaseCurrentContext();
}
}
-
+
/**
* Make the canvas' context current. It is highly recommended that the context
* is only made current inside the AWT thread (for example in an overridden paintGL()).
*/
public void makeCurrent() throws LWJGLException {
- synchronized(SYNC_LOCK) {
- if (context == null)
+ synchronized ( SYNC_LOCK ) {
+ if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
context.makeCurrent();
}
}
-
- /**
- * Destroy the OpenGL context. This happens when the component becomes undisplayable
- */
+
+ /** Destroy the OpenGL context. This happens when the component becomes undisplayable */
private void destroyContext() {
- synchronized(SYNC_LOCK) {
+ synchronized ( SYNC_LOCK ) {
try {
- if (context != null) {
+ if ( context != null ) {
context.forceDestroy();
context = null;
reentry_count = 0;
@@ -243,15 +243,13 @@
/**
* Override this to do initialising of the context.
- * It will be called once from paint(), immediately after
+ * It will be called once from paint(), immediately after
* the context is created and made current.
*/
protected void initGL() {
}
- /**
- * Override this to do painting
- */
+ /** Override this to do painting */
protected void paintGL() {
}
@@ -261,36 +259,36 @@
*/
public final void paint(Graphics g) {
LWJGLException exception = null;
- synchronized (SYNC_LOCK) {
- if (!isDisplayable())
+ synchronized ( SYNC_LOCK ) {
+ if ( !isDisplayable() )
return;
try {
- if (peer_info == null) {
+ if ( peer_info == null ) {
this.peer_info = implementation.createPeerInfo(this, pixel_format);
}
peer_info.lockAndGetHandle();
try {
- if (context == null) {
- this.context = new Context(peer_info, drawable != null ? drawable.getContext() : null);
+ if ( context == null ) {
+ this.context = new Context(peer_info, attribs, drawable != null ? drawable.getContext() : null);
first_run = true;
}
- if (reentry_count == 0)
+ if ( reentry_count == 0 )
context.makeCurrent();
reentry_count++;
try {
- if (update_context) {
+ if ( update_context ) {
context.update();
update_context = false;
}
- if (first_run) {
+ if ( first_run ) {
first_run = false;
initGL();
}
paintGL();
} finally {
reentry_count--;
- if (reentry_count == 0)
+ if ( reentry_count == 0 )
Context.releaseCurrentContext();
}
} finally {
@@ -300,7 +298,7 @@
exception = e;
}
}
- if (exception != null)
+ if ( exception != null )
exceptionOccurred(exception);
}
@@ -314,9 +312,7 @@
LWJGLUtil.log("Unhandled exception occurred, skipping paint(): " + exception);
}
- /**
- * override update to avoid clearing
- */
+ /** override update to avoid clearing */
public void update(Graphics g) {
paint(g);
}
@@ -363,4 +359,5 @@
public void hierarchyChanged(HierarchyEvent e) {
setUpdate();
}
-}
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTSurfaceLock.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTSurfaceLock.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -54,7 +54,7 @@
private boolean firstLockSucceeded = false;
- public AWTSurfaceLock() {
+ AWTSurfaceLock() {
lock_buffer = createHandle();
}
@@ -98,7 +98,7 @@
private static native boolean lockAndInitHandle(ByteBuffer lock_buffer, Canvas component) throws LWJGLException;
- protected void unlock() throws LWJGLException {
+ void unlock() throws LWJGLException {
nUnlock(lock_buffer);
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -113,7 +113,7 @@
final GraphicsConfiguration config = component.getGraphicsConfiguration();
if (config != null) {
PointerInfo pointer_info = (PointerInfo)AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public final Object run() throws Exception {
+ public Object run() throws Exception {
return MouseInfo.getPointerInfo();
}
});
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -31,43 +31,44 @@
*/
package org.lwjgl.opengl;
-import java.nio.ByteBuffer;
-
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.Sys;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+
/**
* <p/>
* Context encapsulates an OpenGL context.
* <p/>
- *
+ * <p/>
* This class is thread-safe.
*
* @author elias_naur <eli...@us...>
* @version $Revision$
- * $Id$
+ * $Id$
*/
final class Context {
- /**
- * The platform specific implementation of context methods
- */
+
+ /** The platform specific implementation of context methods */
private final static ContextImplementation implementation;
/** The current Context */
private final static ThreadLocal current_context_local = new ThreadLocal();
-
- /**
- * Handle to the native GL rendering context
- */
+
+ /** Handle to the native GL rendering context */
private final ByteBuffer handle;
private final PeerInfo peer_info;
+ private final IntBuffer attribList;
+ private final boolean forwardCombatible;
+
/** 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;
@@ -77,7 +78,7 @@
}
private static ContextImplementation createImplementation() {
- switch (LWJGLUtil.getPlatform()) {
+ switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxContextImplementation();
case LWJGLUtil.PLATFORM_WINDOWS:
@@ -97,20 +98,26 @@
return (Context)current_context_local.get();
}
- /**
- * Create a context with the specified peer info and shared context
- */
- public Context(PeerInfo peer_info, Context shared_context) throws LWJGLException {
+ /** 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
+ // 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)
+ 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.handle = implementation.create(peer_info, shared_context != null ? shared_context.handle : null);
+ if ( attribs != null ) {
+ attribList = attribs.getAttribList();
+ forwardCombatible = attribs.isForwardCombatible();
+ } else {
+ attribList = null;
+ forwardCombatible = false;
+ }
+
+ this.handle = implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null);
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
@@ -118,16 +125,14 @@
}
}
- /**
- * Release the current context (if any). After this call, no context is current.
- */
+ /** 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) {
+ if ( current_context != null ) {
implementation.releaseCurrentContext();
GLContext.useContext(null);
current_context_local.set(null);
- synchronized (current_context) {
+ synchronized ( current_context ) {
current_context.thread = null;
current_context.checkDestroy();
}
@@ -141,64 +146,56 @@
* on every releaseCurrentContext results in artifacts.
*/
public synchronized void releaseDrawable() throws LWJGLException {
- if (destroyed)
+ 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
- */
+ /** Update the context. Should be called whenever it's drawable is moved or resized */
public synchronized void update() {
- if (destroyed)
+ if ( destroyed )
throw new IllegalStateException("Context is destroyed");
implementation.update(getHandle());
}
-
- /**
- * Swap the buffers on the current context. Only valid for double-buffered contexts
- */
+
+ /** 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())
+ if ( !canAccess() )
throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current");
}
- /**
- * Make the context current
- */
+ /** Make the context current */
public synchronized void makeCurrent() throws LWJGLException {
checkAccess();
- if (destroyed)
+ if ( destroyed )
throw new IllegalStateException("Context is destroyed");
thread = Thread.currentThread();
current_context_local.set(this);
implementation.makeCurrent(peer_info, handle);
- GLContext.useContext(this);
+ GLContext.useContext(this, forwardCombatible);
}
ByteBuffer getHandle() {
return handle;
}
- /**
- * Query whether the context is current
- */
+ /** Query whether the context is current */
public synchronized boolean isCurrent() throws LWJGLException {
- if (destroyed)
+ if ( destroyed )
throw new IllegalStateException("Context is destroyed");
return implementation.isCurrent(handle);
}
private void checkDestroy() {
- if (!destroyed && destroy_requested) {
+ if ( !destroyed && destroy_requested ) {
try {
releaseDrawable();
implementation.destroy(peer_info, handle);
@@ -215,16 +212,13 @@
* 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.
- *
+ * <p/>
* A video frame period is the time required to display a full frame of video data.
- *
- * @param sync true to synchronize; false to ignore synchronization
*/
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
@@ -234,24 +228,25 @@
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)
+ if ( destroyed )
return;
destroy_requested = true;
boolean was_current = isCurrent();
int error = GL11.GL_NO_ERROR;
- if (was_current) {
- if (GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11)
+ if ( was_current ) {
+ if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
error = GL11.glGetError();
releaseCurrentContext();
}
checkDestroy();
- if (was_current && error != GL11.GL_NO_ERROR)
+ if ( was_current && error != GL11.GL_NO_ERROR )
throw new OpenGLException(error);
}
-}
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -0,0 +1,213 @@
+/*
+ * 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.BufferUtils;
+import org.lwjgl.LWJGLUtil;
+
+import java.nio.IntBuffer;
+
+/**
+ * This class represents the context attributes passed to CreateContextAttribs of the XGL_create_context extension.
+ * 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 XGL_create_context spec for details)
+ * <p/>
+ * Use of this class is optional. If an OpenGL context is created without passing an instance of this class
+ * (or XGL_create_context is not supported), the old context creation code will be used. Use of ContextAttribs is required
+ * to create an OpenGL 3.0 or newer context. 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 combatible
+ * contexts having support for deprecated functionality.
+ * <p/>
+ * Warning: This functionality is currently available on the Windows platform only. However, if the forwardCombatible
+ * 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.
+ *
+ * @author spasi <sp...@us...>
+ */
+public abstract class ContextAttribs {
+
+ private int majorVersion;
+ private int minorVersion;
+
+ private int layerPlane;
+
+ private boolean debug;
+ private boolean forwardCombatible;
+
+ protected ContextAttribs(final int majorVersion, final int minorVersion) {
+ if ( majorVersion < 0 ||
+ 3 < majorVersion ||
+ minorVersion < 0 ||
+ (majorVersion == 3 && 0 < minorVersion) ||
+ (majorVersion == 2 && 1 < minorVersion) ||
+ (majorVersion == 1 && 5 < minorVersion) )
+ throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);
+
+ this.majorVersion = majorVersion;
+ this.minorVersion = minorVersion;
+
+ this.layerPlane = 0;
+
+ this.debug = false;
+ this.forwardCombatible = false;
+ }
+
+ protected ContextAttribs(final ContextAttribs attribs) {
+ this.majorVersion = attribs.majorVersion;
+ this.minorVersion = attribs.minorVersion;
+
+ this.layerPlane = attribs.layerPlane;
+
+ this.debug = attribs.debug;
+ this.forwardCombatible = attribs.forwardCombatible;
+ }
+
+ public static ContextAttribs create() {
+ return create(1, 0);
+ }
+
+ public static ContextAttribs create(final int majorVersion, final int minorVersion) {
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_LINUX:
+ return new LinuxContextAttribs(majorVersion, minorVersion);
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ return new WindowsContextAttribs(majorVersion, minorVersion);
+ case LWJGLUtil.PLATFORM_MACOSX:
+ return new MacOSXContextAttribs(majorVersion, minorVersion);
+ default:
+ throw new IllegalStateException("Unsupported platform");
+ }
+ }
+
+ private static ContextAttribs create(final ContextAttribs attribs) {
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_LINUX:
+ return new LinuxContextAttribs(attribs);
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ return new WindowsContextAttribs(attribs);
+ case LWJGLUtil.PLATFORM_MACOSX:
+ return new MacOSXContextAttribs(attribs);
+ default:
+ throw new IllegalStateException("Unsupported platform");
+ }
+ }
+
+ public final int getMajorVersion() {
+ return majorVersion;
+ }
+
+ public final int getMinorVersion() {
+ return minorVersion;
+ }
+
+ public final int getLayerPlane() {
+ return layerPlane;
+ }
+
+ public final boolean isDebug() {
+ return debug;
+ }
+
+ public final boolean isForwardCombatible() {
+ return forwardCombatible;
+ }
+
+ public final ContextAttribs withLayer(final int layerPlane) {
+ if ( layerPlane < 0 )
+ throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
+
+ final ContextAttribs attribs = create(this);
+ attribs.layerPlane = layerPlane;
+ return attribs;
+ }
+
+ public final ContextAttribs withDebug(final boolean debug) {
+ final ContextAttribs attribs = create(this);
+ attribs.debug = debug;
+ return attribs;
+ }
+
+ public final ContextAttribs withForwardCombatible(final boolean forwardCombatible) {
+ final ContextAttribs attribs = create(this);
+ attribs.forwardCombatible = forwardCombatible;
+ return attribs;
+ }
+
+ protected abstract int getMajorVersionAttrib();
+
+ protected abstract int getMinorVersionAttrib();
+
+ protected abstract int getLayerPlaneAttrib();
+
+ protected abstract int getFlagsAttrib();
+
+ protected abstract int getDebugBit();
+
+ protected abstract int getForwardCombatibleBit();
+
+ final IntBuffer getAttribList() {
+ int attribCount = 0;
+
+ if ( !(majorVersion == 1 && minorVersion == 0) )
+ attribCount += 2;
+ if ( 0 < layerPlane )
+ attribCount++;
+
+ int flags = 0;
+ if ( debug )
+ flags |= getDebugBit();
+ if ( forwardCombatible )
+ flags |= getForwardCombatibleBit();
+ if ( 0 < flags )
+ attribCount++;
+
+ if ( attribCount == 0 )
+ return null;
+
+ final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);
+
+ if ( !(majorVersion == 1 && minorVersion == 0) ) {
+ attribs.put(getMajorVersionAttrib()).put(majorVersion);
+ attribs.put(getMinorVersionAttrib()).put(minorVersion);
+ }
+ if ( 0 < layerPlane )
+ attribs.put(getLayerPlaneAttrib()).put(layerPlane);
+ if ( 0 < flags )
+ attribs.put(getFlagsAttrib()).put(flags);
+
+ attribs.put(0);
+ attribs.rewind();
+ return attribs;
+ }
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/ContextImplementation.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/ContextImplementation.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/ContextImplementation.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -32,6 +32,7 @@
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import org.lwjgl.LWJGLException;
@@ -48,42 +49,42 @@
/**
* Create a context.
*/
- public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException;
+ ByteBuffer create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException;
/**
* Swap the buffers of the current context. Only valid for double-buffered contexts.
*/
- public void swapBuffers() throws LWJGLException;
+ void swapBuffers() throws LWJGLException;
/**
* Release the context from its drawable, if any.
*/
- public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException;
+ void releaseDrawable(ByteBuffer context_handle) throws LWJGLException;
/**
* Release the current context (if any). After this call, no context is current.
*/
- public void releaseCurrentContext() throws LWJGLException;
+ void releaseCurrentContext() throws LWJGLException;
/**
* Update the context. Should be called whenever it's drawable is moved or resized
*/
- public void update(ByteBuffer context_handle);
+ void update(ByteBuffer context_handle);
/**
* Query whether the context is current
*/
- public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException;
+ void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException;
/**
* Query whether the context is current
*/
- public boolean isCurrent(ByteBuffer handle) throws LWJGLException;
+ boolean isCurrent(ByteBuffer handle) throws LWJGLException;
- public void setSwapInterval(int value);
+ void setSwapInterval(int value);
/**
* Destroys the Context.
*/
- public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException;
+ void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-08-12 21:02:06 UTC (rev 3115)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-08-19 16:46:03 UTC (rev 3116)
@@ -43,17 +43,6 @@
* @author foo
*/
-import java.nio.ByteBuffer;
-import java.nio.FloatBuffer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.awt.Canvas;
-import java.awt.event.ComponentListener;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
@@ -62,12 +51,24 @@
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
+import java.awt.*;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.HashSet;
+
public final class Display {
+
private static final Thread shutdown_hook = new Thread() {
- public void run() {
- reset();
- }
- };
+ public void run() {
+ reset();
+ }
+ };
/** The display implementor */
private static final DisplayImplementation display_impl;
@@ -86,7 +87,7 @@
/** X coordinate of the window */
private static int x = -1;
-
+
/** Cached window icons, for when Display is recreated */
private static ByteBuffer[] cached_icons;
@@ -117,8 +118,8 @@
private static boolean parent_resized;
private static ComponentListener component_listener = new ComponentAdapter() {
- public final void componentResized(ComponentEvent e) {
- synchronized (GlobalLock.lock) {
+ public void componentResized(ComponentEvent e) {
+ synchronized ( GlobalLock.lock ) {
parent_resized = true;
}
}
@@ -135,7 +136,7 @@
}
drawable = new Drawable() {
public Context getContext() {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
return isCreated() ? context : null;
}
}
@@ -152,7 +153,7 @@
}
private static DisplayImplementation createDisplayImplementation() {
- switch (LWJGLUtil.getPlatform()) {
+ switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxDisplay();
case LWJGLUtil.PLATFORM_WINDOWS:
@@ -164,9 +165,7 @@
}
}
- /**
- * Only constructed by ourselves
- */
+ /** Only constructed by ourselves */
private Display() {
}
@@ -176,7 +175,7 @@
* given mode is not guaranteed to be available nor is it guaranteed to be within the
* current monitor specs (this is especially a problem with the frequency parameter).
* Furthermore, it is not guaranteed that create() will detect an illegal display mode.
- *
+ * <p/>
* The only certain way to check
* is to call create() and make sure it works.
* Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32).
@@ -186,10 +185,10 @@
* @return an array of all display modes the system reckons it can handle.
*/
public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes();
- if (unfilteredModes == null) {
+ if ( unfilteredModes == null ) {
return new DisplayMode[0];
}
@@ -208,10 +207,11 @@
/**
* Return the current display mode, as set by setDisplayMode().
+ *
* @return The current display mode
*/
public static DisplayMode getDisplayMode() {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
return current_mode;
}
}
@@ -224,20 +224,21 @@
* is also reset.
*
* @param mode The new display mode to set
+ *
* @throws LWJGLException if the display mode could not be set
*/
public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (mode == null)
+ synchronized ( GlobalLock.lock ) {
+ if ( mode == null )
throw new NullPointerException("mode must be non-null");
current_mode = mode;
- if (isCreated()) {
+ if ( isCreated() ) {
destroyWindow();
// If mode is not fullscreen capable, make sure we are in windowed mode
- if (!mode.isFullscreen())
+ if ( !mode.isFullscreen() )
resetFullscreen();
try {
- if (fullscreen)
+ if ( fullscreen )
switchDisplayMode();
createWindow();
makeCurrentAndSetSwapInterval();
@@ -256,9 +257,9 @@
}
private static int getWindowX() {
- if (!fullscreen && parent == null) {
+ if ( !fullscreen && parent == null ) {
// if no display location set, center window
- if (x == -1) {
+ if ( x == -1 ) {
return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
} else {
return x;
@@ -269,9 +270,9 @@
}
private static int getWindowY() {
- if (!fullscreen && parent == null) {
+ if ( !fullscreen && parent == null ) {
// if no display location set, center window
- if (y == -1) {
+ if ( y == -1 ) {
return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
} else {
return y;
@@ -286,24 +287,24 @@
* A native context must exist, and it will be attached to the window.
*/
private static void createWindow() throws LWJGLException {
- if (window_created) {
+ if ( window_created ) {
return;
}
Canvas tmp_parent = fullscreen ? null : parent;
- if (tmp_parent != null && !tmp_parent.isDisplayable()) // Only a best effort check, since the parent can turn undisplayable hereafter
+ if ( tmp_parent != null && !tmp_parent.isDisplayable() ) // Only a best effort check, since the parent can turn undisplayable hereafter
throw new LWJGLException("Parent.isDisplayable() must be true");
- if (tmp_parent != null) {
+ if ( tmp_parent != null ) {
tmp_parent.addComponentListener(component_listener);
}
DisplayMode mode = getEffectiveMode();
display_impl.createWindow(mode, fullscreen, tmp_parent, getWindowX(), getWindowY());
window_created = true;
-
+
setTitle(title);
initControls();
-
+
// set cached window icon if exists
- if(cached_icons != null) {
+ if ( cached_icons != null ) {
setIcon(cached_icons);
} else {
setIcon(new ByteBuffer[] { LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16 });
@@ -312,7 +313,7 @@
private static void releaseDrawable() {
try {
- if (context != null && context.isCurrent()) {
+ if ( context != null && context.isCurrent() ) {
Context.releaseCurrentContext();
context.releaseDrawable();
}
@@ -322,19 +323,19 @@
}
private static void destroyWindow() {
- if (!window_created) {
+ if ( !window_created ) {
return;
}
- if (parent != null) {
+ if ( parent != null ) {
parent.removeComponentListener(component_listener);
}
releaseDrawable();
// Automatically destroy keyboard & mouse
- if (Mouse.isCreated()) {
+ if ( Mouse.isCreated() ) {
Mouse.destroy();
}
- if (Keyboard.isCreated()) {
+ if ( Keyboard.isCreated() ) {
Keyboard.destroy();
}
display_impl.destroyWindow();
@@ -342,7 +343,7 @@
}
private static void switchDisplayMode() throws LWJGLException {
- if (!current_mode.isFullscreen()) {
+ if ( !current_mode.isFullscreen() ) {
throw new IllegalStateException("Only modes acquired from getAvailableDisplayModes() can be used for fullscreen display");
}
display_impl.switchDisplayMode(current_mode);
@@ -352,36 +353,36 @@
* Set the display configuration to the specified gamma, brightness and contrast.
* The configuration changes will be reset when destroy() is called.
*
- * @param gamma The gamma value
+ * @param gamma The gamma value
* @param brightness The brightness value between -1.0 and 1.0, inclusive
- * @param contrast The contrast, larger than 0.0.
+ * @param contrast The contrast, larger than 0.0.
*/
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (!isCreated()) {
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() ) {
throw new LWJGLException("Display not yet created.");
}
- if (brightness < -1.0f || brightness > 1.0f)
+ if ( brightness < -1.0f || brightness > 1.0f )
throw new IllegalArgumentException("Invalid brightness value");
- if (contrast < 0.0f)
+ if ( contrast < 0.0f )
throw new IllegalArgumentException("Invalid contrast value");
int rampSize = display_impl.getGammaRampLength();
- if (rampSize == 0) {
+ if ( rampSize == 0 ) {
throw new LWJGLException("Display configuration not supported");
}
FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
- for (int i = 0; i < rampSize; i++) {
- float intensity = (float)i/(rampSize - 1);
+ for ( int i = 0; i < rampSize; i++ ) {
+ float intensity = (float)i / (rampSize - 1);
// apply gamma
float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
// apply brightness
rampEntry += brightness;
// apply contrast
- rampEntry = (rampEntry - 0.5f)*contrast + 0.5f;
+ rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
// Clamp entry to [0, 1]
- if (rampEntry > 1.0f)
+ if ( rampEntry > 1.0f )
rampEntry = 1.0f;
- else if (rampEntry < 0.0f)
+ else if ( rampEntry < 0.0f )
rampEntry = 0.0f;
gammaRamp.put(i, rampEntry);
}
@@ -401,13 +402,13 @@
long timeNow;
long gapTo;
long savedTimeLate;
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
gapTo = Sys.getTimerResolution() / fps + timeThen;
timeNow = Sys.getTime();
savedTimeLate = timeLate;
}
- while (gapTo > timeNow + savedTimeLate) {
+ while ( gapTo > timeNow + savedTimeLate ) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
@@ -415,8 +416,8 @@
timeNow = Sys.getTime();
}
- synchronized (GlobalLock.lock) {
- if (gapTo < timeNow)
+ synchronized ( GlobalLock.lock ) {
+ if ( gapTo < timeNow )
timeLate = timeNow - gapTo;
else
timeLate = 0;
@@ -425,29 +426,25 @@
}
}
- /**
- * @return the title of the window
- */
+ /** @return the title of the window */
public static String getTitle() {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
return title;
}
}
private static void resetFullscreen() {
- synchronized (GlobalLock.lock) {
- if (Display.fullscreen) {
+ synchronized ( GlobalLock.lock ) {
+ if ( Display.fullscreen ) {
Display.fullscreen = false;
display_impl.resetDisplayMode();
}
}
}
- /**
- * Return the last parent set with setParent().
- */
+ /** Return the last parent set with setParent(). */
public static Canvas getParent() {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
return parent;
}
}
@@ -461,17 +458,16 @@
* and it is difficult to predict which AWT thread will process any given AWT event.<p>
* While the Display is in fullscreen mode, the current parent will be ignored. Additionally, when a non null parent is specified,
* the Dispaly will inherit the size of the parent, disregarding the currently set display mode.<p>
- *
*/
public static void setParent(Canvas parent) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (Display.parent != parent) {
+ synchronized ( GlobalLock.lock ) {
+ if ( Display.parent != parent ) {
Display.parent = parent;
- if (!isCreated())
+ if ( !isCreated() )
return;
destroyWindow();
try {
- if (fullscreen) {
+ if ( fullscreen ) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@@ -496,18 +492,19 @@
* mode returned by getDisplayMode(). The native cursor position is also reset.
*
* @param fullscreen Specify the fullscreen mode of the context.
+ *
* @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not
- * from getAvailableDisplayModes() or if the mode switch fails.
+ * from getAvailableDisplayModes() or if the mode switch fails.
*/
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (Display.fullscreen != fullscreen) {
+ synchronized ( GlobalLock.lock ) {
+ if ( Display.fullscreen != fullscreen ) {
Display.fullscreen = fullscreen;
- if (!isCreated())
+ if ( !isCreated() )
return;
destroyWindow();
try {
- if (fullscreen) {
+ if ( fullscreen ) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@@ -524,58 +521,51 @@
}
}
- /**
- * @return whether the Display is in fullscreen mode
- */
+ /** @return whether the Display is in fullscreen mode */
public static boolean isFullscreen() {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
return fullscreen;
}
}
/**
* Set the title of the window. This may be ignored by the underlying OS.
+ *
* @param newTitle The new window title
*/
public static void setTitle(String newTitle) {
- synchronized (GlobalLock.lock) {
- if (newTitle == null) {
+ synchronized ( GlobalLock.lock ) {
+ if ( newTitle == null ) {
newTitle = "";
}
title = newTitle;
- if (isCreated())
+ if ( isCreated() )
display_impl.setTitle(title);
}
}
- /**
- * @return true if the user or operating system has asked the window to close
- */
+ /** @return true if the user or operating system has asked the window to close */
public static boolean isCloseRequested() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Cannot determine close requested state of uncreated window");
return display_impl.isCloseRequested();
}
}
- /**
- * @return true if the window is visible, false if not
- */
+ /** @return true if the window is visible, false if not */
public static boolean isVisible() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
return display_impl.isVisible();
}
}
- /**
- * @return true if window is active, that is, the foreground display of the operating system.
- */
+ /** @return true if window is active, that is, the foreground display of the operating system. */
public static boolean isActive() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Cannot determine focused state of uncreated window");
return display_impl.isActive();
}
@@ -589,11 +579,11 @@
* redraw when it returns true. The flag is cleared when update() or isDirty() is called.
*
* @return true if the window has been damaged by external changes
- * and needs to repaint itself
+ * and needs to repaint itself
*/
public static boolean isDirty() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Cannot determine dirty state of uncreated window");
return display_impl.isDirty();
}
@@ -605,8 +595,8 @@
* this method if update() is called periodically.
*/
public static void processMessages() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Display not created");
display_impl.update();
@@ -616,11 +606,12 @@
/**
* Swap the display buffers. This method is called from update(), and should normally not be called by
* the application.
+ *
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
*/
public static void swapBuffers() throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Display not created");
Util.checkGLError();
@@ -631,16 +622,17 @@
/**
* Update the window. This calls processMessages(), and if the window is visible
* clears the dirty flag and calls swapBuffers() and finally polls the input devices.
+ *
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
*/
public static void update() {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Display not created");
processMessages();
// We paint only when the window is visible or dirty
- if (display_impl.isVisible() || display_impl.isDirty()) {
+ if ( display_impl.isVisible() || display_impl.isDirty() ) {
try {
swapBuffers();
} catch (LWJGLException e) {
@@ -649,7 +641,7 @@
}
pollDevices();
- if (parent_resized) {
+ if ( parent_resized ) {
reshape();
parent_resized = false;
}
@@ -658,16 +650,16 @@
static void pollDevices() {
// Poll the input devices while we're here
- if (Mouse.isCreated()) {
+ if ( Mouse.isCreated() ) {
Mouse.poll();
Mouse.updateCursor();
}
-
- if (Keyboard.isCreated()) {
+
+ if ( Keyboard.isCreated() ) {
Keyboard.poll();
}
-
- if(Controllers.isCreated()) {
+
+ if ( Controllers.isCreated() ) {
Controllers.poll();
}
}
@@ -678,40 +670,58 @@
* @throws LWJGLException If the context could not be released
*/
public static void releaseContext() throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Display is not created");
- if (context.isCurrent())
+ if ( context.isCurrent() )
Context.releaseCurrentContext();
}
}
-
+
/**
* Make the Display the current rendering context for GL calls.
*
* @throws LWJGLException If the context could not be made current
*/
public static void makeCurrent() throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (!isCreated())
+ synchronized ( GlobalLock.lock ) {
+ if ( !isCreated() )
throw new IllegalStateException("Display is not created");
context.makeCurrent();
}
}
+ private static void removeShutdownHook() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ Runtime.getRuntime().removeShutdownHook(shutdown_hook);
+ return null;
+ }
+ });
+ }
+
+ private static void registerShutdownHook() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ Runtime.getRuntime().addShutdownHook(shutdown_hook);
+ return null;
+ }
+ });
+ }
+
/**
* Create the OpenGL context. If isFullscreen() is true or if windowed
* context are not supported on the platform, the display mode will be switched to the mode returned by
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
* created with the given parameters, a LWJGLException will be thrown.
- *
+ * <p/>
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
*
* @throws LWJGLException
*/
public static void create() throws LWJGLException {
- synchronized (GlobalLock.lock) {
+ synchronized ( GlobalLock.lock ) {
create(new PixelFormat());
}
}
@@ -722,34 +732,57 @@
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
* created with the given parameters, a LWJGLException will be thrown.
- *
+ * <p/>
* <p>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.
+ *
* @throws LWJGLException
*/
public static void create(PixelFormat pixel_format) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- create(pixel_format, null);
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, null, null);
}
}
- private static void removeShutdownHook() {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- Runtime.getRuntime().removeShutdownHook(shutdown_hook);
- return null;
- }
- });
+ /**
+ * Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed
+ * context are not supported on the platform, the display mode will be switched to the mode returned by
+ * getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
+ * will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
+ * created with the given parameters, a LWJGLException will be thrown.
+ * <p/>
+ * <p>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.
+ * @param shared_drawable The Drawable to share context with. (optional, may be null)
+ *
+ * @throws LWJGLException
+ */
+ public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, shared_drawable, null);
+ }
}
- private static void registerShutdownHook() {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- Runtime.getRuntime().addShutdownHook(shutdown_hook);
- return null;
- }
- });
+ /**
+ * Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed
+ * context are not supported on the platform, the display mode will be switched to the mode returned by
+ * getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
+ * will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
+ * created with the given parameters, a LWJGLException will be thrown.
+ * <p/>
+ * <p>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.
+ * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
+ *
+ * @throws LWJGLException
+ */
+ public static void create(PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ create(pixel_format, null, attribs);
+ }
}
/**
@@ -758,29 +791,31 @@
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
* created with the given parameters, a LWJGLException will be thrown.
- *
+ * <p/>
* <p>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.
- * @param shared_drawable The Drawable to share context with or null.
+ * @param pixel_format Describes the minimum specifications the context must fulfill.
+ * @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(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
- synchronized (GlobalLock.lock) {
- if (isCreated())
+ public static void create(PixelFormat pixel_format, Drawable shared_drawable, ContextAttribs attribs) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ if ( isCreated() )
throw new IllegalStateException("Only one LWJGL co...
[truncated message content] |