Fixed ByteOrder of @Return ByteBuffers.

Cleaned up Drawable interface and introduced a reusable base implementation.
Added support for disabling runtime function checks, buffer checks and state tracking. Activated with -Dorg.lwjgl.util.NoChecks=true
This commit is contained in:
Ioannis Tsakpinis 2010-04-22 23:21:48 +00:00
parent 965e398053
commit 47c9991b41
18 changed files with 287 additions and 332 deletions

View File

@ -60,7 +60,7 @@ public class BufferChecks {
* Helper methods to ensure a function pointer is not-null (0)
*/
public static void checkFunctionAddress(long pointer) {
if (pointer == 0) {
if (LWJGLUtil.CHECKS && pointer == 0) {
throw new IllegalStateException("Function is not supported");
}
}
@ -69,20 +69,22 @@ public class BufferChecks {
* Helper methods to ensure a ByteBuffer is null-terminated
*/
public static void checkNullTerminated(ByteBuffer buf) {
if (buf.get(buf.limit() - 1) != 0) {
if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0) {
throw new IllegalArgumentException("Missing null termination");
}
}
public static void checkNullTerminated(ByteBuffer buf, int count) {
int nullFound = 0;
for ( int i = buf.position(); i < buf.limit(); i++ ) {
if ( buf.get(i) == 0 )
nullFound++;
}
if ( LWJGLUtil.CHECKS ) {
int nullFound = 0;
for ( int i = buf.position(); i < buf.limit(); i++ ) {
if ( buf.get(i) == 0 )
nullFound++;
}
if ( nullFound < count )
throw new IllegalArgumentException("Missing null termination");
if ( nullFound < count )
throw new IllegalArgumentException("Missing null termination");
}
}
/** Helper methods to ensure an IntBuffer is null-terminated */
@ -93,7 +95,7 @@ public class BufferChecks {
}
public static void checkNotNull(Object o) {
if (o == null)
if ( LWJGLUtil.CHECKS && o == null)
throw new IllegalArgumentException("Null argument");
}
@ -101,37 +103,37 @@ public class BufferChecks {
* Helper methods to ensure a buffer is direct (and, implicitly, non-null).
*/
public static void checkDirect(ByteBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("ByteBuffer is not direct");
}
}
public static void checkDirect(ShortBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("ShortBuffer is not direct");
}
}
public static void checkDirect(IntBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("IntBuffer is not direct");
}
}
public static void checkDirect(LongBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("LongBuffer is not direct");
}
}
public static void checkDirect(FloatBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("FloatBuffer is not direct");
}
}
public static void checkDirect(DoubleBuffer buf) {
if (!buf.isDirect()) {
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
throw new IllegalArgumentException("DoubleBuffer is not direct");
}
}
@ -154,38 +156,50 @@ public class BufferChecks {
* @throws IllegalArgumentException
*/
public static void checkBufferSize(Buffer buf, int size) {
if (buf.remaining() < size) {
if ( LWJGLUtil.CHECKS && buf.remaining() < size) {
throwBufferSizeException(buf, size);
}
}
public static void checkBuffer(ByteBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
public static void checkBuffer(ShortBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
public static void checkBuffer(IntBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
public static void checkBuffer(LongBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
public static void checkBuffer(FloatBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
public static void checkBuffer(DoubleBuffer buf, int size) {
checkBufferSize(buf, size);
checkDirect(buf);
if ( LWJGLUtil.CHECKS ) {
checkBufferSize(buf, size);
checkDirect(buf);
}
}
}

View File

@ -266,7 +266,9 @@ public class LWJGLUtil {
/** Debug flag. */
public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug");
public static final boolean CHECKS = !getPrivilegedBoolean("org.lwjgl.util.NoChecks");
static {
LWJGLIcon16x16.flip();
LWJGLIcon32x32.flip();

View File

@ -50,7 +50,7 @@ import java.awt.event.HierarchyListener;
* $Id$
* @version $Revision$
*/
public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener {
public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListener, HierarchyListener {
private static final long serialVersionUID = 1L;
@ -109,13 +109,12 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener,
return context;
}
/** This method should only be called internally. */
public Context createSharedContext() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
synchronized ( SYNC_LOCK ) {
if ( context == null ) throw new IllegalStateException("Canvas not yet displayable");
synchronized ( SYNC_LOCK ) {
if ( context == null ) throw new IllegalStateException("Canvas not yet displayable");
return new Context(peer_info, context.getContextAttribs(), context);
}
return new Context(peer_info, context.getContextAttribs(), context);
}
}
@ -213,12 +212,11 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener,
}
}
public void releaseContext() throws LWJGLException {
public boolean isCurrent() throws LWJGLException {
synchronized ( SYNC_LOCK ) {
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
if ( context.isCurrent() )
Context.releaseCurrentContext();
if ( context == null ) throw new IllegalStateException("Canvas not yet displayable");
return context.isCurrent();
}
}
@ -234,6 +232,15 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener,
}
}
public void releaseContext() throws LWJGLException {
synchronized ( SYNC_LOCK ) {
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
if ( context.isCurrent() )
Context.releaseCurrentContext();
}
}
/** Destroy the OpenGL context. This happens when the component becomes undisplayable */
public final void destroy() {
synchronized ( SYNC_LOCK ) {
@ -279,7 +286,7 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener,
peer_info.lockAndGetHandle();
try {
if ( context == null ) {
this.context = new Context(peer_info, attribs, drawable != null ? drawable.getContext() : null);
this.context = new Context(peer_info, attribs, drawable != null ? ((DrawableLWJGL)drawable).getContext() : null);
first_run = true;
}

View File

@ -0,0 +1,82 @@
package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
/**
* @author Spasi
* @since 22 Áðñ 2010
*/
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);
}
}
}
protected final void checkDestroyed() {
if ( context == null )
throw new IllegalStateException("The Drawable has no context available.");
}
}

View File

@ -32,7 +32,6 @@
package org.lwjgl.opengl;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.Arrays;
class BaseReferences {
@ -49,24 +48,19 @@ class BaseReferences {
int indirectBuffer;
BaseReferences(ContextCapabilities caps) {
IntBuffer temp = caps.scratch_int_buffer;
int max_vertex_attribs;
if (caps.OpenGL20 || caps.GL_ARB_vertex_shader) {
GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB, temp);
max_vertex_attribs = temp.get(0);
} else
if (caps.OpenGL20 || caps.GL_ARB_vertex_shader)
max_vertex_attribs = GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB);
else
max_vertex_attribs = 0;
glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs];
int max_texture_units;
if (caps.OpenGL20) {
GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, temp);
max_texture_units = temp.get(0);
} else if (caps.OpenGL13 || caps.GL_ARB_multitexture) {
GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS, temp);
max_texture_units = temp.get(0);
} else
if (caps.OpenGL20)
max_texture_units = GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS);
else if (caps.OpenGL13 || caps.GL_ARB_multitexture)
max_texture_units = GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS);
else
max_texture_units = 1;
glTexCoordPointer_buffer = new Buffer[max_texture_units];
}

View File

@ -106,14 +106,10 @@ public final class Display {
/** Swap interval */
private static int swap_interval;
/** A unique context object, so we can track different contexts between creates() and destroys() */
private static PeerInfo peer_info;
private static Context context;
/** The Drawable instance that tracks the current Display context */
private final static Drawable drawable;
private static final AbstractDrawable drawable;
private static boolean window_created = false;
private static boolean window_created;
private static boolean parent_resized;
@ -137,31 +133,20 @@ public final class Display {
} catch (LWJGLException e) {
throw new RuntimeException(e);
}
drawable = new Drawable() {
public Context getContext() {
synchronized ( GlobalLock.lock ) {
return isCreated() ? context : null;
}
}
public Context createSharedContext() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if ( !isCreated() ) throw new IllegalStateException("Display must be created.");
return new Context(peer_info, context.getContextAttribs(), context);
}
}
public void makeCurrent() throws LWJGLException {
Display.makeCurrent();
}
public void releaseContext() throws LWJGLException {
Display.releaseContext();
}
drawable = new AbstractDrawable() {
public void destroy() {
Display.destroy();
synchronized ( GlobalLock.lock ) {
if ( !isCreated() )
return;
releaseDrawable();
super.destroy();
destroyWindow();
x = y = -1;
cached_icons = null;
reset();
removeShutdownHook();
}
}
};
}
@ -258,24 +243,23 @@ public final class Display {
* @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");
boolean was_fullscreen = isFullscreen();
current_mode = mode;
if (isCreated()) {
if ( isCreated() ) {
destroyWindow();
// If mode is not fullscreen capable, make sure we are in windowed mode
try {
if (was_fullscreen && !isFullscreen())
if ( was_fullscreen && !isFullscreen() )
display_impl.resetDisplayMode();
else if (isFullscreen())
else if ( isFullscreen() )
switchDisplayMode();
createWindow();
makeCurrentAndSetSwapInterval();
} catch (LWJGLException e) {
destroyContext();
destroyPeerInfo();
drawable.destroy();
display_impl.resetDisplayMode();
throw e;
}
@ -288,9 +272,9 @@ public final class Display {
}
private static int getWindowX() {
if (!isFullscreen() && parent == null) {
if ( !isFullscreen() && 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;
@ -301,7 +285,7 @@ public final class Display {
}
private static int getWindowY() {
if (!isFullscreen() && parent == null) {
if ( !isFullscreen() && parent == null ) {
// if no display location set, center window
if ( y == -1 ) {
return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
@ -344,6 +328,7 @@ public final class Display {
private static void releaseDrawable() {
try {
Context context = drawable.context;
if ( context != null && context.isCurrent() ) {
Context.releaseCurrentContext();
context.releaseDrawable();
@ -483,13 +468,13 @@ public final class Display {
*/
public static void setParent(Canvas parent) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if (Display.parent != parent) {
if ( Display.parent != parent ) {
Display.parent = parent;
if ( !isCreated() )
return;
destroyWindow();
try {
if (isFullscreen()) {
if ( isFullscreen() ) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@ -497,8 +482,7 @@ public final class Display {
createWindow();
makeCurrentAndSetSwapInterval();
} catch (LWJGLException e) {
destroyContext();
destroyPeerInfo();
drawable.destroy();
display_impl.resetDisplayMode();
throw e;
}
@ -539,18 +523,18 @@ public final class Display {
private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if (mode == null)
if ( mode == null )
throw new NullPointerException("mode must be non-null");
DisplayMode old_mode = current_mode;
current_mode = mode;
boolean was_fullscreen = isFullscreen();
Display.fullscreen = fullscreen;
if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) {
if (!isCreated())
if ( was_fullscreen != isFullscreen() || !mode.equals(old_mode) ) {
if ( !isCreated() )
return;
destroyWindow();
try {
if (isFullscreen()) {
if ( isFullscreen() ) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@ -558,8 +542,7 @@ public final class Display {
createWindow();
makeCurrentAndSetSwapInterval();
} catch (LWJGLException e) {
destroyContext();
destroyPeerInfo();
drawable.destroy();
display_impl.resetDisplayMode();
throw e;
}
@ -569,7 +552,7 @@ public final class Display {
/** @return whether the Display is in fullscreen mode */
public static boolean isFullscreen() {
synchronized (GlobalLock.lock) {
synchronized ( GlobalLock.lock ) {
return fullscreen && current_mode.isFullscreenCapable();
}
}
@ -671,7 +654,6 @@ public final class Display {
* Update the window. If the window is visible clears
* the dirty flag and calls swapBuffers() and finally
* polls the input devices.
*
*/
public static void update() {
update(true);
@ -730,12 +712,12 @@ public final class Display {
* @throws LWJGLException If the context could not be released
*/
public static void releaseContext() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if ( !isCreated() )
throw new IllegalStateException("Display is not created");
if ( context.isCurrent() )
Context.releaseCurrentContext();
}
drawable.releaseContext();
}
/** Returns true if the Display's context is current in the current thread. */
public static boolean isCurrent() throws LWJGLException {
return drawable.isCurrent();
}
/**
@ -744,11 +726,7 @@ public final class Display {
* @throws LWJGLException If the context could not be made current
*/
public static void makeCurrent() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if ( !isCreated() )
throw new IllegalStateException("Display is not created");
context.makeCurrent();
}
drawable.makeCurrent();
}
private static void removeShutdownHook() {
@ -868,19 +846,19 @@ public final class Display {
throw new NullPointerException("pixel_format cannot be null");
removeShutdownHook();
registerShutdownHook();
if (isFullscreen())
if ( isFullscreen() )
switchDisplayMode();
try {
peer_info = display_impl.createPeerInfo(pixel_format);
drawable.peer_info = display_impl.createPeerInfo(pixel_format);
try {
createWindow();
try {
context = new Context(peer_info, attribs, shared_drawable != null ? shared_drawable.getContext() : null);
drawable.context = new Context(drawable.peer_info, attribs, shared_drawable != null ? ((AbstractDrawable)shared_drawable).getContext() : null);
try {
makeCurrentAndSetSwapInterval();
initContext();
} catch (LWJGLException e) {
destroyContext();
drawable.destroy();
throw e;
}
} catch (LWJGLException e) {
@ -888,7 +866,7 @@ public final class Display {
throw e;
}
} catch (LWJGLException e) {
destroyPeerInfo();
drawable.destroy();
throw e;
}
} catch (LWJGLException e) {
@ -899,13 +877,13 @@ public final class Display {
}
/**
* Set the initial color of the Display. This method is called before the Display is created and will set the
* background color to the one specified in this method.
*
* @param red - color value between 0 - 1
* @param green - color value between 0 - 1
* @param blue - color value between 0 - 1
*/
* Set the initial color of the Display. This method is called before the Display is created and will set the
* background color to the one specified in this method.
*
* @param red - color value between 0 - 1
* @param green - color value between 0 - 1
* @param blue - color value between 0 - 1
*/
public static void setInitialBackground(float red, float green, float blue) {
r = red;
g = green;
@ -977,41 +955,14 @@ public final class Display {
* regardless of whether the Display was the current rendering context.
*/
public static void destroy() {
synchronized ( GlobalLock.lock ) {
if ( !isCreated() ) {
return;
}
releaseDrawable();
destroyContext();
destroyWindow();
destroyPeerInfo();
x = y = -1;
cached_icons = null;
reset();
removeShutdownHook();
}
}
private static void destroyPeerInfo() {
peer_info.destroy();
peer_info = null;
}
private static void destroyContext() {
try {
context.forceDestroy();
} catch (LWJGLException e) {
throw new RuntimeException(e);
} finally {
context = null;
}
drawable.destroy();
}
/*
* Reset display mode if fullscreen. This method is also called from the shutdown hook added
* in the static constructor
*/
private static void reset() {
display_impl.resetDisplayMode();
current_mode = initial_mode;
@ -1070,7 +1021,7 @@ public final class Display {
y = new_y;
// offset if already created
if (isCreated() && !isFullscreen()) {
if ( isCreated() && !isFullscreen() ) {
reshape();
}
}

View File

@ -42,19 +42,8 @@ import org.lwjgl.LWJGLException;
public interface Drawable {
/**
* [INTERNAL USE ONLY] Returns the Drawable's Context.
*
* @return the Drawable's Context
*/
Context getContext();
/**
* [INTERNAL USE ONLY] Creates a new Context that is shared with the Drawable's Context.
*
* @return a Context shared with the Drawable's Context.
*/
Context createSharedContext() throws LWJGLException;
/** Returns true if the Drawable's context is current in the current thread. */
boolean isCurrent() throws LWJGLException;
/**
* Makes the Drawable's context current in the current thread.
@ -70,9 +59,7 @@ public interface Drawable {
*/
void releaseContext() throws LWJGLException;
/**
* Destroys the Drawable.
*/
/** Destroys the Drawable. */
void destroy();
}

View File

@ -0,0 +1,25 @@
package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
/**
* @author Spasi
* @since 23 Áðñ 2010
*/
interface DrawableLWJGL extends Drawable {
/**
* [INTERNAL USE ONLY] Returns the Drawable's Context.
*
* @return the Drawable's Context
*/
Context getContext();
/**
* [INTERNAL USE ONLY] Creates a new Context that is shared with the Drawable's Context.
*
* @return a Context shared with the Drawable's Context.
*/
Context createSharedContext() throws LWJGLException;
}

View File

@ -35,6 +35,7 @@ import java.nio.Buffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
/**
* A class to check buffer boundaries in GL methods. Many GL
@ -60,93 +61,78 @@ class GLChecks {
}
static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) {
IntBuffer scratch_buffer = caps.scratch_int_buffer;
GL15.glGetBufferParameter(buffer_enum, GL15.GL_BUFFER_SIZE, scratch_buffer);
return scratch_buffer.get(0);
return GL15.glGetBufferParameter(buffer_enum, GL15.GL_BUFFER_SIZE);
}
static int getBufferObjectSizeARB(ContextCapabilities caps, int buffer_enum) {
IntBuffer scratch_buffer = caps.scratch_int_buffer;
ARBBufferObject.glGetBufferParameterARB(buffer_enum, ARBBufferObject.GL_BUFFER_SIZE_ARB, scratch_buffer);
return scratch_buffer.get(0);
return ARBBufferObject.glGetBufferParameterARB(buffer_enum, ARBBufferObject.GL_BUFFER_SIZE_ARB);
}
static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) {
IntBuffer scratch_buffer = caps.scratch_int_buffer;
ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI, scratch_buffer);
return scratch_buffer.get(0);
return ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI);
}
static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) {
IntBuffer scratch_buffer = caps.scratch_int_buffer;
EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.GL_BUFFER_SIZE, scratch_buffer);
return scratch_buffer.get(0);
}
private static boolean checkBufferObject(ContextCapabilities caps, int buffer_enum, boolean state) {
IntBuffer scratch_buffer = caps.scratch_int_buffer;
GL11.glGetInteger(buffer_enum, scratch_buffer);
boolean is_enabled = scratch_buffer.get(0) != 0;
return state == is_enabled;
return EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.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(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0)
if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().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(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0)
if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().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(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0)
if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 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(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0)
if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0 )
throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled");
}
/** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
static void ensureIndirectBOdisabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 )
throw new OpenGLException("Cannot use Buffers when Draw Indirect Object is enabled");
}
/** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
static void ensureIndirectBOenabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 )
throw new OpenGLException("Cannot use offsets when Draw Indirect Object is disabled");
}
/** Helper method to ensure that pixel pack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
static void ensurePackPBOdisabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 )
throw new OpenGLException("Cannot use Buffers when Pixel Pack Buffer Object is enabled");
}
/** Helper method to ensure that pixel pack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
static void ensurePackPBOenabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 )
throw new OpenGLException("Cannot use offsets when Pixel Pack Buffer Object is disabled");
}
/** Helper method to ensure that pixel unpack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
static void ensureUnpackPBOdisabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 )
throw new OpenGLException("Cannot use Buffers when Pixel Unpack Buffer Object is enabled");
}
/** Helper method to ensure that pixel unpack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
static void ensureUnpackPBOenabled(ContextCapabilities caps) {
if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 )
if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 )
throw new OpenGLException("Cannot use offsets when Pixel Unpack Buffer Object is disabled");
}
@ -162,19 +148,19 @@ class GLChecks {
* @return the size, in elements, of the image
*/
static int calculateImageStorage(Buffer buffer, int format, int type, int width, int height, int depth) {
return calculateImageStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer);
return LWJGLUtil.CHECKS ? calculateImageStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer) : 0;
}
static int calculateTexImage1DStorage(Buffer buffer, int format, int type, int width) {
return calculateTexImage1DStorage(format, type, width) >> BufferUtils.getElementSizeExponent(buffer);
return LWJGLUtil.CHECKS ? calculateTexImage1DStorage(format, type, width) >> BufferUtils.getElementSizeExponent(buffer) : 0;
}
static int calculateTexImage2DStorage(Buffer buffer, int format, int type, int width, int height) {
return calculateTexImage2DStorage(format, type, width, height) >> BufferUtils.getElementSizeExponent(buffer);
return LWJGLUtil.CHECKS ? calculateTexImage2DStorage(format, type, width, height) >> BufferUtils.getElementSizeExponent(buffer) : 0;
}
static int calculateTexImage3DStorage(Buffer buffer, int format, int type, int width, int height, int depth) {
return calculateTexImage3DStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer);
return LWJGLUtil.CHECKS ? calculateTexImage3DStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer) : 0;
}
/**

View File

@ -78,7 +78,7 @@ final class MacOSXDisplay implements DisplayImplementation {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
public final void handleQuit(ApplicationEvent event) {
public void handleQuit(ApplicationEvent event) {
doHandleQuit();
}
});
@ -271,15 +271,16 @@ final class MacOSXDisplay implements DisplayImplementation {
*
* - elias
*/
AbstractDrawable drawable = (AbstractDrawable)Display.getDrawable();
if (Display.isFullscreen() && (frame != null && frame.getCanvas().syncCanvasPainted() || should_update)) {
try {
MacOSXContextImplementation.resetView(Display.getDrawable().getContext().getPeerInfo(), Display.getDrawable().getContext());
MacOSXContextImplementation.resetView(drawable.peer_info, drawable.context);
} catch (LWJGLException e) {
LWJGLUtil.log("Failed to reset context: " + e);
}
}
if (should_update) {
Display.getDrawable().getContext().update();
drawable.context.update();
/* This is necessary to make sure the context won't "forget" about the view size */
GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport);
GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));

View File

@ -35,7 +35,6 @@ import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.Sys;
/**
@ -49,7 +48,7 @@ import org.lwjgl.Sys;
* @version $Revision$
* $Id$
*/
public final class Pbuffer implements Drawable {
public final class Pbuffer extends AbstractDrawable {
/**
* Indicates that Pbuffers can be created.
*/
@ -135,11 +134,6 @@ public final class Pbuffer implements Drawable {
*/
public static final int DEPTH_BUFFER = RenderTexture.WGL_DEPTH_COMPONENT_NV;
/**
* Handle to the native GL rendering context
*/
private final PeerInfo peer_info;
/**
* Width
*/
@ -150,10 +144,6 @@ public final class Pbuffer implements Drawable {
*/
private final int height;
private final Context context;
private boolean destroyed;
static {
Sys.initialize();
}
@ -227,14 +217,11 @@ public final class Pbuffer implements Drawable {
this.width = width;
this.height = height;
this.peer_info = createPbuffer(width, height, pixel_format, renderTexture);
Context shared_context = null;
if (shared_drawable != null) {
shared_context = shared_drawable.getContext();
} else {
Drawable display_drawable = Display.getDrawable();
if (display_drawable != null)
shared_context = display_drawable.getContext();
}
Context shared_context;
if (shared_drawable != null)
shared_context = ((DrawableLWJGL)shared_drawable).getContext();
else
shared_context = ((DrawableLWJGL)Display.getDrawable()).getContext(); // May be null
this.context = new Context(peer_info, attribs, shared_context);
}
@ -251,21 +238,6 @@ public final class Pbuffer implements Drawable {
renderTexture.pBufferAttribs);
}
public Context getContext() {
return context;
}
public Context createSharedContext() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
return new Context(peer_info, context.getContextAttribs(), context);
}
}
private void checkDestroyed() {
if (destroyed)
throw new IllegalStateException("Pbuffer is destroyed");
}
/**
* Method to test for validity of the buffer. If this function returns true, the buffer contents is lost. The buffer can still
* be used, but the results are undefined. The application is expected to release the buffer if needed, destroy it and recreate
@ -278,21 +250,6 @@ public final class Pbuffer implements Drawable {
return Display.getImplementation().isBufferLost(peer_info);
}
/**
* Method to make the Pbuffer context current. All subsequent OpenGL calls will go to this buffer.
* @throws LWJGLException if the context could not be made current
*/
public synchronized void makeCurrent() throws LWJGLException {
checkDestroyed();
context.makeCurrent();
}
public void releaseContext() throws LWJGLException {
checkDestroyed();
if ( context.isCurrent() )
Context.releaseCurrentContext();
}
/**
* Gets the Pbuffer capabilities.
*
@ -302,22 +259,6 @@ public final class Pbuffer implements Drawable {
return Display.getImplementation().getPbufferCapabilities();
}
/**
* Destroys the Pbuffer. After this call, there will be no valid GL rendering context - regardless of whether this Pbuffer was
* the current rendering context or not.
*/
public synchronized void destroy() {
if (destroyed)
return;
try {
context.forceDestroy();
peer_info.destroy();
destroyed = true;
} catch (LWJGLException e) {
LWJGLUtil.log("Exception occurred while destroying pbuffer: " + e);
}
}
// -----------------------------------------------------------------------------------------
// ------------------------------- Render-to-Texture Methods -------------------------------
// -----------------------------------------------------------------------------------------

View File

@ -32,7 +32,6 @@
package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
/**
* @author Spasi
@ -46,51 +45,14 @@ import org.lwjgl.LWJGLUtil;
*
* @author Spasi
*/
public final class SharedDrawable implements Drawable {
private Context context;
private boolean destroyed;
public final class SharedDrawable extends AbstractDrawable {
public SharedDrawable(final Drawable drawable) throws LWJGLException {
this.context = drawable.createSharedContext();
}
public Context getContext() {
return context;
this.context = ((DrawableLWJGL)drawable).createSharedContext();
}
public Context createSharedContext() {
throw new UnsupportedOperationException();
}
public void makeCurrent() throws LWJGLException {
checkDestroyed();
context.makeCurrent();
}
public void releaseContext() throws LWJGLException {
checkDestroyed();
if ( context.isCurrent() )
Context.releaseCurrentContext();
}
public void destroy() {
if ( destroyed )
return;
try {
context.forceDestroy();
destroyed = true;
} catch (LWJGLException e) {
LWJGLUtil.log("Exception occurred while destroying SharedDrawable: " + e);
}
}
private void checkDestroyed() {
if ( destroyed )
throw new IllegalStateException("SharedDrawable is destroyed");
}
}

View File

@ -437,8 +437,9 @@ final class WindowsDisplay implements DisplayImplementation {
* is maximized helps some gfx cards recover from fullscreen
*/
try {
if (Display.getDrawable().getContext() != null && Display.getDrawable().getContext().isCurrent())
Display.getDrawable().getContext().makeCurrent();
Context context = ((DrawableLWJGL)Display.getDrawable()).getContext();
if (context != null && context.isCurrent())
context.makeCurrent();
} catch (LWJGLException e) {
LWJGLUtil.log("Exception occurred while trying to make context current: " + e);
}
@ -973,4 +974,4 @@ final class WindowsDisplay implements DisplayImplementation {
return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right;
}
}
}
}

View File

@ -78,8 +78,6 @@ abstract class BackgroundLoader {
System.out.println("** Sleeping, no texture created yet **");
long start = System.currentTimeMillis();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {

View File

@ -63,7 +63,6 @@ public class ContextCapabilitiesGenerator {
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
writer.println("\tstatic final boolean DEBUG = " + Boolean.toString(generate_error_checks) + ";");
writer.println("\tfinal StateTracker tracker = new StateTracker();");
writer.println("\tfinal IntBuffer scratch_int_buffer = BufferUtils.createIntBuffer(16);");
writer.println();
if ( !context_specific ) {
writer.println("\tprivate static boolean " + STUBS_LOADED_NAME + " = false;");

View File

@ -180,10 +180,7 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
java_writer.println();
java_writer.println("package " + d.getPackage().getQualifiedName() + ";");
java_writer.println();
java_writer.println("import org.lwjgl.LWJGLException;");
java_writer.println("import org.lwjgl.BufferChecks;");
// DISABLED: indirect buffer support
//java_writer.println("import org.lwjgl.NondirectBufferWrapper;");
java_writer.println("import org.lwjgl.*;");
java_writer.println("import java.nio.*;");
java_writer.println();
Utils.printDocComment(java_writer, d);

View File

@ -261,9 +261,12 @@ public class JavaMethodsGenerator {
// DISABLED: indirect buffer support
//printNondirectParameterCopies(writer, method, mode);
if (has_result) {
if ( method.getAnnotation(GLreturn.class) == null )
writer.println("\t\treturn " + Utils.RESULT_VAR_NAME + ";");
else
if ( method.getAnnotation(GLreturn.class) == null ) {
if ( ByteBuffer.class.equals(Utils.getJavaType(result_type)) )
writer.println("\t\treturn " + Utils.RESULT_VAR_NAME + ".order(ByteOrder.nativeOrder());"); // safeNewBuffer returns a direct ByteBuffer with BIG_ENDIAN order.
else
writer.println("\t\treturn " + Utils.RESULT_VAR_NAME + ";");
} else
Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class));
}
writer.println("\t}");
@ -490,7 +493,7 @@ public class JavaMethodsGenerator {
cachedReference != null &&
(mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) &&
param.getAnnotation(Result.class) == null) {
writer.print("\t\t" + Utils.CHECKS_CLASS_NAME + ".getReferences(caps).");
writer.print("\t\tif ( LWJGLUtil.CHECKS ) " + Utils.CHECKS_CLASS_NAME + ".getReferences(caps).");
if(cachedReference.name().length() > 0) {
writer.print(cachedReference.name());
} else {

View File

@ -71,6 +71,11 @@ public interface ATI_vertex_array_object {
@StripPostfix("params")
void glGetObjectBufferivATI(@GLuint int buffer, @GLenum int pname, @OutParameter @Check IntBuffer params);
@Alternate("glGetObjectBufferivATI")
@GLreturn("params")
@StripPostfix("params")
void glGetObjectBufferivATI2(@GLuint int buffer, @GLenum int pname, @OutParameter IntBuffer params);
void glFreeObjectBufferATI(@GLuint int buffer);
void glArrayObjectATI(@GLenum int array, int size, @GLenum int type, @GLsizei int stride, @GLuint int buffer, @GLuint int offset);