Replaced asserts with proper runtime exceptions

This commit is contained in:
Elias Naur 2004-03-27 11:55:07 +00:00
parent afb8491cfa
commit c093f3ace1
11 changed files with 1058 additions and 1013 deletions

View File

@ -196,8 +196,10 @@ public final class Display {
* @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 Exception { public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws Exception {
assert brightness >= -1.0f && brightness <= 1.0f; if (brightness < -1.0f || brightness > 1.0f)
assert contrast >= 0.0f; throw new IllegalArgumentException("Invalid brightness value");
if (contrast < 0.0f)
throw new IllegalArgumentException("Invalid contrast value");
int rampSize = getGammaRampLength(); int rampSize = getGammaRampLength();
if (rampSize == 0) { if (rampSize == 0) {
throw new Exception("Display configuration not supported"); throw new Exception("Display configuration not supported");

View File

@ -164,9 +164,8 @@ public class Controller {
* @throws Exception if the controller could not be created for any reason * @throws Exception if the controller could not be created for any reason
*/ */
public static void create() throws Exception { public static void create() throws Exception {
if (!Window.isCreated())
assert Window.isCreated() : "Window must be created prior to creating controller"; throw new IllegalStateException("Window must be created before you can create Controller");
if (!initialized) { if (!initialized) {
initialize(); initialize();
} }
@ -203,7 +202,8 @@ public class Controller {
* Polls the controller. * Polls the controller.
*/ */
public static void poll() { public static void poll() {
assert created : "The controller has not been created."; if (!created)
throw new IllegalStateException("Controller must be created before you can poll the device");
nPoll(); nPoll();
} }
@ -215,7 +215,8 @@ public class Controller {
* @see #buttonCount * @see #buttonCount
*/ */
public static boolean isButtonDown(int button) { public static boolean isButtonDown(int button) {
assert created : "The controller has not been created."; if (!created)
throw new IllegalStateException("Controller must be created before you can query button state");
return buttons[button]; return buttons[button];
} }
@ -231,7 +232,7 @@ public class Controller {
* it always throws a RuntimeException. * it always throws a RuntimeException.
*/ */
public static void read() { public static void read() {
throw new RuntimeException("Buffering is not implemented for Controllers."); throw new UnsupportedOperationException("Buffering is not implemented for Controllers.");
} }
/** /**

View File

@ -50,185 +50,190 @@ import org.lwjgl.Sys;
public class Cursor { public class Cursor {
/** Lazy initialization */ /** Lazy initialization */
private static boolean initialized = false; private static boolean initialized = false;
/** First element to display */ /** First element to display */
private CursorElement[] cursors = null; private CursorElement[] cursors = null;
/** Index into list of cursors */ /** Index into list of cursors */
private int index = -1; private int index = -1;
/** /**
* Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create * Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create
* Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported. * Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported.
* So to maximize portability, lwjgl applications should only create cursor images with 0x00 or 0xff as alpha values. * So to maximize portability, lwjgl applications should only create cursor images with 0x00 or 0xff as alpha values.
* The constructor will copy the images and delays, so there's no need to keep them around. * The constructor will copy the images and delays, so there's no need to keep them around.
* *
* @param width cursor image width * @param width cursor image width
* @param height cursor image height * @param height cursor image height
* @param xHotspot the x coordinate of the cursor hotspot * @param xHotspot the x coordinate of the cursor hotspot
* @param yHotspot the y coordinate of the cursor hotspot * @param yHotspot the y coordinate of the cursor hotspot
* @param numImages number of cursor images specified. Must be 1 if animations are not supported. * @param numImages number of cursor images specified. Must be 1 if animations are not supported.
* @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL. * @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL.
* @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null * @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null
* @throws Exception if the cursor could not be created for any reason * @throws Exception if the cursor could not be created for any reason
*/ */
public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception { public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
assert Mouse.isCreated(); if (!Mouse.isCreated())
assert width*height*numImages <= images.remaining() : "width*height*numImages > images.remaining()"; throw new IllegalStateException("Mouse must be created before creating cursor objects");
assert delays == null || numImages <= delays.remaining() : "delays != null && numImages > delays.remaining()"; if (width*height*numImages > images.remaining())
assert xHotspot < width && xHotspot >= 0 : "xHotspot > width || xHotspot < 0"; throw new IllegalArgumentException("width*height*numImages > images.remaining()");
assert yHotspot < height && yHotspot >= 0 : "yHotspot > height || yHotspot < 0"; if (delays != null && numImages > delays.remaining())
throw new IllegalArgumentException("delays != null && numImages > delays.remaining()");
// initialize if (xHotspot >= width || xHotspot < 0)
if (!initialized) { throw new IllegalArgumentException("xHotspot > width || xHotspot < 0");
initialize(); if (yHotspot >= height || yHotspot < 0)
} throw new IllegalArgumentException("yHotspot > height || yHotspot < 0");
// Hmm // initialize
yHotspot = height - 1 - yHotspot; if (!initialized) {
initialize();
// create cursor (or cursors if multiple images supplied) }
createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
} // Hmm
yHotspot = height - 1 - yHotspot;
/**
* Initializes the cursor class // create cursor (or cursors if multiple images supplied)
*/ createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
private static void initialize() { }
System.loadLibrary(Sys.getLibraryName());
initialized = true; /**
} * Initializes the cursor class
*/
private static void initialize() {
System.loadLibrary(Sys.getLibraryName());
initialized = true;
}
/** /**
* Creates the actual cursor, using a platform specific class * Creates the actual cursor, using a platform specific class
*/ */
private void createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception { private void createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
// create copy and flip images to match ogl // create copy and flip images to match ogl
IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer(); IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer();
flipImages(width, height, numImages, images, images_copy); flipImages(width, height, numImages, images, images_copy);
// create our cursor elements // create our cursor elements
cursors = new CursorElement[numImages]; cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) { for(int i=0; i<numImages; i++) {
cursors[i] = new CursorElement(); cursors[i] = new CursorElement();
cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position()); cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position());
cursors[i].delay = (delays != null) ? delays.get(i) : 0; cursors[i].delay = (delays != null) ? delays.get(i) : 0;
cursors[i].timeout = System.currentTimeMillis(); cursors[i].timeout = System.currentTimeMillis();
// offset to next image // offset to next image
images_copy.position(width*height*(i+1)); images_copy.position(width*height*(i+1));
} }
// set index // set index
index = 0; index = 0;
} }
/** /**
* Flips the images so they're oriented according to opengl * Flips the images so they're oriented according to opengl
* *
* @param width Width of image * @param width Width of image
* @param height Height of images * @param height Height of images
* @param numImages How many images to flip * @param numImages How many images to flip
* @param images Source images * @param images Source images
* @param images_copy Destination images * @param images_copy Destination images
*/ */
private static void flipImages(int width, int height, int numImages, IntBuffer images, IntBuffer images_copy) { private static void flipImages(int width, int height, int numImages, IntBuffer images, IntBuffer images_copy) {
for (int i = 0; i < numImages; i++) { for (int i = 0; i < numImages; i++) {
int start_index = i*width*height; int start_index = i*width*height;
flipImage(width, height, start_index, images, images_copy); flipImage(width, height, start_index, images, images_copy);
} }
} }
/** /**
* @param width Width of image * @param width Width of image
* @param height Height of images * @param height Height of images
* @param start_index index into source buffer to copy to * @param start_index index into source buffer to copy to
* @param images Source images * @param images Source images
* @param images_copy Destination images * @param images_copy Destination images
*/ */
private static void flipImage(int width, int height, int start_index, IntBuffer images, IntBuffer images_copy) { private static void flipImage(int width, int height, int start_index, IntBuffer images, IntBuffer images_copy) {
for (int y = 0; y < height>>1; y++) { for (int y = 0; y < height>>1; y++) {
int index_y_1 = y*width + start_index; int index_y_1 = y*width + start_index;
int index_y_2 = (height - y - 1)*width + start_index; int index_y_2 = (height - y - 1)*width + start_index;
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
int index1 = index_y_1 + x; int index1 = index_y_1 + x;
int index2 = index_y_2 + x; int index2 = index_y_2 + x;
int temp_pixel = images.get(index1 + images.position()); int temp_pixel = images.get(index1 + images.position());
images_copy.put(index1, images.get(index2 + images.position())); images_copy.put(index1, images.get(index2 + images.position()));
images_copy.put(index2, temp_pixel); images_copy.put(index2, temp_pixel);
} }
} }
} }
/** /**
* Gets the native handle associated with the cursor object. * Gets the native handle associated with the cursor object.
*/ */
public long getHandle() { public long getHandle() {
return cursors[index].cursorHandle; return cursors[index].cursorHandle;
} }
/** /**
* Destroy the native cursor. Cursor must not be current. * Destroy the native cursor. Cursor must not be current.
*/ */
public void destroy() { public void destroy() {
for(int i=0; i<cursors.length; i++) { for(int i=0; i<cursors.length; i++) {
nDestroyCursor(cursors[i].cursorHandle); nDestroyCursor(cursors[i].cursorHandle);
} }
} }
/** /**
* Sets the timout property to the time it should be changed * Sets the timout property to the time it should be changed
*/ */
protected void setTimeout() { protected void setTimeout() {
cursors[index].timeout = System.currentTimeMillis() + cursors[index].delay; cursors[index].timeout = System.currentTimeMillis() + cursors[index].delay;
} }
/** /**
* Determines whether this cursor has timed out * Determines whether this cursor has timed out
* @return true if the this cursor has timed out, false if not * @return true if the this cursor has timed out, false if not
*/ */
protected boolean hasTimedOut() { protected boolean hasTimedOut() {
return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis(); return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis();
} }
/** /**
* Changes to the next cursor * Changes to the next cursor
*/ */
protected void nextCursor() { protected void nextCursor() {
index = ++index % cursors.length; index = ++index % cursors.length;
} }
/** /**
* Resets the index of the cursor animation to the first in the list. * Resets the index of the cursor animation to the first in the list.
*/ */
public void resetAnimation() { public void resetAnimation() {
index = 0; index = 0;
} }
/** /**
* Native method to create a native cursor * Native method to create a native cursor
*/ */
private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset); private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset);
/** /**
* Native method to destroy a native cursor * Native method to destroy a native cursor
*/ */
private static native void nDestroyCursor(long cursorHandle); private static native void nDestroyCursor(long cursorHandle);
/** /**
* A single cursor element, used when animating * A single cursor element, used when animating
*/ */
protected class CursorElement { protected class CursorElement {
/** Handle to cursor */ /** Handle to cursor */
long cursorHandle; long cursorHandle;
/** How long a delay this element should have */ /** How long a delay this element should have */
long delay; long delay;
/** Absolute time this element times out */ /** Absolute time this element times out */
long timeout; long timeout;
} }
} }

View File

@ -285,7 +285,8 @@ public class Keyboard {
* @throws Exception if the keyboard could not be created for any reason * @throws Exception if the keyboard could not be created for any reason
*/ */
public static void create() throws Exception { public static void create() throws Exception {
assert Window.isCreated() : "Window must be created prior to creating keyboard"; if (!Window.isCreated())
throw new IllegalStateException("Window must be created before you can create Keyboard");
if (!initialized) if (!initialized)
initialize(); initialize();
if (created) if (created)
@ -334,7 +335,8 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#read() * @see org.lwjgl.input.Keyboard#read()
*/ */
public static void poll() { public static void poll() {
assert created : "The keyboard has not been created."; if (!created)
throw new IllegalStateException("Keyboard must be created before you can poll the device");
nPoll(keyDownBuffer); nPoll(keyDownBuffer);
} }
@ -361,8 +363,10 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#getEventCharacter() * @see org.lwjgl.input.Keyboard#getEventCharacter()
*/ */
public static void read() { public static void read() {
assert created : "The keyboard has not been created."; if (!created)
assert readBuffer != null : "Keyboard buffering has not been enabled."; throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
readBuffer.compact(); readBuffer.compact();
int numEvents = nRead(readBuffer, readBuffer.position()); int numEvents = nRead(readBuffer, readBuffer.position());
if (translationEnabled) if (translationEnabled)
@ -383,8 +387,10 @@ public class Keyboard {
* and keyboard buffering must be enabled. * and keyboard buffering must be enabled.
*/ */
public static void enableTranslation() throws Exception { public static void enableTranslation() throws Exception {
assert created : "The keyboard has not been created."; if (!created)
assert readBuffer != null : "Keyboard buffering has not been enabled."; throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
nEnableTranslation(); nEnableTranslation();
translationEnabled = true; translationEnabled = true;
} }
@ -398,7 +404,8 @@ public class Keyboard {
* Enable keyboard buffering. Must be called after the keyboard is created. * Enable keyboard buffering. Must be called after the keyboard is created.
*/ */
public static void enableBuffer() throws Exception { public static void enableBuffer() throws Exception {
assert created : "The keyboard has not been created."; if (!created)
throw new IllegalStateException("Keyboard must be created before you can enable buffering");
readBuffer = BufferUtils.createByteBuffer(4*BUFFER_SIZE); readBuffer = BufferUtils.createByteBuffer(4*BUFFER_SIZE);
readBuffer.limit(0); readBuffer.limit(0);
nEnableBuffer(); nEnableBuffer();
@ -417,7 +424,8 @@ public class Keyboard {
* @return true if the key is down according to the last poll() * @return true if the key is down according to the last poll()
*/ */
public static boolean isKeyDown(int key) { public static boolean isKeyDown(int key) {
assert created : "The keyboard has not been created."; if (!created)
throw new IllegalStateException("Keyboard must be created before you can query key state");
return keyDownBuffer.get(key) != 0; return keyDownBuffer.get(key) != 0;
} }
@ -442,7 +450,8 @@ public class Keyboard {
* @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown * @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
*/ */
public static int isStateKeySet(int key) { public static int isStateKeySet(int key) {
assert created : "The keyboard has not been created."; if (!created)
throw new IllegalStateException("Keyboard must be created before you can query key state");
return nisStateKeySet(key); return nisStateKeySet(key);
} }
private static native int nisStateKeySet(int key); private static native int nisStateKeySet(int key);
@ -473,7 +482,8 @@ public class Keyboard {
* @return the number of keyboard events * @return the number of keyboard events
*/ */
public static int getNumKeyboardEvents() { public static int getNumKeyboardEvents() {
assert created : "The keyboard has not been created."; if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events");
if (translationEnabled) if (translationEnabled)
return readBuffer.remaining()/4; return readBuffer.remaining()/4;
else else
@ -492,8 +502,10 @@ public class Keyboard {
* @return true if a keyboard event was read, false otherwise * @return true if a keyboard event was read, false otherwise
*/ */
public static boolean next() { public static boolean next() {
assert created : "The keyboard has not been created."; if (!created)
assert readBuffer != null : "Keyboard buffering has not been enabled."; throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
if (readBuffer.hasRemaining()) { if (readBuffer.hasRemaining()) {
eventKey = readBuffer.get() & 0xFF; eventKey = readBuffer.get() & 0xFF;

View File

@ -167,7 +167,10 @@ public class Mouse {
* @throws Exception if the cursor could not be set for any reason * @throws Exception if the cursor could not be set for any reason
*/ */
public static Cursor setNativeCursor(Cursor cursor) throws Exception { public static Cursor setNativeCursor(Cursor cursor) throws Exception {
assert created && ((getNativeCursorCaps() | CURSOR_ONE_BIT_TRANSPARENCY) != 0); if (!created)
throw new IllegalStateException("Create the Mouse before setting the native cursor");
if ((getNativeCursorCaps() & CURSOR_ONE_BIT_TRANSPARENCY) == 0)
throw new IllegalStateException("Mouse doesn't support native cursors");
Cursor oldCursor = currentCursor; Cursor oldCursor = currentCursor;
currentCursor = cursor; currentCursor = cursor;
if (currentCursor != null) { if (currentCursor != null) {
@ -239,7 +242,8 @@ public class Mouse {
*/ */
public static void create() throws Exception { public static void create() throws Exception {
assert Window.isCreated() : "Window must be created prior to creating mouse"; if (!Window.isCreated())
throw new IllegalStateException("Window must be created prior to creating mouse");
if (!initialized) { if (!initialized) {
initialize(); initialize();
@ -327,7 +331,8 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#read() * @see org.lwjgl.input.Mouse#read()
*/ */
public static void poll() { public static void poll() {
assert created : "The mouse has not been created."; if (!created)
throw new IllegalStateException("Mouse must be created before you can poll it");
nPoll(); nPoll();
// set absolute position // set absolute position
@ -363,7 +368,8 @@ public class Mouse {
* @return true if the specified button is down * @return true if the specified button is down
*/ */
public static boolean isButtonDown(int button) { public static boolean isButtonDown(int button) {
assert created : "The mouse has not been created."; if (!created)
throw new IllegalStateException("Mouse must be created before you can poll the button state");
if (button >= buttonCount || button < 0) if (button >= buttonCount || button < 0)
return false; return false;
else else
@ -398,7 +404,8 @@ public class Mouse {
* Enable mouse button buffering. Must be called after the mouse is created. * Enable mouse button buffering. Must be called after the mouse is created.
*/ */
public static void enableBuffer() throws Exception { public static void enableBuffer() throws Exception {
assert created : "The mouse has not been created."; if (!created)
throw new IllegalStateException("Mouse must be created before you can enable buffering");
readBuffer = BufferUtils.createByteBuffer(2*BUFFER_SIZE); readBuffer = BufferUtils.createByteBuffer(2*BUFFER_SIZE);
readBuffer.limit(0); readBuffer.limit(0);
nEnableBuffer(); nEnableBuffer();
@ -424,8 +431,10 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#getEventButtonState() * @see org.lwjgl.input.Mouse#getEventButtonState()
*/ */
public static void read() { public static void read() {
assert created : "The mouse has not been created."; if (!created)
assert readBuffer != null : "Mouse buffering has not been enabled."; throw new IllegalStateException("Mouse must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
readBuffer.compact(); readBuffer.compact();
int numEvents = nRead(readBuffer, readBuffer.position()); int numEvents = nRead(readBuffer, readBuffer.position());
readBuffer.position(readBuffer.position() + numEvents*2); readBuffer.position(readBuffer.position() + numEvents*2);
@ -447,8 +456,10 @@ public class Mouse {
* @return true if a mouse event was read, false otherwise * @return true if a mouse event was read, false otherwise
*/ */
public static boolean next() { public static boolean next() {
assert created : "The mouse has not been created."; if (!created)
assert readBuffer != null : "Mouse buffering has not been enabled."; throw new IllegalStateException("Mouse must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
if (readBuffer.hasRemaining()) { if (readBuffer.hasRemaining()) {
eventButton = readBuffer.get() & 0xFF; eventButton = readBuffer.get() & 0xFF;

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,7 @@ public final class ARBVertexBufferObject {
case GL_ARRAY_BUFFER_ARB: case GL_ARRAY_BUFFER_ARB:
VBOTracker.getVBOArrayStack().setState(buffer); VBOTracker.getVBOArrayStack().setState(buffer);
break; break;
default: assert false: "Unsupported VBO target " + target; default: throw new IllegalArgumentException("Unsupported VBO target " + target);
} }
nglBindBufferARB(target, buffer); nglBindBufferARB(target, buffer);
} }

View File

@ -67,7 +67,7 @@ public final class ARBVertexShader {
// --------------------------- // ---------------------------
public static void glBindAttribLocationARB(int programObj, int index, ByteBuffer name) { public static void glBindAttribLocationARB(int programObj, int index, ByteBuffer name) {
if ( name.get(name.limit() - 1) != 0 ) { if ( name.get(name.limit() - 1) != 0 ) {
throw new RuntimeException("<name> must be a null-terminated string."); throw new IllegalArgumentException("<name> must be a null-terminated string.");
} }
nglBindAttribLocationARB(programObj, index, name, name.position()); nglBindAttribLocationARB(programObj, index, name, name.position());
} }
@ -99,7 +99,7 @@ public final class ARBVertexShader {
// --------------------------- // ---------------------------
public static int glGetAttribLocationARB(int programObj, ByteBuffer name) { public static int glGetAttribLocationARB(int programObj, ByteBuffer name) {
if ( name.get(name.limit() - 1) != 0 ) { if ( name.get(name.limit() - 1) != 0 ) {
throw new RuntimeException("<name> must be a null-terminated string."); throw new IllegalArgumentException("<name> must be a null-terminated string.");
} }
return nglGetAttribLocationARB(programObj, name, name.position()); return nglGetAttribLocationARB(programObj, name, name.position());
} }
@ -107,4 +107,4 @@ public final class ARBVertexShader {
private static native int nglGetAttribLocationARB(int programObj, ByteBuffer name, int nameOffset); private static native int nglGetAttribLocationARB(int programObj, ByteBuffer name, int nameOffset);
// --------------------------- // ---------------------------
} }

View File

@ -68,7 +68,7 @@ public final class ATIDrawBuffers {
// --------------------------- // ---------------------------
public static void glDrawBuffersATI(IntBuffer buffers) { public static void glDrawBuffersATI(IntBuffer buffers) {
if (buffers.remaining() == 0) { if (buffers.remaining() == 0) {
throw new RuntimeException("<buffers> must have at least 1 integer available."); throw new IllegalArgumentException("<buffers> must have at least 1 integer available.");
} }
nglDrawBuffersATI(buffers.remaining(), buffers, buffers.position()); nglDrawBuffersATI(buffers.remaining(), buffers, buffers.position());
} }
@ -76,4 +76,4 @@ public final class ATIDrawBuffers {
private static native void nglDrawBuffersATI(int size, IntBuffer buffers, int buffersOffset); private static native void nglDrawBuffersATI(int size, IntBuffer buffers, int buffersOffset);
// --------------------------- // ---------------------------
} }

View File

@ -87,7 +87,7 @@ public final class GL15 {
VBOTracker.getVBOArrayStack().setState(buffer); VBOTracker.getVBOArrayStack().setState(buffer);
break; break;
default: default:
assert false: "Unsupported VBO target " + target; throw new IllegalArgumentException("Unsupported VBO target " + target);
} }
nglBindBuffer(target, buffer); nglBindBuffer(target, buffer);
} }
@ -296,4 +296,4 @@ public final class GL15 {
int paramsOffset); int paramsOffset);
// --------------------------- // ---------------------------
} }

View File

@ -108,7 +108,8 @@ public final class Window {
* @return the width of the window * @return the width of the window
*/ */
public static int getWidth() { public static int getWidth() {
assert isCreated() : "Cannot get width on uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot get width on uncreated window");
return width; return width;
} }
@ -116,7 +117,8 @@ public final class Window {
* @return the height of the window * @return the height of the window
*/ */
public static int getHeight() { public static int getHeight() {
assert isCreated() : "Cannot get height on uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot get height on uncreated window");
return height; return height;
} }
@ -124,15 +126,17 @@ public final class Window {
* @return the title of the window * @return the title of the window
*/ */
public static String getTitle() { public static String getTitle() {
assert isCreated() : "Cannot get title on uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot get title on uncreated window");
return title; return title;
} }
/** /**
* @return whether this window is in fullscreen mode * @return whether this window is in fullscreen mode
*/ */
public static boolean isFullscreen() { public static boolean isFullscreen() {
assert isCreated() : "Cannot determine state of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine fullscreen state of uncreated window");
return fullscreen; return fullscreen;
} }
@ -141,7 +145,8 @@ public final class Window {
* @param newTitle The new window title * @param newTitle The new window title
*/ */
public static void setTitle(String newTitle) { public static void setTitle(String newTitle) {
assert isCreated() : "Cannot set title of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot set title on uncreated window");
title = newTitle; title = newTitle;
nSetTitle(title); nSetTitle(title);
} }
@ -156,7 +161,8 @@ public final class Window {
* @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() { public static boolean isCloseRequested() {
assert isCreated() : "Cannot determine state of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine close requested state of uncreated window");
return nIsCloseRequested(); return nIsCloseRequested();
} }
@ -166,7 +172,8 @@ public final class Window {
* @return true if the window is minimized or otherwise not visible * @return true if the window is minimized or otherwise not visible
*/ */
public static boolean isMinimized() { public static boolean isMinimized() {
assert isCreated() : "Cannot determine state of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
return nIsMinimized(); return nIsMinimized();
} }
@ -176,7 +183,8 @@ public final class Window {
* @return true if window is focused * @return true if window is focused
*/ */
public static boolean isFocused() { public static boolean isFocused() {
assert isCreated() : "Cannot determine state of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine focused state of uncreated window");
return nIsFocused(); return nIsFocused();
} }
@ -210,7 +218,8 @@ public final class Window {
* and needs to repaint itself * and needs to repaint itself
*/ */
public static boolean isDirty() { public static boolean isDirty() {
assert isCreated() : "Cannot determine state of uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine dirty state of uncreated window");
return nIsDirty(); return nIsDirty();
} }
@ -222,7 +231,8 @@ public final class Window {
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
*/ */
public static void update() { public static void update() {
assert isCreated() : "Cannot paint uncreated window"; if (!isCreated())
throw new IllegalStateException("Cannot determine update uncreated window");
nUpdate(); nUpdate();
if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) { if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) {
Util.checkGLError(); Util.checkGLError();
@ -259,7 +269,8 @@ public final class Window {
* Make the Window the current rendering context for GL calls. * Make the Window the current rendering context for GL calls.
*/ */
public static synchronized void makeCurrent() { public static synchronized void makeCurrent() {
assert isCreated() : "No window has been created."; if (!isCreated())
throw new IllegalStateException("No window created to make current");
nMakeCurrent(); nMakeCurrent();
GLContext.useContext(context); GLContext.useContext(context);
} }
@ -315,7 +326,7 @@ public final class Window {
*/ */
public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws Exception { public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws Exception {
if (isCreated()) if (isCreated())
throw new Exception("Only one LWJGL window may be instantiated at any one time."); throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = true; Window.fullscreen = true;
Window.x = 0; Window.x = 0;
Window.y = 0; Window.y = 0;
@ -371,7 +382,7 @@ public final class Window {
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples) public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples)
throws Exception { throws Exception {
if (isCreated()) if (isCreated())
throw new Exception("Only one LWJGL window may be instantiated at any one time."); throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = false; Window.fullscreen = false;
Window.x = x; Window.x = x;
Window.y = y; Window.y = y;
@ -518,7 +529,8 @@ public final class Window {
* @return boolean * @return boolean
*/ */
public static boolean isVSyncEnabled() { public static boolean isVSyncEnabled() {
assert isCreated() : "Cannot determine sync of uncreated window"; if (isCreated())
throw new IllegalStateException("Cannot determine vsync state of uncreated window");
return nIsVSyncEnabled(); return nIsVSyncEnabled();
} }
@ -531,11 +543,10 @@ public final class Window {
* @param sync true to synchronize; false to ignore synchronization * @param sync true to synchronize; false to ignore synchronization
*/ */
public static void setVSyncEnabled(boolean sync) { public static void setVSyncEnabled(boolean sync) {
assert isCreated() : "Cannot set sync of uncreated window"; if (isCreated())
throw new IllegalStateException("Cannot set vsync state of uncreated window");
nSetVSyncEnabled(sync); nSetVSyncEnabled(sync);
} }
private static native void nSetVSyncEnabled(boolean sync); private static native void nSetVSyncEnabled(boolean sync);
} }