+ *
+ * @return The capacity of this buffer
+ */
+ public final int capacity() {
+ return view.capacity();
+ }
+
+ /**
+ * Returns this buffer's position.
+ *
+ * @return The position of this buffer
+ */
+ public final int position() {
+ return view.position();
+ }
+
+ /**
+ * Returns this buffer's position, in bytes.
+ *
+ * @return The position of this buffer in bytes.
+ */
+ public final int positionByte() {
+ return position() * getPointerSize();
+ }
+
+ /**
+ * Sets this buffer's position. If the mark is defined and larger than the
+ * new position then it is discarded.
+ *
+ * @param newPosition The new position value; must be non-negative
+ * and no larger than the current limit
+ *
+ * @return This buffer
+ *
+ * @throws IllegalArgumentException If the preconditions on newPosition do not hold
+ */
+ public final PointerBuffer position(int newPosition) {
+ view.position(newPosition);
+ return this;
+ }
+
+ /**
+ * Returns this buffer's limit.
+ *
+ * @return The limit of this buffer
+ */
+ public final int limit() {
+ return view.limit();
+ }
+
+ /**
+ * Sets this buffer's limit. If the position is larger than the new limit
+ * then it is set to the new limit. If the mark is defined and larger than
+ * the new limit then it is discarded.
+ *
+ * @param newLimit The new limit value; must be non-negative
+ * and no larger than this buffer's capacity
+ *
+ * @return This buffer
+ *
+ * @throws IllegalArgumentException If the preconditions on newLimit do not hold
+ */
+ public final PointerBuffer limit(int newLimit) {
+ view.limit(newLimit);
+ return this;
+ }
+
+ /**
+ * Sets this buffer's mark at its position.
+ *
+ * @return This buffer
+ */
+ public final PointerBuffer mark() {
+ view.mark();
+ return this;
+ }
+
+ /**
+ * Resets this buffer's position to the previously-marked position.
+ *
+ *
Invoking this method neither changes nor discards the mark's
+ * value.
+ *
+ * @return This buffer
+ *
+ * @throws java.nio.InvalidMarkException If the mark has not been set
+ */
+ public final PointerBuffer reset() {
+ view.reset();
+ return this;
+ }
+
+ /**
+ * Clears this buffer. The position is set to zero, the limit is set to
+ * the capacity, and the mark is discarded.
+ *
+ *
Invoke this method before using a sequence of channel-read or
+ * put operations to fill this buffer. For example:
+ *
+ *
+ * buf.clear(); // Prepare buffer for reading
+ * in.read(buf); // Read data
+ *
+ *
This method does not actually erase the data in the buffer, but it
+ * is named as if it did because it will most often be used in situations
+ * in which that might as well be the case.
+ *
+ * @return This buffer
+ */
+ public final PointerBuffer clear() {
+ view.clear();
+ return this;
+ }
+
+ /**
+ * Flips this buffer. The limit is set to the current position and then
+ * the position is set to zero. If the mark is defined then it is
+ * discarded.
+ *
+ *
After a sequence of channel-read or put operations, invoke
+ * this method to prepare for a sequence of channel-write or relative
+ * get operations. For example:
+ *
+ *
+ * buf.put(magic); // Prepend header
+ * in.read(buf); // Read data into rest of buffer
+ * buf.flip(); // Flip buffer
+ * out.write(buf); // Write header + data to channel
+ *
+ *
This method is often used in conjunction with the {@link
+ * java.nio.ByteBuffer#compact compact} method when transferring data from
+ * one place to another.
+ *
+ * @return This buffer
+ */
+ public final PointerBuffer flip() {
+ view.flip();
+ return this;
+ }
+
+ /**
+ * Rewinds this buffer. The position is set to zero and the mark is
+ * discarded.
+ *
+ *
Invoke this method before a sequence of channel-write or get
+ * operations, assuming that the limit has already been set
+ * appropriately. For example:
+ *
+ *
+ * out.write(buf); // Write remaining data
+ * buf.rewind(); // Rewind buffer
+ * buf.get(array); // Copy data into array
+ *
+ * @return This buffer
+ */
+ public final PointerBuffer rewind() {
+ view.rewind();
+ return this;
+ }
+
+ /**
+ * Returns the number of elements between the current position and the
+ * limit.
+ *
+ * @return The number of elements remaining in this buffer
+ */
+ public final int remaining() {
+ return view.remaining();
+ }
+
+ /**
+ * Tells whether there are any elements between the current position and
+ * the limit.
+ *
+ * @return true if, and only if, there is at least one element
+ * remaining in this buffer
+ */
+ public final boolean hasRemaining() {
+ return view.hasRemaining();
+ }
+
+ /**
+ * Allocates a new pointer buffer.
+ *
+ *
The new buffer's position will be zero, its limit will be its
+ * capacity, and its mark will be undefined.
+ *
+ * @param capacity The new buffer's capacity, in pointers
+ *
+ * @return The new pointer buffer
+ *
+ * @throws IllegalArgumentException If the capacity is a negative integer
+ */
+ public static PointerBuffer allocateDirect(int capacity) {
+ return new PointerBuffer(capacity);
+ }
+
+ /**
+ * This method is used in slice and duplicate instead of normal object construction,
+ * so that subclasses can return themselves.
+ *
+ * @param source
+ *
+ * @return A new PointerBuffer instance
+ */
+ protected PointerBuffer newInstance(final ByteBuffer source) {
+ return new PointerBuffer(source);
+ }
+
+ /**
+ * Creates a new pointer buffer whose content is a shared subsequence of
+ * this buffer's content.
+ *
+ *
The content of the new buffer will start at this buffer's current
+ * position. Changes to this buffer's content will be visible in the new
+ * buffer, and vice versa; the two buffers' position, limit, and mark
+ * values will be independent.
+ *
+ *
The new buffer's position will be zero, its capacity and its limit
+ * will be the number of longs remaining in this buffer, and its mark
+ * will be undefined. The new buffer will be direct if, and only if, this
+ * buffer is direct, and it will be read-only if, and only if, this buffer
+ * is read-only.
+ *
+ * @return The new pointer buffer
+ */
+ public PointerBuffer slice() {
+ final int pointerSize = getPointerSize();
+
+ pointers.position(view.position() * pointerSize);
+ pointers.limit(view.limit() * pointerSize);
+
+ try {
+ // We're slicing in the constructor.
+ return newInstance(pointers);
+ } finally {
+ pointers.clear();
+ }
+ }
+
+ /**
+ * Creates a new pointer buffer that shares this buffer's content.
+ *
+ *
The content of the new buffer will be that of this buffer. Changes
+ * to this buffer's content will be visible in the new buffer, and vice
+ * versa; the two buffers' position, limit, and mark values will be
+ * independent.
+ *
+ *
The new buffer's capacity, limit and position will be
+ * identical to those of this buffer. The new buffer will be direct if,
+ * and only if, this buffer is direct, and it will be read-only if, and
+ * only if, this buffer is read-only.
+ *
+ * @return The new pointer buffer
+ */
+ public PointerBuffer duplicate() {
+ final PointerBuffer buffer = newInstance(pointers);
+
+ buffer.position(view.position());
+ buffer.limit(view.limit());
+
+ return buffer;
+ }
+
+ /**
+ * Creates a new, read-only pointer buffer that shares this buffer's
+ * content.
+ *
+ *
The content of the new buffer will be that of this buffer. Changes
+ * to this buffer's content will be visible in the new buffer; the new
+ * buffer itself, however, will be read-only and will not allow the shared
+ * content to be modified. The two buffers' position, limit, and mark
+ * values will be independent.
+ *
+ *
The new buffer's capacity, limit and position will be
+ * identical to those of this buffer.
+ *
+ *
If this buffer is itself read-only then this method behaves in
+ * exactly the same way as the {@link #duplicate duplicate} method.
+ *
+ * @return The new, read-only pointer buffer
+ */
+ public PointerBuffer asReadOnlyBuffer() {
+ final PointerBuffer buffer = new PointerBufferR(pointers);
+
+ buffer.position(view.position());
+ buffer.limit(view.limit());
+
+ return buffer;
+ }
+
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ /**
+ * Relative get method. Reads the long at this buffer's
+ * current position, and then increments the position.
+ *
+ * @return The long at the buffer's current position
+ *
+ * @throws BufferUnderflowException If the buffer's current position is not smaller than its limit
+ */
+ public long get() {
+ if ( is64Bit )
+ return view64.get();
+ else
+ return view32.get() & 0x00000000FFFFFFFFL;
+ }
+
+ /**
+ * Relative put method (optional operation).
+ *
+ *
Writes the given long into this buffer at the current
+ * position, and then increments the position.
+ *
+ * @param l The long to be written
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException If this buffer's current position is not smaller than its limit
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public PointerBuffer put(long l) {
+ if ( is64Bit )
+ view64.put(l);
+ else
+ view32.put((int)l);
+ return this;
+ }
+
+ /**
+ * Convenience put that accepts PointerWrapper objects.
+ *
+ * @see #put(long)
+ */
+ public PointerBuffer put(final PointerWrapper pointer) {
+ return put(pointer.getPointer());
+ }
+
+ /**
+ * Convenience put on a target ByteBuffer.
+ *
+ * @param target the target ByteBuffer
+ * @param l the long value to be written
+ */
+ public static void put(final ByteBuffer target, long l) {
+ if ( is64Bit )
+ target.putLong(l);
+ else
+ target.putInt((int)l);
+ }
+
+ /**
+ * Absolute get method. Reads the long at the given
+ * index.
+ *
+ * @param index The index from which the long will be read
+ *
+ * @return The long at the given index
+ *
+ * @throws IndexOutOfBoundsException If index is negative
+ * or not smaller than the buffer's limit
+ */
+ public long get(int index) {
+ if ( is64Bit )
+ return view64.get(index);
+ else
+ return view32.get(index) & 0x00000000FFFFFFFFL;
+ }
+
+ /**
+ * Absolute put method (optional operation).
+ *
+ *
Writes the given long into this buffer at the given
+ * index.
+ *
+ * @param index The index at which the long will be written
+ * @param l The long value to be written
+ *
+ * @return This buffer
+ *
+ * @throws IndexOutOfBoundsException If index is negative
+ * or not smaller than the buffer's limit
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public PointerBuffer put(int index, long l) {
+ if ( is64Bit )
+ view64.put(index, l);
+ else
+ view32.put(index, (int)l);
+ return this;
+ }
+
+ /**
+ * Convenience put that accepts PointerWrapper objects.
+ *
+ * @see #put(int, long)
+ */
+ public PointerBuffer put(int index, PointerWrapper pointer) {
+ return put(index, pointer.getPointer());
+ }
+
+ /**
+ * Convenience put on a target ByteBuffer.
+ *
+ * @param target the target ByteBuffer
+ * @param index the index at which the long will be written
+ * @param l the long value to be written
+ */
+ public static void put(final ByteBuffer target, int index, long l) {
+ if ( is64Bit )
+ target.putLong(index * 8, l);
+ else
+ target.putInt(index * 4, (int)l);
+ }
+
+ // -- Bulk get operations --
+
+ /**
+ * Relative bulk get method.
+ *
+ *
This method transfers longs from this buffer into the given
+ * destination array. If there are fewer longs remaining in the
+ * buffer than are required to satisfy the request, that is, if
+ * length>remaining(), then no
+ * longs are transferred and a {@link BufferUnderflowException} is
+ * thrown.
+ *
+ *
Otherwise, this method copies length longs from this
+ * buffer into the given array, starting at the current position of this
+ * buffer and at the given offset in the array. The position of this
+ * buffer is then incremented by length.
+ *
+ *
In other words, an invocation of this method of the form
+ * src.get(dst, off, len) has exactly the same effect as
+ * the loop
+ *
+ *
+ * for (int i = off; i < off + len; i++)
+ * dst[i] = src.get();
+ *
+ * except that it first checks that there are sufficient longs in
+ * this buffer and it is potentially much more efficient.
+ *
+ * @param dst The array into which longs are to be written
+ * @param offset The offset within the array of the first long to be
+ * written; must be non-negative and no larger than
+ * dst.length
+ * @param length The maximum number of longs to be written to the given
+ * array; must be non-negative and no larger than
+ * dst.length - offset
+ *
+ * @return This buffer
+ *
+ * @throws BufferUnderflowException If there are fewer than length longs
+ * remaining in this buffer
+ * @throws IndexOutOfBoundsException If the preconditions on the offset and length
+ * parameters do not hold
+ */
+ public PointerBuffer get(long[] dst, int offset, int length) {
+ if ( is64Bit )
+ view64.get(dst, offset, length);
+ else {
+ checkBounds(offset, length, dst.length);
+ if ( length > view32.remaining() )
+ throw new BufferUnderflowException();
+ int end = offset + length;
+ for ( int i = offset; i < end; i++ )
+ dst[i] = view32.get() & 0x00000000FFFFFFFFL;
+ }
+
+ return this;
+ }
+
+ /**
+ * Relative bulk get method.
+ *
+ *
This method transfers longs from this buffer into the given
+ * destination array. An invocation of this method of the form
+ * src.get(a) behaves in exactly the same way as the invocation
+ *
+ *
+ * src.get(a, 0, a.length)
+ *
+ * @return This buffer
+ *
+ * @throws BufferUnderflowException If there are fewer than length longs
+ * remaining in this buffer
+ */
+ public PointerBuffer get(long[] dst) {
+ return get(dst, 0, dst.length);
+ }
+
+ /**
+ * Relative bulk put method (optional operation).
+ *
+ *
This method transfers the longs remaining in the given source
+ * buffer into this buffer. If there are more longs remaining in the
+ * source buffer than in this buffer, that is, if
+ * src.remaining()>remaining(),
+ * then no longs are transferred and a {@link
+ * BufferOverflowException} is thrown.
+ *
+ *
Otherwise, this method copies
+ * n = src.remaining() longs from the given
+ * buffer into this buffer, starting at each buffer's current position.
+ * The positions of both buffers are then incremented by n.
+ *
+ *
In other words, an invocation of this method of the form
+ * dst.put(src) has exactly the same effect as the loop
+ *
+ *
+ * while (src.hasRemaining())
+ * dst.put(src.get());
+ *
+ * except that it first checks that there is sufficient space in this
+ * buffer and it is potentially much more efficient.
+ *
+ * @param src The source buffer from which longs are to be read;
+ * must not be this buffer
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException If there is insufficient space in this buffer
+ * for the remaining longs in the source buffer
+ * @throws IllegalArgumentException If the source buffer is this buffer
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public PointerBuffer put(PointerBuffer src) {
+ if ( is64Bit )
+ view64.put(src.view64);
+ else
+ view32.put(src.view32);
+ return this;
+ }
+
+ /**
+ * Relative bulk put method (optional operation).
+ *
+ *
This method transfers longs into this buffer from the given
+ * source array. If there are more longs to be copied from the array
+ * than remain in this buffer, that is, if
+ * length>remaining(), then no
+ * longs are transferred and a {@link BufferOverflowException} is
+ * thrown.
+ *
+ *
Otherwise, this method copies length longs from the
+ * given array into this buffer, starting at the given offset in the array
+ * and at the current position of this buffer. The position of this buffer
+ * is then incremented by length.
+ *
+ *
In other words, an invocation of this method of the form
+ * dst.put(src, off, len) has exactly the same effect as
+ * the loop
+ *
+ *
+ * for (int i = off; i < off + len; i++)
+ * dst.put(a[i]);
+ *
+ * except that it first checks that there is sufficient space in this
+ * buffer and it is potentially much more efficient.
+ *
+ * @param src The array from which longs are to be read
+ * @param offset The offset within the array of the first long to be read;
+ * must be non-negative and no larger than array.length
+ * @param length The number of longs to be read from the given array;
+ * must be non-negative and no larger than
+ * array.length - offset
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException If there is insufficient space in this buffer
+ * @throws IndexOutOfBoundsException If the preconditions on the offset and length
+ * parameters do not hold
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public PointerBuffer put(long[] src, int offset, int length) {
+ if ( is64Bit )
+ view64.put(src, offset, length);
+ else {
+ checkBounds(offset, length, src.length);
+ if ( length > view32.remaining() )
+ throw new BufferOverflowException();
+ int end = offset + length;
+ for ( int i = offset; i < end; i++ )
+ view32.put((int)src[i]);
+ }
+
+ return this;
+ }
+
+ /**
+ * Relative bulk put method (optional operation).
+ *
+ *
This method transfers the entire content of the given source
+ * long array into this buffer. An invocation of this method of the
+ * form dst.put(a) behaves in exactly the same way as the
+ * invocation
+ *
+ *
+ * dst.put(a, 0, a.length)
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException If there is insufficient space in this buffer
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public final PointerBuffer put(long[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /**
+ * Compacts this buffer (optional operation).
+ *
+ *
The longs between the buffer's current position and its limit,
+ * if any, are copied to the beginning of the buffer. That is, the
+ * long at index p = position() is copied
+ * to index zero, the long at index p + 1 is copied
+ * to index one, and so forth until the long at index
+ * limit() - 1 is copied to index
+ * n = limit() - 1 - p.
+ * The buffer's position is then set to n+1 and its limit is set to
+ * its capacity. The mark, if defined, is discarded.
+ *
+ *
The buffer's position is set to the number of longs copied,
+ * rather than to zero, so that an invocation of this method can be
+ * followed immediately by an invocation of another relative put
+ * method.
+ *
+ * @return This buffer
+ *
+ * @throws ReadOnlyBufferException If this buffer is read-only
+ */
+ public PointerBuffer compact() {
+ if ( is64Bit )
+ view64.compact();
+ else
+ view32.compact();
+ return this;
+ }
+
+ /**
+ * Retrieves this buffer's byte order.
+ *
+ *
The byte order of a pointer buffer created by allocation or by
+ * wrapping an existing long array is the {@link
+ * ByteOrder#nativeOrder native order} of the underlying
+ * hardware. The byte order of a pointer buffer created as a view of a byte buffer is that of the
+ * byte buffer at the moment that the view is created.
+ *
+ * @return This buffer's byte order
+ */
+ public ByteOrder order() {
+ if ( is64Bit )
+ return view64.order();
+ else
+ return view32.order();
+ }
+
+ /**
+ * Returns a string summarizing the state of this buffer.
+ *
+ * @return A summary string
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(48);
+ sb.append(getClass().getName());
+ sb.append("[pos=");
+ sb.append(position());
+ sb.append(" lim=");
+ sb.append(limit());
+ sb.append(" cap=");
+ sb.append(capacity());
+ sb.append("]");
+ return sb.toString();
+ }
+
+ /**
+ * Returns the current hash code of this buffer.
+ *
+ *
The hash code of a pointer buffer depends only upon its remaining
+ * elements; that is, upon the elements from position() up to, and
+ * including, the element at limit() - 1.
+ *
+ *
Because buffer hash codes are content-dependent, it is inadvisable
+ * to use buffers as keys in hash maps or similar data structures unless it
+ * is known that their contents will not change.
+ *
+ * @return The current hash code of this buffer
+ */
+ public int hashCode() {
+ int h = 1;
+ int p = position();
+ for ( int i = limit() - 1; i >= p; i-- )
+ h = 31 * h + (int)get(i);
+ return h;
+ }
+
+ /**
+ * Tells whether or not this buffer is equal to another object.
+ *
+ *
Two pointer buffers are equal if, and only if,
+ *
+ *
+ *
+ *
They have the same element type,
+ *
+ *
They have the same number of remaining elements, and
+ *
+ *
+ *
The two sequences of remaining elements, considered
+ * independently of their starting positions, are pointwise equal.
+ *
+ *
+ *
+ *
+ *
A pointer buffer is not equal to any other type of object.
+ *
+ * @param ob The object to which this buffer is to be compared
+ *
+ * @return true if, and only if, this buffer is equal to the
+ * given object
+ */
+ public boolean equals(Object ob) {
+ if ( !(ob instanceof PointerBuffer) )
+ return false;
+ PointerBuffer that = (PointerBuffer)ob;
+ if ( this.remaining() != that.remaining() )
+ return false;
+ int p = this.position();
+ for ( int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j-- ) {
+ long v1 = this.get(i);
+ long v2 = that.get(j);
+ if ( v1 != v2 ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Compares this buffer to another.
+ *
+ *
Two pointer buffers are compared by comparing their sequences of
+ * remaining elements lexicographically, without regard to the starting
+ * position of each sequence within its corresponding buffer.
+ *
+ *
A pointer buffer is not comparable to any other type of object.
+ *
+ * @return A negative integer, zero, or a positive integer as this buffer
+ * is less than, equal to, or greater than the given buffer
+ */
+ public int compareTo(Object o) {
+ final PointerBuffer that = (PointerBuffer)o;
+ int n = this.position() + Math.min(this.remaining(), that.remaining());
+ for ( int i = this.position(), j = that.position(); i < n; i++, j++ ) {
+ long v1 = this.get(i);
+ long v2 = that.get(j);
+ if ( v1 == v2 )
+ continue;
+ if ( v1 < v2 )
+ return -1;
+ return +1;
+ }
+ return this.remaining() - that.remaining();
+ }
+
+ private static void checkBounds(int off, int len, int size) {
+ if ( (off | len | (off + len) | (size - (off + len))) < 0 )
+ throw new IndexOutOfBoundsException();
+ }
+
+ /**
+ * Read-only version of PointerBuffer.
+ *
+ * @author Spasi
+ */
+ private static final class PointerBufferR extends PointerBuffer {
+
+ PointerBufferR(final ByteBuffer source) {
+ super(source);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected PointerBuffer newInstance(final ByteBuffer source) {
+ return new PointerBufferR(source);
+ }
+
+ public PointerBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public PointerBuffer put(final long l) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public PointerBuffer put(final int index, final long l) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public PointerBuffer put(final PointerBuffer src) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public PointerBuffer put(final long[] src, final int offset, final int length) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public PointerBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/PointerWrapper.java b/src/java/org/lwjgl/PointerWrapper.java
similarity index 93%
rename from src/java/org/lwjgl/opengl/PointerWrapper.java
rename to src/java/org/lwjgl/PointerWrapper.java
index 123c6028..25bad96c 100644
--- a/src/java/org/lwjgl/opengl/PointerWrapper.java
+++ b/src/java/org/lwjgl/PointerWrapper.java
@@ -29,9 +29,13 @@
* 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;
+package org.lwjgl;
-/** @author spasi */
+/**
+ * A common interface for classes that wrap pointer addresses.
+ *
+ * @author Spasi
+ */
public interface PointerWrapper {
long getPointer();
diff --git a/src/java/org/lwjgl/PointerWrapperAbstract.java b/src/java/org/lwjgl/PointerWrapperAbstract.java
new file mode 100644
index 00000000..2f718bd7
--- /dev/null
+++ b/src/java/org/lwjgl/PointerWrapperAbstract.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl;
+
+/**
+ * Base PointerWrapper implementation.
+ *
+ * @author Spasi
+ */
+public abstract class PointerWrapperAbstract implements PointerWrapper {
+
+ protected final long pointer;
+
+ protected PointerWrapperAbstract(final long pointer) {
+ this.pointer = pointer;
+ }
+
+ public final boolean isNull() {
+ return pointer == 0;
+ }
+
+ public final void checkNull() {
+ if ( LWJGLUtil.DEBUG && pointer == 0 )
+ throw new IllegalStateException("This pointer is null.");
+ }
+
+ public long getPointer() {
+ return pointer;
+ }
+
+ public boolean equals(final Object o) {
+ if ( this == o ) return true;
+ if ( !(o instanceof PointerWrapperAbstract) ) return false;
+
+ final PointerWrapperAbstract that = (PointerWrapperAbstract)o;
+
+ if ( pointer != that.pointer ) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (int)(pointer ^ (pointer >>> 32));
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java
index 70681fd4..59ba4f23 100644
--- a/src/java/org/lwjgl/Sys.java
+++ b/src/java/org/lwjgl/Sys.java
@@ -56,17 +56,18 @@ public final class Sys {
/** Current version of library */
private static final String VERSION = "2.6";
- /** The implementation instance to delegate platform specific behavior to */
- private final static SysImplementation implementation;
+ private static final String POSTFIX64BIT = "64";
+
+ /** The implementation instance to delegate platform specific behavior to */
+ private static final SysImplementation implementation;
+ private static final boolean is64Bit;
- private final static String POSTFIX64BIT = "64";
-
private static void doLoadLibrary(final String lib_name) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
String library_path = System.getProperty("org.lwjgl.librarypath");
if (library_path != null) {
- System.load(library_path + File.separator +
+ System.load(library_path + File.separator +
System.mapLibraryName(lib_name));
} else {
System.loadLibrary(lib_name);
@@ -76,14 +77,15 @@ public final class Sys {
});
}
- private static void loadLibrary(final String lib_name) {
+ private static boolean loadLibrary(final String lib_name) {
try {
doLoadLibrary(lib_name);
+ return false;
} catch (UnsatisfiedLinkError e) {
if (implementation.has64Bit()) {
try {
doLoadLibrary(lib_name + POSTFIX64BIT);
- return;
+ return true;
} catch (UnsatisfiedLinkError e2) {
LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage());
}
@@ -91,12 +93,12 @@ public final class Sys {
// Throw original error
throw e;
}
- }
+ }
static {
implementation = createImplementation();
- loadLibrary(JNI_LIBRARY_NAME);
-
+ is64Bit = loadLibrary(JNI_LIBRARY_NAME);
+
int native_jni_version = implementation.getJNIVersion();
int required_version = implementation.getRequiredJNIVersion();
if (native_jni_version != required_version)
@@ -130,13 +132,18 @@ public final class Sys {
public static String getVersion() {
return VERSION;
}
-
+
/**
* Initialization. This is just a dummy method to trigger the static constructor.
*/
public static void initialize() {
}
+ /** Returns true if a 64bit implementation was loaded. */
+ public static boolean is64Bit() {
+ return is64Bit;
+ }
+
/**
* Obtains the number of ticks that the hires timer does in a second. This method is fast;
* it should be called as frequently as possible, as it recalibrates the timer.
diff --git a/src/java/org/lwjgl/opencl/APIUtil.java b/src/java/org/lwjgl/opencl/APIUtil.java
new file mode 100644
index 00000000..e53edf87
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/APIUtil.java
@@ -0,0 +1,580 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.nio.*;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.util.*;
+
+/**
+ * Utility class for OpenCL API calls.
+ * TODO: Remove useless stuff
+ *
+ * @author spasi
+ */
+final class APIUtil {
+
+ private static final int INITIAL_BUFFER_SIZE = 256;
+ private static final int INITIAL_LENGTHS_SIZE = 4;
+
+ private static final int BUFFERS_SIZE = 32;
+
+ private static final ThreadLocal arrayTL = new ThreadLocal() {
+ protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
+ };
+
+ private static final ThreadLocal bufferByteTL = new ThreadLocal() {
+ protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
+ };
+
+ private static final ThreadLocal bufferPointerTL = new ThreadLocal() {
+ protected PointerBuffer initialValue() { return BufferUtils.createPointerBuffer(INITIAL_BUFFER_SIZE); }
+ };
+
+ private static final ThreadLocal lengthsTL = new ThreadLocal() {
+ protected PointerBuffer initialValue() { return BufferUtils.createPointerBuffer(INITIAL_LENGTHS_SIZE); }
+ };
+
+ private static final ThreadLocal infiniteSeqTL = new ThreadLocal() {
+ protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); }
+ };
+
+ private static final ThreadLocal buffersTL = new ThreadLocal() {
+ protected Buffers initialValue() { return new Buffers(); }
+ };
+
+ private static final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
+
+ private static final ObjectDestructor DESTRUCTOR_CLSubDevice = new ObjectDestructor() {
+ public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLMem = new ObjectDestructor() {
+ public void release(final CLMem object) { CL10.clReleaseMemObject(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLCommandQueue = new ObjectDestructor() {
+ public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLSampler = new ObjectDestructor() {
+ public void release(final CLSampler object) { CL10.clReleaseSampler(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLProgram = new ObjectDestructor() {
+ public void release(final CLProgram object) { CL10.clReleaseProgram(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLKernel = new ObjectDestructor() {
+ public void release(final CLKernel object) { CL10.clReleaseKernel(object); }
+ };
+ private static final ObjectDestructor DESTRUCTOR_CLEvent = new ObjectDestructor() {
+ public void release(final CLEvent object) { CL10.clReleaseEvent(object); }
+ };
+
+ private APIUtil() {
+ }
+
+ private static char[] getArray(final int size) {
+ char[] array = arrayTL.get();
+
+ if ( array.length < size ) {
+ int sizeNew = array.length << 1;
+ while ( sizeNew < size )
+ sizeNew <<= 1;
+
+ array = new char[size];
+ arrayTL.set(array);
+ }
+
+ return array;
+ }
+
+ static ByteBuffer getBufferByte(final int size) {
+ ByteBuffer buffer = bufferByteTL.get();
+
+ if ( buffer.capacity() < size ) {
+ int sizeNew = buffer.capacity() << 1;
+ while ( sizeNew < size )
+ sizeNew <<= 1;
+
+ buffer = BufferUtils.createByteBuffer(size);
+ bufferByteTL.set(buffer);
+ } else
+ buffer.clear();
+
+ return buffer;
+ }
+
+ private static ByteBuffer getBufferByteOffset(final int size) {
+ ByteBuffer buffer = bufferByteTL.get();
+
+ if ( buffer.capacity() < size ) {
+ int sizeNew = buffer.capacity() << 1;
+ while ( sizeNew < size )
+ sizeNew <<= 1;
+
+ final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size);
+ bufferNew.put(buffer);
+ bufferByteTL.set(buffer = bufferNew);
+ } else {
+ buffer.position(buffer.limit());
+ buffer.limit(buffer.capacity());
+ }
+
+ return buffer;
+ }
+
+ static PointerBuffer getBufferPointer(final int size) {
+ PointerBuffer buffer = bufferPointerTL.get();
+
+ if ( buffer.capacity() < size ) {
+ int sizeNew = buffer.capacity() << 1;
+ while ( sizeNew < size )
+ sizeNew <<= 1;
+
+ buffer = BufferUtils.createPointerBuffer(size);
+ bufferPointerTL.set(buffer);
+ } else
+ buffer.clear();
+
+ return buffer;
+ }
+
+ static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
+
+ static IntBuffer getBufferInt() { return buffersTL.get().ints; }
+
+ static IntBuffer getBufferIntDebug() { return buffersTL.get().intsDebug; }
+
+ static LongBuffer getBufferLong() { return buffersTL.get().longs; }
+
+ static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
+
+ static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; }
+
+ static PointerBuffer getBufferPointer() { return buffersTL.get().pointers; }
+
+ static PointerBuffer getLengths() {
+ return getLengths(1);
+ }
+
+ static PointerBuffer getLengths(final int size) {
+ PointerBuffer lengths = lengthsTL.get();
+
+ if ( lengths.capacity() < size ) {
+ int sizeNew = lengths.capacity();
+ while ( sizeNew < size )
+ sizeNew <<= 1;
+
+ lengths = BufferUtils.createPointerBuffer(size);
+ lengthsTL.set(lengths);
+ } else
+ lengths.clear();
+
+ return lengths;
+ }
+
+ private static InfiniteCharSequence getInfiniteSeq() {
+ return infiniteSeqTL.get();
+ }
+
+ private static void encode(final ByteBuffer buffer, final CharSequence string) {
+ final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
+ infiniteSeq.setString(string);
+ encoder.encode(infiniteSeq.buffer, buffer, true);
+ infiniteSeq.clear();
+ }
+
+ /**
+ * Reads a byte string from the specified buffer.
+ *
+ * @param buffer
+ *
+ * @return the buffer as a String.
+ */
+ static String getString(final ByteBuffer buffer) {
+ final int length = buffer.remaining();
+ final char[] charArray = getArray(length);
+
+ for ( int i = buffer.position(); i < buffer.limit(); i++ )
+ charArray[i - buffer.position()] = (char)buffer.get(i);
+
+ return new String(charArray, 0, length);
+ }
+
+ /**
+ * Returns a buffer containing the specified string as bytes.
+ *
+ * @param string
+ *
+ * @return the String as a ByteBuffer
+ */
+ static ByteBuffer getBuffer(final CharSequence string) {
+ final ByteBuffer buffer = getBufferByte(string.length());
+
+ encode(buffer, string);
+
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Returns a buffer containing the specified string as bytes, starting at the specified offset.
+ *
+ * @param string
+ *
+ * @return the String as a ByteBuffer
+ */
+ static ByteBuffer getBuffer(final CharSequence string, final int offset) {
+ final ByteBuffer buffer = getBufferByteOffset(offset + string.length());
+
+ encode(buffer, string);
+
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Returns a buffer containing the specified string as bytes, including null-termination.
+ *
+ * @param string
+ *
+ * @return the String as a ByteBuffer
+ */
+ static ByteBuffer getBufferNT(final CharSequence string) {
+ final ByteBuffer buffer = getBufferByte(string.length() + 1);
+
+ encode(buffer, string);
+
+ buffer.put((byte)0);
+ buffer.flip();
+ return buffer;
+ }
+
+ static int getTotalLength(final CharSequence[] strings) {
+ int length = 0;
+ for ( int i = 0; i < strings.length; i++ )
+ length += strings[i].length();
+
+ return length;
+ }
+
+ /**
+ * Returns a buffer containing the specified strings as bytes.
+ *
+ * @param strings
+ *
+ * @return the Strings as a ByteBuffer
+ */
+ static ByteBuffer getBuffer(final CharSequence[] strings) {
+ final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
+
+ final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
+ for ( int i = 0; i < strings.length; i++ ) {
+ infiniteSeq.setString(strings[i]);
+ encoder.encode(infiniteSeq.buffer, buffer, true);
+ }
+ infiniteSeq.clear();
+
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Returns a buffer containing the specified strings as bytes, including null-termination.
+ *
+ * @param strings
+ *
+ * @return the Strings as a ByteBuffer
+ */
+ static ByteBuffer getBufferNT(final CharSequence[] strings) {
+ final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
+
+ final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
+ for ( int i = 0; i < strings.length; i++ ) {
+ infiniteSeq.setString(strings[i]);
+ encoder.encode(infiniteSeq.buffer, buffer, true);
+ buffer.put((byte)0);
+ }
+ infiniteSeq.clear();
+
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Returns a buffer containing the lengths of the specified strings.
+ *
+ * @param strings
+ *
+ * @return the String lengths in a PointerBuffer
+ */
+ static PointerBuffer getLengths(final CharSequence[] strings) {
+ PointerBuffer buffer = getLengths(strings.length);
+
+ for ( int i = 0; i < strings.length; i++ )
+ buffer.put(strings[i].length());
+
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Returns a buffer containing the lengths of the specified buffers.
+ *
+ * @param buffers the buffer array
+ *
+ * @return the buffer lengths in a PointerBuffer
+ */
+ static PointerBuffer getLengths(final ByteBuffer[] buffers) {
+ PointerBuffer buffer = getLengths(buffers.length);
+
+ for ( int i = 0; i < buffers.length; i++ )
+ buffer.put(buffers[i].remaining());
+
+ buffer.flip();
+ return buffer;
+ }
+
+ static int getSize(final PointerBuffer lengths) {
+ long size = 0;
+ for ( int i = lengths.position(); i < lengths.limit(); i++ )
+ size += lengths.get(i);
+
+ return (int)size;
+ }
+
+ static void getClassTokens(final Class[] tokenClasses, final Map target, final TokenFilter filter) {
+ getClassTokens(Arrays.asList(tokenClasses), target, filter);
+ }
+
+ static void getClassTokens(final Iterable tokenClasses, final Map target, final TokenFilter filter) {
+ final int TOKEN_MODIFIERS = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
+
+ for ( final Class tokenClass : tokenClasses ) {
+ for ( final Field field : tokenClass.getDeclaredFields() ) {
+ // Get only fields.
+ if ( (field.getModifiers() & TOKEN_MODIFIERS) == TOKEN_MODIFIERS && field.getType() == int.class ) {
+ try {
+ final int value = field.getInt(null);
+ if ( filter != null && !filter.accept(field, value) )
+ continue;
+
+ if ( target.containsKey(value) ) // Print colliding tokens in their hex representation.
+ target.put(value, "0x" + Integer.toHexString(value).toUpperCase());
+ else
+ target.put(value, field.getName());
+ } catch (IllegalAccessException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ static ByteBuffer getNativeKernelArgs(final long user_func_ref, final CLMem[] clMems, final long[] sizes) {
+ final ByteBuffer args = getBufferByte(8 + 4 + (clMems == null ? 0 : clMems.length * (4 + PointerBuffer.getPointerSize())));
+
+ args.putLong(0, user_func_ref);
+ if ( clMems == null )
+ args.putInt(8, 0);
+ else {
+ args.putInt(8, clMems.length);
+ int byteIndex = 12;
+ for ( int i = 0; i < clMems.length; i++ ) {
+ if ( LWJGLUtil.DEBUG && !clMems[i].isValid() )
+ throw new IllegalArgumentException("An invalid CLMem object was specified.");
+ args.putInt(byteIndex, (int)sizes[i]); // CLMem size
+ byteIndex += (4 + PointerBuffer.getPointerSize()); // Skip size and make room for the pointer
+ }
+ }
+
+ return args;
+ }
+
+ /**
+ * Releases all sub-devices created from the specified CLDevice.
+ *
+ * @param device the CLDevice to clear
+ */
+ static void releaseObjects(final CLDevice device) {
+ // Release objects only if we're about to hit 0.
+ if ( device.getReferenceCount() > 1 )
+ return;
+
+ releaseObjects(device.getSubCLDeviceRegistry(), DESTRUCTOR_CLSubDevice);
+ }
+
+ /**
+ * Releases all objects contained in the specified CLContext.
+ *
+ * @param context the CLContext to clear
+ */
+ static void releaseObjects(final CLContext context) {
+ // Release objects only if we're about to hit 0.
+ if ( context.getReferenceCount() > 1 )
+ return;
+
+ releaseObjects(context.getCLEventRegistry(), DESTRUCTOR_CLEvent);
+ releaseObjects(context.getCLProgramRegistry(), DESTRUCTOR_CLProgram);
+ releaseObjects(context.getCLSamplerRegistry(), DESTRUCTOR_CLSampler);
+ releaseObjects(context.getCLMemRegistry(), DESTRUCTOR_CLMem);
+ releaseObjects(context.getCLCommandQueueRegistry(), DESTRUCTOR_CLCommandQueue);
+ }
+
+ /**
+ * Releases all objects contained in the specified CLProgram.
+ *
+ * @param program the CLProgram to clear
+ */
+ static void releaseObjects(final CLProgram program) {
+ // Release objects only if we're about to hit 0.
+ if ( program.getReferenceCount() > 1 )
+ return;
+
+ releaseObjects(program.getCLKernelRegistry(), DESTRUCTOR_CLKernel);
+ }
+
+ /**
+ * Releases all objects contained in the specified CLCommandQueue.
+ *
+ * @param queue the CLCommandQueue to clear
+ */
+ static void releaseObjects(final CLCommandQueue queue) {
+ // Release objects only if we're about to hit 0.
+ if ( queue.getReferenceCount() > 1 )
+ return;
+
+ releaseObjects(queue.getCLEventRegistry(), DESTRUCTOR_CLEvent);
+ }
+
+ static Set getExtensions(final String extensionList) {
+ final Set extensions = new HashSet();
+
+ final StringTokenizer tokenizer = new StringTokenizer(extensionList);
+ while ( tokenizer.hasMoreTokens() )
+ extensions.add(tokenizer.nextToken());
+
+ return extensions;
+ }
+
+ private static void releaseObjects(final CLObjectRegistry registry, final ObjectDestructor destructor) {
+ if ( registry.isEmpty() )
+ return;
+
+ for ( final T object : registry.getAll() ) {
+ while ( object.isValid() )
+ destructor.release(object);
+ }
+ }
+
+ private interface ObjectDestructor {
+
+ void release(T object);
+
+ }
+
+ /**
+ * A mutable CharSequence with very large initial length. We can wrap this in a re-usable CharBuffer for decoding.
+ * We cannot subclass CharBuffer because of {@link java.nio.CharBuffer#toString(int,int)}.
+ */
+ private static class InfiniteCharSequence implements CharSequence {
+
+ final CharBuffer buffer;
+
+ CharSequence string;
+
+ InfiniteCharSequence() {
+ buffer = CharBuffer.wrap(this);
+ }
+
+ void setString(final CharSequence string) {
+ this.string = string;
+ this.buffer.position(0);
+ this.buffer.limit(string.length());
+ }
+
+ void clear() {
+ this.string = null;
+ }
+
+ public int length() {
+ return Integer.MAX_VALUE;
+ }
+
+ public char charAt(final int index) {
+ return string.charAt(index);
+ }
+
+ public CharSequence subSequence(final int start, final int end) {
+ return string.subSequence(start, end);
+ }
+ }
+
+ private static class Buffers {
+
+ final ShortBuffer shorts;
+ final IntBuffer ints;
+ final IntBuffer intsDebug;
+ final LongBuffer longs;
+
+ final FloatBuffer floats;
+ final DoubleBuffer doubles;
+
+ final PointerBuffer pointers;
+
+ Buffers() {
+ shorts = BufferUtils.createShortBuffer(BUFFERS_SIZE);
+ ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
+ intsDebug = BufferUtils.createIntBuffer(1);
+ longs = BufferUtils.createLongBuffer(BUFFERS_SIZE);
+
+ floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
+ doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE);
+
+ pointers = BufferUtils.createPointerBuffer(BUFFERS_SIZE);
+ }
+
+ }
+
+ /** Simple interface for Field filtering */
+ interface TokenFilter {
+
+ /** Should return true if the specified Field passes the filter. */
+ boolean accept(Field field, int value);
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java b/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java
new file mode 100644
index 00000000..f69284d6
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Utility class that provides CLContextCallback implementations that use
+ * the APPLE_ContextLoggingFunctions callback functions.
+ *
+ * TODO: Test this class
+ *
+ * @author Spasi
+ */
+public final class APPLEContextLoggingUtil {
+
+ /** Sends all log messages to the Apple System Logger. */
+ public static final CLContextCallback SYSTEM_LOG_CALLBACK;
+
+ /** Sends all log messages to the file descriptor stdout. */
+ public static final CLContextCallback STD_OUT_CALLBACK;
+
+ /** Sends all log messages to the file descriptor stderr. */
+ public static final CLContextCallback STD_ERR_CALLBACK;
+
+ static {
+ if ( CLCapabilities.isExtensionSupported("CL_APPLE_ContextLoggingFunctions") ) {
+ SYSTEM_LOG_CALLBACK = new CLContextCallback(CallbackUtil.getLogMessageToSystemLogAPPLE()) {
+ protected void handleMessage(final String errinfo, final ByteBuffer private_info) { throw new UnsupportedOperationException(); }
+ };
+
+ STD_OUT_CALLBACK = new CLContextCallback(CallbackUtil.getLogMessageToStdoutAPPLE()) {
+ protected void handleMessage(final String errinfo, final ByteBuffer private_info) { throw new UnsupportedOperationException(); }
+ };
+
+ STD_ERR_CALLBACK = new CLContextCallback(CallbackUtil.getLogMessageToStderrAPPLE()) {
+ protected void handleMessage(final String errinfo, final ByteBuffer private_info) { throw new UnsupportedOperationException(); }
+ };
+ } else {
+ SYSTEM_LOG_CALLBACK = null;
+ STD_OUT_CALLBACK = null;
+ STD_ERR_CALLBACK = null;
+ }
+ }
+
+ private APPLEContextLoggingUtil() {}
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CL.java b/src/java/org/lwjgl/opencl/CL.java
new file mode 100644
index 00000000..981d6c19
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CL.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.Sys;
+
+/**
+ * LWJGL users must use this class to initialize OpenCL
+ * before using any other class in the org.lwjgl.opencl package.
+ *
+ * @author Spasi
+ */
+public final class CL {
+
+ private static boolean created;
+
+ static {
+ Sys.initialize();
+ }
+
+ private CL() {
+ }
+
+ /**
+ * Native method to create CL instance
+ *
+ * @param oclPaths Array of strings containing paths to search for OpenCL library
+ */
+ private static native void nCreate(String oclPaths) throws LWJGLException;
+
+ /**
+ * Native method to create CL instance from the Mac OS X 10.4 OpenCL framework.
+ * It is only defined in the Mac OS X native library.
+ */
+ private static native void nCreateDefault() throws LWJGLException;
+
+ /** Native method the destroy the CL */
+ private static native void nDestroy();
+
+ /** @return true if CL has been created */
+ public static boolean isCreated() {
+ return created;
+ }
+
+ public static void create() throws LWJGLException {
+ if ( created )
+ return;
+ //throw new IllegalStateException("OpenCL has already been created.");
+
+ final String libname;
+ final String[] library_names;
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ libname = "OpenCL";
+ library_names = new String[] { "OpenCL.dll" };
+ break;
+ case LWJGLUtil.PLATFORM_LINUX:
+ libname = "OpenCL";
+ library_names = new String[] { "libOpenCL64.so", "libOpenCL.so" }; // TODO: Fix this
+ break;
+ case LWJGLUtil.PLATFORM_MACOSX:
+ libname = "OpenCL";
+ library_names = new String[] { "OpenCL.dylib" }; // TODO: Fix this
+ break;
+ default:
+ throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
+ }
+
+ final String[] oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
+ LWJGLUtil.log("Found " + oclPaths.length + " OpenCL paths");
+ for ( int i = 0; i < oclPaths.length; i++ ) {
+ try {
+ nCreate(oclPaths[i]);
+ created = true;
+ break;
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to load " + oclPaths[i] + ": " + e.getMessage());
+ }
+ }
+
+ if ( !created && LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX ) {
+ // Try to load OpenCL from the framework instead
+ nCreateDefault();
+ created = true;
+ }
+
+ if ( !created )
+ throw new LWJGLException("Could not locate OpenCL library.");
+
+ if ( !CLCapabilities.isExtensionSupported("OpenCL10") )
+ throw new RuntimeException("OpenCL 1.0 not supported.");
+ }
+
+ public static void destroy() {
+ }
+
+ /**
+ * Helper method to get a pointer to a named function with aliases in the OpenCL library.
+ *
+ * @param aliases the function name aliases.
+ *
+ * @return the function pointer address
+ */
+ static long getFunctionAddress(String[] aliases) {
+ for ( int i = 0; i < aliases.length; i++ ) {
+ long address = getFunctionAddress(aliases[i]);
+ if ( address != 0 )
+ return address;
+ }
+ return 0;
+ }
+
+ static native long getFunctionAddress(String name);
+
+ private static native void resetNativeStubs(Class clazz);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java b/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java
new file mode 100644
index 00000000..0da9c7b0
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Instances of this class can be used to receive OpenCL program build notifications.
+ *
+ * @author Spasi
+ */
+public abstract class CLBuildProgramCallback extends CLCallback {
+
+ protected CLBuildProgramCallback() {
+ super(CallbackUtil.getBuildProgramCallback());
+ }
+
+ /**
+ * Called from native code.
+ *
+ * @param program_address the CLProgram object pointer
+ */
+ private void handleMessage(long program_address) {
+ handleMessage(CLContext.getCLProgramGlobal(program_address));
+ }
+
+ /**
+ * The callback method.
+ *
+ * @param program the CLProgram object that was built
+ */
+ protected abstract void handleMessage(CLProgram program);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLCallback.java b/src/java/org/lwjgl/opencl/CLCallback.java
new file mode 100644
index 00000000..48aa024b
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLCallback.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Base class for OpenCL callback objects.
+ *
+ * @author Spasi
+ */
+abstract class CLCallback extends PointerWrapperAbstract {
+
+ private final boolean custom;
+
+ protected CLCallback(final long pointer) {
+ this(pointer, false);
+ }
+
+ protected CLCallback(final long pointer, final boolean custom) {
+ super(pointer);
+
+ this.custom = custom;
+ }
+
+ final boolean isCustom() {
+ return custom;
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLChecks.java b/src/java/org/lwjgl/opencl/CLChecks.java
new file mode 100644
index 00000000..c1606fff
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLChecks.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Utility class that provides runtime checks for OpenCL method calls.
+ * TODO: Revisit this when Java 7.0 is released, there will be new Buffer API with 64bit indices/sizes.
+ *
+ * @author Spasi
+ */
+final class CLChecks {
+
+ private CLChecks() {
+ }
+
+ /**
+ * Calculates the number of bytes in the specified cl_mem buffer rectangle region.
+ *
+ * @param origin the host origin
+ * @param region the rectangle region
+ * @param row_pitch the host row pitch
+ * @param slice_pitch the host slice pitch
+ *
+ * @return the region size in bytes
+ */
+ static int calculateBufferRectSize(final PointerBuffer origin, final PointerBuffer region, long row_pitch, long slice_pitch) {
+ if ( !LWJGLUtil.CHECKS )
+ return 0;
+
+ final long x = origin.get(0);
+ final long y = origin.get(1);
+ final long z = origin.get(2);
+
+ if ( x < 0 || y < 0 || z < 0 )
+ throw new IllegalArgumentException("Invalid cl_mem host origin: " + x + ", " + y + ", " + z);
+
+ final long w = region.get(0);
+ final long h = region.get(1);
+ final long d = region.get(2);
+
+ if ( w < 1 || h < 1 || d < 1 )
+ throw new IllegalArgumentException("Invalid cl_mem rectangle region dimensions: " + w + " x " + h + " x " + d);
+
+ if ( row_pitch == 0 )
+ row_pitch = w;
+ else if ( row_pitch < w )
+ throw new IllegalArgumentException("Invalid host row pitch specified: " + row_pitch);
+
+ if ( slice_pitch == 0 )
+ slice_pitch = row_pitch * h;
+ else if ( slice_pitch < (row_pitch * h) )
+ throw new IllegalArgumentException("Invalid host slice pitch specified: " + slice_pitch);
+
+ return (int)((z * slice_pitch + y * row_pitch + x) + (w * h * d));
+ }
+
+ /**
+ * Calculates the number of bytes in the specified cl_mem image region.
+ * This implementation assumes 1 byte per element, because we cannot the
+ * image type.
+ *
+ * @param region the image region
+ * @param row_pitch the row pitch
+ * @param slice_pitch the slice pitch
+ *
+ * @return the region size in bytes
+ */
+ static int calculateImageSize(final PointerBuffer region, long row_pitch, long slice_pitch) {
+ if ( !LWJGLUtil.CHECKS )
+ return 0;
+
+ final long w = region.get(0);
+ final long h = region.get(1);
+ final long d = region.get(2);
+
+ if ( w < 1 || h < 1 || d < 1 )
+ throw new IllegalArgumentException("Invalid cl_mem image region dimensions: " + w + " x " + h + " x " + d);
+
+ if ( row_pitch == 0 )
+ row_pitch = w;
+ else if ( row_pitch < w )
+ throw new IllegalArgumentException("Invalid row pitch specified: " + row_pitch);
+
+ if ( slice_pitch == 0 )
+ slice_pitch = row_pitch * h;
+ else if ( slice_pitch < (row_pitch * h) )
+ throw new IllegalArgumentException("Invalid slice pitch specified: " + slice_pitch);
+
+ return (int)(slice_pitch * d);
+
+ }
+
+ /**
+ * Calculates the number of bytes in the specified 2D image.
+ *
+ * @param format the cl_image_format struct
+ * @param w the image width
+ * @param h the image height
+ * @param row_pitch the image row pitch
+ *
+ * @return the 2D image size in bytes
+ */
+ static int calculateImage2DSize(final ByteBuffer format, final long w, final long h, long row_pitch) {
+ if ( LWJGLUtil.CHECKS && (w < 1 || h < 1) )
+ throw new IllegalArgumentException("Invalid 2D image dimensions: " + w + " x " + h);
+
+ final int elementSize = getElementSize(format);
+
+ if ( row_pitch == 0 )
+ row_pitch = w * elementSize;
+ else if ( LWJGLUtil.CHECKS && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) )
+ throw new IllegalArgumentException("Invalid image_row_pitch specified: " + row_pitch);
+
+ return (int)(row_pitch * h);
+ }
+
+ /**
+ * Calculates the number of bytes in the specified 3D image.
+ *
+ * @param format the cl_image_format struct
+ * @param w the image width
+ * @param h the image height
+ * @param d the image depth
+ * @param row_pitch the image row pitch
+ * @param slice_pitch the image slice pitch
+ *
+ * @return the 3D image size in bytes
+ */
+ static int calculateImage3DSize(final ByteBuffer format, final long w, final long h, final long d, long row_pitch, long slice_pitch) {
+ if ( LWJGLUtil.CHECKS && (w < 1 || h < 1 || d < 2) )
+ throw new IllegalArgumentException("Invalid 3D image dimensions: " + w + " x " + h + " x " + d);
+
+ final int elementSize = getElementSize(format);
+
+ if ( row_pitch == 0 )
+ row_pitch = w * elementSize;
+ else if ( LWJGLUtil.CHECKS && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) )
+ throw new IllegalArgumentException("Invalid image_row_pitch specified: " + row_pitch);
+
+ if ( slice_pitch == 0 )
+ slice_pitch = row_pitch * h;
+ else if ( LWJGLUtil.CHECKS && ((row_pitch < row_pitch * h) || (slice_pitch % row_pitch != 0)) )
+ throw new IllegalArgumentException("Invalid image_slice_pitch specified: " + row_pitch);
+
+ return (int)(slice_pitch * d);
+ }
+
+ /**
+ * Returns the number of bytes per element for the specified image format.
+ *
+ * @param format a cl_image_format struct.
+ *
+ * @return the number of bytes per image element
+ */
+ private static int getElementSize(final ByteBuffer format) {
+ final int channelOrder = format.getInt(format.position() + 0);
+ final int channelType = format.getInt(format.position() + 4);
+
+ return getChannelCount(channelOrder) * getChannelSize(channelType);
+ }
+
+ /**
+ * Returns the number of channels in the specified cl_channel_order.
+ *
+ * @param channelOrder the cl_channel_order
+ *
+ * @return the number of channels
+ */
+ private static int getChannelCount(final int channelOrder) {
+ switch ( channelOrder ) {
+ case CL10.CL_R:
+ case CL10.CL_A:
+ case CL10.CL_INTENSITY:
+ case CL10.CL_LUMINANCE:
+ case CL11.CL_Rx:
+ return 1;
+ case CL10.CL_RG:
+ case CL10.CL_RA:
+ case CL11.CL_RGx:
+ return 2;
+ case CL10.CL_RGB:
+ case CL11.CL_RGBx:
+ return 3;
+ case CL10.CL_RGBA:
+ case CL10.CL_BGRA:
+ case CL10.CL_ARGB:
+ return 4;
+ default:
+ throw new IllegalArgumentException("Invalid cl_channel_order specified: 0x" + Integer.toHexString(channelOrder).toUpperCase());
+ }
+ }
+
+ /**
+ * Returns the number of bytes in the specified cl_channel_type.
+ *
+ * @param channelType the cl_channel_type
+ *
+ * @return the number of bytes
+ */
+ private static int getChannelSize(final int channelType) {
+ switch ( channelType ) {
+ case CL10.CL_SNORM_INT8:
+ case CL10.CL_UNORM_INT8:
+ case CL10.CL_SIGNED_INT8:
+ case CL10.CL_UNSIGNED_INT8:
+ return 1;
+ case CL10.CL_SNORM_INT16:
+ case CL10.CL_UNORM_INT16:
+ case CL10.CL_UNORM_SHORT_565:
+ case CL10.CL_UNORM_SHORT_555:
+ case CL10.CL_SIGNED_INT16:
+ case CL10.CL_UNSIGNED_INT16:
+ case CL10.CL_HALF_FLOAT:
+ return 2;
+ case CL10.CL_UNORM_INT_101010:
+ case CL10.CL_SIGNED_INT32:
+ case CL10.CL_UNSIGNED_INT32:
+ case CL10.CL_FLOAT:
+ return 4;
+ default:
+ throw new IllegalArgumentException("Invalid cl_channel_type specified: 0x" + Integer.toHexString(channelType).toUpperCase());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLCommandQueue.java b/src/java/org/lwjgl/opencl/CLCommandQueue.java
new file mode 100644
index 00000000..f972b00e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLCommandQueue.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+
+/**
+ * This class is a wrapper around a cl_command_queue pointer.
+ *
+ * @author Spasi
+ */
+public final class CLCommandQueue extends CLObjectChild {
+
+ private final CLDevice device;
+
+ private final CLObjectRegistry clEvents;
+
+ CLCommandQueue(final long pointer, final CLContext context, final CLDevice device) {
+ super(pointer, context);
+ if ( isValid() ) {
+ this.device = device;
+ this.clEvents = new CLObjectRegistryGlobal(CLContext.clEventsGlobal);
+ context.getCLCommandQueueRegistry().registerObject(this);
+ } else {
+ this.device = null;
+ this.clEvents = null;
+ }
+ }
+
+ public CLDevice getCLDevice() {
+ return device;
+ }
+
+ /**
+ * Returns a CLEvent associated with this command-queue.
+ *
+ * @param id the event object id
+ *
+ * @return the CLEvent object
+ */
+ public CLEvent getCLEvent(final long id) {
+ return clEvents.getObject(id);
+ }
+
+ // -------[ IMPLEMENTATION STUFF BELOW ]-------
+
+ CLObjectRegistry getCLEventRegistry() { return clEvents; }
+
+ /**
+ * Called from OpenCL methods that generate CLEvents.
+ *
+ * @param event a buffer containing a CLEvent pointer.
+ */
+ void registerCLEvent(final PointerBuffer event) {
+ if ( event != null )
+ new CLEvent(event.get(event.position()), this);
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().getCLCommandQueueRegistry().unregisterObject(this);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLContext.java b/src/java/org/lwjgl/opencl/CLContext.java
new file mode 100644
index 00000000..d36c9466
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLContext.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This class is a wrapper around a cl_context pointer.
+ *
+ * @author Spasi
+ */
+public final class CLContext extends CLObject {
+
+ private final CLObjectRegistry clCommandQueues;
+ private final CLObjectRegistry clMems;
+ private final CLObjectRegistry clSamplers;
+ private final CLObjectRegistry clPrograms;
+ private final CLObjectRegistry clEvents;
+
+ /** Global registry for build callbacks. */
+ static Map clProgramsGlobal = new HashMap();
+
+ /** Global registry for event callbacks. */
+ static Map clEventsGlobal = new HashMap();
+
+ CLContext(final long pointer) {
+ super(pointer);
+
+ if ( isValid() ) {
+ clCommandQueues = new CLObjectRegistry();
+ clMems = new CLObjectRegistry();
+ clSamplers = new CLObjectRegistry();
+ clPrograms = new CLObjectRegistryGlobal(clProgramsGlobal);
+ clEvents = new CLObjectRegistryGlobal(clEventsGlobal);
+ } else {
+ clCommandQueues = null;
+ clMems = null;
+ clSamplers = null;
+ clPrograms = null;
+ clEvents = null;
+ }
+ }
+
+ /**
+ * Returns a CLCommandQueue associated with this context.
+ *
+ * @param id the command queue object id
+ *
+ * @return the CLCommandQueue object
+ */
+ public CLCommandQueue getCLCommandQueue(final long id) { return clCommandQueues.getObject(id); }
+
+ /**
+ * Returns a CLMem associated with this context.
+ *
+ * @param id the memory object id
+ *
+ * @return the CLMem object
+ */
+ public CLMem getCLMem(final long id) { return clMems.getObject(id); }
+
+ /**
+ * Returns a CLSampler associated with this context.
+ *
+ * @param id the sampler object id
+ *
+ * @return the CLSampler object
+ */
+ public CLSampler getCLSampler(final long id) { return clSamplers.getObject(id); }
+
+ /**
+ * Returns a CLProgram associated with this context.
+ *
+ * @param id the program object id
+ *
+ * @return the CLProgram object
+ */
+ public CLProgram getCLProgram(final long id) { return clPrograms.getObject(id); }
+
+ /**
+ * Returns a user CLEvent associated with this context.
+ *
+ * @param id the event object id
+ *
+ * @return the CLEvent object
+ */
+ public CLEvent getCLEvent(final long id) { return clEvents.getObject(id); }
+
+ // -------[ IMPLEMENTATION STUFF BELOW ]-------
+
+ CLObjectRegistry getCLCommandQueueRegistry() { return clCommandQueues; }
+
+ CLObjectRegistry getCLMemRegistry() { return clMems; }
+
+ CLObjectRegistry getCLSamplerRegistry() { return clSamplers; }
+
+ CLObjectRegistry getCLProgramRegistry() { return clPrograms; }
+
+ CLObjectRegistry getCLEventRegistry() { return clEvents; }
+
+ static CLProgram getCLProgramGlobal(final long id) { return clProgramsGlobal.get(id); }
+
+ static CLEvent getCLEventGlobal(final long id) { return clEventsGlobal.get(id); }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLContextCallback.java b/src/java/org/lwjgl/opencl/CLContextCallback.java
new file mode 100644
index 00000000..ab33b709
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLContextCallback.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Instances of this class can be used to receive OpenCL context error notifications.
+ *
+ * @author Spasi
+ */
+public abstract class CLContextCallback extends PointerWrapperAbstract {
+
+ private final boolean custom;
+
+ protected CLContextCallback() {
+ super(CallbackUtil.getContextCallback());
+ custom = false;
+ }
+
+ /**
+ * This constructor allows non-LWJGL implementations.
+ *
+ * @param pointer
+ */
+ protected CLContextCallback(final long pointer) {
+ super(pointer);
+
+ if ( pointer == 0 )
+ throw new RuntimeException("Invalid callback function pointer specified.");
+
+ custom = true;
+ }
+
+ final boolean isCustom() {
+ return custom;
+ }
+
+ /**
+ * The callback method.
+ *
+ * @param errinfo the error description
+ * @param private_info optional error data (may be null)
+ */
+ protected abstract void handleMessage(String errinfo, ByteBuffer private_info);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLDevice.java b/src/java/org/lwjgl/opencl/CLDevice.java
new file mode 100644
index 00000000..a978b1c1
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLDevice.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+
+/**
+ * This class is a wrapper around a cl_device_id pointer.
+ *
+ * @author Spasi
+ */
+public final class CLDevice extends CLObjectChild {
+
+ private static final CLDeviceImpl impl = (CLDeviceImpl)CLPlatform.getClassInstance("org.lwjgl.opencl.CLDeviceImpl");
+
+ private final CLObjectRegistry subCLDevices;
+
+ private Object caps;
+
+ public CLDevice(final long pointer) {
+ this(pointer, null);
+ }
+
+ /**
+ * EXT_device_fission constructor.
+ *
+ * @param pointer the sub-device pointer
+ * @param parent the parent CLDevice
+ */
+ CLDevice(final long pointer, final CLDevice parent) {
+ super(pointer, parent);
+
+ if ( isValid() ) {
+ subCLDevices = new CLObjectRegistry();
+ if ( parent != null )
+ parent.subCLDevices.registerObject(this);
+ } else
+ subCLDevices = null;
+ }
+
+ void setCapabilities(final Object caps) {
+ this.caps = caps;
+ }
+
+ Object getCapabilities() {
+ return caps;
+ }
+
+ /**
+ * Returns a sub-device of this device.
+ *
+ * @param id the sub-device object id
+ *
+ * @return the CLDevice object
+ */
+ public CLDevice getSubCLDevice(final long id) { return subCLDevices.getObject(id); }
+
+ int retain() {
+ if ( getParent() == null )
+ return getReferenceCount(); // NO-OP, root devices cannot be retained
+
+ return super.retain();
+ }
+
+ int release() {
+ if ( getParent() == null )
+ return getReferenceCount(); // NO-OP, root devices cannot be released
+
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().subCLDevices.unregisterObject(this);
+ }
+ }
+
+ CLObjectRegistry getSubCLDeviceRegistry() { return subCLDevices; }
+
+ /**
+ * Called from clCreateSubDevicesEXT to register new sub-devices.
+ *
+ * @param devices a buffer containing CLDevice pointers.
+ */
+ void registerSubCLDevices(final PointerBuffer devices) {
+ for ( int i = devices.position(); i < devices.limit(); i++ ) {
+ final long pointer = devices.get(i);
+ if ( pointer != 0 )
+ new CLDevice(pointer, this);
+ }
+ }
+
+ // ---------------[ HELPER METHODS ]---------------
+
+ /**
+ * Returns the value of the specified String parameter.
+ *
+ * @param param_name the parameter
+ *
+ * @return the parameter value
+ */
+ public String getInfoString(int param_name) {
+ return impl.getInfoString(this, param_name);
+ }
+
+ /**
+ * Returns the integer value of the specified parameter.
+ *
+ * @param param_name the parameter
+ *
+ * @return the parameter value
+ */
+ public int getInfoInt(int param_name) {
+ return impl.getInfoInt(this, param_name);
+ }
+
+ /**
+ * Returns the boolean value of the specified parameter.
+ *
+ * @param param_name the parameter
+ *
+ * @return the parameter value
+ */
+ public boolean getInfoBoolean(int param_name) {
+ return impl.getInfoInt(this, param_name) != 0;
+ }
+
+ /**
+ * Returns the size_t value of the specified parameter.
+ *
+ * @param param_name the parameter
+ *
+ * @return the parameter value
+ */
+ public long getInfoSize(int param_name) {
+ return impl.getInfoSize(this, param_name);
+ }
+
+ /**
+ * Returns the long value of the specified parameter. Can be used
+ * for both cl_ulong and cl_bitfield parameters.
+ *
+ * @param param_name the parameter
+ *
+ * @return the parameter value
+ */
+ public long getInfoLong(int param_name) {
+ return impl.getInfoLong(this, param_name);
+ }
+
+ /** CLDevice helper methods implementation interface. */
+ interface CLDeviceImpl {
+
+ String getInfoString(CLDevice device, int param_name);
+
+ int getInfoInt(CLDevice device, int param_name);
+
+ long getInfoSize(CLDevice device, int param_name);
+
+ long getInfoLong(CLDevice device, int param_name);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLDeviceImpl.java b/src/java/org/lwjgl/opencl/CLDeviceImpl.java
new file mode 100644
index 00000000..26e5d15a
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLDeviceImpl.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+
+import java.nio.ByteBuffer;
+
+import static org.lwjgl.opencl.CL10.*;
+
+/**
+ * Implementation of CLDevice helper methods.
+ *
+ * @author Spasi
+ */
+final class CLDeviceImpl implements CLDevice.CLDeviceImpl {
+
+ CLDeviceImpl() {
+ }
+
+ static CLDeviceCapabilities getCapabilities(final CLDevice device) {
+ device.checkValid();
+
+ CLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();
+ if ( caps == null )
+ device.setCapabilities(caps = new CLDeviceCapabilities(device));
+
+ return caps;
+ }
+
+ private static int getInfoBytes(final CLDevice device, final int param_name) {
+ final PointerBuffer bytes = APIUtil.getBufferPointer();
+ clGetDeviceInfo(device, param_name, null, bytes);
+ return (int)bytes.get(0);
+ }
+
+ public String getInfoString(final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final int bytes = getInfoBytes(device, param_name);
+
+ final ByteBuffer versionBuffer = APIUtil.getBufferByte(bytes);
+ clGetDeviceInfo(device, param_name, versionBuffer, null);
+
+ versionBuffer.limit(bytes - 1); // Exclude null-termination
+ return APIUtil.getString(versionBuffer);
+ }
+
+ public int getInfoInt(final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final ByteBuffer versionBuffer = APIUtil.getBufferByte(4);
+ clGetDeviceInfo(device, param_name, versionBuffer, null);
+
+ return versionBuffer.getInt(0);
+ }
+
+ public long getInfoSize(final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final PointerBuffer pointerBuffer = APIUtil.getBufferPointer();
+ clGetDeviceInfo(device, param_name, pointerBuffer.getBuffer(), null);
+
+ return pointerBuffer.get(0);
+ }
+
+ public long getInfoLong(final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final ByteBuffer versionBuffer = APIUtil.getBufferByte(8);
+ clGetDeviceInfo(device, param_name, versionBuffer, null);
+
+ return versionBuffer.getLong(0);
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLEvent.java b/src/java/org/lwjgl/opencl/CLEvent.java
new file mode 100644
index 00000000..d5dc6b13
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLEvent.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * This class is a wrapper around a cl_mem pointer.
+ *
+ * @author Spasi
+ */
+public final class CLEvent extends CLObjectChild {
+
+ private final CLCommandQueue queue;
+
+ CLEvent(final long pointer, final CLContext context) {
+ this(pointer, context, null);
+ }
+
+ CLEvent(final long pointer, final CLCommandQueue queue) {
+ this(pointer, queue.getParent(), queue);
+ }
+
+ CLEvent(final long pointer, final CLContext context, final CLCommandQueue queue) {
+ super(pointer, context);
+ if ( isValid() ) {
+ this.queue = queue;
+ if ( queue == null )
+ context.getCLEventRegistry().registerObject(this);
+ else
+ queue.getCLEventRegistry().registerObject(this);
+ } else
+ this.queue = null;
+ }
+
+ /**
+ * Returns the command-queue associated with this event. For
+ * user events this method returns null.
+ *
+ * @return the command-queue or null if this is a user event
+ */
+ public CLCommandQueue getCLCommandQueue() {
+ return queue;
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() ) {
+ if ( queue == null )
+ getParent().getCLEventRegistry().unregisterObject(this);
+ else
+ queue.getCLEventRegistry().unregisterObject(this);
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLEventCallback.java b/src/java/org/lwjgl/opencl/CLEventCallback.java
new file mode 100644
index 00000000..43bb6651
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLEventCallback.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * Instances of this class can be used to receive OpenCL memory object destruction notifications.
+ *
+ * @author Spasi
+ */
+public abstract class CLEventCallback extends CLCallback {
+
+ protected CLEventCallback() {
+ super(CallbackUtil.getEventCallback());
+ }
+
+ /**
+ * Called from native code.
+ *
+ * @param event_address the CLEvent object pointer
+ */
+ private void handleMessage(long event_address, int event_command_exec_status) {
+ handleMessage(CLContext.getCLEventGlobal(event_address), event_command_exec_status);
+ }
+
+ /**
+ * The callback method.
+ *
+ * @param event the CLEvent object
+ */
+ protected abstract void handleMessage(CLEvent event, int event_command_exec_status);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLFunctionAddress.java b/src/java/org/lwjgl/opencl/CLFunctionAddress.java
new file mode 100644
index 00000000..77f2c956
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLFunctionAddress.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * This class is a wrapper around an OpenCL extension function pointer.
+ *
+ * @author Spasi
+ */
+final class CLFunctionAddress extends PointerWrapperAbstract {
+
+ CLFunctionAddress(final long pointer) {
+ super(pointer);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLKernel.java b/src/java/org/lwjgl/opencl/CLKernel.java
new file mode 100644
index 00000000..6b272260
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLKernel.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapper;
+
+/**
+ * This class is a wrapper around a cl_kernel pointer.
+ *
+ * @author Spasi
+ */
+public final class CLKernel extends CLObjectChild {
+
+ private static final CLKernelImpl impl = (CLKernelImpl)CLPlatform.getClassInstance("org.lwjgl.opencl.CLKernelImpl");
+
+ CLKernel(final long pointer, final CLProgram program) {
+ super(pointer, program);
+ if ( isValid() )
+ program.getCLKernelRegistry().registerObject(this);
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().getCLKernelRegistry().unregisterObject(this);
+ }
+ }
+
+ public CLKernel setArg(final int index, final byte value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final short value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final int value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final long value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final float value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final double value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ public CLKernel setArg(final int index, final PointerWrapper value) {
+ impl.setArg(this, index, value);
+ return this;
+ }
+
+ interface CLKernelImpl {
+
+ void setArg(CLKernel clKernel, int index, byte value);
+
+ void setArg(CLKernel clKernel, int index, short value);
+
+ void setArg(CLKernel clKernel, int index, int value);
+
+ void setArg(CLKernel clKernel, int index, long value);
+
+ void setArg(CLKernel clKernel, int index, float value);
+
+ void setArg(CLKernel clKernel, int index, double value);
+
+ void setArg(CLKernel clKernel, int index, PointerWrapper pointer);
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLKernelImpl.java b/src/java/org/lwjgl/opencl/CLKernelImpl.java
new file mode 100644
index 00000000..fc2f3695
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLKernelImpl.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.PointerWrapper;
+
+import static org.lwjgl.opencl.CL10.*;
+
+/**
+ * Implementation of CLKernel helper methods.
+ *
+ * @author Spasi
+ */
+final class CLKernelImpl implements CLKernel.CLKernelImpl {
+
+ CLKernelImpl() {
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final byte value) {
+ clSetKernelArg(clKernel, index, 1, APIUtil.getBufferByte(1).put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final short value) {
+ clSetKernelArg(clKernel, index, 2, APIUtil.getBufferShort().put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final int value) {
+ clSetKernelArg(clKernel, index, 4, APIUtil.getBufferInt().put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final long value) {
+ clSetKernelArg(clKernel, index, 8, APIUtil.getBufferLong().put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final float value) {
+ clSetKernelArg(clKernel, index, 4, APIUtil.getBufferFloat().put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final double value) {
+ clSetKernelArg(clKernel, index, 8, APIUtil.getBufferDouble().put(0, value));
+ }
+
+ public void setArg(final CLKernel clKernel, final int index, final PointerWrapper pointer) {
+ clSetKernelArg(clKernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer());
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLMem.java b/src/java/org/lwjgl/opencl/CLMem.java
new file mode 100644
index 00000000..e94cf7da
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLMem.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * This class is a wrapper around a cl_mem pointer.
+ *
+ * @author Spasi
+ */
+public final class CLMem extends CLObjectChild {
+
+ CLMem(final long pointer, final CLContext context) {
+ super(pointer, context);
+ if ( isValid() )
+ context.getCLMemRegistry().registerObject(this);
+ }
+
+ static CLMem create(final long pointer, final CLContext context) {
+ CLMem clMem = context.getCLMemRegistry().getObject(pointer);
+ if ( clMem == null )
+ clMem = new CLMem(pointer, context);
+ else
+ clMem.retain();
+
+ return clMem;
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().getCLMemRegistry().unregisterObject(this);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java b/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java
new file mode 100644
index 00000000..9e84fd2e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * Instances of this class can be used to receive OpenCL memory object destruction notifications.
+ *
+ * @author Spasi
+ */
+public abstract class CLMemObjectDestructorCallback extends CLCallback {
+
+ protected CLMemObjectDestructorCallback() {
+ super(CallbackUtil.getMemObjectDestructorCallback());
+ }
+
+ /**
+ * The callback method.
+ *
+ * @param memobj id of the CLMem object that was destroyed
+ */
+ protected abstract void handleMessage(long memobj);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLNativeKernel.java b/src/java/org/lwjgl/opencl/CLNativeKernel.java
new file mode 100644
index 00000000..f1375355
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLNativeKernel.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Instances of this class can be used to execute native kernels. clEnqueueNativeKernel will build
+ * the its arguments automatically, in a way that allows execute to receive an array
+ * of ByteBuffers, pointing to cl_mem objects in global memory. The ByteBuffer objects should not
+ * be used outside the handleMessage method.
+ *
+ * @author Spasi
+ * @see CL10#clEnqueueNativeKernel
+ * @see #execute(java.nio.ByteBuffer[])
+ */
+public abstract class CLNativeKernel extends CLCallback {
+
+ protected CLNativeKernel() {
+ super(CallbackUtil.getNativeKernelCallback());
+ }
+
+ /**
+ * Implement this method to execute an action on cl_mem objects in global memory.
+ *
+ * @param memobjs an array of ByteBuffers pointing to cl_mem global memory.
+ */
+ protected abstract void execute(ByteBuffer[] memobjs);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLObject.java b/src/java/org/lwjgl/opencl/CLObject.java
new file mode 100644
index 00000000..3377456c
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLObject.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerWrapperAbstract;
+
+/**
+ * Base class for all retainable OpenCL objects.
+ *
+ * @author Spasi
+ */
+abstract class CLObject extends PointerWrapperAbstract {
+
+ private int refCount;
+
+ CLObject(final long pointer) {
+ super(pointer);
+
+ if ( pointer != 0 )
+ this.refCount = 1;
+ }
+
+ public final int getReferenceCount() {
+ return refCount;
+ }
+
+ public final boolean isValid() {
+ return refCount > 0;
+ }
+
+ public final long getPointer() {
+ checkValid();
+ return super.getPointer();
+ }
+
+ final long getPointerUnsafe() {
+ return super.getPointer();
+ }
+
+ int retain() {
+ checkValid();
+ //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount + 1));
+ return ++refCount;
+ }
+
+ int release() {
+ checkValid();
+ //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount - 1));
+ return --refCount;
+ }
+
+ final void checkValid() {
+ checkNull();
+ if ( LWJGLUtil.DEBUG && refCount == 0 )
+ throw new IllegalStateException("This CL object is invalid.");
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLObjectChild.java b/src/java/org/lwjgl/opencl/CLObjectChild.java
new file mode 100644
index 00000000..c3b8b219
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLObjectChild.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.LWJGLUtil;
+
+/**
+ * Base class for all CLObjects that are associated with a parent CLObject.
+ *
+ * @author Spasi
+ */
+abstract class CLObjectChild
extends CLObject {
+
+ private final P parent;
+
+ CLObjectChild(final long pointer, final P parent) {
+ super(pointer);
+
+ if ( LWJGLUtil.DEBUG && parent != null && !parent.isValid() )
+ throw new IllegalStateException("The parent specified is not a valid CL object.");
+
+ this.parent = parent;
+ }
+
+ public P getParent() {
+ return parent;
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLObjectRegistry.java b/src/java/org/lwjgl/opencl/CLObjectRegistry.java
new file mode 100644
index 00000000..0641983e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLObjectRegistry.java
@@ -0,0 +1,55 @@
+package org.lwjgl.opencl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A CLContextObject container.
+ *
+ * @author Spasi
+ */
+class CLObjectRegistry {
+
+ private Map registry;
+
+ CLObjectRegistry() {
+ }
+
+ final boolean isEmpty() {
+ return registry == null || registry.isEmpty();
+ }
+
+ final T getObject(final long id) {
+ return registry == null ? null : registry.get(id);
+ }
+
+ final boolean hasObject(final long id) {
+ return registry != null && registry.containsKey(id);
+ }
+
+ final List getAll() {
+ return registry == null ? null : new ArrayList(registry.values());
+ }
+
+ void registerObject(final T object) {
+ final Map map = getMap();
+ final Long key = object.getPointer();
+
+ if ( !map.containsKey(key) )
+ getMap().put(object.getPointer(), object);
+ }
+
+ void unregisterObject(final T object) {
+ getMap().remove(object.getPointerUnsafe());
+ }
+
+ private Map getMap() {
+ if ( registry == null )
+ registry = new HashMap();
+
+ return registry;
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java b/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java
new file mode 100644
index 00000000..24267314
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import java.util.Map;
+
+/**
+ * A CLObject registry that also registers/unregisters objects to/from a global registry.
+ *
+ * @author Spasi
+ */
+final class CLObjectRegistryGlobal extends CLObjectRegistry {
+
+ private final Map globalRegistry;
+
+ CLObjectRegistryGlobal(final Map globalRegistry) {
+ this.globalRegistry = globalRegistry;
+ }
+
+ void registerObject(final T object) {
+ super.registerObject(object);
+ globalRegistry.put(object.getPointer(), object);
+ }
+
+ void unregisterObject(final T object) {
+ super.unregisterObject(object);
+ globalRegistry.remove(object.getPointerUnsafe());
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLPlatform.java b/src/java/org/lwjgl/opencl/CLPlatform.java
new file mode 100644
index 00000000..65880a15
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLPlatform.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerWrapperAbstract;
+import org.lwjgl.opencl.api.Filter;
+
+import java.util.List;
+
+/**
+ * This class is a wrapper around a cl_platform_id pointer.
+ *
+ * @author Spasi
+ */
+public final class CLPlatform extends PointerWrapperAbstract {
+
+ private static final CLPlatformImpl impl = (CLPlatformImpl)getClassInstance("org.lwjgl.opencl.CLPlatformImpl");
+
+ private Object caps;
+
+ public CLPlatform(final long pointer) {
+ super(pointer);
+ }
+
+ void setCapabilities(final Object caps) {
+ this.caps = caps;
+ }
+
+ Object getCapabilities() {
+ return caps;
+ }
+
+ // ---------------[ HELPER METHODS ]---------------
+
+ static Object getClassInstance(final String className) {
+ Object instance = null;
+ try {
+ instance = Class.forName(className).newInstance();
+ } finally {
+ return instance;
+ }
+ }
+
+ public static List getPlatforms() {
+ return getPlatforms(null);
+ }
+
+ public static List getPlatforms(final Filter filter) {
+ return impl.getPlatforms(filter);
+ }
+
+ public String getInfoString(int param_name) {
+ return impl.getInfoString(this, param_name);
+ }
+
+ public List getDevices(final int device_type) {
+ return getDevices(device_type, null);
+ }
+
+ public List getDevices(final int device_type, final Filter filter) {
+ return impl.getDevices(this, device_type, filter);
+ }
+
+ /** CLPlatform helper methods implementation interface. */
+ interface CLPlatformImpl {
+
+ List getPlatforms(Filter filter);
+
+ String getInfoString(CLPlatform platform, int param_name);
+
+ List getDevices(CLPlatform platform, int device_type, final Filter filter);
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLPlatformImpl.java b/src/java/org/lwjgl/opencl/CLPlatformImpl.java
new file mode 100644
index 00000000..967a0b4e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLPlatformImpl.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.opencl.api.Filter;
+
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.lwjgl.opencl.CL10.*;
+
+/**
+ * Implementation of CLPlatform helper methods.
+ *
+ * @author Spasi
+ */
+final class CLPlatformImpl implements CLPlatform.CLPlatformImpl {
+
+ CLPlatformImpl() {
+ }
+
+ static CLPlatformCapabilities getCapabilities(final CLPlatform platform) {
+ platform.checkNull();
+
+ CLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();
+ if ( caps == null )
+ platform.setCapabilities(caps = new CLPlatformCapabilities(platform));
+
+ return caps;
+ }
+
+ public List getPlatforms(final Filter filter) {
+ final IntBuffer numBuffer = APIUtil.getBufferInt();
+ clGetPlatformIDs(null, numBuffer);
+
+ final int num_platforms = numBuffer.get(0);
+ if ( num_platforms == 0 )
+ return null;
+
+ final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
+ clGetPlatformIDs(platformIDs, null);
+
+ final List platforms = new ArrayList(num_platforms);
+ for ( int i = 0; i < num_platforms; i++ ) {
+ final CLPlatform platform = new CLPlatform(platformIDs.get(i));
+ if ( filter == null || filter.accept(platform) )
+ platforms.add(platform);
+ }
+
+ return platforms.size() == 0 ? null : platforms;
+ }
+
+ public String getInfoString(final CLPlatform platform, final int param_name) {
+ platform.checkNull();
+
+ final PointerBuffer bytes = APIUtil.getBufferPointer();
+ clGetPlatformInfo(platform, param_name, null, bytes);
+
+ final ByteBuffer versionBuffer = APIUtil.getBufferByte((int)bytes.get(0));
+ clGetPlatformInfo(platform, param_name, versionBuffer, null);
+
+ versionBuffer.limit((int)bytes.get(0) - 1); // Exclude null-termination
+ return APIUtil.getString(versionBuffer);
+ }
+
+ public List getDevices(final CLPlatform platform, final int device_type, final Filter filter) {
+ platform.checkNull();
+
+ final IntBuffer numBuffer = APIUtil.getBufferInt();
+ clGetDeviceIDs(platform, device_type, null, numBuffer);
+
+ final int num_devices = numBuffer.get(0);
+ if ( num_devices == 0 )
+ return null;
+
+ final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
+ clGetDeviceIDs(platform, device_type, deviceIDs, null);
+
+ final List devices = new ArrayList(num_devices);
+ for ( int i = 0; i < num_devices; i++ ) {
+ final CLDevice device = new CLDevice(deviceIDs.get(i));
+ if ( filter == null || filter.accept(device) )
+ devices.add(device);
+ }
+
+ return devices.size() == 0 ? null : devices;
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLProgram.java b/src/java/org/lwjgl/opencl/CLProgram.java
new file mode 100644
index 00000000..f50d4e56
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLProgram.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+
+import java.io.Serializable;
+
+/**
+ * This class is a wrapper around a cl_program pointer.
+ *
+ * @author Spasi
+ */
+public final class CLProgram extends CLObjectChild {
+
+ private final CLObjectRegistry clKernels;
+
+ CLProgram(final long pointer, final CLContext context) {
+ super(pointer, context);
+
+ if ( isValid() ) {
+ context.getCLProgramRegistry().registerObject(this);
+ clKernels = new CLObjectRegistry();
+ } else
+ clKernels = null;
+ }
+
+ /**
+ * Returns a CLKernel associated with this program.
+ *
+ * @param id the kernel id
+ *
+ * @return the CLKernel object
+ */
+ public CLKernel getCLKernel(final long id) {
+ return clKernels.getObject(id);
+ }
+
+ // -------[ IMPLEMENTATION STUFF BELOW ]-------
+
+ CLObjectRegistry getCLKernelRegistry() { return clKernels; }
+
+ /**
+ * Called from clCreateKernelsInProgram to register new CLKernels.
+ *
+ * @param kernels a buffer containing CLKernel pointers.
+ */
+ void registerCLKernels(final PointerBuffer kernels) {
+ for ( int i = kernels.position(); i < kernels.limit(); i++ ) {
+ final long pointer = kernels.get(i);
+ if ( pointer != 0 )
+ new CLKernel(pointer, this);
+ }
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().getCLProgramRegistry().unregisterObject(this);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLSampler.java b/src/java/org/lwjgl/opencl/CLSampler.java
new file mode 100644
index 00000000..2b25d674
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CLSampler.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * This class is a wrapper around a cl_sampler pointer.
+ *
+ * @author Spasi
+ */
+public final class CLSampler extends CLObjectChild {
+
+ CLSampler(final long pointer, final CLContext context) {
+ super(pointer, context);
+ if ( isValid() )
+ context.getCLSamplerRegistry().registerObject(this);
+ }
+
+ int release() {
+ try {
+ return super.release();
+ } finally {
+ if ( !isValid() )
+ getParent().getCLSamplerRegistry().unregisterObject(this);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CallbackUtil.java b/src/java/org/lwjgl/opencl/CallbackUtil.java
new file mode 100644
index 00000000..f83798fd
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/CallbackUtil.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility class that handles OpenCL API callbacks.
+ *
+ * @author Spasi
+ */
+final class CallbackUtil {
+
+ private static final Map contextUserData = new HashMap();
+
+ private CallbackUtil() {}
+
+ /**
+ * Creates a new global reference to the specified Object.
+ *
+ * @param obj the Object
+ *
+ * @return the GlobalRef memory address or 0 if the Object is null.
+ */
+ static long createGlobalRef(final Object obj) {
+ return obj == null ? 0 : ncreateGlobalRef(obj);
+ }
+
+ /**
+ * Creates a new global reference to the specified Object.
+ *
+ * @param obj the Object
+ *
+ * @return the GlobalRef memory address.
+ */
+ private static native long ncreateGlobalRef(Object obj);
+
+ /**
+ * Deletes a global reference.
+ *
+ * @param ref the GlobalRef memory address.
+ */
+ private static native void deleteGlobalRef(long ref);
+
+ /**
+ * Deletes the global reference represented by user_data if an OpenCL error occured.
+ *
+ * @param errcode the error code
+ * @param user_data the GlobalRef memory address
+ */
+ static void checkCallback(final int errcode, final long user_data) {
+ if ( errcode != 0x0 && user_data != 0 )
+ deleteGlobalRef(user_data);
+ }
+
+ /* [ Context callback functionality ]
+ This is a little weird, so here's an explanation of what's happening for future reference:
+ Before making the clCreateContext call we create a global reference to the CLContextCallback object (using JNI's NewGlobalRef function).
+ We pass that global reference to the user_data parameter of clCreateContext. If clCreateContext returns anything but CL_SUCCESS, we
+ immediately destroy the global reference to avoid the memory leak. If the new context was created successfully, we associate the context
+ with the global reference in the contextUserData HashMap. On a future call to clReleaseContext, we clear that association and destroy the
+ global reference (if the reference count is 0).
+ */
+
+ /**
+ * Returns the memory address of the native function we pass to clCreateContext(FromType).
+ *
+ * @return the callback function address
+ */
+ static native long getContextCallback();
+
+ /**
+ * Associates the specified CLContext with the specified global reference. If the context
+ * is invalid, the global reference is deleted. NO-OP if user_data is 0.
+ *
+ * @param context the CLContext to register
+ * @param user_data the global reference pointer
+ */
+ static void registerCallback(final CLContext context, final long user_data) {
+ if ( context.getPointer() == 0 ) {
+ if ( user_data != 0 )
+ deleteGlobalRef(user_data);
+ return;
+ }
+
+ if ( user_data != 0 )
+ contextUserData.put(context, user_data);
+ }
+
+ /**
+ * Decrements the specified context's reference count, clears its association
+ * with a CLContextCallback object if it exists and deletes the corresponding
+ * global reference.
+ *
+ * @param context the CLContext to unregister
+ */
+ static void unregisterCallback(final CLContext context) {
+ if ( context.release() > 0 )
+ return;
+
+ final Long user_data = contextUserData.remove(context);
+
+ if ( user_data != null )
+ deleteGlobalRef(user_data);
+ }
+
+ /* [ Other callback functionality ]
+ The other callbacks are simpler. We create the GlobalRef before passing the callback,
+ we delete it when we receive the callback call.
+ */
+
+ /**
+ * Returns the memory address of the native function we pass to clSetMemObjectDestructorCallback.
+ *
+ * @return the callback function address
+ */
+ static native long getMemObjectDestructorCallback();
+
+ /**
+ * Returns the memory address of the native function we pass to clBuildProgram.
+ *
+ * @return the callback function address
+ */
+ static native long getBuildProgramCallback();
+
+ /**
+ * Returns the memory address of the native function we pass to clEnqueueNativeKernel.
+ *
+ * @return the callback function address
+ */
+ static native long getNativeKernelCallback();
+
+ /**
+ * Returns the memory address of the native function we pass to clSetEventCallback.
+ *
+ * @return the callback function address
+ */
+ static native long getEventCallback();
+
+ /**
+ * Returns the memory address of the native function we pass to clCreateContext(FromType),
+ * when APPLEContextLoggingUtil.SYSTEM_LOG_CALLBACK is used.
+ *
+ * @return the callback function address
+ *
+ * @see APPLEContextLoggingUtil#SYSTEM_LOG_CALLBACK
+ */
+ static native long getLogMessageToSystemLogAPPLE();
+
+ /**
+ * Returns the memory address of the native function we pass to clCreateContext(FromType),
+ * when APPLEContextLoggingUtil.STD_OUT_CALLBACK is used.
+ *
+ * @return the callback function address
+ *
+ * @see APPLEContextLoggingUtil#STD_OUT_CALLBACK
+ */
+ static native long getLogMessageToStdoutAPPLE();
+
+ /**
+ * Returns the memory address of the native function we pass to clCreateContext(FromType),
+ * when APPLEContextLoggingUtil.STD_ERR_CALLBACK is used.
+ *
+ * @return the callback function address
+ *
+ * @see APPLEContextLoggingUtil#STD_ERR_CALLBACK
+ */
+ static native long getLogMessageToStderrAPPLE();
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/OpenCLException.java b/src/java/org/lwjgl/opencl/OpenCLException.java
new file mode 100644
index 00000000..fe1e9038
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/OpenCLException.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+public class OpenCLException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OpenCLException() {
+ super();
+ }
+
+ public OpenCLException(final String message) {
+ super(message);
+ }
+
+ public OpenCLException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ public OpenCLException(final Throwable cause) {
+ super(cause);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/Util.java b/src/java/org/lwjgl/opencl/Util.java
new file mode 100644
index 00000000..848b5357
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/Util.java
@@ -0,0 +1,76 @@
+/*
+ * 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.opencl;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility methods for OpenCL
+ *
+ * @author Spasi
+ */
+public final class Util {
+
+ /** Maps OpenCL error token values to their String representations. */
+ private static final Map CL_ERROR_TOKENS = new HashMap(64);
+
+ static {
+ APIUtil.getClassTokens(new Class[] {
+ CL10.class, CL11.class,
+ KHRGLSharing.class, KHRICD.class,
+ APPLEGLSharing.class,
+ EXTDeviceFission.class,
+ }, CL_ERROR_TOKENS, new APIUtil.TokenFilter() {
+ public boolean accept(final Field field, final int value) {
+ return value < 0; // Currently, all OpenCL errors have negative values.
+ }
+ });
+ }
+
+ private Util() {
+ }
+
+ public static void checkCLError(final int errcode) {
+ if ( errcode != CL10.CL_SUCCESS )
+ throwCLError(errcode);
+ }
+
+ private static void throwCLError(final int errcode) {
+ String errname = CL_ERROR_TOKENS.get(errcode);
+ if ( errname == null )
+ errname = "UNKNOWN";
+ throw new OpenCLException("Error Code: " + errname + " (0x" + Integer.toHexString(errcode).toUpperCase() + ")");
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/api/Filter.java b/src/java/org/lwjgl/opencl/api/Filter.java
new file mode 100644
index 00000000..6f7db60c
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/api/Filter.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.lwjgl.opencl.api;
+
+/**
+ * Simple filter interface.
+ *
+ * @author Spasi
+ */
+public interface Filter {
+
+ /**
+ * Returns true if the specified object passes the filter.
+ *
+ * @param object the object to test
+ *
+ * @return true if the object is accepted
+ */
+ boolean accept(T object);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
index 6ff3b9d3..1146839c 100644
--- a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
+++ b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
@@ -31,6 +31,8 @@
*/
package org.lwjgl.opengl;
+import org.lwjgl.PointerWrapperAbstract;
+
/**
* Instances of this class are needed to use the callback functionality of the AMD_debug_output extension.
* A debug context must be current before creating instances of this class. Users of this class may provide
@@ -39,7 +41,7 @@ package org.lwjgl.opengl;
*
* @author Spasi
*/
-public final class AMDDebugOutputCallback implements PointerWrapper {
+public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
/** Severity levels. */
private static final int GL_DEBUG_SEVERITY_HIGH_AMD = 0x9146,
@@ -56,7 +58,7 @@ public final class AMDDebugOutputCallback implements PointerWrapper {
GL_DEBUG_CATEGORY_APPLICATION_AMD = 0x914F,
GL_DEBUG_CATEGORY_OTHER_AMD = 0x9150;
- private final long pointer;
+ private final Handler handler;
/**
* Creates an AMDDebugOutputCallback with a default callback handler.
@@ -120,30 +122,31 @@ public final class AMDDebugOutputCallback implements PointerWrapper {
}
/**
- * Creates an AMDDebugOutputCallback with the specified callback handlers.
+ * Creates an AMDDebugOutputCallback with the specified callback handler.
* The handler's {@code handleMessage} method will be called whenever
* debug output is generated by the GL.
*
* @param handler the callback handler
*/
public AMDDebugOutputCallback(final Handler handler) {
+ super(getFunctionPointer());
+
+ this.handler = handler;
+ }
+
+ Handler getHandler() {
+ return handler;
+ }
+
+ private static long getFunctionPointer() {
try {
- // We have to call registerHandler reflectively because we need this class to compile before we run the Generator.
- // The registerHandler method depends on org.lwjgl.opengl.Context, if we touched that we would need to compile
- // the whole library (which is not possible).
- Class.forName("org.lwjgl.opengl.AMDDebugOutputUtil").getMethod("registerHandler", new Class[] { Handler.class }).invoke(null, new Object[] { handler });
+ // Call reflectively so that we can compile this class for the Generator.
+ return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackAMD", null).invoke(null, null)).longValue();
} catch (Exception e) {
throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
}
- this.pointer = getFunctionPointer();
}
- public long getPointer() {
- return pointer;
- }
-
- private static native long getFunctionPointer();
-
/** Implementations of this interface can be used to receive AMD_debug_output notifications. */
public interface Handler {
diff --git a/src/java/org/lwjgl/opengl/AMDDebugOutputUtil.java b/src/java/org/lwjgl/opengl/AMDDebugOutputUtil.java
deleted file mode 100644
index 38f7d901..00000000
--- a/src/java/org/lwjgl/opengl/AMDDebugOutputUtil.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.lwjgl.opengl;
-
-import org.lwjgl.opengl.AMDDebugOutputCallback.Handler;
-
-import java.nio.ByteBuffer;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * This class handles AMDDebugOutputCallback.Handler registration and notification.
- * We could have put this in AMDDebugOutputCallback, but we need to compile it for
- * the generator. Registration is done reflectively in the AMDDebugOutputCallback
- * constructor.
- *
- * @author Spasi
- */
-final class AMDDebugOutputUtil {
-
- private static final Map handlers = new WeakHashMap();
-
- private AMDDebugOutputUtil() {}
-
- public static void registerHandler(final Handler handler) {
- final Context ctx = Context.getCurrentContext();
- if ( ctx == null )
- throw new IllegalStateException("No context is current.");
-
- if ( !ctx.getContextAttribs().isDebug() )
- throw new IllegalStateException("The current context is not a debug context.");
-
- if ( !GLContext.getCapabilities().GL_AMD_debug_output )
- throw new IllegalStateException("AMD_debug_output is not supported.");
-
- handlers.put(ctx, handler);
- }
-
- /**
- * This method is called by native code. If finds the callback handler associated
- * with the current Thread and calls its {@code handleMessage} method.
- *
- * @param id the message ID
- * @param category the message category
- * @param severity the message severity
- * @param message the string representation of the message.
- * @param userParam the user-specified data specified in glDebugMessageCallbackAMD. For the current implementation this is always null and we ignore it.
- */
- private static void messageCallback(final int id, final int category, final int severity, final String message, final ByteBuffer userParam) {
- synchronized ( GlobalLock.lock ) {
- final Context ctx = Context.getCurrentContext();
- if ( ctx == null )
- return;
-
- final Handler handler = (Handler)handlers.get(ctx);
- if ( handler != null )
- handler.handleMessage(id, category, severity, message);
- }
- }
-
-}
diff --git a/src/java/org/lwjgl/opengl/APIUtils.java b/src/java/org/lwjgl/opengl/APIUtil.java
similarity index 99%
rename from src/java/org/lwjgl/opengl/APIUtils.java
rename to src/java/org/lwjgl/opengl/APIUtil.java
index 51ded17e..d3584317 100644
--- a/src/java/org/lwjgl/opengl/APIUtils.java
+++ b/src/java/org/lwjgl/opengl/APIUtil.java
@@ -38,7 +38,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
/** @author spasi */
-final class APIUtils {
+final class APIUtil {
private static final int INITIAL_BUFFER_SIZE = 256;
private static final int INITIAL_LENGTHS_SIZE = 4;
@@ -67,7 +67,7 @@ final class APIUtils {
private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
- private APIUtils() {
+ private APIUtil() {
}
private static char[] getArray(final int size) {
diff --git a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
index 69bf1db2..2602d5b2 100644
--- a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
+++ b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
@@ -31,6 +31,8 @@
*/
package org.lwjgl.opengl;
+import org.lwjgl.PointerWrapperAbstract;
+
/**
* Instances of this class are needed to use the callback functionality of the ARB_debug_output extension.
* A debug context must be current before creating instances of this class. Users of this class may provide
@@ -39,7 +41,7 @@ package org.lwjgl.opengl;
*
* @author Spasi
*/
-public final class ARBDebugOutputCallback implements PointerWrapper {
+public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
/** Severity levels. */
private static final int
@@ -65,7 +67,7 @@ public final class ARBDebugOutputCallback implements PointerWrapper {
GL_DEBUG_TYPE_PERFORMANCE_ARB = 0x8250,
GL_DEBUG_TYPE_OTHER_ARB = 0x8251;
- private final long pointer;
+ private final Handler handler;
/**
* Creates an ARBDebugOutputCallback with a default callback handler.
@@ -147,35 +149,36 @@ public final class ARBDebugOutputCallback implements PointerWrapper {
}
/**
- * Creates an ARBDebugOutputCallback with the specified callback handlers.
+ * Creates an ARBDebugOutputCallback with the specified callback handler.
* The handler's {@code handleMessage} method will be called whenever
* debug output is generated by the GL.
*
* @param handler the callback handler
*/
public ARBDebugOutputCallback(final Handler handler) {
+ super(getFunctionPointer());
+
+ this.handler = handler;
+ }
+
+ Handler getHandler() {
+ return handler;
+ }
+
+ private static long getFunctionPointer() {
try {
- // We have to call registerHandler reflectively because we need this class to compile before we run the Generator.
- // The registerHandler method depends on org.lwjgl.opengl.Context, if we touched that we would need to compile
- // the whole library (which is not possible).
- Class.forName("org.lwjgl.opengl.ARBDebugOutputUtil").getMethod("registerHandler", new Class[] { Handler.class }).invoke(null, new Object[] { handler });
+ // Call reflectively so that we can compile this class for the Generator.
+ return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackARB", null).invoke(null, null)).longValue();
} catch (Exception e) {
throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
}
- this.pointer = getFunctionPointer();
}
- public long getPointer() {
- return pointer;
- }
-
- private static native long getFunctionPointer();
-
/** Implementations of this interface can be used to receive ARB_debug_output notifications. */
public interface Handler {
/**
- * This method will be called when an AMD_debug_output message is generated.
+ * This method will be called when an ARB_debug_output message is generated.
*
* @param id the message ID
* @param source the message source
diff --git a/src/java/org/lwjgl/opengl/ARBDebugOutputUtil.java b/src/java/org/lwjgl/opengl/ARBDebugOutputUtil.java
deleted file mode 100644
index e59ac05d..00000000
--- a/src/java/org/lwjgl/opengl/ARBDebugOutputUtil.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.lwjgl.opengl;
-
-import org.lwjgl.opengl.ARBDebugOutputCallback.Handler;
-
-import java.nio.ByteBuffer;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * This class handles ARBDebugOutputCallback.Handler registration and notification.
- * We could have put this in ARBDebugOutputCallback, but we need to compile it for
- * the generator. Registration is done reflectively in the ARBDebugOutputCallback
- * constructor.
- *
- * @author Spasi
- */
-final class ARBDebugOutputUtil {
-
- private static final Map handlers = new WeakHashMap();
-
- private ARBDebugOutputUtil() {}
-
- public static void registerHandler(final Handler handler) {
- final Context ctx = Context.getCurrentContext();
- if ( ctx == null )
- throw new IllegalStateException("No context is current.");
-
- if ( !ctx.getContextAttribs().isDebug() )
- throw new IllegalStateException("The current context is not a debug context.");
-
- if ( !GLContext.getCapabilities().GL_ARB_debug_output )
- throw new IllegalStateException("ARB_debug_output is not supported.");
-
- handlers.put(ctx, handler);
- }
-
- /**
- * This method is called by native code. If finds the callback handler associated
- * with the current Thread and calls its {@code handleMessage} method.
- *
- * @param source the message source
- * @param type the message type
- * @param id the message ID
- * @param severity the message severity
- * @param message the string representation of the message.
- * @param userParam the user-specified data specified in glDebugMessageCallbackAMD. For the current implementation this is always null and we ignore it.
- */
- private static void messageCallback(final int source, final int type, final int id, final int severity, final String message, final ByteBuffer userParam) {
- synchronized ( GlobalLock.lock ) {
- final Context ctx = Context.getCurrentContext();
- if ( ctx == null )
- return;
-
- final Handler handler = (Handler)handlers.get(ctx);
- if ( handler != null )
- handler.handleMessage(source, type, id, severity, message);
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/AWTGLCanvas.java b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
index 39bd9be0..d5e433d8 100644
--- a/src/java/org/lwjgl/opengl/AWTGLCanvas.java
+++ b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
@@ -33,6 +33,7 @@ package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
import org.lwjgl.Sys;
import java.awt.*;
@@ -258,6 +259,14 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
}
}
+ public final void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ synchronized ( SYNC_LOCK ) {
+ if ( context == null )
+ throw new IllegalStateException("Canvas not yet displayable");
+ context.setCLSharingProperties(properties);
+ }
+ }
+
/**
* Override this to do initialising of the context.
* It will be called once from paint(), immediately after
diff --git a/src/java/org/lwjgl/opengl/AbstractDrawable.java b/src/java/org/lwjgl/opengl/AbstractDrawable.java
index 18778a86..88235973 100644
--- a/src/java/org/lwjgl/opengl/AbstractDrawable.java
+++ b/src/java/org/lwjgl/opengl/AbstractDrawable.java
@@ -2,6 +2,7 @@ package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
/**
* @author Spasi
@@ -73,6 +74,13 @@ abstract class AbstractDrawable implements DrawableLWJGL {
}
}
+ public void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ synchronized ( GlobalLock.lock ) {
+ checkDestroyed();
+ context.setCLSharingProperties(properties);
+ }
+ }
+
protected final void checkDestroyed() {
if ( context == null )
throw new IllegalStateException("The Drawable has no context available.");
diff --git a/src/java/org/lwjgl/opengl/CallbackUtil.java b/src/java/org/lwjgl/opengl/CallbackUtil.java
new file mode 100644
index 00000000..728ece3e
--- /dev/null
+++ b/src/java/org/lwjgl/opengl/CallbackUtil.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opengl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility class that handles OpenGL API callbacks.
+ *
+ * @author Spasi
+ */
+final class CallbackUtil {
+
+ /** Context -> Long */
+ private static final Map contextUserParamsARB = new HashMap();
+ /** Context -> Long */
+ private static final Map contextUserParamsAMD = new HashMap();
+
+ private CallbackUtil() {}
+
+ /**
+ * Creates a new global reference to the specified Object.
+ *
+ * @param obj the Object
+ *
+ * @return the GlobalRef memory address or 0 if the Object is null.
+ */
+ static long createGlobalRef(final Object obj) {
+ return obj == null ? 0 : ncreateGlobalRef(obj);
+ }
+
+ /**
+ * Creates a new global reference to the specified Object.
+ *
+ * @param obj the Object
+ *
+ * @return the GlobalRef memory address.
+ */
+ private static native long ncreateGlobalRef(Object obj);
+
+ /**
+ * Deletes a global reference.
+ *
+ * @param ref the GlobalRef memory address.
+ */
+ private static native void deleteGlobalRef(long ref);
+
+ // --------- [ XXX_debug_output ] ---------
+
+ /**
+ * Associates the current OpenGL context with the specified global reference. If there
+ * is no context current, the global reference is deleted and an exception is thrown.
+ * Any previous callback registrations will be cleared.
+ *
+ * @param userParam the global reference pointer
+ */
+ private static void registerContextCallback(final long userParam, final Map contextUserData) {
+ Context context = Context.getCurrentContext();
+ if ( context == null ) {
+ deleteGlobalRef(userParam);
+ throw new IllegalStateException("No context is current.");
+ }
+
+ final Long userParam_old = (Long)contextUserData.remove(context);
+ if ( userParam_old != null )
+ deleteGlobalRef(userParam_old.longValue());
+
+ if ( userParam != 0 )
+ contextUserData.put(context, new Long(userParam));
+ }
+
+ /**
+ * Releases references to any callbacks associated with the specified GL context.
+ *
+ * @param context the Context to unregister
+ */
+ static void unregisterCallbacks(final Context context) {
+ Long userParam = (Long)contextUserParamsARB.remove(context);
+ if ( userParam != null )
+ deleteGlobalRef(userParam.longValue());
+
+ userParam = (Long)contextUserParamsAMD.remove(context);
+ if ( userParam != null )
+ deleteGlobalRef(userParam.longValue());
+ }
+
+ // --------- [ ARB_debug_output ] ---------
+
+ /**
+ * Returns the memory address of the native function we pass to glDebugMessageCallbackARB.
+ *
+ * @return the callback function address
+ */
+ static native long getDebugOutputCallbackARB();
+
+ /**
+ * Associates the current OpenGL context with the specified global reference. If there
+ * is no context current, the global reference is deleted and an exception is thrown.
+ * Any previous callback registrations will be cleared.
+ *
+ * @param userParam the global reference pointer
+ */
+ static void registerContextCallbackARB(final long userParam) {
+ registerContextCallback(userParam, contextUserParamsARB);
+ }
+
+ // --------- [ AMD_debug_output ] ---------
+
+ /**
+ * Returns the memory address of the native function we pass to glDebugMessageCallbackAMD.
+ *
+ * @return the callback function address
+ */
+ static native long getDebugOutputCallbackAMD();
+
+ /**
+ * Associates the current OpenGL context with the specified global reference. If there
+ * is no context current, the global reference is deleted and an exception is thrown.
+ * Any previous callback registrations will be cleared.
+ *
+ * @param userParam the global reference pointer
+ */
+ static void registerContextCallbackAMD(final long userParam) {
+ registerContextCallback(userParam, contextUserParamsAMD);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/Context.java b/src/java/org/lwjgl/opengl/Context.java
index fa15faa1..fa9d0074 100644
--- a/src/java/org/lwjgl/opengl/Context.java
+++ b/src/java/org/lwjgl/opengl/Context.java
@@ -33,7 +33,9 @@ package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.PointerBuffer;
import org.lwjgl.Sys;
+import org.lwjgl.opencl.KHRGLSharing;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -52,10 +54,10 @@ import java.nio.IntBuffer;
final class Context {
/** The platform specific implementation of context methods */
- private final static ContextImplementation implementation;
+ private static final ContextImplementation implementation;
/** The current Context */
- private final static ThreadLocal current_context_local = new ThreadLocal();
+ private static final ThreadLocal current_context_local = new ThreadLocal();
/** Handle to the native GL rendering context */
private final ByteBuffer handle;
@@ -206,6 +208,7 @@ final class Context {
try {
releaseDrawable();
implementation.destroy(peer_info, handle);
+ CallbackUtil.unregisterCallbacks(this);
destroyed = true;
thread = null;
GLContext.unloadOpenGLLibrary();
@@ -256,4 +259,26 @@ final class Context {
throw new OpenGLException(error);
}
+ public synchronized void setCLSharingProperties(final PointerBuffer properties) throws LWJGLException {
+ final ByteBuffer peer_handle = peer_info.lockAndGetHandle();
+ try {
+ switch ( LWJGLUtil.getPlatform() ) {
+ case LWJGLUtil.PLATFORM_WINDOWS:
+ final WindowsContextImplementation implWindows = (WindowsContextImplementation)implementation;
+ properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implWindows.getHGLRC(handle));
+ properties.put(KHRGLSharing.CL_WGL_HDC_KHR).put(implWindows.getHDC(peer_handle));
+ break;
+ case LWJGLUtil.PLATFORM_LINUX:
+ final LinuxContextImplementation implLinux = (LinuxContextImplementation)implementation;
+ properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implLinux.getGLXContext(handle));
+ properties.put(KHRGLSharing.CL_GLX_DISPLAY_KHR).put(implLinux.getDisplay(peer_handle));
+ break;
+ default:
+ throw new UnsupportedOperationException("CL/GL context sharing is not supposed on this platform.");
+ }
+ } finally {
+ peer_info.unlock();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/ContextAttribs.java b/src/java/org/lwjgl/opengl/ContextAttribs.java
index 3c0ad6ec..c87e39ff 100644
--- a/src/java/org/lwjgl/opengl/ContextAttribs.java
+++ b/src/java/org/lwjgl/opengl/ContextAttribs.java
@@ -57,6 +57,8 @@ import java.nio.IntBuffer;
public final class ContextAttribs {
// Same values for GLX & WGL
+ private static final int CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
+
private static final int CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004;
private static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256;
private static final int
@@ -74,6 +76,7 @@ public final class ContextAttribs {
private boolean profileCore;
private boolean profileCompatibility;
+ private boolean profileES;
private boolean loseContextOnReset;
@@ -106,6 +109,7 @@ public final class ContextAttribs {
this.profileCore = attribs.profileCore;
this.profileCompatibility = attribs.profileCompatibility;
+ this.profileES = attribs.profileES;
this.loseContextOnReset = attribs.loseContextOnReset;
}
@@ -138,6 +142,10 @@ public final class ContextAttribs {
return profileCompatibility;
}
+ public boolean isProfileES() {
+ return profileES;
+ }
+
public ContextAttribs withLayer(final int layerPlane) {
if ( layerPlane < 0 )
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
@@ -198,6 +206,19 @@ public final class ContextAttribs {
return attribs;
}
+ public ContextAttribs withProfileES(final boolean profileES) {
+ if ( !(majorVersion == 2 && minorVersion == 0) )
+ throw new IllegalArgumentException("The OpenGL ES profiles is only supported for OpenGL version 2.0.");
+
+ if ( profileES == this.profileES )
+ return this;
+
+ final ContextAttribs attribs = new ContextAttribs(this);
+ attribs.profileES = profileES;
+
+ return attribs;
+ }
+
/**
* Returns a ContextAttribs instance with CONTEXT_RESET_NOTIFICATION_STRATEGY set
* to LOSE_CONTEXT_ON_RESET if the parameter is true or to NO_RESET_NOTIFICATION
@@ -254,6 +275,8 @@ public final class ContextAttribs {
profileMask |= implementation.getProfileCoreBit();
else if ( profileCompatibility )
profileMask |= implementation.getProfileCompatibilityBit();
+ else if ( profileES )
+ profileMask |= CONTEXT_ES2_PROFILE_BIT_EXT;
if ( 0 < profileMask )
attribCount++;
diff --git a/src/java/org/lwjgl/opengl/Drawable.java b/src/java/org/lwjgl/opengl/Drawable.java
index 84327aa2..d5fdc4b8 100644
--- a/src/java/org/lwjgl/opengl/Drawable.java
+++ b/src/java/org/lwjgl/opengl/Drawable.java
@@ -32,6 +32,7 @@
package org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
+import org.lwjgl.PointerBuffer;
/**
* The Drawable interface describes an OpenGL drawable with an associated
@@ -62,4 +63,15 @@ public interface Drawable {
/** Destroys the Drawable. */
void destroy();
+ /**
+ * Sets the appropriate khr_gl_sharing properties in the target PointerBuffer,
+ * so that if it is used in a clCreateContext(FromType) call, the created CL
+ * context will be sharing objects with this Drawable's GL context. After a
+ * call to this method, the target buffer position will have advanced by 2 to 4 positions,
+ * depending on the implementation.
+ *
+ * @param properties The target properties buffer. It must have at least 4 positions remaining.
+ */
+ void setCLSharingProperties(PointerBuffer properties) throws LWJGLException;
+
}
diff --git a/src/java/org/lwjgl/opengl/GLSync.java b/src/java/org/lwjgl/opengl/GLSync.java
index 721990e0..f9166b09 100644
--- a/src/java/org/lwjgl/opengl/GLSync.java
+++ b/src/java/org/lwjgl/opengl/GLSync.java
@@ -31,19 +31,17 @@
*/
package org.lwjgl.opengl;
+import org.lwjgl.PointerWrapperAbstract;
+
/**
+ * This class is a wrapper around a GLsync pointer.
+ *
* @author spasi
*/
-public final class GLSync implements PointerWrapper {
-
- private final long sync;
+public final class GLSync extends PointerWrapperAbstract {
GLSync(final long sync) {
- this.sync = sync;
- }
-
- public long getPointer() {
- return sync;
+ super(sync);
}
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
index 48feedb8..f64c9723 100644
--- a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
+++ b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
@@ -59,6 +59,10 @@ final class LinuxContextImplementation implements ContextImplementation {
private static native ByteBuffer nCreate(ByteBuffer peer_handle, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException;
+ native long getGLXContext(ByteBuffer context_handle);
+
+ native long getDisplay(ByteBuffer peer_info_handle);
+
public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException {
}
diff --git a/src/java/org/lwjgl/opengl/WindowsContextImplementation.java b/src/java/org/lwjgl/opengl/WindowsContextImplementation.java
index c0169667..a835506b 100644
--- a/src/java/org/lwjgl/opengl/WindowsContextImplementation.java
+++ b/src/java/org/lwjgl/opengl/WindowsContextImplementation.java
@@ -55,6 +55,10 @@ final class WindowsContextImplementation implements ContextImplementation {
private static native ByteBuffer nCreate(ByteBuffer peer_handle, IntBuffer attribs_handle, ByteBuffer shared_context_handle) throws LWJGLException;
+ native long getHGLRC(ByteBuffer context_handle);
+
+ native long getHDC(ByteBuffer peer_info_handle);
+
public void swapBuffers() throws LWJGLException {
Context current_context = Context.getCurrentContext();
if ( current_context == null )
diff --git a/src/java/org/lwjgl/test/opencl/HelloOpenCL.java b/src/java/org/lwjgl/test/opencl/HelloOpenCL.java
new file mode 100644
index 00000000..76c5725c
--- /dev/null
+++ b/src/java/org/lwjgl/test/opencl/HelloOpenCL.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.test.opencl;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLException;
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.opencl.*;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import static org.lwjgl.opencl.CL10.*;
+import static org.lwjgl.opencl.CL11.*;
+
+/** Basic OpenCL test. */
+public class HelloOpenCL {
+
+ public HelloOpenCL() {
+ }
+
+ protected void execute() {
+ try {
+ CL.create();
+
+ final List platforms = CLPlatform.getPlatforms();
+ for ( CLPlatform platform : platforms ) {
+ System.out.println("\n-------------------------");
+ System.out.println("NEW PLATFORM: " + platform.getPointer());
+ System.out.println(CLCapabilities.getPlatformCapabilities(platform));
+ System.out.println("-------------------------");
+ printPlatformInfo(platform, "CL_PLATFORM_PROFILE", CL_PLATFORM_PROFILE);
+ printPlatformInfo(platform, "CL_PLATFORM_VERSION", CL_PLATFORM_VERSION);
+ printPlatformInfo(platform, "CL_PLATFORM_NAME", CL_PLATFORM_NAME);
+ printPlatformInfo(platform, "CL_PLATFORM_VENDOR", CL_PLATFORM_VENDOR);
+ System.out.println("");
+
+ final PointerBuffer ctxProps = BufferUtils.createPointerBuffer(3);
+ ctxProps.put(CL_CONTEXT_PLATFORM).put(platform.getPointer()).put(0).flip();
+
+ final List devices = platform.getDevices(CL_DEVICE_TYPE_ALL);
+ for ( CLDevice device : devices ) {
+ System.out.println("\n\tNEW DEVICE: " + device.getPointer());
+ System.out.println(CLCapabilities.getDeviceCapabilities(device));
+ System.out.println("\t-------------------------");
+
+ System.out.println("\tCL_DEVICE_TYPE = " + device.getInfoInt(CL_DEVICE_TYPE));
+ System.out.println("\tCL_DEVICE_VENDOR_ID = " + device.getInfoInt(CL_DEVICE_VENDOR_ID));
+ System.out.println("\tCL_DEVICE_MAX_COMPUTE_UNITS = " + device.getInfoInt(CL_DEVICE_MAX_COMPUTE_UNITS));
+ System.out.println("\tCL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = " + device.getInfoInt(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS));
+ //CL10.clGetDeviceInfo(device, CL10.CL_DEVICE_MAX_WORK_ITEM_SIZES, info, size_ret);
+ //System.out.println("\tCL_DEVICE_MAX_WORK_ITEM_SIZES = " + info.getInt(0));
+ System.out.println("\tCL_DEVICE_MAX_WORK_GROUP_SIZE = " + device.getInfoSize(CL_DEVICE_MAX_WORK_GROUP_SIZE));
+ System.out.println("\tCL_DEVICE_MAX_CLOCK_FREQUENCY = " + device.getInfoInt(CL_DEVICE_MAX_CLOCK_FREQUENCY));
+ System.out.println("\tCL_DEVICE_ADDRESS_BITS = " + device.getInfoInt(CL_DEVICE_ADDRESS_BITS));
+ System.out.println("\tCL_DEVICE_AVAILABLE = " + device.getInfoBoolean(CL_DEVICE_AVAILABLE));
+ System.out.println("\tCL_DEVICE_COMPILER_AVAILABLE = " + device.getInfoBoolean(CL_DEVICE_COMPILER_AVAILABLE));
+
+ printDeviceInfo(device, "CL_DEVICE_NAME", CL_DEVICE_NAME);
+ printDeviceInfo(device, "CL_DEVICE_VENDOR", CL_DEVICE_VENDOR);
+ printDeviceInfo(device, "CL_DRIVER_VERSION", CL_DRIVER_VERSION);
+ printDeviceInfo(device, "CL_DEVICE_PROFILE", CL_DEVICE_PROFILE);
+ printDeviceInfo(device, "CL_DEVICE_VERSION", CL_DEVICE_VERSION);
+ printDeviceInfo(device, "CL_DEVICE_OPENCL_C_VERSION", CL_DEVICE_OPENCL_C_VERSION);
+
+ CLContext context = clCreateContext(ctxProps, device, new CLContextCallback() {
+ protected void handleMessage(final String errinfo, final ByteBuffer private_info) {
+ System.out.println("IN CLContextCallback :: " + errinfo);
+ }
+ }, null);
+
+ CLMem buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, 128, null);
+
+ clSetMemObjectDestructorCallback(buffer, new CLMemObjectDestructorCallback() {
+ protected void handleMessage(final long memobj) {
+ System.out.println("FIRST Buffer destructed: " + memobj);
+ }
+ });
+
+ clSetMemObjectDestructorCallback(buffer, new CLMemObjectDestructorCallback() {
+ protected void handleMessage(final long memobj) {
+ System.out.println("SECOND Buffer destructed: " + memobj);
+ }
+ });
+
+ ByteBuffer bufferCreateInfo = BufferUtils.createByteBuffer(2 * PointerBuffer.getPointerSize());
+ PointerBuffer.put(bufferCreateInfo, 0);
+ PointerBuffer.put(bufferCreateInfo, 64);
+ bufferCreateInfo.flip();
+ CLMem subbuffer = clCreateSubBuffer(buffer, CL10.CL_MEM_READ_ONLY, CL11.CL_BUFFER_CREATE_TYPE_REGION, bufferCreateInfo, null);
+
+ clSetMemObjectDestructorCallback(subbuffer, new CLMemObjectDestructorCallback() {
+ protected void handleMessage(final long memobj) {
+ System.out.println("Sub Buffer destructed: " + memobj);
+ }
+ });
+
+ clRetainMemObject(buffer);
+
+ final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES);
+ if ( (exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL ) {
+ System.out.println("-TRYING TO EXEC NATIVE KERNEL-");
+ final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null);
+
+ clEnqueueNativeKernel(queue, new CLNativeKernel() {
+ protected void execute(final ByteBuffer[] memobjs) {
+ if ( memobjs == null )
+ System.out.println("OK, it's null");
+ else {
+ System.out.println("memobjs = " + memobjs.length);
+ for ( int k = 0; k < memobjs.length; k++ ) {
+ System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining());
+ for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) {
+ memobjs[k].put(l, (byte)l);
+ }
+ }
+ }
+ }
+ }, new CLMem[] { buffer }, new long[] { 128 }, null, null);
+
+ clFinish(queue);
+ }
+
+ clReleaseMemObject(buffer);
+ clReleaseContext(context);
+ }
+ }
+ } catch (LWJGLException le) {
+ die("Init", le.getMessage());
+ }
+
+ CL.destroy();
+ }
+
+ private static void printPlatformInfo(final CLPlatform platform, final String param_name, final int param) {
+ System.out.println("\t" + param_name + " = " + platform.getInfoString(param));
+ }
+
+ private static void printDeviceInfo(final CLDevice device, final String param_name, final int param) {
+ System.out.println("\t" + param_name + " = " + device.getInfoString(param));
+ }
+
+ private static void die(String kind, String description) {
+ System.out.println(kind + " error " + description + " occured");
+ }
+
+ /**
+ * main entry point
+ *
+ * @param args String array containing arguments
+ */
+ public static void main(String[] args) {
+ new HelloOpenCL().execute();
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java b/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java
new file mode 100644
index 00000000..1bc646fd
--- /dev/null
+++ b/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java
@@ -0,0 +1,675 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.test.opencl.gl;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLException;
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opencl.*;
+import org.lwjgl.opencl.api.Filter;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.DisplayMode;
+import org.lwjgl.opengl.Drawable;
+import org.lwjgl.util.Color;
+import org.lwjgl.util.ReadableColor;
+
+import java.io.*;
+import java.nio.IntBuffer;
+import java.util.List;
+
+import static java.lang.Math.*;
+import static org.lwjgl.opencl.CL10.*;
+import static org.lwjgl.opencl.CL10GL.*;
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL12.*;
+import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.GL21.*;
+
+/*
+ THIS DEMO USES CODE PORTED FROM JogAmp.org
+ Original code: http://github.com/mbien/jocl-demos
+ Original author: Michael Bien
+
+ ___ ___ ___
+ / /\ / /\ ___ / /\ http://jocl.jogamp.org/
+ / /:/ / /::\ /__/\ / /::\ a http://jogamp.org/ project.
+ /__/::\ / /:/\:\ \ \:\ / /:/\:\
+ \__\/\:\ / /:/~/::\ \ \:\ / /:/~/::\
+ \ \:\ /__/:/ /:/\:\ ___ \__\:\/__/:/ /:/\:\
+ \__\:\\ \:\/:/__\//__/\ | |:|\ \:\/:/__\/
+ / /:/ \ \::/ \ \:\| |:| \ \::/
+ /__/:/ \ \:\ \ \:\__|:| \ \:\
+ \__\/ \ \:\ \__\::::/ \ \:\
+ \__\/ ~~~~ \__\/
+ ___ ___ ___ ___ ___
+ / /\ / /\ / /\ /__/\ / /\
+ / /::\ / /::\ / /:/_ \ \:\ / /:/
+ / /:/\:\ / /:/\:\ / /:/ /\ \ \:\ / /:/ ___ ___
+ / /:/ \:\ / /:/~/:// /:/ /:/_ _____\__\:\ / /:/ ___ /__/\ / /\
+ /__/:/ \__\:\/__/:/ /://__/:/ /:/ /\/__/::::::::\/__/:/ / /\\ \:\ / /:/
+ \ \:\ / /:/\ \:\/:/ \ \:\/:/ /:/\ \:\~~\~~\/\ \:\ / /:/ \ \:\ /:/
+ \ \:\ /:/ \ \::/ \ \::/ /:/ \ \:\ ~~~ \ \:\ /:/ \ \:\/:/
+ \ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\/:/ \ \::/
+ \ \::/ \ \:\ \ \::/ \ \:\ \ \::/ \__\/
+ \__\/ \__\/ \__\/ \__\/ \__\/
+
+ _____ ___ ___ ___ ___
+ / /::\ / /\ /__/\ / /\ / /\
+ / /:/\:\ / /:/_ | |::\ / /::\ / /:/_
+ / /:/ \:\ / /:/ /\ | |:|:\ / /:/\:\ / /:/ /\
+ /__/:/ \__\:| / /:/ /:/_ __|__|:|\:\ / /:/ \:\ / /:/ /::\
+ \ \:\ / /:/ /__/:/ /:/ /\ /__/::::| \:\ /__/:/ \__\:\ /__/:/ /:/\:\
+ \ \:\ /:/ \ \:\/:/ /:/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\/:/~/:/
+ \ \:\/:/ \ \::/ /:/ \ \:\ \ \:\ /:/ \ \::/ /:/
+ \ \::/ \ \:\/:/ \ \:\ \ \:\/:/ \__\/ /:/
+ \__\/ \ \::/ \ \:\ \ \::/ /__/:/
+ \__\/ \__\/ \__\/ \__\/
+*/
+
+/**
+ * Computes the Mandelbrot set with OpenCL using multiple GPUs and renders the result with OpenGL.
+ * A shared PBO is used as storage for the fractal image.
+ * http://en.wikipedia.org/wiki/Mandelbrot_set
+ *
+ * controls:
+ * keys 1-9 control parallelism level
+ * space enables/disables slice seperator
+ * 'd' toggles between 32/64bit floatingpoint precision
+ * mouse/mousewheel to drag and zoom
+ * 'Home' to reset the viewport
+ *
+ *
+ * @author Michael Bien, Spasi
+ */
+public class DemoFractal {
+
+ // max number of used GPUs
+ private static final int MAX_PARALLELISM_LEVEL = 8;
+
+ // max per pixel iterations to compute the fractal
+ private static final int MAX_ITERATIONS = 500;
+
+ private CLContext clContext;
+ private CLCommandQueue[] queues;
+ private CLKernel[] kernels;
+ private CLProgram[] programs;
+
+ private CLMem[] pboBuffers;
+ private IntBuffer pboIDs;
+
+ private CLMem[] colorMap;
+ private IntBuffer[] colorMapBuffer;
+
+ private final PointerBuffer kernel2DGlobalWorkSize;
+
+ private int width = 0;
+ private int height = 0;
+
+ private double minX = -2f;
+ private double minY = -1.2f;
+ private double maxX = 0.6f;
+ private double maxY = 1.3f;
+
+ private boolean dragging;
+ private double dragX;
+ private double dragY;
+ private double dragMinX;
+ private double dragMinY;
+ private double dragMaxX;
+ private double dragMaxY;
+
+ private int mouseX;
+ private int mouseY;
+
+ private int slices;
+
+ private boolean drawSeparator;
+ private boolean doublePrecision = true;
+ private boolean buffersInitialized;
+ private boolean rebuild;
+
+ private boolean run = true;
+
+ public DemoFractal(int width, int height) {
+ kernel2DGlobalWorkSize = BufferUtils.createPointerBuffer(2);
+
+ this.width = width;
+ this.height = height;
+ }
+
+ private void run() {
+ long startTime = System.currentTimeMillis() + 5000;
+ long fps = 0;
+
+ while ( run ) {
+ if ( !Display.isVisible() )
+ Thread.yield();
+
+ handleIO();
+ display();
+
+ Display.update();
+ if ( Display.isCloseRequested() )
+ break;
+
+ if ( startTime > System.currentTimeMillis() ) {
+ fps++;
+ } else {
+ long timeUsed = 5000 + (startTime - System.currentTimeMillis());
+ startTime = System.currentTimeMillis() + 5000;
+ System.out.println(fps + " frames in 5 seconds = " + (fps / (timeUsed / 1000f)));
+ fps = 0;
+ }
+ }
+
+ CL.destroy();
+ Display.destroy();
+ }
+
+ private void handleIO() {
+ if ( Keyboard.getNumKeyboardEvents() != 0 ) {
+ while ( Keyboard.next() ) {
+ if ( Keyboard.getEventKeyState() )
+ continue;
+
+ final int key = Keyboard.getEventKey();
+
+ if ( Keyboard.KEY_1 <= key && key <= Keyboard.KEY_8 ) {
+ int number = key - Keyboard.KEY_1 + 1;
+ slices = min(number, min(queues.length, MAX_PARALLELISM_LEVEL));
+ System.out.println("NEW PARALLELISM LEVEL: " + slices);
+ buffersInitialized = false;
+ } else {
+ switch ( Keyboard.getEventKey() ) {
+ case Keyboard.KEY_SPACE:
+ drawSeparator = !drawSeparator;
+ System.out.println("SEPARATOR DRAWING IS NOW: " + (drawSeparator ? "ON" : "OFF"));
+ break;
+ case Keyboard.KEY_D:
+ doublePrecision = !doublePrecision;
+ System.out.println("DOUBLE PRECISION IS NOW: " + (doublePrecision ? "ON" : "OFF"));
+ rebuild = true;
+ break;
+ case Keyboard.KEY_HOME:
+ minX = -2f;
+ minY = -1.2f;
+ maxX = 0.6f;
+ maxY = 1.3f;
+ break;
+ case Keyboard.KEY_ESCAPE:
+ run = false;
+ break;
+ }
+ }
+ }
+ }
+
+ while ( Mouse.next() ) {
+ final int eventBtn = Mouse.getEventButton();
+
+ final int x = Mouse.getX();
+ final int y = Mouse.getY();
+
+ if ( Mouse.isButtonDown(0) && (x != mouseX || y != mouseY) ) {
+ if ( !dragging ) {
+ dragging = true;
+
+ dragX = mouseX;
+ dragY = mouseY;
+
+ dragMinX = minX;
+ dragMinY = minY;
+ dragMaxX = maxX;
+ dragMaxY = maxY;
+ }
+
+ double offsetX = (x - dragX) * (maxX - minX) / width;
+ double offsetY = (y - dragY) * (maxY - minY) / height;
+
+ minX = dragMinX - offsetX;
+ minY = dragMinY - offsetY;
+
+ maxX = dragMaxX - offsetX;
+ maxY = dragMaxY - offsetY;
+ } else {
+ if ( dragging )
+ dragging = false;
+
+ if ( eventBtn == -1 ) {
+ final int dwheel = Mouse.getEventDWheel();
+ if ( dwheel != 0 ) {
+ double scale = dwheel > 0 ? 0.05 : -0.05;
+
+ double deltaX = scale * (maxX - minX);
+ double deltaY = scale * (maxY - minY);
+
+ // offset for "zoom to cursor"
+ double offsetX = (x / (double)width - 0.5) * deltaX * 2.0;
+ double offsetY = (y / (double)height - 0.5) * deltaY * 2.0;
+
+ minX += deltaX + offsetX;
+ minY += deltaY - offsetY;
+
+ maxX += -deltaX + offsetX;
+ maxY += -deltaY - offsetY;
+ }
+ }
+ }
+
+ mouseX = x;
+ mouseY = y;
+ }
+ }
+
+ public void init() {
+ try {
+ Display.setDisplayMode(new DisplayMode(width, height));
+ Display.setTitle("OpenCL Fractal Demo");
+ Display.create();
+ CL.create();
+ } catch (LWJGLException e) {
+ throw new RuntimeException(e);
+ }
+
+ try {
+ initCL(Display.getDrawable());
+ } catch (Exception e) {
+ if ( clContext != null )
+ clReleaseContext(clContext);
+ Display.destroy();
+ throw new RuntimeException(e);
+ }
+
+ Display.setSwapInterval(0);
+ glDisable(GL_DEPTH_TEST);
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+
+ initView(Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
+
+ initPBO();
+ glFinish();
+
+ setKernelConstants();
+ }
+
+ private void initCL(Drawable drawable) throws Exception {
+ // Find a platform
+ List platforms = CLPlatform.getPlatforms();
+ if ( platforms == null )
+ throw new RuntimeException("No OpenCL platforms found.");
+
+ final CLPlatform platform = platforms.get(0); // just grab the first one
+
+ // Find devices with GL sharing support
+ final Filter glSharingFilter = new Filter() {
+ public boolean accept(final CLDevice device) {
+ final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device);
+ return caps.CL_KHR_gl_sharing;
+ }
+ };
+ List devices = platform.getDevices(CL_DEVICE_TYPE_GPU, glSharingFilter);
+ if ( devices == null ) {
+ devices = platform.getDevices(CL_DEVICE_TYPE_CPU, glSharingFilter);
+ if ( devices == null )
+ throw new RuntimeException("No OpenCL devices found.");
+ }
+
+ // Create the context
+ final PointerBuffer deviceIDs = BufferUtils.createPointerBuffer(devices.size());
+ for ( CLDevice device : devices )
+ deviceIDs.put(device);
+ deviceIDs.flip();
+
+ final PointerBuffer contextProps = BufferUtils.createPointerBuffer(2 + 4 + 1);
+ contextProps.put(CL_CONTEXT_PLATFORM).put(platform);
+
+ drawable.setCLSharingProperties(contextProps); // Enable GL sharing
+
+ contextProps.put(0);
+ contextProps.flip();
+ clContext = clCreateContext(contextProps, deviceIDs, null, null);
+
+ slices = min(devices.size(), MAX_PARALLELISM_LEVEL);
+
+ // create command queues for every GPU, setup colormap and init kernels
+ queues = new CLCommandQueue[slices];
+ kernels = new CLKernel[slices];
+ colorMap = new CLMem[slices];
+ colorMapBuffer = new IntBuffer[slices];
+
+ for ( int i = 0; i < slices; i++ ) {
+ colorMapBuffer[i] = BufferUtils.createIntBuffer(32 * 2);
+ colorMap[i] = clCreateBuffer(clContext, CL_MEM_READ_ONLY, colorMapBuffer[i].capacity() * 4, null);
+ colorMap[i].checkNull();
+
+ initColorMap(colorMapBuffer[i], 32, Color.BLUE, Color.GREEN, Color.RED);
+
+ // create command queue and upload color map buffer on each used device
+ queues[i] = clCreateCommandQueue(clContext, devices.get(i), CL_QUEUE_PROFILING_ENABLE, null);
+ queues[i].checkNull();
+ clEnqueueWriteBuffer(queues[i], colorMap[i], CL_TRUE, 0, colorMapBuffer[i], null, null); // blocking upload
+
+ }
+
+ // check if we have 64bit FP support on all devices
+ // if yes we can use only one program for all devices + one kernel per device.
+ // if not we will have to create (at least) one program for 32 and one for 64bit devices.
+ // since there are different vendor extensions for double FP we use one program per device.
+ // (OpenCL spec is not very clear about this usecases)
+ boolean all64bit = true;
+ for ( CLDevice device : devices ) {
+ if ( !isDoubleFPAvailable(device) ) {
+ all64bit = false;
+ break;
+ }
+ }
+
+ // load program(s)
+ programs = new CLProgram[all64bit ? 1 : slices];
+
+ buildPrograms();
+ }
+
+ private void createPrograms() throws IOException {
+ final String source = getProgramSource("Mandelbrot.cl");
+ for ( int i = 0; i < programs.length; i++ )
+ programs[i] = clCreateProgramWithSource(clContext, source, null);
+ }
+
+ private String getProgramSource(final String file) throws IOException {
+ InputStream source = getClass().getResourceAsStream(file);
+ if ( source == null ) // dev-mode
+ source = new FileInputStream("src/java/org/lwjgl/test/opencl/gl/" + file);
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(source));
+
+ final StringBuilder sb = new StringBuilder();
+ String line;
+ try {
+ while ( (line = reader.readLine()) != null )
+ sb.append(line).append("\n");
+ } finally {
+ source.close();
+ }
+
+ return sb.toString();
+ }
+
+ private static void initColorMap(IntBuffer colorMap, int stepSize, ReadableColor... colors) {
+ for ( int n = 0; n < colors.length - 1; n++ ) {
+ ReadableColor color = colors[n];
+ int r0 = color.getRed();
+ int g0 = color.getGreen();
+ int b0 = color.getBlue();
+
+ color = colors[n + 1];
+ int r1 = color.getRed();
+ int g1 = color.getGreen();
+ int b1 = color.getBlue();
+
+ int deltaR = r1 - r0;
+ int deltaG = g1 - g0;
+ int deltaB = b1 - b0;
+
+ for ( int step = 0; step < stepSize; step++ ) {
+ float alpha = (float)step / (stepSize - 1);
+ int r = (int)(r0 + alpha * deltaR);
+ int g = (int)(g0 + alpha * deltaG);
+ int b = (int)(b0 + alpha * deltaB);
+ colorMap.put((r << 16) | (g << 8) | (b << 0));
+ }
+ }
+ colorMap.rewind();
+ }
+
+ private static void initView(int width, int height) {
+ glViewport(0, 0, width, height);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0, width, 0.0, height, 0.0, 1.0);
+ }
+
+ private void initPBO() {
+ if ( pboBuffers == null ) {
+ pboBuffers = new CLMem[slices];
+ pboIDs = BufferUtils.createIntBuffer(slices);
+ } else {
+ for ( CLMem pboBuffer : pboBuffers )
+ clReleaseMemObject(pboBuffer);
+ glDeleteBuffers(pboIDs);
+ }
+
+ glGenBuffers(pboIDs);
+
+ // setup one empty PBO per slice
+ for ( int i = 0; i < slices; i++ ) {
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIDs.get(i));
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, width * height * 4 / slices, GL_STREAM_DRAW);
+
+ pboBuffers[i] = clCreateFromGLBuffer(clContext, CL_MEM_WRITE_ONLY, pboIDs.get(i), null);
+ }
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+
+ buffersInitialized = true;
+ }
+
+ private void buildPrograms() {
+ /*
+ * workaround: The driver keeps using the old binaries for some reason.
+ * to solve this we simple create a new program and release the old.
+ * however rebuilding programs should be possible -> remove when drivers are fixed.
+ * (again: the spec is not very clear about this kind of usages)
+ */
+ if ( programs[0] != null ) {
+ for ( CLProgram program : programs )
+ clReleaseProgram(program);
+ }
+
+ try {
+ createPrograms();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ // disable 64bit floating point math if not available
+ for ( int i = 0; i < programs.length; i++ ) {
+ final CLDevice device = queues[i].getCLDevice();
+
+ final StringBuilder options = new StringBuilder("-cl-fast-relaxed-math");
+ final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device);
+ if ( doublePrecision && isDoubleFPAvailable(device) ) {
+ //cl_khr_fp64
+ options.append(" -D DOUBLE_FP");
+
+ //amd's verson of double precision floating point math
+ if ( !caps.CL_KHR_fp64 && caps.CL_AMD_fp64 )
+ options.append(" -D AMD_FP");
+ }
+
+ System.out.println("COMPILER OPTIONS: " + options);
+
+ clBuildProgram(programs[i], device, options, null);
+ }
+
+ rebuild = false;
+
+ for ( int i = 0; i < kernels.length; i++ ) {
+ // init kernel with constants
+ kernels[i] = clCreateKernel(programs[min(i, programs.length)], "mandelbrot", null);
+ }
+
+ }
+
+ // init kernels with constants
+
+ private void setKernelConstants() {
+ for ( int i = 0; i < slices; i++ ) {
+ kernels[i]
+ .setArg(6, pboBuffers[i])
+ .setArg(7, colorMap[i])
+ .setArg(8, colorMapBuffer[i].capacity())
+ .setArg(9, MAX_ITERATIONS);
+ }
+ }
+
+ // rendering cycle
+
+ public void display() {
+ // make sure GL does not use our objects before we start computeing
+ glFinish();
+
+ if ( !buffersInitialized ) {
+ initPBO();
+ setKernelConstants();
+ }
+
+ if ( rebuild ) {
+ buildPrograms();
+ setKernelConstants();
+ }
+ compute(doublePrecision);
+
+ render();
+ }
+
+ // OpenCL
+
+ private void compute(final boolean is64bit) {
+ int sliceWidth = (int)(width / (float)slices);
+ double rangeX = (maxX - minX) / slices;
+ double rangeY = (maxY - minY);
+
+ kernel2DGlobalWorkSize.put(0, sliceWidth).put(1, height);
+
+ // start computation
+ for ( int i = 0; i < slices; i++ ) {
+ kernels[i].setArg(0, sliceWidth).setArg(1, height);
+ if ( !is64bit || !isDoubleFPAvailable(queues[i].getCLDevice()) ) {
+ kernels[i]
+ .setArg(2, (float)(minX + rangeX * i)).setArg(3, (float)minY)
+ .setArg(4, (float)rangeX).setArg(5, (float)rangeY);
+ } else {
+ kernels[i]
+ .setArg(2, minX + rangeX * i).setArg(3, minY)
+ .setArg(4, rangeX).setArg(5, rangeY);
+ }
+
+ // aquire GL objects, and enqueue a kernel with a probe from the list
+ clEnqueueAcquireGLObjects(queues[i], pboBuffers[i], null, null);
+
+ clEnqueueNDRangeKernel(queues[i], kernels[i], 2,
+ null,
+ kernel2DGlobalWorkSize,
+ null,
+ null, null);
+
+ clEnqueueReleaseGLObjects(queues[i], pboBuffers[i], null, null);
+ }
+
+ // block until done (important: finish before doing further gl work)
+ for ( int i = 0; i < slices; i++ ) {
+ clFinish(queues[i]);
+ }
+
+ }
+
+ // OpenGL
+
+ private void render() {
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ //draw slices
+ int sliceWidth = width / slices;
+
+ for ( int i = 0; i < slices; i++ ) {
+ int seperatorOffset = drawSeparator ? i : 0;
+
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIDs.get(i));
+ glRasterPos2i(sliceWidth * i + seperatorOffset, 0);
+
+ glDrawPixels(sliceWidth, height, GL_BGRA, GL_UNSIGNED_BYTE, 0);
+
+ }
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+
+ //draw info text
+ /*
+ textRenderer.beginRendering(width, height, false);
+
+ textRenderer.draw("device/time/precision", 10, height - 15);
+
+ for ( int i = 0; i < slices; i++ ) {
+ CLDevice device = queues[i].getDevice();
+ boolean doubleFP = doublePrecision && isDoubleFPAvailable(device);
+ CLEvent event = probes.getEvent(i);
+ long start = event.getProfilingInfo(START);
+ long end = event.getProfilingInfo(END);
+ textRenderer.draw(device.getType().toString() + i + " "
+ + (int)((end - start) / 1000000.0f) + "ms @"
+ + (doubleFP ? "64bit" : "32bit"), 10, height - (20 + 16 * (slices - i)));
+ }
+
+ textRenderer.endRendering();
+ */
+ }
+
+ public void reshape(int x, int y, int width, int height) {
+ if ( this.width == width && this.height == height )
+ return;
+
+ this.width = width;
+ this.height = height;
+
+ initPBO();
+ setKernelConstants();
+
+ initView(width, height);
+
+ }
+
+ private static boolean isDoubleFPAvailable(CLDevice device) {
+ final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device);
+ return caps.CL_KHR_fp64 || caps.CL_AMD_fp64;
+ }
+
+ public static void main(String args[]) {
+ DemoFractal demo = new DemoFractal(512, 512);
+ demo.init();
+ demo.run();
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl b/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl
new file mode 100644
index 00000000..2fc959c2
--- /dev/null
+++ b/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl
@@ -0,0 +1,55 @@
+#ifdef DOUBLE_FP
+ #ifdef AMD_FP
+ #pragma OPENCL EXTENSION cl_amd_fp64 : enable
+ #else
+ #pragma OPENCL EXTENSION cl_khr_fp64 : enable
+ #endif
+ typedef double varfloat;
+#else
+ typedef float varfloat;
+#endif
+
+/**
+ * For a description of this algorithm please refer to
+ * http://en.wikipedia.org/wiki/Mandelbrot_set
+ * @author Michael Bien
+ */
+kernel void mandelbrot(
+ const int width, const int height,
+ const varfloat x0, const varfloat y0,
+ const varfloat rangeX, const varfloat rangeY,
+ global uint *output, global uint *colorMap,
+ const int colorMapSize, const int maxIterations) {
+
+ unsigned int ix = get_global_id(0);
+ unsigned int iy = get_global_id(1);
+
+ varfloat r = x0 + ix * rangeX / width;
+ varfloat i = y0 + iy * rangeY / height;
+
+ varfloat x = 0;
+ varfloat y = 0;
+
+ varfloat magnitudeSquared = 0;
+ int iteration = 0;
+
+ while (magnitudeSquared < 4 && iteration < maxIterations) {
+ varfloat x2 = x*x;
+ varfloat y2 = y*y;
+ y = 2 * x * y + i;
+ x = x2 - y2 + r;
+ magnitudeSquared = x2+y2;
+ iteration++;
+ }
+
+ if (iteration == maxIterations) {
+ output[iy * width + ix] = 0;
+ }else {
+ varfloat alpha = (varfloat)iteration / maxIterations;
+ int colorIndex = (int)(alpha * colorMapSize);
+ output[iy * width + ix] = colorMap[colorIndex];
+ // monochrom
+ // output[iy * width + ix] = 255*iteration/maxIterations;
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/test/opengl/VersionTest.java b/src/java/org/lwjgl/test/opengl/VersionTest.java
index 44d94437..87d3de40 100644
--- a/src/java/org/lwjgl/test/opengl/VersionTest.java
+++ b/src/java/org/lwjgl/test/opengl/VersionTest.java
@@ -81,6 +81,8 @@ public final class VersionTest {
ca = ca.withProfileCore(true);
else if ( "compatibility".equalsIgnoreCase(args[i]) )
ca = ca.withProfileCompatibility(true);
+ else if ( "es".equalsIgnoreCase(args[i]) )
+ ca = ca.withProfileES(true);
else
argsError("Unknown argument: \'" + args[i] + "\'");
}
@@ -236,6 +238,7 @@ public final class VersionTest {
System.out.println("majorVersion\t- Minor OpenGL version.");
System.out.println("core\t- Sets the Core Profile bit (optional, requires 3.2+).");
System.out.println("compatibility\t- Sets the Compatibility Profile bit (optional, requires 3.2+).");
+ System.out.println("ws\t- Sets the OpenGL ES Profile bit (optional, requires 2.0).");
System.out.println("layer\t- Layer plane (optional).");
System.out.println("debug\t- Enables debug mode (optional).");
System.out.println("fc\t- Enables forward compatibility mode (optional, requires 3.0+).");
diff --git a/src/java/org/lwjgl/util/generator/Alternate.java b/src/java/org/lwjgl/util/generator/Alternate.java
index 67fe5188..c1374154 100644
--- a/src/java/org/lwjgl/util/generator/Alternate.java
+++ b/src/java/org/lwjgl/util/generator/Alternate.java
@@ -49,6 +49,9 @@ public @interface Alternate {
/** If true, an alternate Java->native call will be created. Useful when the alternate implementation uses different types. */
boolean nativeAlt() default false;
+ /** Applicable when nativeAlt is true. If true, no extra native call will be generated. Useful when there's another nativeAlt already defined. */
+ boolean skipNative() default false;
+
/** If true, the alternate method's name will be used for the Java call. */
boolean javaAlt() default false;
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/AutoSize.java b/src/java/org/lwjgl/util/generator/AutoSize.java
index 90318dcb..319bef53 100644
--- a/src/java/org/lwjgl/util/generator/AutoSize.java
+++ b/src/java/org/lwjgl/util/generator/AutoSize.java
@@ -45,9 +45,10 @@ import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Auto
-@Target(ElementType.PARAMETER)
+@Target({ElementType.METHOD,ElementType.PARAMETER})
public @interface AutoSize {
String value(); // The name of the Buffer parameter
String expression() default ""; // This value is added after the argument
boolean canBeNull() default false; // When this is true and the Buffer parameter is null, 0 will be used.
+ boolean isNative() default false; // When this is true, auto-sizing will be performed in native code.
}
diff --git a/src/java/org/lwjgl/util/generator/Check.java b/src/java/org/lwjgl/util/generator/Check.java
index 759ec4a1..6421bbc1 100644
--- a/src/java/org/lwjgl/util/generator/Check.java
+++ b/src/java/org/lwjgl/util/generator/Check.java
@@ -41,7 +41,7 @@ package org.lwjgl.util.generator;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
-@Target(ElementType.PARAMETER)
+@Target({ElementType.PARAMETER, ElementType.METHOD})
public @interface Check {
String value() default "";
boolean canBeNull() default false;
diff --git a/src/java/org/lwjgl/util/generator/Code.java b/src/java/org/lwjgl/util/generator/Code.java
index 15091415..84cd2ffc 100644
--- a/src/java/org/lwjgl/util/generator/Code.java
+++ b/src/java/org/lwjgl/util/generator/Code.java
@@ -38,10 +38,22 @@ package org.lwjgl.util.generator;
* $Id$
*/
-import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
@Target(ElementType.METHOD)
public @interface Code {
- String value();
+
+ String value() default ""; // Java, before everything
+
+ boolean tryBlock() default false; // Add a try/finally block around the native call and return statement
+
+ String javaBeforeNative() default ""; // Before the native call
+ String javaAfterNative() default ""; // After the native call
+ String javaFinally() default ""; // In the finally block
+
+ String nativeAfterVars() default ""; // After variable declaration
+ String nativeBeforeCall() default ""; // Before the API call
+ String nativeAfterCall() default ""; // After the API call
+
}
diff --git a/src/java/org/lwjgl/util/generator/Constant.java b/src/java/org/lwjgl/util/generator/Constant.java
index 82b62c1f..b6ca32ca 100644
--- a/src/java/org/lwjgl/util/generator/Constant.java
+++ b/src/java/org/lwjgl/util/generator/Constant.java
@@ -46,4 +46,6 @@ public @interface Constant {
String value();
/** If true, the original parameter will not be removed from the method. */
boolean keepParam() default false;
+ /** If true, this is a native code constant. */
+ boolean isNative() default false;
}
diff --git a/src/java/org/lwjgl/util/generator/AutoResultSize.java b/src/java/org/lwjgl/util/generator/Extern.java
similarity index 87%
rename from src/java/org/lwjgl/util/generator/AutoResultSize.java
rename to src/java/org/lwjgl/util/generator/Extern.java
index d68c404c..b4e8f6fa 100644
--- a/src/java/org/lwjgl/util/generator/AutoResultSize.java
+++ b/src/java/org/lwjgl/util/generator/Extern.java
@@ -1,50 +1,46 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * AutoResultSize specifies the size of a returned Buffer
- * as an expression.
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@Target(ElementType.METHOD)
-public @interface AutoResultSize {
- String value(); // The size as a java expression
-}
+/*
+ * 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.util.generator;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * Functions marked with @Extern will not be declared as static in the C implementation.
+ * This allows other source files to call them.
+ *
+ * @author Spasi
+ */
+@Target(ElementType.METHOD)
+public @interface Extern {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/GenerateAutos.java b/src/java/org/lwjgl/util/generator/GenerateAutos.java
index d042c546..2127bd43 100644
--- a/src/java/org/lwjgl/util/generator/GenerateAutos.java
+++ b/src/java/org/lwjgl/util/generator/GenerateAutos.java
@@ -43,4 +43,6 @@ import java.lang.annotation.ElementType;
@Target(ElementType.METHOD)
public @interface GenerateAutos {
+ /** If true, a size variable will be generated. */
+ String[] sizeVariables() default {};
}
diff --git a/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java
index 1a8faa4b..79979e7b 100644
--- a/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java
+++ b/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java
@@ -32,29 +32,32 @@
package org.lwjgl.util.generator;
-import com.sun.mirror.apt.*;
-import com.sun.mirror.declaration.*;
-
import java.io.File;
import java.io.FileFilter;
-import java.util.Collection;
-import java.util.Set;
-import java.util.Map;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import com.sun.mirror.apt.*;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
-import static java.util.Collections.*;
import static com.sun.mirror.util.DeclarationVisitors.*;
+import static java.util.Collections.*;
/**
- *
* Generator tool for creating the java classes and native code
* from an annotated template java interface.
*
* @author elias_naur
* @version $Revision$
- * $Id$
+ * $Id$
*/
public class GeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
+
private static boolean first_round = true;
// Process any set of annotations
@@ -78,7 +81,7 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
// Only process the initial types, not the generated ones
- if (first_round) {
+ if ( first_round ) {
env.addListener(this);
return new GeneratorProcessor(env);
} else
@@ -86,6 +89,7 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
}
private static class GeneratorProcessor implements AnnotationProcessor {
+
private final AnnotationProcessorEnvironment env;
GeneratorProcessor(AnnotationProcessorEnvironment env) {
@@ -97,22 +101,22 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
String typemap_classname = null;
boolean generate_error_checks = options.containsKey("-Ageneratechecks");
boolean context_specific = options.containsKey("-Acontextspecific");
- for (String k : options.keySet()) {
+ for ( String k : options.keySet() ) {
int delimiter = k.indexOf('=');
- if (delimiter != -1) {
- if (k.startsWith("-Atypemap")) {
+ if ( delimiter != -1 ) {
+ if ( k.startsWith("-Atypemap") ) {
typemap_classname = k.substring(delimiter + 1);
}
}
}
- if (typemap_classname == null)
+ if ( typemap_classname == null )
throw new RuntimeException("No TypeMap class name specified with -Atypemap=");
TypeDeclaration lastFile = null;
try {
long generatorLM = getGeneratorLastModified();
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
- for (TypeDeclaration typedecl : env.getSpecifiedTypeDeclarations()) {
+ for ( TypeDeclaration typedecl : env.getSpecifiedTypeDeclarations() ) {
lastFile = typedecl;
typedecl.accept(getDeclarationScanner(new GeneratorVisitor(env, type_map, generate_error_checks, context_specific, generatorLM), NO_OP));
}
@@ -130,7 +134,16 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
* @return time of the latest change
*/
private static long getGeneratorLastModified() {
- final File pck = new File(System.getProperty("user.dir") + "/bin/org/lwjgl/util/generator");
+ long lastModified = getDirectoryLastModified("/bin/org/lwjgl/util/generator");
+ lastModified = Math.max(lastModified, getDirectoryLastModified("/bin/org/lwjgl/util/generator/openal"));
+ lastModified = Math.max(lastModified, getDirectoryLastModified("/bin/org/lwjgl/util/generator/opengl"));
+ lastModified = Math.max(lastModified, getDirectoryLastModified("/bin/org/lwjgl/util/generator/opencl"));
+
+ return lastModified;
+ }
+
+ private static long getDirectoryLastModified(final String path) {
+ final File pck = new File(System.getProperty("user.dir") + path);
if ( !pck.exists() || !pck.isDirectory() )
return Long.MAX_VALUE;
diff --git a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java
index a3f74177..8c28287d 100644
--- a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java
+++ b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java
@@ -37,12 +37,11 @@ import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
import com.sun.mirror.util.*;
+import java.io.*;
+import java.lang.annotation.Annotation;
+import java.nio.channels.FileChannel;
import java.util.*;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.io.File;
-
import java.nio.*;
/**
@@ -68,11 +67,6 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
this.generatorLM = generatorLM;
}
- private void validateMethods(InterfaceDeclaration d) {
- for (MethodDeclaration method : d.getMethods())
- validateMethod(method);
- }
-
private void validateMethod(MethodDeclaration method) {
if (method.isVarArgs())
throw new RuntimeException("Method " + method.getSimpleName() + " is variadic");
@@ -96,13 +90,13 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
if (method.getAnnotation(CachedResult.class) != null) {
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null)
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
- if (method.getAnnotation(AutoResultSize.class) == null)
- throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoResultSize annotation");
+ if (method.getAnnotation(AutoSize.class) == null)
+ throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoSize annotation");
}
validateTypes(method, method.getAnnotationMirrors(), method.getReturnType());
}
- private void validateType(MethodDeclaration method, Class annotation_type, Class type) {
+ private void validateType(MethodDeclaration method, Class annotation_type, Class type) {
Class[] valid_types = type_map.getValidAnnotationTypes(type);
for (int i = 0; i < valid_types.length; i++)
if (valid_types[i].equals(annotation_type))
@@ -115,7 +109,11 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
for (AnnotationMirror annotation : annotations) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) {
- Class annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
+ Class extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
+ /*System.out.println("\nYO:");
+ System.out.println("annotation = " + annotation);
+ System.out.println("native_type_annotation = " + native_type_annotation);
+ System.out.println("annotation_type = " + annotation_type);*/
Class type = Utils.getJavaType(type_mirror);
if (Buffer.class.equals(type))
continue;
@@ -172,7 +170,9 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
}
private static void generateMethodNativePointers(PrintWriter writer, MethodDeclaration method) {
- writer.println("static " + Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
+ if ( method.getAnnotation(Extern.class) == null )
+ writer.print("static ");
+ writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
}
private void generateJavaSource(InterfaceDeclaration d, PrintWriter java_writer) throws IOException {
@@ -182,9 +182,15 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
java_writer.println();
java_writer.println("import org.lwjgl.*;");
java_writer.println("import java.nio.*;");
+ Imports imports = d.getAnnotation(Imports.class);
+ if ( imports != null ) {
+ for ( String i : imports.value() )
+ java_writer.println("import " + i + ";");
+ }
java_writer.println();
Utils.printDocComment(java_writer, d);
- java_writer.print("public ");
+ if ( d.getAnnotation(Private.class) == null )
+ java_writer.print("public ");
boolean is_final = Utils.isFinal(d);
if (is_final)
java_writer.write("final ");
@@ -223,8 +229,10 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
native_writer.println("#include ");
type_map.printNativeIncludes(native_writer);
native_writer.println();
+ //if ( d.getAnnotation(NoTypeDefs.class) == null ) {
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, d.getMethods());
native_writer.println();
+ //}
if (!context_specific) {
generateMethodsNativePointers(native_writer, d.getMethods());
native_writer.println();
@@ -247,29 +255,98 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
}
public void visitInterfaceDeclaration(InterfaceDeclaration d) {
- File input = d.getPosition().file();
- File output = new File(env.getOptions().get("-s") + '/' + d.getPackage().getQualifiedName().replace('.', '/'), Utils.getSimpleClassName(d) + ".java");
+ final File input = d.getPosition().file();
+ final File outputJava = new File(env.getOptions().get("-s") + '/' + d.getPackage().getQualifiedName().replace('.', '/'), Utils.getSimpleClassName(d) + ".java");
PrintWriter java_writer = null;
try {
- // Skip this class if the output exists and the input has not been modified.
- if ( output.exists() && Math.max(input.lastModified(), generatorLM) < output.lastModified() )
+ final Collection extends MethodDeclaration> methods = d.getMethods();
+ if ( methods.size() == 0 && d.getFields().size() == 0 )
return;
- if (d.getMethods().size() > 0 || d.getFields().size() > 0) {
- validateMethods(d);
- java_writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, d.getPackage().getQualifiedName(), new File(Utils.getSimpleClassName(d) + ".java"), null);
- generateJavaSource(d, java_writer);
+ // Skip this class if the output exists and the input has not been modified.
+ if ( outputJava.exists() && Math.max(input.lastModified(), generatorLM) < outputJava.lastModified() )
+ return;
+
+ for ( final MethodDeclaration method : methods )
+ validateMethod(method);
+ java_writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, d.getPackage().getQualifiedName(), new File(Utils.getSimpleClassName(d) + ".java"), null);
+ generateJavaSource(d, java_writer);
+
+ if ( methods.size() > 0 ) {
+ boolean hasNative = false;
+ for ( final MethodDeclaration method : methods ) {
+ Alternate alt_annotation = method.getAnnotation(Alternate.class);
+ if ( (alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null ) {
+ hasNative = true;
+ break;
+ }
+ }
+ if ( !hasNative )
+ return;
+
+ final String outputPath = env.getOptions().get("-d") + '/' + Utils.getNativeQualifiedName(Utils.getQualifiedClassName(d));
+ final File outputNative = new File(outputPath + ".c");
+ final File outputBackup = new File(outputPath + "_backup.c");
+
+ // If the native file exists, rename.
+ final ByteBuffer nativeBefore;
+ if ( outputNative.exists() ) {
+ nativeBefore = readFile(outputNative);
+ outputNative.renameTo(outputBackup);
+ } else
+ nativeBefore = null;
+
+ try {
+ generateNativeSource(d);
+
+ // If the native file did exist, compare with the new file. If they're the same,
+ // reset the last modified time to avoid ridiculous C compilation times.
+ if ( nativeBefore != null && outputNative.length() == nativeBefore.capacity() ) {
+ final ByteBuffer nativeAfter = readFile(outputNative);
+ boolean same = true;
+ for ( int i = nativeBefore.position(); i < nativeBefore.limit(); i++ ) {
+ if ( nativeBefore.get(i) != nativeAfter.get(i) ) {
+ same = false;
+ break;
+ }
+ }
+
+ if ( same ) {
+ outputNative.delete();
+ outputBackup.renameTo(outputNative);
+ }
+ }
+ } finally {
+ if ( outputBackup.exists() )
+ outputBackup.delete();
+ }
}
- if (d.getMethods().size() > 0)
- generateNativeSource(d);
} catch (Exception e) {
// If anything goes wrong mid-gen, delete output to allow regen next time we run.
if ( java_writer != null ) java_writer.close();
- if ( output.exists() ) output.delete();
+ if ( outputJava.exists() ) outputJava.delete();
throw new RuntimeException(e);
}
}
+
+ private static ByteBuffer readFile(final File file) throws IOException {
+ final FileChannel channel = new FileInputStream(file).getChannel();
+
+ final long bytesTotal = channel.size();
+ final ByteBuffer buffer = ByteBuffer.allocateDirect((int)bytesTotal);
+
+ long bytesRead = 0;
+ do {
+ bytesRead += channel.read(buffer);
+ } while ( bytesRead < bytesTotal );
+ buffer.flip();
+
+ channel.close();
+
+ return buffer;
+ }
+
}
diff --git a/src/java/org/lwjgl/util/generator/Helper.java b/src/java/org/lwjgl/util/generator/Helper.java
new file mode 100644
index 00000000..b2795256
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/Helper.java
@@ -0,0 +1,46 @@
+/*
+ * 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.util.generator;
+
+/**
+ * Method parameters marked with @Helper will be considered Java-API
+ * parameters and will be ignored when generating native stubs/code.
+ *
+ * @author Spasi
+ */
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.PARAMETER)
+public @interface Helper {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/Imports.java b/src/java/org/lwjgl/util/generator/Imports.java
new file mode 100644
index 00000000..6a278baa
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/Imports.java
@@ -0,0 +1,46 @@
+/*
+ * 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.util.generator;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation can be used when an extension template needs
+ * extra imports in its generated class.
+ *
+ * @author Spasi
+ */
+@Target(ElementType.TYPE)
+public @interface Imports {
+ String[] value();
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/JNITypeTranslator.java b/src/java/org/lwjgl/util/generator/JNITypeTranslator.java
index a43330b0..d0294dc2 100644
--- a/src/java/org/lwjgl/util/generator/JNITypeTranslator.java
+++ b/src/java/org/lwjgl/util/generator/JNITypeTranslator.java
@@ -56,8 +56,13 @@ public class JNITypeTranslator implements TypeVisitor {
}
public void visitArrayType(ArrayType t) {
- if ( "java.lang.CharSequence".equals(t.getComponentType().toString()) )
+ final String className = t.getComponentType().toString();
+ if ( "java.lang.CharSequence".equals(className) )
signature.append("jobject");
+ else if ( "java.nio.ByteBuffer".equals(className) )
+ signature.append("jobjectArray");
+ else if ( "org.lwjgl.opencl.CLMem".equals(className) )
+ signature.append("jobjectArray");
else
throw new RuntimeException(t + " is not allowed");
}
diff --git a/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java b/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
index 6f07a2ed..860ee6ce 100644
--- a/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
+++ b/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
@@ -41,6 +41,9 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.util.generator.opengl.GLreturn;
+
import com.sun.mirror.apt.*;
import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
@@ -50,7 +53,7 @@ import java.util.*;
import java.nio.*;
public class JavaMethodsGenerator {
- private final static String SAVED_PARAMETER_POSTFIX = "_saved";
+ private static final String SAVED_PARAMETER_POSTFIX = "_saved";
public static void generateMethodsJava(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration interface_decl, boolean generate_error_checks, boolean context_specific) {
for (MethodDeclaration method : interface_decl.getMethods())
@@ -71,8 +74,14 @@ public class JavaMethodsGenerator {
if ( method.getAnnotation(CachedResult.class) != null && !method.getAnnotation(CachedResult.class).isRange() ) {
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.CACHEDRESULT, generate_error_checks, context_specific);
}
+
+ // Skip the native function if we're re-using.
+ Reuse reuse_annotation = method.getAnnotation(Reuse.class);
+ if ( reuse_annotation != null )
+ return;
+
Alternate alt_annotation = method.getAnnotation(Alternate.class);
- if ( alt_annotation == null || alt_annotation.nativeAlt() ) {
+ if ( alt_annotation == null || (alt_annotation.nativeAlt() && !alt_annotation.skipNative()) ) {
if ( alt_annotation != null && method.getSimpleName().equals(alt_annotation.value()) )
throw new RuntimeException("An alternate function with native code should have a different name than the main function.");
printJavaNativeStub(writer, method, Mode.NORMAL, generate_error_checks, context_specific);
@@ -90,12 +99,12 @@ public class JavaMethodsGenerator {
Utils.printDocComment(writer, method);
writer.print("\tpublic static native ");
}
- printResultType(writer, method, true);
+ writer.print(getResultType(method, true));
writer.print(" " + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT)
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
writer.print("(");
- boolean first_parameter = generateParametersJava(writer, method, TypeInfo.getDefaultTypeInfoMap(method), true, mode);
+ boolean first_parameter = generateParametersJava(writer, method, TypeInfo.getDefaultTypeInfoMap(method), true, true, mode);
if (context_specific) {
if (!first_parameter)
writer.print(", ");
@@ -104,10 +113,14 @@ public class JavaMethodsGenerator {
writer.println(");");
}
- private static boolean generateParametersJava(PrintWriter writer, MethodDeclaration method, Map typeinfos_instance,
- boolean native_stub, Mode mode) {
+ private static boolean generateParametersJava(PrintWriter writer, MethodDeclaration method, Map typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) {
boolean first_parameter = true;
for (ParameterDeclaration param : method.getParameters()) {
+ if ( native_stub && param.getAnnotation(Helper.class) != null )
+ continue;
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( constant_annotation != null && constant_annotation.isNative() )
+ continue;
AnnotationMirror auto_annotation_mirror = Utils.getParameterAutoAnnotation(param);
boolean hide_auto_parameter = mode == Mode.NORMAL && !native_stub && auto_annotation_mirror != null;
if (hide_auto_parameter) {
@@ -119,44 +132,53 @@ public class JavaMethodsGenerator {
if (!first_parameter)
writer.print(", ");
first_parameter = false;
- writer.print("boolean " + TypeInfo.UNSIGNED_PARAMETER_NAME);
+ if ( printTypes )
+ writer.print("boolean ");
+ writer.print( TypeInfo.UNSIGNED_PARAMETER_NAME);
}
}
} else if (
param.getAnnotation(Result.class) == null
&& (native_stub || ((param.getAnnotation(Constant.class) == null || param.getAnnotation(Constant.class).keepParam()) && !Utils.isReturnParameter(method, param)))
- && (getAutoTypeParameter(method, param) == null || mode != Mode.AUTOS)
- )
- {
- TypeInfo type_info = typeinfos_instance.get(param);
- first_parameter = generateParameterJava(writer, param, type_info, native_stub, first_parameter, mode);
+ && (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)
+ ) {
+ first_parameter = generateParameterJava(writer, param, typeinfos_instance.get(param), native_stub, printTypes, first_parameter, mode);
}
}
CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
TypeMirror result_type = Utils.getMethodReturnType(method);
if ((native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method)) {
- if (cached_result_annotation == null || !cached_result_annotation.isRange()) {
- if (!first_parameter)
- writer.print(", ");
- first_parameter = false;
- writer.print("long " + Utils.RESULT_SIZE_NAME);
+ AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
+ if ( auto_size_annotation == null || !auto_size_annotation.isNative() ) {
+ if (cached_result_annotation == null || !cached_result_annotation.isRange()) {
+ if (!first_parameter)
+ writer.print(", ");
+ first_parameter = false;
+ if ( printTypes )
+ writer.print("long ");
+ writer.print(Utils.RESULT_SIZE_NAME);
+ }
}
}
if (cached_result_annotation != null) {
if (!first_parameter)
writer.print(", ");
- if ( mode == Mode.CACHEDRESULT )
- writer.print("long " + Utils.CACHED_BUFFER_LENGTH_NAME + ", ");
+ if ( mode == Mode.CACHEDRESULT ) {
+ if ( printTypes )
+ writer.print("long ");
+ writer.print(Utils.CACHED_BUFFER_LENGTH_NAME + ", ");
+ }
first_parameter = false;
- printResultType(writer, method, native_stub);
+ if ( printTypes )
+ writer.print(getResultType(method, native_stub));
writer.print(" " + Utils.CACHED_BUFFER_NAME);
}
return first_parameter;
}
- private static boolean generateParameterJava(PrintWriter writer, ParameterDeclaration param, TypeInfo type_info, boolean native_stub, boolean first_parameter, Mode mode) {
+ private static boolean generateParameterJava(PrintWriter writer, ParameterDeclaration param, TypeInfo type_info, boolean native_stub, final boolean printTypes, boolean first_parameter, Mode mode) {
Class buffer_type = Utils.getNIOBufferType(param.getType());
if (!first_parameter)
writer.print(", ");
@@ -164,18 +186,23 @@ public class JavaMethodsGenerator {
if (bo_annotation != null && mode == Mode.BUFFEROBJECT) {
if (buffer_type == null)
throw new RuntimeException("type of " + param + " is not a nio Buffer parameter but is annotated as buffer object");
- writer.print("long " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
+ if ( printTypes )
+ writer.print("long ");
+ writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else {
- if ( native_stub && param.getAnnotation(GLpointer.class) != null )
- writer.print("long");
+ if ( native_stub && param.getAnnotation(PointerWrapper.class) != null )
+ writer.print("long ");
else {
Class type = type_info.getType();
- if ( native_stub && (type == CharSequence.class || type == CharSequence[].class) )
- writer.print("ByteBuffer");
- else
- writer.print(type_info.getType().getSimpleName());
+ if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class) )
+ writer.print("ByteBuffer ");
+ else if ( printTypes )
+ writer.print(type_info.getType().getSimpleName() + " ");
}
- writer.print(" " + param.getSimpleName());
+ AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
+ if ( auto_size_annotation != null )
+ writer.print(auto_size_annotation.value() + "_");
+ writer.print(param.getSimpleName());
if ( native_stub && buffer_type != null )
writer.print(", int " + param.getSimpleName() + NativeMethodStubsGenerator.BUFFER_POSITION_POSTFIX);
}
@@ -205,8 +232,11 @@ public class JavaMethodsGenerator {
private static void printMethodWithMultiType(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method, Map typeinfos_instance, Mode mode, boolean generate_error_checks, boolean context_specific) {
Utils.printDocComment(writer, method);
- writer.print("\tpublic static ");
- printResultType(writer, method, false);
+ if ( interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null )
+ writer.print("\tpublic static ");
+ else
+ writer.print("\tstatic ");
+ writer.print(getResultType(method, false));
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
String method_name;
Alternate alt_annotation = method.getAnnotation(Alternate.class);
@@ -214,32 +244,60 @@ public class JavaMethodsGenerator {
if (strip_annotation != null && mode == Mode.NORMAL)
method_name = getPostfixStrippedName(type_map, interface_decl, method);
writer.print(" " + method_name + "(");
- generateParametersJava(writer, method, typeinfos_instance, false, mode);
- TypeMirror result_type = Utils.getMethodReturnType(method);
+ generateParametersJava(writer, method, typeinfos_instance, false, true, mode);
writer.println(") {");
+
+ final TypeMirror result_type = Utils.getMethodReturnType(method);
+ boolean has_result = !result_type.equals(env.getTypeUtils().getVoidType());
+
+ final Reuse reuse_annotation = method.getAnnotation(Reuse.class);
+ if ( reuse_annotation != null ) {
+ writer.print("\t\t");
+ if ( has_result || method.getAnnotation(GLreturn.class) != null )
+ writer.print("return ");
+
+ writer.print(reuse_annotation.value() + "." + method_name + "(");
+ generateParametersJava(writer, method, typeinfos_instance, false, false, mode);
+ writer.println(");\n\t}");
+ return;
+ }
+
if (context_specific) {
- writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
- writer.print("\t\tlong " + Utils.FUNCTION_POINTER_VAR_NAME + " = caps.");
+ type_map.printCapabilitiesInit(writer);
+ writer.print("\t\tlong " + Utils.FUNCTION_POINTER_VAR_NAME + " = " + type_map.getCapabilities() + ".");
writer.println(Utils.getFunctionAddressName(interface_decl, method, true) + ";");
writer.print("\t\tBufferChecks.checkFunctionAddress(");
writer.println(Utils.FUNCTION_POINTER_VAR_NAME + ");");
}
- Code code_annotation = method.getAnnotation(Code.class);
- if (code_annotation != null)
+ final Code code_annotation = method.getAnnotation(Code.class);
+ if (code_annotation != null && code_annotation.value().length() > 0)
writer.println(code_annotation.value());
printBufferObjectChecks(writer, method, mode);
- printParameterChecks(writer, method, typeinfos_instance, mode);
+ printParameterChecks(writer, method, typeinfos_instance, mode, generate_error_checks);
printParameterCaching(writer, interface_decl, method, mode);
- writer.print("\t\t");
- boolean has_result = !result_type.equals(env.getTypeUtils().getVoidType());
- if (has_result) {
- printResultType(writer, method, false);
- writer.print(" " + Utils.RESULT_VAR_NAME + " = ");
- if ( method.getAnnotation(GLpointer.class) != null )
- writer.print("new " + method.getReturnType() + "(");
- }
- if ( method.getAnnotation(GLreturn.class) != null ) {
+ if ( code_annotation != null && code_annotation.javaBeforeNative().length() > 0 )
+ writer.println(code_annotation.javaBeforeNative());
+ writer.print("\t\t");
+
+ final PointerWrapper pointer_wrapper_annotation = method.getAnnotation(PointerWrapper.class);
+ if (has_result) {
+ writer.print(getResultType(method, false) + " " + Utils.RESULT_VAR_NAME);
+
+ if ( code_annotation != null && code_annotation.tryBlock() ) {
+ writer.print(" = " + getDefaultResultValue(method));
+ writer.println(";\n\t\ttry {");
+ writer.print("\t\t\t" + Utils.RESULT_VAR_NAME);
+ }
+
+ writer.print(" = ");
+ if ( pointer_wrapper_annotation != null ) {
+ if ( pointer_wrapper_annotation.factory().length() > 0 )
+ writer.print(pointer_wrapper_annotation.factory() + "(");
+ else
+ writer.print("new " + getResultType(method, false) + "(");
+ }
+ } else if ( method.getAnnotation(GLreturn.class) != null ) {
has_result = true;
Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class));
}
@@ -253,22 +311,36 @@ public class JavaMethodsGenerator {
writer.print(", ");
writer.print(Utils.FUNCTION_POINTER_VAR_NAME);
}
- if ( has_result && method.getAnnotation(GLpointer.class) != null )
+ if ( has_result && pointer_wrapper_annotation != null ) {
writer.print(")");
+ if ( pointer_wrapper_annotation.params().length() > 0 )
+ writer.print(", " + pointer_wrapper_annotation.params());
+ }
writer.println(");");
+
+ if ( code_annotation != null && code_annotation.javaAfterNative().length() > 0 )
+ writer.println(code_annotation.javaAfterNative());
+
+ final String tabs = code_annotation != null && code_annotation.tryBlock() ? "\t\t\t" : "\t\t";
if (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null)
- writer.println("\t\t" + type_map.getErrorCheckMethodName() + ";");
+ type_map.printErrorCheckMethod(writer, method, tabs);
// DISABLED: indirect buffer support
//printNondirectParameterCopies(writer, method, mode);
if (has_result) {
if ( method.getAnnotation(GLreturn.class) == null ) {
if ( ByteBuffer.class.equals(Utils.getJavaType(result_type)) )
- writer.println("\t\treturn LWJGLUtil.CHECKS && " + Utils.RESULT_VAR_NAME + " == null ? null : " + Utils.RESULT_VAR_NAME + ".order(ByteOrder.nativeOrder());"); // safeNewBuffer returns a direct ByteBuffer with BIG_ENDIAN order.
+ writer.println(tabs + "return LWJGLUtil.CHECKS && " + Utils.RESULT_VAR_NAME + " == null ? null : " + 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 + ";");
+ writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";");
} else
Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class));
}
+
+ if ( code_annotation != null && code_annotation.tryBlock() ) {
+ writer.println("\t\t} finally {");
+ writer.println(code_annotation.javaFinally());
+ writer.println("\t\t}");
+ }
writer.println("\t}");
}
@@ -296,7 +368,7 @@ public class JavaMethodsGenerator {
else if (annotation_type.equals(AutoSize.class))
parameter_name = param.getAnnotation(AutoSize.class).value();
else
- throw new RuntimeException("Unkown annotation type " + annotation_type);
+ throw new RuntimeException("Unknown annotation type " + annotation_type);
if (target_parameter.getSimpleName().equals(parameter_name))
return param;
}
@@ -368,6 +440,7 @@ public class JavaMethodsGenerator {
private static boolean printMethodCallArgument(PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Map typeinfos_instance, Mode mode, boolean first_parameter) {
if (!first_parameter)
writer.print(", ");
+
AnnotationMirror auto_annotation = Utils.getParameterAutoAnnotation(param);
Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation != null) {
@@ -375,31 +448,34 @@ public class JavaMethodsGenerator {
} else if (auto_annotation != null && mode == Mode.NORMAL) {
Class param_type = NativeTypeTranslator.getClassFromType(auto_annotation.getAnnotationType());
if (AutoType.class.equals(param_type)) {
- AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
- String auto_parameter_name = auto_type_annotation.value();
- ParameterDeclaration auto_parameter = Utils.findParameter(method, auto_parameter_name);
- String auto_type = typeinfos_instance.get(auto_parameter).getAutoType();
- if (auto_type == null)
+ final AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
+ final ParameterDeclaration auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
+ final String auto_type = typeinfos_instance.get(auto_parameter).getAutoType();
+ if ( auto_type == null )
throw new RuntimeException("No auto type for parameter " + param.getSimpleName() + " in method " + method);
writer.print(auto_type);
} else if (AutoSize.class.equals(param_type)) {
- AutoSize auto_type_annotation = param.getAnnotation(AutoSize.class);
- String auto_parameter_name = auto_type_annotation.value();
- ParameterDeclaration auto_target_param = Utils.findParameter(method, auto_parameter_name);
- TypeInfo auto_target_type_info = typeinfos_instance.get(auto_target_param);
- if ( auto_type_annotation.canBeNull() )
- writer.print("((" + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + ".remaining())");
- else
- writer.print("(" + auto_parameter_name + ".remaining()");
- // Shift the remaining if the target parameter is multityped and there's no AutoType to track type
- boolean shift_remaining = !hasAnyParameterAutoTypeAnnotation(method, auto_target_param) && Utils.isParameterMultiTyped(auto_target_param);
- if (shift_remaining) {
- int shifting = getBufferElementSizeExponent(auto_target_type_info.getType());
- if (shifting > 0)
- writer.print(" << " + shifting);
+ final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
+ final String auto_parameter_name = auto_size_annotation.value();
+ final ParameterDeclaration auto_target_param = Utils.findParameter(method, auto_parameter_name);
+ final TypeInfo auto_target_type_info = typeinfos_instance.get(auto_target_param);
+ final boolean shift_remaining = !hasAnyParameterAutoTypeAnnotation(method, auto_target_param) && Utils.isParameterMultiTyped(auto_target_param);
+ int shifting = 0;
+ if ( shift_remaining ) {
+ shifting = getBufferElementSizeExponent(auto_target_type_info.getType());
+ if ( shifting > 0 )
+ writer.print("(");
}
- writer.print(")");
- writer.print(auto_type_annotation.expression());
+ if ( auto_size_annotation.canBeNull() )
+ writer.print("(" + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + ".remaining())");
+ else
+ writer.print(auto_parameter_name + ".remaining()");
+ // Shift the remaining if the target parameter is multityped and there's no AutoType to track type
+ if (shift_remaining && shifting > 0) {
+ writer.print(" << " + shifting);
+ writer.print(")");
+ }
+ writer.print(auto_size_annotation.expression());
} else
throw new RuntimeException("Unknown auto annotation " + param_type);
} else {
@@ -407,14 +483,15 @@ public class JavaMethodsGenerator {
writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else {
Class type = typeinfos_instance.get(param).getType();
+ Check check_annotation = param.getAnnotation(Check.class);
boolean hide_buffer = mode == Mode.AUTOS && getAutoTypeParameter(method, param) != null;
- if (hide_buffer)
+ if (hide_buffer) {
writer.print("null");
- else {
+ } else {
if ( type == CharSequence.class || type == CharSequence[].class ) {
final String offset = Utils.getStringOffset(method, param);
- writer.print("APIUtils.getBuffer");
+ writer.print("APIUtil.getBuffer");
if ( param.getAnnotation(NullTerminated.class) != null )
writer.print("NT");
writer.print("(" + param.getSimpleName());
@@ -422,24 +499,37 @@ public class JavaMethodsGenerator {
writer.print(", " + offset);
writer.print(")");
hide_buffer = true;
- } else
+ } else {
+ final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
+ if ( auto_size_annotation != null )
+ writer.print(auto_size_annotation.value() + "_");
writer.print(param.getSimpleName());
+ if ( PointerBuffer.class.isAssignableFrom(type) ) {
+ if ( check_annotation != null && check_annotation.canBeNull() )
+ writer.print(" != null ? " + param.getSimpleName());
+ writer.print(".getBuffer()");
+ if ( check_annotation != null && check_annotation.canBeNull() )
+ writer.print(" : null");
+ }
+ }
}
Class buffer_type = Utils.getNIOBufferType(param.getType());
if (buffer_type != null) {
writer.print(", ");
if (!hide_buffer) {
- TypeInfo type_info = typeinfos_instance.get(param);
- Check check_annotation = param.getAnnotation(Check.class);
int shifting;
- if (Utils.getNIOBufferType(param.getType()).equals(Buffer.class))
- shifting = getBufferElementSizeExponent(type_info.getType());
- else
+ if (Utils.getNIOBufferType(param.getType()).equals(Buffer.class)) {
+ shifting = getBufferElementSizeExponent(type == Buffer.class ? ByteBuffer.class : type); // TODO: This will always throw an exception
+ //shifting = 0;
+ } else
shifting = 0;
writer.print(param.getSimpleName());
if (check_annotation != null && check_annotation.canBeNull())
writer.print(" != null ? " + param.getSimpleName());
- writer.print(".position()");
+ if ( type == PointerBuffer.class )
+ writer.print(".positionByte()");
+ else
+ writer.print(".position()");
if (shifting > 0)
writer.print(" << " + shifting);
if (check_annotation != null && check_annotation.canBeNull())
@@ -449,8 +539,8 @@ public class JavaMethodsGenerator {
writer.print(offset == null ? "0" : offset);
} else
writer.print("0");
- } else {
- GLpointer pointer_annotation = param.getAnnotation(GLpointer.class);
+ } else if ( type != long.class ) {
+ PointerWrapper pointer_annotation = param.getAnnotation(PointerWrapper.class);
if ( pointer_annotation != null ) {
if ( pointer_annotation.canBeNull() )
writer.print(" == null ? 0 : " + param.getSimpleName());
@@ -464,30 +554,35 @@ public class JavaMethodsGenerator {
private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map typeinfos_instance, Mode mode) {
boolean first_parameter = true;
- for (ParameterDeclaration param : method.getParameters())
- if (param.getAnnotation(Result.class) == null) {
+ for ( ParameterDeclaration param : method.getParameters() ) {
+ if ( param.getAnnotation(Result.class) != null || param.getAnnotation(Helper.class) != null )
+ continue;
+
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( constant_annotation== null || !constant_annotation.isNative() )
first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter);
- }
+ }
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) {
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) {
first_parameter = false;
Utils.printExtraCallArguments(writer, method, "");
} else {
- if (!first_parameter)
- writer.print(", ");
- first_parameter = false;
+ AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
+ if ( auto_size_annotation == null || !auto_size_annotation.isNative() ) {
+ if (!first_parameter)
+ writer.print(", ");
+ first_parameter = false;
- String result_size_expression;
- if ( mode == Mode.CACHEDRESULT )
- result_size_expression = Utils.CACHED_BUFFER_LENGTH_NAME;
- else {
- AutoResultSize auto_result_size_annotation = method.getAnnotation(AutoResultSize.class);
- if (auto_result_size_annotation == null)
+ String result_size_expression;
+ if ( mode == Mode.CACHEDRESULT )
+ result_size_expression = Utils.CACHED_BUFFER_LENGTH_NAME;
+ else if ( auto_size_annotation == null )
result_size_expression = Utils.RESULT_SIZE_NAME;
else
- result_size_expression = auto_result_size_annotation.value();
+ result_size_expression = auto_size_annotation.value();
+
+ Utils.printExtraCallArguments(writer, method, result_size_expression);
}
- Utils.printExtraCallArguments(writer, method, result_size_expression);
}
}
return first_parameter;
@@ -531,14 +626,33 @@ public class JavaMethodsGenerator {
}
}
- private static void printParameterChecks(PrintWriter writer, MethodDeclaration method, Map typeinfos, Mode mode) {
+ private static void printParameterChecks(PrintWriter writer, MethodDeclaration method, Map typeinfos, Mode mode, final boolean generate_error_checks) {
+ if ( mode == Mode.NORMAL ) {
+ final GenerateAutos gen_autos_annotation = method.getAnnotation(GenerateAutos.class);
+ if ( gen_autos_annotation != null && gen_autos_annotation.sizeVariables().length > 0 ) {
+ // For the auto-generated parameters, declare and init a size variable (that can be reused by @Code)
+ for ( final ParameterDeclaration param : method.getParameters() ) {
+ if ( Arrays.binarySearch(gen_autos_annotation.sizeVariables(), param.getSimpleName()) >= 0 ) {
+ final int shifting = getBufferElementSizeExponent(typeinfos.get(param).getType());
+ final Check check_annotation = param.getAnnotation(Check.class);
+
+ writer.print("\t\tlong " + param.getSimpleName() + "_size = ");
+ if ( check_annotation == null || !check_annotation.canBeNull() )
+ writer.println(param.getSimpleName() + ".remaining() << " + shifting + ";");
+ else
+ writer.println(param.getSimpleName() + " == null ? 0 : " + param.getSimpleName() + ".remaining() << " + shifting + ";");
+ }
+ }
+ }
+ }
+
for (ParameterDeclaration param : method.getParameters()) {
Class java_type = Utils.getJavaType(param.getType());
- if (Utils.isAddressableType(java_type) &&
+ if ( java_type.isArray() || (Utils.isAddressableType(java_type) &&
(mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) &&
(mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) &&
param.getAnnotation(Result.class) == null &&
- !Utils.isReturnParameter(method, param) ) {
+ !Utils.isReturnParameter(method, param)) ) {
String check_value = null;
boolean can_be_null = false;
Check check_annotation = param.getAnnotation(Check.class);
@@ -546,59 +660,115 @@ public class JavaMethodsGenerator {
check_value = check_annotation.value();
can_be_null = check_annotation.canBeNull();
}
- NullTerminated null_terminated = param.getAnnotation(NullTerminated.class);
- if (Buffer.class.isAssignableFrom(java_type) && param.getAnnotation(Constant.class) == null) {
+ if ((Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null) {
boolean indirect_buffer_allowed = false && param.getAnnotation(CachedReference.class) == null; // DISABLED: indirect buffer support
boolean out_parameter = param.getAnnotation(OutParameter.class) != null;
TypeInfo typeinfo = typeinfos.get(param);
- printParameterCheck(writer, param.getSimpleName(), typeinfo.getType().getSimpleName(), check_value, can_be_null, null_terminated, indirect_buffer_allowed, out_parameter);
+ printParameterCheck(writer, method, param.getSimpleName(), typeinfo.getType().getSimpleName(), check_value, can_be_null, param.getAnnotation(NullTerminated.class), indirect_buffer_allowed, out_parameter, generate_error_checks);
} else if ( String.class.equals(java_type)) {
if (!can_be_null)
writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");");
+ } else if ( java_type.isArray() ) {
+ final TypeInfo typeinfo = typeinfos.get(param);
+ printArrayParameterCheck(writer, param.getSimpleName(), typeinfo.getType().getSimpleName(), check_value, can_be_null);
}
}
}
if (method.getAnnotation(CachedResult.class) != null)
- printParameterCheck(writer, Utils.CACHED_BUFFER_NAME, null, null, true, null, false, false);
+ printParameterCheck(writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, false, false, generate_error_checks);
}
- private static void printParameterCheck(PrintWriter writer, String name, String type, String check_value, boolean can_be_null, NullTerminated null_terminated, boolean indirect_buffer_allowed, boolean out_parameter) {
+ private static void printParameterCheck(PrintWriter writer, MethodDeclaration method, String name, String type, String check_value, boolean can_be_null, NullTerminated null_terminated, boolean indirect_buffer_allowed, boolean out_parameter, final boolean generate_error_checks) {
if (indirect_buffer_allowed && out_parameter) {
writer.println("\t\t" + type + " " + name + SAVED_PARAMETER_POSTFIX + " = " + name + ";");
}
+ String tabs;
if (can_be_null) {
- writer.println("\t\tif (" + name + " != null)");
- writer.print("\t");
- }
+ writer.print("\t\tif (" + name + " != null)");
+ if ( null_terminated != null )
+ writer.println(" {");
+ else
+ writer.println();
+ tabs = "\t\t\t";
+ } else
+ tabs = "\t\t";
if (indirect_buffer_allowed) {
- writer.print("\t\t" + name + " = NondirectBufferWrapper.wrap");
+ writer.print(tabs + name + " = NondirectBufferWrapper.wrap");
if (out_parameter)
writer.print("NoCopy");
} else
- writer.print("\t\tBufferChecks.check");
- if (check_value != null && !"".equals(check_value) ) {
- writer.print("Buffer(" + name + ", " + check_value);
+ writer.print(tabs + "BufferChecks.check");
+ if (check_value != null && check_value.length() > 0) {
+ writer.print("Buffer");
+ if ( "Buffer".equals(type) )
+ writer.print("Size"); // Check size only, Buffer.isDirect() was added in 1.6, cannot use yet. TODO: Remove?
+ writer.print("(" + name + ", " + check_value);
} else {
writer.print("Direct(" + name);
}
writer.println(");");
+ if ( can_be_null && generate_error_checks ) {
+ final Check check_annotation = method.getAnnotation(Check.class);
+ if ( check_annotation != null && check_annotation.value().equals(name) ) {
+ writer.println("\t\telse");
+ writer.println("\t\t\t" + name + " = APIUtil.getBufferIntDebug();"); // Use an exclusive buffer here
+ }
+ }
if (null_terminated != null) {
- writer.print("\t\tBufferChecks.checkNullTerminated(");
+ writer.print(tabs + "BufferChecks.checkNullTerminated(");
writer.print(name);
if ( null_terminated.value().length() > 0 ) {
writer.print(", ");
writer.print(null_terminated.value());
}
writer.println(");");
+ if ( can_be_null )
+ writer.println("\t\t}");
}
}
- private static void printResultType(PrintWriter writer, MethodDeclaration method, boolean native_stub) {
- if ( native_stub && method.getAnnotation(GLpointer.class) != null )
- writer.print("long");
- else if ( !native_stub && method.getAnnotation(GLreturn.class) != null )
- writer.print(Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false));
- else
- writer.print(Utils.getMethodReturnType(method).toString());
+ private static void printArrayParameterCheck(PrintWriter writer, String name, String type, String check_value, boolean can_be_null) {
+ String tabs;
+ if ( can_be_null ) {
+ writer.println("\t\tif (" + name + " != null)");
+ tabs = "\t\t\t";
+ } else
+ tabs = "\t\t";
+
+ writer.print(tabs + "BufferChecks.checkArray(" + name);
+ if ( check_value != null && check_value.length() > 0)
+ writer.print(", " + check_value);
+ writer.println(");");
}
+
+ private static String getResultType(MethodDeclaration method, boolean native_stub) {
+ if ( native_stub && method.getAnnotation(PointerWrapper.class) != null )
+ return "long";
+ else if ( !native_stub && method.getAnnotation(GLreturn.class) != null )
+ return Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
+ else
+ return Utils.getJavaType(Utils.getMethodReturnType(method)).getSimpleName();
+ }
+
+ private static String getDefaultResultValue(MethodDeclaration method) {
+ if ( method.getAnnotation(GLreturn.class) != null ) {
+ final String type = Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
+ if ( "boolean".equals(type) )
+ return "false";
+ else if ( Character.isLowerCase(type.charAt(0)) )
+ return "0";
+ else
+ return "null";
+ } else {
+ final Class type = Utils.getJavaType(Utils.getMethodReturnType(method));
+ if ( type.isPrimitive() ) {
+ if ( type == boolean.class )
+ return "false";
+ else
+ return "0";
+ } else
+ return "null";
+ }
+ }
+
}
diff --git a/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java b/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java
index 721f16ef..69e93afe 100644
--- a/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java
+++ b/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java
@@ -32,11 +32,14 @@
package org.lwjgl.util.generator;
+import org.lwjgl.opencl.CLMem;
+
+import java.nio.ByteBuffer;
+
import com.sun.mirror.type.*;
import com.sun.mirror.util.*;
/**
- *
* A TypeVisitor that translates (annotated) TypeMirrors to
* java types (represented by a Class)
*
@@ -56,10 +59,42 @@ public class JavaTypeTranslator implements TypeVisitor {
}
public void visitArrayType(ArrayType t) {
- if ( "java.lang.CharSequence".equals(t.getComponentType().toString()) )
+ final TypeMirror componentType = t.getComponentType();
+ if ( componentType instanceof PrimitiveType ) {
+ type = getPrimitiveArrayClassFromKind(((PrimitiveType)componentType).getKind());
+ } else {
+ try {
+ final Class c = Class.forName(t.getComponentType().toString());
+ if ( CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c) )
+ type = Class.forName("[L" + t.getComponentType() + ";");
+ else {
+ throw new RuntimeException(t + " is not allowed");
+ }
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ final String className = t.getComponentType().toString();
+ if ( "java.lang.CharSequence".equals(className) )
type = CharSequence[].class;
+ else if ( "java.nio.ByteBuffer".equals(className) )
+ type = ByteBuffer[].class;
+ else if ( "org.lwjgl.opencl.CLMem".equals(className) )
+ type = CLMem[].class;
else
throw new RuntimeException(t + " is not allowed");
+ //*/
+ /*
+ try {
+ System.out.println("t = " + t);
+ System.out.println("t.getClass() = " + t.getClass());
+ System.out.println("t.getComponentType() = " + t.getComponentType());
+ type = Class.forName(t.toString());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }*/
}
public static Class getPrimitiveClassFromKind(PrimitiveType.Kind kind) {
@@ -83,6 +118,27 @@ public class JavaTypeTranslator implements TypeVisitor {
}
}
+ private static Class getPrimitiveArrayClassFromKind(PrimitiveType.Kind kind) {
+ switch ( kind ) {
+ case LONG:
+ return long[].class;
+ case INT:
+ return int[].class;
+ case DOUBLE:
+ return double[].class;
+ case FLOAT:
+ return float[].class;
+ case SHORT:
+ return short[].class;
+ case BYTE:
+ return byte[].class;
+ case BOOLEAN:
+ return boolean[].class;
+ default:
+ throw new RuntimeException(kind + " is not allowed");
+ }
+ }
+
public void visitPrimitiveType(PrimitiveType t) {
type = getPrimitiveClassFromKind(t.getKind());
}
diff --git a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
index 858df19f..dfbc4c49 100644
--- a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
+++ b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
@@ -41,6 +41,8 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.PointerBuffer;
+
import com.sun.mirror.apt.*;
import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
@@ -52,12 +54,13 @@ import java.nio.*;
public class NativeMethodStubsGenerator {
private static final String BUFFER_ADDRESS_POSTFIX = "_address";
public static final String BUFFER_POSITION_POSTFIX = "_position";
- private static final String STRING_LIST_POSTFIX = "_str";
+ private static final String STRING_LIST_NAME = "_str";
+ private static final String POINTER_LIST_NAME = "_ptr";
public static void generateNativeMethodStubs(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration d, boolean generate_error_checks, boolean context_specific) {
for (MethodDeclaration method : d.getMethods()) {
Alternate alt_annotation = method.getAnnotation(Alternate.class);
- if ( alt_annotation != null && !alt_annotation.nativeAlt() )
+ if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
continue;
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.NORMAL, generate_error_checks, context_specific);
if (Utils.hasMethodBufferObjectParameter(method))
@@ -66,16 +69,20 @@ public class NativeMethodStubsGenerator {
}
private static void generateParameters(PrintWriter writer, Collection params, Mode mode) {
- for (ParameterDeclaration param : params)
- if (param.getAnnotation(Result.class) == null)
+ for (ParameterDeclaration param : params) {
+ if ( param.getAnnotation(Helper.class) != null || param.getAnnotation(Result.class) != null )
+ continue;
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( constant_annotation == null || !constant_annotation.isNative() )
generateParameter(writer, param, mode);
+ }
}
private static void generateParameter(PrintWriter writer, ParameterDeclaration param, Mode mode) {
writer.print(", ");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
writer.print("jlong " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
- } else if ( param.getAnnotation(GLpointer.class) != null ) {
+ } else if ( param.getAnnotation(PointerWrapper.class) != null ) {
writer.print("jlong " + param.getSimpleName());
} else {
JNITypeTranslator translator = new JNITypeTranslator();
@@ -92,9 +99,11 @@ public class NativeMethodStubsGenerator {
else
writer.print("JNIEXPORT ");
- TypeMirror result_type = Utils.getMethodReturnType(method);
+ final TypeMirror result_type = Utils.getMethodReturnType(method);
+ final CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
+ final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
- if ( method.getAnnotation(GLpointer.class) != null ) {
+ if ( method.getAnnotation(PointerWrapper.class) != null ) {
writer.print("jlong");
} else {
JNITypeTranslator translator = new JNITypeTranslator();
@@ -109,8 +118,7 @@ public class NativeMethodStubsGenerator {
writer.print("(JNIEnv *env, jclass clazz");
generateParameters(writer, method.getParameters(), mode);
if (Utils.getNIOBufferType(result_type) != null) {
- CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
- if (cached_result_annotation == null || !cached_result_annotation.isRange())
+ if ( (cached_result_annotation == null || !cached_result_annotation.isRange()) && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
if (cached_result_annotation != null)
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
@@ -119,6 +127,7 @@ public class NativeMethodStubsGenerator {
writer.print(", jlong " + Utils.FUNCTION_POINTER_VAR_NAME);
}
writer.println(") {");
+
generateBufferParameterAddresses(type_map, writer, method, mode);
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if (context_specific) {
@@ -127,49 +136,59 @@ public class NativeMethodStubsGenerator {
writer.print(" = (" + typedef_name + ")((intptr_t)");
writer.println(Utils.FUNCTION_POINTER_VAR_NAME + ");");
}
- generateStringListInits(writer, method.getParameters());
+
+ final Code code_annotation = method.getAnnotation(Code.class);
+
+ final boolean hasResult = !result_type.equals(env.getTypeUtils().getVoidType());
+ final boolean resultPreDeclare = hasResult && (hasPointerArrayInits(method.getParameters()) || (code_annotation != null && (code_annotation.nativeAfterVars().length() > 0 || code_annotation.nativeBeforeCall().length() > 0)));
+ if ( resultPreDeclare )
+ printResultParam(type_map, writer, method, result_type, true);
+
+ if ( code_annotation != null && code_annotation.nativeAfterVars().length() > 0 )
+ writer.println(code_annotation.nativeAfterVars());
+
+ generatePointerArrayInits(type_map, writer, method.getParameters());
+
+ if ( code_annotation != null && code_annotation.nativeBeforeCall().length() > 0 )
+ writer.println(code_annotation.nativeBeforeCall());
+
writer.print("\t");
- if (!result_type.equals(env.getTypeUtils().getVoidType())) {
- Declaration return_declaration;
- ParameterDeclaration result_param = Utils.getResultParameter(method);
- if (result_param != null)
- return_declaration = result_param;
- else
- return_declaration = method;
- NativeTypeTranslator native_translator = new NativeTypeTranslator(type_map, return_declaration);
- result_type.accept(native_translator);
- writer.print(native_translator.getSignature() + " " + Utils.RESULT_VAR_NAME);
- if (result_param != null) {
- writer.println(";");
- writer.print("\t");
- } else
- writer.print(" = ");
- }
+ if ( resultPreDeclare )
+ writer.print(Utils.RESULT_VAR_NAME + " = ");
+ else if ( hasResult )
+ printResultParam(type_map, writer, method, result_type, false);
writer.print((alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + "(");
generateCallParameters(writer, type_map, method.getParameters());
writer.print(")");
writer.println(";");
+
+ if ( code_annotation != null && code_annotation.nativeAfterCall().length() > 0 )
+ writer.println(code_annotation.nativeAfterCall());
+
generateStringDeallocations(writer, method.getParameters());
if (!result_type.equals(env.getTypeUtils().getVoidType())) {
writer.print("\treturn ");
Class java_result_type = Utils.getJavaType(result_type);
if (Buffer.class.isAssignableFrom(java_result_type)) {
- if (method.getAnnotation(CachedResult.class) != null)
+ if (cached_result_annotation != null)
writer.print("safeNewBufferCached(env, ");
else
writer.print("safeNewBuffer(env, ");
} else if (String.class.equals(java_result_type)) {
writer.print("NewStringNativeUnsigned(env, ");
- } else if ( method.getAnnotation(GLpointer.class) != null ) {
+ } else if ( method.getAnnotation(PointerWrapper.class) != null ) {
writer.print("(intptr_t)");
}
writer.print(Utils.RESULT_VAR_NAME);
if (Buffer.class.isAssignableFrom(java_result_type)) {
- writer.print(", ");
- if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange())
- Utils.printExtraCallArguments(writer, method, method.getAnnotation(AutoResultSize.class).value());
+ final String size_parameter_name;
+ if ( auto_size_annotation != null && (auto_size_annotation.isNative() || (cached_result_annotation != null && cached_result_annotation.isRange())) )
+ size_parameter_name = auto_size_annotation.value();
else
- Utils.printExtraCallArguments(writer, method, Utils.RESULT_SIZE_NAME);
+ size_parameter_name = Utils.RESULT_SIZE_NAME;
+
+ writer.print(", ");
+ Utils.printExtraCallArguments(writer, method, size_parameter_name);
}
if (Buffer.class.isAssignableFrom(java_result_type) ||
String.class.equals(java_result_type))
@@ -180,133 +199,226 @@ public class NativeMethodStubsGenerator {
writer.println();
}
+ private static void printResultParam(final TypeMap type_map, final PrintWriter writer, final MethodDeclaration method, final TypeMirror result_type, final boolean preDeclare) {
+ final ParameterDeclaration result_param = Utils.getResultParameter(method);
+ final Declaration return_declaration = result_param == null ? method : result_param;
+ final NativeTypeTranslator result_translator = new NativeTypeTranslator(type_map, return_declaration);
+ result_type.accept(result_translator);
+ if ( preDeclare )
+ writer.print("\t");
+ writer.print(result_translator.getSignature() + " " + Utils.RESULT_VAR_NAME);
+ if ( preDeclare)
+ writer.println(";");
+ else
+ writer.print(result_param == null ? " = " : ";\n\t");
+ }
+
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, Collection params) {
if (params.size() > 0) {
- Iterator it = params.iterator();
- generateCallParameter(writer, type_map, it.next());
- while (it.hasNext()) {
- writer.print(", ");
- generateCallParameter(writer, type_map, it.next());
+ boolean first = true;
+ for ( ParameterDeclaration param : params ) {
+ if ( param.getAnnotation(Helper.class) != null )
+ continue;
+
+ if ( first )
+ first = false;
+ else
+ writer.print(", ");
+
+ generateCallParameter(writer, type_map, param);
}
}
}
private static void generateCallParameter(PrintWriter writer, TypeMap type_map, ParameterDeclaration param) {
+ if ( param.getAnnotation(Helper.class) != null )
+ return;
+
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( constant_annotation != null && constant_annotation.isNative() ) {
+ writer.print(constant_annotation.value());
+ return;
+ }
+
boolean is_indirect = param.getAnnotation(Indirect.class) != null;
- if (is_indirect || param.getAnnotation(StringList.class) != null) {
+ if (is_indirect || param.getAnnotation(PointerArray.class) != null) {
writer.print("(");
- NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
+ final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.getType().accept(translator);
writer.print(translator.getSignature());
writer.print("*)");
}
- if ( param.getAnnotation(GLpointer.class) != null )
- writer.print("(" + param.getAnnotation(GLpointer.class).value() + ")(intptr_t)");
+ if ( param.getAnnotation(PointerWrapper.class) != null )
+ writer.print("(" + param.getAnnotation(PointerWrapper.class).value() + ")(intptr_t)");
if (param.getAnnotation(Result.class) != null || is_indirect)
writer.print("&");
- if (param.getAnnotation(Result.class) != null) {
+
+ if ( param.getAnnotation(Result.class) != null ) {
writer.print(Utils.RESULT_VAR_NAME);
} else {
writer.print(param.getSimpleName());
- if ( param.getAnnotation(StringList.class) != null )
- writer.print(STRING_LIST_POSTFIX);
- else if (Utils.isAddressableType(param.getType()))
+ if ( param.getAnnotation(PointerArray.class) != null )
+ writer.print(getPointerArrayName(Utils.getJavaType(param.getType())));
+ else if ( Utils.isAddressableType(param.getType()) )
writer.print(BUFFER_ADDRESS_POSTFIX);
}
}
private static void generateStringDeallocations(PrintWriter writer, Collection params) {
for (ParameterDeclaration param : params) {
- if (Utils.getJavaType(param.getType()).equals(String.class) &&
- param.getAnnotation(Result.class) == null)
+ final Class java_type = Utils.getJavaType(param.getType());
+ if ( java_type.equals(String.class) && param.getAnnotation(Result.class) == null )
writer.println("\tfree(" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ");");
- else if (param.getAnnotation(StringList.class) != null ) // Free the string array mem
- writer.println("\tfree(" + param.getSimpleName() + STRING_LIST_POSTFIX + ");");
+ else if (param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
+ writer.println("\tfree(" + param.getSimpleName() + getPointerArrayName(java_type) + ");");
}
}
private static void generateBufferParameterAddresses(TypeMap type_map, PrintWriter writer, MethodDeclaration method, Mode mode) {
- boolean loopDeclared = false;
- for (ParameterDeclaration param : method.getParameters())
- if (Utils.isAddressableType(param.getType()) && param.getAnnotation(Result.class) == null)
- loopDeclared = generateBufferParameterAddress(type_map, writer, method, param, mode, loopDeclared);
+ strLoopDeclared = false;
+ ptrLoopDeclared = false;
+ for ( ParameterDeclaration param : method.getParameters() ) {
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.getType()))
+ generateBufferParameterAddress(type_map, writer, method, param, mode);
+ }
}
- private static boolean generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Mode mode, boolean loopDeclared) {
- NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
+ private static boolean strLoopDeclared;
+ private static boolean ptrLoopDeclared;
+
+ private static void generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Mode mode) {
+ final Check check_annotation = param.getAnnotation(Check.class);
+ final PointerArray array_annotation = param.getAnnotation(PointerArray.class);
+ final Class java_type = Utils.getJavaType(param.getType());
+
+ final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.getType().accept(translator);
- writer.print("\t" + translator.getSignature() + param.getSimpleName());
- writer.print(BUFFER_ADDRESS_POSTFIX + " = ((");
- writer.print(translator.getSignature());
- Check check_annotation = param.getAnnotation(Check.class);
- writer.print(")");
- if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
- writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + "))");
- } else {
- Class java_type = Utils.getJavaType(param.getType());
- if (Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class)) {
- boolean explicitly_byte_sized = java_type.equals(Buffer.class) ||
- translator.getAnnotationType().equals(type_map.getVoidType());
- if (explicitly_byte_sized)
- writer.print("(((char *)");
- if (method.getAnnotation(GenerateAutos.class) != null || (check_annotation != null && check_annotation.canBeNull())) {
- writer.print("safeGetBufferAddress(env, " + param.getSimpleName());
- } else {
- writer.print("(*env)->GetDirectBufferAddress(env, " + param.getSimpleName());
- }
- writer.print("))");
- writer.print(" + " + param.getSimpleName() + BUFFER_POSITION_POSTFIX);
- if (explicitly_byte_sized)
+ final String native_type = translator.getSignature();
+
+ if ( !java_type.isArray() || CharSequence.class.isAssignableFrom(java_type.getComponentType()) ) {
+ writer.print("\t" + native_type + param.getSimpleName());
+ writer.print(BUFFER_ADDRESS_POSTFIX + " = ((");
+ writer.print(native_type);
+ writer.print(")");
+
+ if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
+ writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + "))");
+ } else {
+ if (Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
+ boolean explicitly_byte_sized = java_type.equals(Buffer.class) ||
+ translator.getAnnotationType().equals(type_map.getVoidType()) ||
+ param.getAnnotation(NativeType.class) != null;
+ if (explicitly_byte_sized)
+ writer.print("(((char *)");
+ if (method.getAnnotation(GenerateAutos.class) != null || (check_annotation != null && check_annotation.canBeNull())) {
+ writer.print("safeGetBufferAddress(env, " + param.getSimpleName());
+ } else {
+ writer.print("(*env)->GetDirectBufferAddress(env, " + param.getSimpleName());
+ }
writer.print("))");
- } else if (java_type.equals(String.class)) {
- writer.print("GetStringNativeChars(env, " + param.getSimpleName() + "))");
- } else
- throw new RuntimeException("Illegal type " + java_type);
- }
- writer.println(";");
-
- if ( param.getAnnotation(StringList.class) != null ) {
- if ( Utils.getJavaType(param.getType()) != CharSequence[].class && (
- param.getAnnotation(GLchar.class) == null ||
- param.getAnnotation(NullTerminated.class) == null ||
- param.getAnnotation(NullTerminated.class).value().length() == 0
- )
- )
- throw new RuntimeException("StringList annotation can only be applied on null-terminated GLchar buffers.");
-
- if ( "_str".equals(param.getSimpleName()) )
- throw new RuntimeException("The name '_str' is not valid for arguments annotated with StringList");
-
- // Declare loop counters and allocate string array
- if ( !loopDeclared ) {
- writer.println("\tunsigned int _str_i;");
- writer.println("\tGLchar *_str_address;");
- loopDeclared = true;
+ writer.print(" + " + param.getSimpleName() + BUFFER_POSITION_POSTFIX);
+ if (explicitly_byte_sized)
+ writer.print("))");
+ } else if (java_type.equals(String.class)) {
+ writer.print("GetStringNativeChars(env, " + param.getSimpleName() + "))");
+ } else if ( array_annotation == null )
+ throw new RuntimeException("Illegal type " + java_type);
}
- writer.println("\tGLchar **" + param.getSimpleName() + STRING_LIST_POSTFIX + " = (GLchar **) malloc(" + param.getAnnotation(StringList.class).value() + "*sizeof(GLchar*));");
+ writer.println(";");
+ }
+
+ if ( array_annotation != null ) {
+ final String n = getPointerArrayName(java_type);
+ final String arrayType;
+ if ( POINTER_LIST_NAME.equals(n) ) {
+ if ( n.equals(param.getSimpleName()) )
+ throw new RuntimeException("The name '" + n + "' is not valid for object array arguments annotated with PointerArray");
+
+ arrayType = translator.getSignature(true) + (org.lwjgl.PointerWrapper.class.isAssignableFrom(java_type.getComponentType()) ? " " : "");
+
+ // Declare loop counters and allocate object array
+ if ( !ptrLoopDeclared ) {
+ writer.println("\tunsigned int " + n + "_i;");
+ writer.println("\tjobject " + n + "_object;");
+ ptrLoopDeclared = true;
+ }
+ } else {
+ if ( n.equals(param.getSimpleName()) )
+ throw new RuntimeException("The name '" + n + "' is not valid for arguments annotated with PointerArray");
+
+ arrayType = translator.getSignature(true);
+
+ // Declare loop counters and allocate string array
+ if ( !strLoopDeclared ) {
+ writer.println("\tunsigned int " + n + "_i;");
+ writer.println("\t" + arrayType + n + "_address;");
+ strLoopDeclared = true;
+ }
+ }
+
+ writer.print("\t" + arrayType + "*" + param.getSimpleName() + n + " = ");
+ if ( check_annotation != null && check_annotation.canBeNull() )
+ writer.print(array_annotation.value() + " == 0 ? NULL : ");
+ writer.println("(" + arrayType + "*) malloc(" + array_annotation.value() + " * sizeof(" + arrayType + "));");
}
- return loopDeclared;
}
- private static void generateStringListInits(PrintWriter writer, Collection params) {
- for ( ParameterDeclaration param : params ) {
- StringList stringList_annotation = param.getAnnotation(StringList.class);
- if ( stringList_annotation != null ) {
- String lengths = stringList_annotation.lengths();
+ private static String getPointerArrayName(final Class java_type) {
+ final Class> component_type = java_type.getComponentType();
+ if ( component_type != null && (Buffer.class.isAssignableFrom(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type)) )
+ return POINTER_LIST_NAME;
+ else
+ return STRING_LIST_NAME;
+ }
- // Init vars
- writer.println("\t_str_i = 0;");
- writer.println("\t_str_address = (GLchar *)" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ";");
- // Fill string array with the string pointers
- writer.println("\twhile ( _str_i < " + stringList_annotation.value() + " ) {");
- if ( lengths.length() == 0 ) {
- writer.println("\t\t" + param.getSimpleName() + STRING_LIST_POSTFIX + "[_str_i++] = _str_address;");
- writer.println("\t\t_str_address += strlen(_str_address) + 1;");
+ private static boolean hasPointerArrayInits(Collection params) {
+ for ( ParameterDeclaration param : params ) {
+ PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
+ if ( pointerArray_annotation != null )
+ return true;
+ }
+ return false;
+ }
+
+ private static void generatePointerArrayInits(TypeMap type_map, PrintWriter writer, Collection params) {
+ for ( ParameterDeclaration param : params ) {
+ PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
+ if ( pointerArray_annotation != null ) {
+ final Class java_type = Utils.getJavaType(param.getType());
+ final Class> component_type = java_type.isArray() ? java_type.getComponentType() : null;
+ final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
+ param.getType().accept(translator);
+
+ final String n = getPointerArrayName(java_type);
+ if ( POINTER_LIST_NAME.equals(n) ) {
+ // Init vars
+ writer.println("\t" + n + "_i = 0;");
+ // Fill pointer array with the buffer pointers
+ writer.println("\twhile ( " + n + "_i < " + pointerArray_annotation.value() + " ) {");
+ if ( component_type.isAssignableFrom(Buffer.class) )
+ writer.println("\t\t" + n + "_object = (*env)->GetObjectArrayElement(env, " + param.getSimpleName() + ", " + n + "_i);");
+ else
+ writer.println("\t\t" + n + "_object = (*env)->GetObjectArrayElement(env, " + param.getSimpleName() + ", " + n + "_i);");
+ writer.println("\t\t" + param.getSimpleName() + n + "[" + n + "_i++] = (" + translator.getSignature(true) + ")(intptr_t)getPointerWrapperAddress(env, " + n + "_object);");
+ writer.println("\t}");
} else {
- writer.println("\t\t" + param.getSimpleName() + STRING_LIST_POSTFIX + "[_str_i] = _str_address;");
- writer.println("\t\t_str_address += " + lengths + BUFFER_ADDRESS_POSTFIX + "[_str_i++];");
+ final String lengths = pointerArray_annotation.lengths();
+
+ // Init vars
+ writer.println("\t" + n + "_i = 0;");
+ writer.println("\t" + n + "_address = (" + translator.getSignature(true) + ")" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ";");
+ // Fill string array with the string pointers
+ writer.println("\twhile ( " + n + "_i < " + pointerArray_annotation.value() + " ) {");
+ if ( lengths.length() == 0 ) {
+ writer.println("\t\t" + param.getSimpleName() + n + "[" + n + "_i++] = " + n + "_address;");
+ writer.println("\t\t" + n + "_address += strlen(" + n + "_address) + 1;");
+ } else {
+ writer.println("\t\t" + param.getSimpleName() + n + "[" + n + "_i] = " + n + "_address;");
+ writer.println("\t\t" + n + "_address += " + lengths + BUFFER_ADDRESS_POSTFIX + "[" + n + "_i++];");
+ }
+ writer.println("\t}");
}
- writer.println("\t}");
}
}
}
diff --git a/src/java/org/lwjgl/util/generator/NativeType.java b/src/java/org/lwjgl/util/generator/NativeType.java
index d37187c1..5c7d1ccb 100644
--- a/src/java/org/lwjgl/util/generator/NativeType.java
+++ b/src/java/org/lwjgl/util/generator/NativeType.java
@@ -44,6 +44,7 @@ package org.lwjgl.util.generator;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
-@Target(ElementType.ANNOTATION_TYPE)
+@Target({ElementType.ANNOTATION_TYPE, ElementType.PARAMETER})
public @interface NativeType {
+ String value() default "";
}
diff --git a/src/java/org/lwjgl/util/generator/NativeTypeTranslator.java b/src/java/org/lwjgl/util/generator/NativeTypeTranslator.java
index f751d02f..a053a03b 100644
--- a/src/java/org/lwjgl/util/generator/NativeTypeTranslator.java
+++ b/src/java/org/lwjgl/util/generator/NativeTypeTranslator.java
@@ -42,22 +42,21 @@ package org.lwjgl.util.generator;
* $Id$
*/
-import org.lwjgl.opengl.PointerWrapper;
-
-import com.sun.mirror.declaration.*;
-import com.sun.mirror.type.*;
-import com.sun.mirror.util.*;
-
-import java.util.Collection;
-import java.util.ArrayList;
-
-import java.nio.*;
+import org.lwjgl.PointerBuffer;
import java.lang.annotation.Annotation;
+import java.nio.*;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.type.*;
+import com.sun.mirror.util.TypeVisitor;
/**
* $Id$
- *
+ *
* A TypeVisitor that translates (annotated) TypeMirrors to
* native types
*
@@ -65,6 +64,7 @@ import java.lang.annotation.Annotation;
* @version $Revision$
*/
public class NativeTypeTranslator implements TypeVisitor {
+
private Collection native_types;
private boolean is_indirect;
private final Declaration declaration;
@@ -76,26 +76,32 @@ public class NativeTypeTranslator implements TypeVisitor {
}
public String getSignature() {
+ return getSignature(false);
+ }
+
+ public String getSignature(final boolean skipConst) {
StringBuilder signature = new StringBuilder();
- if (declaration.getAnnotation(Const.class) != null)
+ if ( !skipConst && declaration.getAnnotation(Const.class) != null )
signature.append("const ");
- if ( declaration.getAnnotation(GLpointer.class) != null ) {
- signature.append(declaration.getAnnotation(GLpointer.class).value());
+ if ( declaration.getAnnotation(PointerWrapper.class) != null ) {
+ signature.append(declaration.getAnnotation(PointerWrapper.class).value());
+ } else if ( declaration.getAnnotation(NativeType.class) != null ) {
+ signature.append(declaration.getAnnotation(NativeType.class).value());
} else {
// Use the name of the native type annotation as the C type name
signature.append(getAnnotationType().getSimpleName());
}
- if (is_indirect)
+ if ( is_indirect )
signature.append(" *");
return signature.toString();
}
public Class getAnnotationType() {
- if (native_types.size() != 1)
+ if ( native_types.size() != 1 )
throw new RuntimeException("Expected only one native type for declaration " + declaration +
- ", but got " + native_types.size());
+ ", but got " + native_types.size());
return native_types.iterator().next();
}
@@ -104,34 +110,43 @@ public class NativeTypeTranslator implements TypeVisitor {
}
public void visitArrayType(ArrayType t) {
- if ( "java.lang.CharSequence".equals(t.getComponentType().toString()) ) {
+ final Class> type = Utils.getJavaType(t).getComponentType();
+
+ if ( CharSequence.class.isAssignableFrom(type) ) {
is_indirect = true;
native_types = new ArrayList();
- native_types.add(GLchar.class);
+ native_types.add(type_map.getStringArrayType());
+ } else if ( Buffer.class.isAssignableFrom(type) ) {
+ is_indirect = true;
+ native_types = new ArrayList();
+ native_types.add(type_map.getByteBufferArrayType());
+ } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
+ is_indirect = false;
} else
throw new RuntimeException(t + " is not allowed");
}
public static PrimitiveType.Kind getPrimitiveKindFromBufferClass(Class c) {
- if (IntBuffer.class.equals(c))
+ if ( IntBuffer.class.equals(c) )
return PrimitiveType.Kind.INT;
- else if (DoubleBuffer.class.equals(c))
+ else if ( DoubleBuffer.class.equals(c) )
return PrimitiveType.Kind.DOUBLE;
- else if (ShortBuffer.class.equals(c))
+ else if ( ShortBuffer.class.equals(c) )
return PrimitiveType.Kind.SHORT;
- else if (ByteBuffer.class.equals(c))
+ else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) )
return PrimitiveType.Kind.BYTE;
- else if (FloatBuffer.class.equals(c))
+ else if ( FloatBuffer.class.equals(c) )
return PrimitiveType.Kind.FLOAT;
- else if (LongBuffer.class.equals(c))
+ else if ( LongBuffer.class.equals(c) )
return PrimitiveType.Kind.LONG;
else
throw new RuntimeException(c + " is not allowed");
}
- public static Class> getClassFromType(DeclaredType t) {
+ @SuppressWarnings("unchecked")
+ public static Class extends Annotation> getClassFromType(DeclaredType t) {
try {
- return Class.forName(t.getDeclaration().getQualifiedName());
+ return (Class extends Annotation>)Class.forName(t.getDeclaration().getQualifiedName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
@@ -139,7 +154,7 @@ public class NativeTypeTranslator implements TypeVisitor {
private void getNativeTypeFromAnnotatedPrimitiveType(PrimitiveType.Kind kind) {
native_types = translateAnnotations();
- if (native_types.size() == 0)
+ if ( native_types.size() == 0 )
native_types.add(type_map.getNativeTypeFromPrimitiveType(kind));
}
@@ -147,18 +162,21 @@ public class NativeTypeTranslator implements TypeVisitor {
is_indirect = true;
Class> c = getClassFromType(t);
- if (String.class.equals(c)) {
+ if ( String.class.equals(c) ) {
native_types = new ArrayList();
native_types.add(type_map.getStringElementType());
- } else if (Buffer.class.equals(c)) {
+ } else if ( Buffer.class.equals(c) ) {
native_types = new ArrayList();
native_types.add(type_map.getVoidType());
- } else if (Buffer.class.isAssignableFrom(c)) {
+ } else if ( Buffer.class.isAssignableFrom(c) ) {
PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c);
getNativeTypeFromAnnotatedPrimitiveType(kind);
- } else if ( PointerWrapper.class.isAssignableFrom(c) ) {
+ } else if ( PointerBuffer.class.isAssignableFrom(c) ) {
native_types = new ArrayList();
- native_types.add(GLpointer.class);
+ native_types.add(PointerBuffer.class);
+ } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
+ native_types = new ArrayList();
+ native_types.add(PointerWrapper.class);
is_indirect = false;
} else
@@ -182,13 +200,14 @@ public class NativeTypeTranslator implements TypeVisitor {
}
// Check if the annotation is itself annotated with a certain annotation type
+
public static T getAnnotation(AnnotationMirror annotation, Class type) {
return annotation.getAnnotationType().getDeclaration().getAnnotation(type);
}
private static Class translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = getAnnotation(annotation, NativeType.class);
- if (native_type != null) {
+ if ( native_type != null ) {
return getClassFromType(annotation.getAnnotationType());
} else
return null;
@@ -196,9 +215,9 @@ public class NativeTypeTranslator implements TypeVisitor {
private Collection translateAnnotations() {
Collection result = new ArrayList();
- for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors())) {
+ for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) ) {
Class translated_result = translateAnnotation(annotation);
- if (translated_result != null) {
+ if ( translated_result != null ) {
result.add(translated_result);
}
}
@@ -219,7 +238,7 @@ public class NativeTypeTranslator implements TypeVisitor {
public void visitVoidType(VoidType t) {
native_types = translateAnnotations();
- if (native_types.size() == 0)
+ if ( native_types.size() == 0 )
native_types.add(void.class);
}
diff --git a/src/java/org/lwjgl/util/generator/StringList.java b/src/java/org/lwjgl/util/generator/PointerArray.java
similarity index 96%
rename from src/java/org/lwjgl/util/generator/StringList.java
rename to src/java/org/lwjgl/util/generator/PointerArray.java
index 0d9e20da..0eaa4939 100644
--- a/src/java/org/lwjgl/util/generator/StringList.java
+++ b/src/java/org/lwjgl/util/generator/PointerArray.java
@@ -40,7 +40,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface StringList {
+public @interface PointerArray {
/** Number of values in the string list (name of native-side parameter) */
String value();
/** List of string lengths (name of native-side parameter) */
diff --git a/src/java/org/lwjgl/util/generator/GLpointer.java b/src/java/org/lwjgl/util/generator/PointerWrapper.java
similarity index 87%
rename from src/java/org/lwjgl/util/generator/GLpointer.java
rename to src/java/org/lwjgl/util/generator/PointerWrapper.java
index ef77e874..0efe2259 100644
--- a/src/java/org/lwjgl/util/generator/GLpointer.java
+++ b/src/java/org/lwjgl/util/generator/PointerWrapper.java
@@ -38,7 +38,9 @@ import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLpointer {
+public @interface PointerWrapper {
String value(); // The native pointer type.
boolean canBeNull() default false; // Whether the pointer may be null.
+ String params() default ""; // Pass these extra parameters when constructing PointerWrapper objects.
+ String factory() default ""; // Use this factory method call instead of normal object construction.
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/PostfixTranslator.java b/src/java/org/lwjgl/util/generator/PostfixTranslator.java
index 6603a55a..8e76e70d 100644
--- a/src/java/org/lwjgl/util/generator/PostfixTranslator.java
+++ b/src/java/org/lwjgl/util/generator/PostfixTranslator.java
@@ -46,6 +46,7 @@ import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
import com.sun.mirror.util.*;
+import java.lang.annotation.Annotation;
import java.nio.*;
public class PostfixTranslator implements TypeVisitor {
@@ -108,7 +109,7 @@ public class PostfixTranslator implements TypeVisitor {
private boolean translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type != null) {
- Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
+ Class extends Annotation> annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
signature.append(type_map.translateAnnotation(annotation_class));
return true;
} else
diff --git a/src/java/org/lwjgl/util/generator/Private.java b/src/java/org/lwjgl/util/generator/Private.java
new file mode 100644
index 00000000..3cfcc12e
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/Private.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator;
+
+/**
+ * Extension templates marked with @Private will result in classes without the public keyword.
+ *
+ * @author Spasi
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface Private {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java b/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java
index 0f4d4c30..bdd3299d 100644
--- a/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java
+++ b/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java
@@ -41,6 +41,8 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.opencl.CLMem;
+
import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
@@ -52,7 +54,8 @@ public class RegisterStubsGenerator {
Iterator extends MethodDeclaration> it = d.getMethods().iterator();
while (it.hasNext()) {
MethodDeclaration method = it.next();
- if ( method.getAnnotation(Alternate.class) != null )
+ Alternate alt_annotation = method.getAnnotation(Alternate.class);
+ if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
continue;
EnumSet platforms;
PlatformDependent platform_annotation = method.getAnnotation(PlatformDependent.class);
@@ -83,20 +86,30 @@ public class RegisterStubsGenerator {
Collection params = method.getParameters();
String signature = "(";
for (ParameterDeclaration param : params) {
- if (param.getAnnotation(Result.class) != null)
+ if ( param.getAnnotation(Helper.class) != null || param.getAnnotation(Result.class) != null )
continue;
- if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
+
+ final Constant constant_annotation = param.getAnnotation(Constant.class);
+ if ( constant_annotation != null && constant_annotation.isNative() )
+ continue;
+
+ if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null)
signature += "I";
- } else {
+ else
signature += getTypeSignature(param.getType(), true);
- }
}
- TypeMirror result_type = Utils.getMethodReturnType(method);
- if (Utils.getNIOBufferType(result_type) != null)
- signature += "I";
+
+ final TypeMirror result_type = Utils.getMethodReturnType(method);
+ final CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
+ final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
+
+ if ( Utils.getNIOBufferType(result_type) != null && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
+ signature += "J";
+
String result_type_signature = getTypeSignature(result_type, false);
- if (method.getAnnotation(CachedResult.class) != null)
+ if ( cached_result_annotation != null )
signature += result_type_signature;
+
signature += ")";
signature += result_type_signature;
return signature;
@@ -110,8 +123,11 @@ public class RegisterStubsGenerator {
writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT)
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
- String opengl_handle_name = method.getSimpleName().replaceFirst("gl", platform.getPrefix());
- writer.print(", \"" + opengl_handle_name + "\", (void *)&" + method.getSimpleName() + "}");
+
+ final Alternate alt_annotation = method.getAnnotation(Alternate.class);
+ final String methodName = alt_annotation == null ? method.getSimpleName() : alt_annotation.value();
+ String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix());
+ writer.print(", \"" + opengl_handle_name + "\", (void *)&" + methodName + "}");
if (has_more)
writer.println(",");
}
diff --git a/src/java/org/lwjgl/util/generator/Reuse.java b/src/java/org/lwjgl/util/generator/Reuse.java
new file mode 100644
index 00000000..63f1ae58
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/Reuse.java
@@ -0,0 +1,49 @@
+/*
+ * 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.util.generator;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * Reuse can be used to annotate methods that duplicate functionality that has been already
+ * defined somewhere else. For example, this can be applied to OpenGL core functionality that
+ * exists as an ARB extension as well, but with the exact same entry points.
+ *
+ * @author Spasi
+ */
+@Target(ElementType.METHOD)
+public @interface Reuse {
+ /** The extension Class that defines the method. */
+ String value();
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/SignatureTranslator.java b/src/java/org/lwjgl/util/generator/SignatureTranslator.java
index dcf178ba..e07ee7bb 100644
--- a/src/java/org/lwjgl/util/generator/SignatureTranslator.java
+++ b/src/java/org/lwjgl/util/generator/SignatureTranslator.java
@@ -41,6 +41,8 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.PointerBuffer;
+
import com.sun.mirror.type.*;
import com.sun.mirror.util.*;
@@ -67,17 +69,33 @@ class SignatureTranslator implements TypeVisitor {
}
public void visitArrayType(ArrayType t) {
- throw new RuntimeException(t + " is not allowed");
+ final Class type = Utils.getJavaType(t.getComponentType());
+ if ( CharSequence.class.isAssignableFrom(type) )
+ signature.append("Ljava/nio/ByteBuffer;I");
+ else if ( Buffer.class.isAssignableFrom(type) )
+ signature.append("[Ljava/nio/ByteBuffer;");
+ else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
+ signature.append("[L" + getNativeNameFromClassName(type.getName()) + ";");
+ else
+ throw new RuntimeException(t + " is not allowed");
}
public void visitClassType(ClassType t) {
- String type_name = getNativeNameFromClassName(t.getDeclaration().getQualifiedName());
+ Class type = NativeTypeTranslator.getClassFromType(t);
+ String type_name;
+ if ( CharSequence.class.isAssignableFrom(type) || CharSequence[].class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) )
+ type_name = ByteBuffer.class.getName();
+ else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
+ signature.append("J");
+ return;
+ } else
+ type_name = t.getDeclaration().getQualifiedName();
+
signature.append("L");
- signature.append(type_name);
+ signature.append(getNativeNameFromClassName(type_name));
signature.append(";");
- if (add_position_signature && Buffer.class.isAssignableFrom(NativeTypeTranslator.getClassFromType(t))) {
+ if ( add_position_signature && Utils.isAddressableType(type) )
signature.append("I");
- }
}
public void visitDeclaredType(DeclaredType t) {
diff --git a/src/java/org/lwjgl/util/generator/TypeInfo.java b/src/java/org/lwjgl/util/generator/TypeInfo.java
index 21093e11..eccf57db 100644
--- a/src/java/org/lwjgl/util/generator/TypeInfo.java
+++ b/src/java/org/lwjgl/util/generator/TypeInfo.java
@@ -41,9 +41,12 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.util.generator.opengl.GLvoid;
+
import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
+import java.lang.annotation.Annotation;
import java.util.*;
import java.nio.*;
@@ -95,6 +98,9 @@ public class TypeInfo {
case BYTE:
type = byte.class;
break;
+ case BOOLEAN:
+ type = boolean.class;
+ break;
default:
throw new RuntimeException(kind + " is not allowed");
}
@@ -151,7 +157,7 @@ public class TypeInfo {
for (AnnotationMirror annotation : annotations) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) {
- Class annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
+ Class extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
Signedness signedness = type_map.getSignednessFromType(annotation_type);
Class inverse_type = type_map.getInverseType(annotation_type);
String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
diff --git a/src/java/org/lwjgl/util/generator/TypeMap.java b/src/java/org/lwjgl/util/generator/TypeMap.java
index 8db38643..d70bc3ee 100644
--- a/src/java/org/lwjgl/util/generator/TypeMap.java
+++ b/src/java/org/lwjgl/util/generator/TypeMap.java
@@ -45,19 +45,25 @@ import com.sun.mirror.declaration.*;
import com.sun.mirror.type.*;
import java.io.*;
+import java.lang.annotation.Annotation;
public interface TypeMap {
- String getErrorCheckMethodName();
+ void printCapabilitiesInit(PrintWriter writer);
+ String getCapabilities();
+ void printErrorCheckMethod(PrintWriter writer, MethodDeclaration method, String tabs);
String getRegisterNativesFunctionName();
- PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type);
- String getTypedefPrefix();
+ PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class extends Annotation> native_type);
+ String getTypedefPostfix();
+ String getFunctionPrefix();
void printNativeIncludes(PrintWriter writer);
- Class getStringElementType();
+ Class extends Annotation> getStringElementType();
+ Class extends Annotation> getStringArrayType();
+ Class extends Annotation> getByteBufferArrayType();
Class[] getValidAnnotationTypes(Class type);
- Class getVoidType();
- String translateAnnotation(Class annotation_type);
+ Class extends Annotation> getVoidType();
+ String translateAnnotation(Class extends Annotation> annotation_type);
Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind);
String getAutoTypeFromAnnotation(AnnotationMirror annotation);
- Class getInverseType(Class type);
- Signedness getSignednessFromType(Class type);
+ Class extends Annotation> getInverseType(Class extends Annotation> type);
+ Signedness getSignednessFromType(Class extends Annotation> type);
}
diff --git a/src/java/org/lwjgl/util/generator/TypedefsGenerator.java b/src/java/org/lwjgl/util/generator/TypedefsGenerator.java
index 2096a9fd..af1c7db5 100644
--- a/src/java/org/lwjgl/util/generator/TypedefsGenerator.java
+++ b/src/java/org/lwjgl/util/generator/TypedefsGenerator.java
@@ -51,11 +51,12 @@ public class TypedefsGenerator {
private static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, MethodDeclaration method) {
TypeMirror return_type = method.getReturnType();
writer.print("typedef ");
+ writer.print(type_map.getTypedefPostfix());
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, method);
return_type.accept(translator);
writer.print(translator.getSignature());
writer.print(" (");
- writer.print(type_map.getTypedefPrefix());
+ writer.print(type_map.getFunctionPrefix());
writer.print(" *" + Utils.getTypedefName(method) + ") (");
generateNativeTypedefsParameters(type_map, writer, method.getParameters());
writer.println(");");
@@ -63,11 +64,17 @@ public class TypedefsGenerator {
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection params) {
if (params.size() > 0) {
- Iterator it = params.iterator();
- generateNativeTypedefsParameter(type_map, writer, it.next());
- while (it.hasNext()) {
- writer.print(", ");
- generateNativeTypedefsParameter(type_map, writer, it.next());
+ boolean first = true;
+ for ( ParameterDeclaration param : params ) {
+ if ( param.getAnnotation(Helper.class) != null )
+ continue;
+
+ if ( first )
+ first = false;
+ else
+ writer.print(", ");
+
+ generateNativeTypedefsParameter(type_map, writer, param);
}
}
}
@@ -76,14 +83,14 @@ public class TypedefsGenerator {
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.getType().accept(translator);
writer.print(translator.getSignature());
- if (param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(StringList.class) != null)
+ if (param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null)
writer.print("*");
writer.print(" " + param.getSimpleName());
}
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection extends MethodDeclaration> methods) {
for (MethodDeclaration method : methods) {
- if ( method.getAnnotation(Alternate.class) == null )
+ if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null )
generateNativeTypedefs(type_map, writer, method);
}
}
diff --git a/src/java/org/lwjgl/util/generator/Utils.java b/src/java/org/lwjgl/util/generator/Utils.java
index 34066f05..45610136 100644
--- a/src/java/org/lwjgl/util/generator/Utils.java
+++ b/src/java/org/lwjgl/util/generator/Utils.java
@@ -40,6 +40,12 @@ package org.lwjgl.util.generator;
* $Id$
*/
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.util.generator.opengl.GLboolean;
+import org.lwjgl.util.generator.opengl.GLchar;
+import org.lwjgl.util.generator.opengl.GLcharARB;
+import org.lwjgl.util.generator.opengl.GLreturn;
+
import java.io.PrintWriter;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -75,11 +81,19 @@ public class Utils {
}
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method, boolean forceAlt) {
- Alternate alt_annotation = method.getAnnotation(Alternate.class);
+ final Alternate alt_annotation = method.getAnnotation(Alternate.class);
+
+ /* Removed prefix so that we can identify reusable entry points, removed postfix because it's not needed and looks nicer.
+ String interfaceName = interface_decl.getSimpleName(); // If we add this back, we need to fix @Reuse (add a param for the template name)
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) )
- return interface_decl.getSimpleName() + "_" + method.getSimpleName() + FUNCTION_POINTER_POSTFIX;
+ return interfaceName + "_" + method.getSimpleName() + FUNCTION_POINTER_POSTFIX;
else
- return interface_decl.getSimpleName() + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
+ return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
+ */
+ if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) )
+ return method.getSimpleName();
+ else
+ return alt_annotation.value();
}
public static boolean isFinal(InterfaceDeclaration d) {
@@ -115,7 +129,15 @@ public class Utils {
}
public static boolean isAddressableType(Class type) {
- return Buffer.class.isAssignableFrom(type) || String.class.equals(type) || CharSequence.class.equals(type) || CharSequence[].class.equals(type);
+ if ( type.isArray() ) {
+ final Class component_type = type.getComponentType();
+ return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type);
+ }
+ return isAddressableTypeImpl(type);
+ }
+
+ private static boolean isAddressableTypeImpl(Class type) {
+ return Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) || CharSequence.class.isAssignableFrom(type);
}
public static Class getJavaType(TypeMirror type_mirror) {
@@ -149,11 +171,23 @@ public class Utils {
public static void printDocComment(PrintWriter writer, Declaration decl) {
String doc_comment = decl.getDocComment();
if (doc_comment != null) {
- String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
+ final String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
writer.println(tab + "/**");
- StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n");
- while (doc_lines.hasMoreTokens())
- writer.println(tab + " * " + doc_lines.nextToken());
+
+ final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true);
+ boolean lastWasNL = false;
+ while (doc_lines.hasMoreTokens()) {
+ final String t = doc_lines.nextToken();
+ if ( "\n".equals(t) ) {
+ if ( lastWasNL )
+ writer.println(tab + " *");
+ lastWasNL = true;
+ } else {
+ writer.println(tab + " * " + t);
+ lastWasNL = false;
+ }
+ }
+
writer.println(tab + " */");
} else if ( (decl instanceof MethodDeclaration) && decl.getAnnotation(Alternate.class) != null )
writer.println("\t/** Overloads " + decl.getAnnotation(Alternate.class).value() + " */");
@@ -241,7 +275,7 @@ public class Utils {
}
public static boolean needResultSize(MethodDeclaration method) {
- return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoResultSize.class) == null;
+ return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoSize.class) == null;
}
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
@@ -289,7 +323,7 @@ public class Utils {
Class> param_type = getJavaType(t);
if (Buffer.class.isAssignableFrom(param_type))
return param_type;
- else if ( param_type == CharSequence.class || param_type == CharSequence[].class )
+ else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class )
return ByteBuffer.class;
else
return null;
@@ -337,9 +371,9 @@ public class Utils {
} else if ( type.equals(CharSequence[].class) ) {
if ( offset == null )
- offset = "APIUtils.getTotalLength(" + p.getSimpleName() + ")";
+ offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
else
- offset += " + APIUtils.getTotalLength(" + p.getSimpleName() + ")";
+ offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")";
if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length";
}
@@ -352,10 +386,10 @@ public class Utils {
if ( "String".equals(return_type) ) {
if ( !return_annotation.forceMaxLength() ) {
- writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtils.getLengths();");
+ writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths();");
writer.print("\t\t");
}
- writer.print("ByteBuffer " + return_annotation.value() + " = APIUtils.getBufferByte(" + return_annotation.maxLength());
+ writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + return_annotation.maxLength());
/*
Params that use the return buffer will advance its position while filling it. When we return, the position will be
at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was
@@ -367,13 +401,18 @@ public class Utils {
writer.println(");");
} else {
final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type;
- writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtils.getBuffer" + buffer_type + "(");
+ writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(");
if ( "Byte".equals(buffer_type) )
writer.print('1');
writer.println(");");
}
- writer.print("\t\t");
+ final Code code_annotation = method.getAnnotation(Code.class);
+ if ( code_annotation != null && code_annotation.tryBlock() ) {
+ writer.println("\t\ttry {");
+ writer.print("\t\t\t");
+ } else
+ writer.print("\t\t");
}
static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation) {
@@ -389,7 +428,7 @@ public class Utils {
else
writer.print(return_annotation.value() + "_length.get(0)");
writer.println(");");
- writer.println("\t\treturn APIUtils.getString(" + return_annotation.value() + ");");
+ writer.println("\t\treturn APIUtil.getString(" + return_annotation.value() + ");");
} else {
writer.print("\t\treturn " + return_annotation.value() + ".get(0)");
if ( "Boolean".equals(return_type) )
diff --git a/src/java/org/lwjgl/util/generator/ALTypeMap.java b/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java
similarity index 83%
rename from src/java/org/lwjgl/util/generator/ALTypeMap.java
rename to src/java/org/lwjgl/util/generator/openal/ALTypeMap.java
index 8e379fd6..d5c32da9 100644
--- a/src/java/org/lwjgl/util/generator/ALTypeMap.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java
@@ -1,218 +1,242 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * The OpenAL specific generator behaviour
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import com.sun.mirror.declaration.*;
-import com.sun.mirror.type.*;
-
-import java.io.*;
-import java.util.*;
-import java.nio.*;
-
-public class ALTypeMap implements TypeMap {
- private static final Map native_types_to_primitive;
-
- static {
- native_types_to_primitive = new HashMap();
- native_types_to_primitive.put(ALboolean.class, PrimitiveType.Kind.BOOLEAN);
- native_types_to_primitive.put(ALbyte.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(ALenum.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(ALfloat.class, PrimitiveType.Kind.FLOAT);
- native_types_to_primitive.put(ALdouble.class, PrimitiveType.Kind.DOUBLE);
- native_types_to_primitive.put(ALint.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(ALshort.class, PrimitiveType.Kind.SHORT);
- native_types_to_primitive.put(ALsizei.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(ALubyte.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(ALuint.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(ALvoid.class, PrimitiveType.Kind.BYTE);
- }
-
- public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
- PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
- if (kind == null)
- throw new RuntimeException("Unsupported type " + native_type);
- return kind;
- }
-
- public Signedness getSignednessFromType(Class type) {
- if (ALuint.class.equals(type))
- return Signedness.UNSIGNED;
- else if (ALint.class.equals(type))
- return Signedness.SIGNED;
- else if (ALshort.class.equals(type))
- return Signedness.SIGNED;
- else if (ALbyte.class.equals(type))
- return Signedness.SIGNED;
- else
- return Signedness.NONE;
- }
-
- public String translateAnnotation(Class annotation_type) {
- if (annotation_type.equals(ALuint.class))
- return "i";
- else if (annotation_type.equals(ALint.class))
- return "i";
- else if (annotation_type.equals(ALshort.class))
- return "s";
- else if (annotation_type.equals(ALbyte.class))
- return "b";
- else if (annotation_type.equals(ALfloat.class))
- return "f";
- else if (annotation_type.equals(ALdouble.class))
- return "d";
- else if (annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class))
- return "";
- else
- throw new RuntimeException(annotation_type + " is not allowed");
- }
-
- public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
- Class type;
- switch (kind) {
- case INT:
- type = ALint.class;
- break;
- case FLOAT:
- type = ALfloat.class;
- break;
- case DOUBLE:
- type = ALdouble.class;
- break;
- case SHORT:
- type = ALshort.class;
- break;
- case BYTE:
- type = ALbyte.class;
- break;
- case BOOLEAN:
- type = ALboolean.class;
- break;
- default:
- throw new RuntimeException(kind + " is not allowed");
- }
- return type;
- }
-
- private static Class[] getValidBufferTypes(Class type) {
- if (type.equals(IntBuffer.class))
- return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
- else if (type.equals(FloatBuffer.class))
- return new Class[]{ALfloat.class};
- else if (type.equals(ByteBuffer.class))
- return new Class[]{ALboolean.class, ALbyte.class, ALvoid.class};
- else if (type.equals(ShortBuffer.class))
- return new Class[]{ALshort.class};
- else if (type.equals(DoubleBuffer.class))
- return new Class[]{ALdouble.class};
- else
- return new Class[]{};
- }
-
- private static Class[] getValidPrimitiveTypes(Class type) {
- if (type.equals(int.class))
- return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
- else if (type.equals(double.class))
- return new Class[]{ALdouble.class};
- else if (type.equals(float.class))
- return new Class[]{ALfloat.class};
- else if (type.equals(short.class))
- return new Class[]{ALshort.class};
- else if (type.equals(byte.class))
- return new Class[]{ALbyte.class};
- else if (type.equals(boolean.class))
- return new Class[]{ALboolean.class};
- else if (type.equals(void.class))
- return new Class[]{ALvoid.class};
- else
- return new Class[]{};
- }
-
- public String getErrorCheckMethodName() {
- return "Util.checkALError()";
- }
-
- public String getRegisterNativesFunctionName() {
- return "extal_InitializeClass";
- }
-
- public String getTypedefPrefix() {
- return "ALAPIENTRY";
- }
-
- public void printNativeIncludes(PrintWriter writer) {
- writer.println("#include \"extal.h\"");
- }
-
- public Class getStringElementType() {
- return ALubyte.class;
- }
-
- public Class[] getValidAnnotationTypes(Class type) {
- Class[] valid_types;
- if (Buffer.class.isAssignableFrom(type))
- valid_types = getValidBufferTypes(type);
- else if (type.isPrimitive())
- valid_types = getValidPrimitiveTypes(type);
- else if (type.equals(String.class))
- valid_types = new Class[]{ALubyte.class};
- else
- valid_types = new Class[]{};
- return valid_types;
- }
-
- public Class getVoidType() {
- return ALvoid.class;
- }
-
- public Class getInverseType(Class type) {
- if (ALuint.class.equals(type))
- return ALint.class;
- else if (ALint.class.equals(type))
- return ALuint.class;
- else
- return null;
- }
-
- public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
- return null;
- }
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * The OpenAL specific generator behaviour
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALTypeMap.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.Signedness;
+import org.lwjgl.util.generator.TypeMap;
+
+import com.sun.mirror.declaration.*;
+import com.sun.mirror.type.*;
+
+import java.io.*;
+import java.lang.annotation.Annotation;
+import java.util.*;
+import java.nio.*;
+
+public class ALTypeMap implements TypeMap {
+ private static final Map native_types_to_primitive;
+
+ static {
+ native_types_to_primitive = new HashMap();
+ native_types_to_primitive.put(ALboolean.class, PrimitiveType.Kind.BOOLEAN);
+ native_types_to_primitive.put(ALbyte.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(ALenum.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(ALfloat.class, PrimitiveType.Kind.FLOAT);
+ native_types_to_primitive.put(ALdouble.class, PrimitiveType.Kind.DOUBLE);
+ native_types_to_primitive.put(ALint.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(ALshort.class, PrimitiveType.Kind.SHORT);
+ native_types_to_primitive.put(ALsizei.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(ALubyte.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(ALuint.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(ALvoid.class, PrimitiveType.Kind.BYTE);
+ }
+
+ public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
+ PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
+ if (kind == null)
+ throw new RuntimeException("Unsupported type " + native_type);
+ return kind;
+ }
+
+ public Signedness getSignednessFromType(Class type) {
+ if (ALuint.class.equals(type))
+ return Signedness.UNSIGNED;
+ else if (ALint.class.equals(type))
+ return Signedness.SIGNED;
+ else if (ALshort.class.equals(type))
+ return Signedness.SIGNED;
+ else if (ALbyte.class.equals(type))
+ return Signedness.SIGNED;
+ else
+ return Signedness.NONE;
+ }
+
+ public String translateAnnotation(Class annotation_type) {
+ if (annotation_type.equals(ALuint.class))
+ return "i";
+ else if (annotation_type.equals(ALint.class))
+ return "i";
+ else if (annotation_type.equals(ALshort.class))
+ return "s";
+ else if (annotation_type.equals(ALbyte.class))
+ return "b";
+ else if (annotation_type.equals(ALfloat.class))
+ return "f";
+ else if (annotation_type.equals(ALdouble.class))
+ return "d";
+ else if (annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class))
+ return "";
+ else
+ throw new RuntimeException(annotation_type + " is not allowed");
+ }
+
+ public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
+ Class type;
+ switch (kind) {
+ case INT:
+ type = ALint.class;
+ break;
+ case FLOAT:
+ type = ALfloat.class;
+ break;
+ case DOUBLE:
+ type = ALdouble.class;
+ break;
+ case SHORT:
+ type = ALshort.class;
+ break;
+ case BYTE:
+ type = ALbyte.class;
+ break;
+ case BOOLEAN:
+ type = ALboolean.class;
+ break;
+ default:
+ throw new RuntimeException(kind + " is not allowed");
+ }
+ return type;
+ }
+
+ private static Class[] getValidBufferTypes(Class type) {
+ if (type.equals(IntBuffer.class))
+ return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
+ else if (type.equals(FloatBuffer.class))
+ return new Class[]{ALfloat.class};
+ else if (type.equals(ByteBuffer.class))
+ return new Class[]{ALboolean.class, ALbyte.class, ALvoid.class};
+ else if (type.equals(ShortBuffer.class))
+ return new Class[]{ALshort.class};
+ else if (type.equals(DoubleBuffer.class))
+ return new Class[]{ALdouble.class};
+ else
+ return new Class[]{};
+ }
+
+ private static Class[] getValidPrimitiveTypes(Class type) {
+ if (type.equals(int.class))
+ return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
+ else if (type.equals(double.class))
+ return new Class[]{ALdouble.class};
+ else if (type.equals(float.class))
+ return new Class[]{ALfloat.class};
+ else if (type.equals(short.class))
+ return new Class[]{ALshort.class};
+ else if (type.equals(byte.class))
+ return new Class[]{ALbyte.class};
+ else if (type.equals(boolean.class))
+ return new Class[]{ALboolean.class};
+ else if (type.equals(void.class))
+ return new Class[]{ALvoid.class};
+ else
+ return new Class[]{};
+ }
+
+ public void printCapabilitiesInit(final PrintWriter writer) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getCapabilities() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
+ writer.println(tabs + "Util.checkALError();");
+ }
+
+ public String getRegisterNativesFunctionName() {
+ return "extal_InitializeClass";
+ }
+
+ public String getTypedefPostfix() {
+ return "";
+ }
+
+ public String getFunctionPrefix() {
+ return "ALAPIENTRY";
+ }
+
+ public void printNativeIncludes(PrintWriter writer) {
+ writer.println("#include \"extal.h\"");
+ }
+
+ public Class extends Annotation> getStringElementType() {
+ return ALubyte.class;
+ }
+
+ public Class extends Annotation> getStringArrayType() {
+ return ALubyte.class;
+ }
+
+ public Class extends Annotation> getByteBufferArrayType() {
+ return ALubyte.class;
+ }
+
+ public Class[] getValidAnnotationTypes(Class type) {
+ Class[] valid_types;
+ if (Buffer.class.isAssignableFrom(type))
+ valid_types = getValidBufferTypes(type);
+ else if (type.isPrimitive())
+ valid_types = getValidPrimitiveTypes(type);
+ else if (type.equals(String.class))
+ valid_types = new Class[]{ALubyte.class};
+ else
+ valid_types = new Class[]{};
+ return valid_types;
+ }
+
+ public Class extends Annotation> getVoidType() {
+ return ALvoid.class;
+ }
+
+ public Class extends Annotation> getInverseType(Class type) {
+ if (ALuint.class.equals(type))
+ return ALint.class;
+ else if (ALint.class.equals(type))
+ return ALuint.class;
+ else
+ return null;
+ }
+
+ public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
+ return null;
+ }
+}
diff --git a/src/java/org/lwjgl/util/generator/ALboolean.java b/src/java/org/lwjgl/util/generator/openal/ALboolean.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALboolean.java
rename to src/java/org/lwjgl/util/generator/openal/ALboolean.java
index 9c96fe62..ed45b774 100644
--- a/src/java/org/lwjgl/util/generator/ALboolean.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALboolean.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALboolean {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALboolean.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALboolean {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALbyte.java b/src/java/org/lwjgl/util/generator/openal/ALbyte.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALbyte.java
rename to src/java/org/lwjgl/util/generator/openal/ALbyte.java
index e400aa07..412e4b25 100644
--- a/src/java/org/lwjgl/util/generator/ALbyte.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALbyte.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALbyte {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALbyte.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALbyte {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALdouble.java b/src/java/org/lwjgl/util/generator/openal/ALdouble.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALdouble.java
rename to src/java/org/lwjgl/util/generator/openal/ALdouble.java
index 721126bb..aa6e0813 100644
--- a/src/java/org/lwjgl/util/generator/ALdouble.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALdouble.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALdouble {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALdouble.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALdouble {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALenum.java b/src/java/org/lwjgl/util/generator/openal/ALenum.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALenum.java
rename to src/java/org/lwjgl/util/generator/openal/ALenum.java
index 7a6ed660..45636915 100644
--- a/src/java/org/lwjgl/util/generator/ALenum.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALenum.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALenum {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALenum.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALenum {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALfloat.java b/src/java/org/lwjgl/util/generator/openal/ALfloat.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALfloat.java
rename to src/java/org/lwjgl/util/generator/openal/ALfloat.java
index 1ddbd5c4..39e358a3 100644
--- a/src/java/org/lwjgl/util/generator/ALfloat.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALfloat.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALfloat {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALfloat.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALfloat {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALint.java b/src/java/org/lwjgl/util/generator/openal/ALint.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALint.java
rename to src/java/org/lwjgl/util/generator/openal/ALint.java
index ce16ce67..ae347e76 100644
--- a/src/java/org/lwjgl/util/generator/ALint.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALint.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALint {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALint.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALint {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALshort.java b/src/java/org/lwjgl/util/generator/openal/ALshort.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALshort.java
rename to src/java/org/lwjgl/util/generator/openal/ALshort.java
index a978014c..603386b3 100644
--- a/src/java/org/lwjgl/util/generator/ALshort.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALshort.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALshort {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALshort.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALshort {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALsizei.java b/src/java/org/lwjgl/util/generator/openal/ALsizei.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALsizei.java
rename to src/java/org/lwjgl/util/generator/openal/ALsizei.java
index 6185d796..b079c8f9 100644
--- a/src/java/org/lwjgl/util/generator/ALsizei.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALsizei.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALsizei {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALsizei.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALsizei {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALubyte.java b/src/java/org/lwjgl/util/generator/openal/ALubyte.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALubyte.java
rename to src/java/org/lwjgl/util/generator/openal/ALubyte.java
index e0151e52..caf22ef5 100644
--- a/src/java/org/lwjgl/util/generator/ALubyte.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALubyte.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALubyte {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALubyte.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALubyte {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALuint.java b/src/java/org/lwjgl/util/generator/openal/ALuint.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALuint.java
rename to src/java/org/lwjgl/util/generator/openal/ALuint.java
index 5f7acb1f..a31c2a39 100644
--- a/src/java/org/lwjgl/util/generator/ALuint.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALuint.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALuint {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALuint.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALuint {
+}
diff --git a/src/java/org/lwjgl/util/generator/ALvoid.java b/src/java/org/lwjgl/util/generator/openal/ALvoid.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/ALvoid.java
rename to src/java/org/lwjgl/util/generator/openal/ALvoid.java
index 5744cd91..9b645eb0 100644
--- a/src/java/org/lwjgl/util/generator/ALvoid.java
+++ b/src/java/org/lwjgl/util/generator/openal/ALvoid.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface ALvoid {
-}
+/*
+ * 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.util.generator.openal;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: ALvoid.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface ALvoid {
+}
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java
new file mode 100644
index 00000000..77247aab
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java
@@ -0,0 +1,152 @@
+/*
+ * 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.util.generator.opencl;
+
+import org.lwjgl.util.generator.*;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+
+/**
+ * CLCapabilities generator.
+ *
+ * @author Spasi
+ */
+public class CLCapabilitiesGenerator {
+
+ private static final String SUPPORTED_EXTS = "supported_extensions";
+
+ static void generateClassPrologue(final PrintWriter writer) {
+ writer.println("public final class " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + " {");
+ writer.println();
+ }
+
+ static void generateSymbolAddresses(final PrintWriter writer, final InterfaceDeclaration d) {
+ final Alias alias_annotation = d.getAnnotation(Alias.class);
+ final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
+
+ boolean first = true;
+ for ( final MethodDeclaration method : d.getMethods() ) {
+ if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
+ continue;
+
+ if ( first ) {
+ writer.println("\t// " + d.getSimpleName());
+ first = false;
+ }
+ writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress(");
+
+ if ( aliased )
+ writer.println("new String [] {\"" + Utils.getFunctionAddressName(d, method) + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"});");
+ else
+ writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");");
+ }
+ }
+
+ static void generateConstructor(final PrintWriter writer, final Collection interface_decls) {
+ writer.println("\tprivate static final Set " + SUPPORTED_EXTS + " = new HashSet();");
+ writer.println();
+ writer.println("\tprivate " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + "() {}");
+ writer.println();
+ writer.println("\tstatic {");
+
+ for ( final TypeDeclaration d : interface_decls ) {
+ if ( d.getMethods().isEmpty() )
+ continue;
+
+ writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
+ writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + "\");");
+ }
+
+ writer.println("\t}\n");
+ }
+
+ static void generateExtensionSupported(final PrintWriter writer) {
+ writer.println("\tstatic boolean isExtensionSupported(final String name) {\n" +
+ "\t\treturn " + SUPPORTED_EXTS + ".contains(name);\n" +
+ "\t}\n");
+ }
+
+ static void generateExtensionChecks(final PrintWriter writer, final InterfaceDeclaration d) {
+ Iterator extends MethodDeclaration> methods = d.getMethods().iterator();
+ if ( !methods.hasNext() )
+ return;
+
+ writer.println("\tstatic boolean " + getExtensionSupportedName(d.getSimpleName()) + "() {");
+ writer.println("\t\treturn ");
+
+ boolean first = true;
+ while ( methods.hasNext() ) {
+ MethodDeclaration method = methods.next();
+ if ( method.getAnnotation(Alternate.class) != null )
+ continue;
+
+ if ( !first )
+ writer.println(" &");
+ else
+ first = false;
+
+ final boolean optional = method.getAnnotation(Optional.class) != null;
+
+ writer.print("\t\t\t");
+ if ( optional )
+ writer.print('(');
+ writer.print(Utils.getFunctionAddressName(d, method) + " != 0");
+ if ( optional )
+ writer.print(" || true)");
+ }
+ writer.println(";");
+ writer.println("\t}");
+ writer.println();
+ }
+
+ private static String getExtensionSupportedName(final String class_name) {
+ return "is" + class_name + "Supported";
+ }
+
+ public static void generateCapabilitiesGetters(final PrintWriter writer) {
+ writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n" +
+ "\t\treturn CLPlatformImpl.getCapabilities(platform);\n" +
+ "\t}\n");
+
+ writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n" +
+ "\t\treturn CLDeviceImpl.getCapabilities(device);\n" +
+ "\t}\n");
+
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLDeviceExtension.java b/src/java/org/lwjgl/util/generator/opencl/CLDeviceExtension.java
new file mode 100644
index 00000000..f34e8f57
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLDeviceExtension.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/** Extension templates marked with @CLDeviceExtension will be considered CL device extensions. */
+@Target(ElementType.TYPE)
+public @interface CLDeviceExtension {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java
new file mode 100644
index 00000000..b5bba949
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java
@@ -0,0 +1,183 @@
+/*
+ * 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.util.generator.opencl;
+
+import org.lwjgl.PointerWrapper;
+import org.lwjgl.opencl.CLDevice;
+import org.lwjgl.opencl.CLPlatform;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+
+import com.sun.mirror.apt.*;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.util.DeclarationFilter;
+
+import static java.util.Collections.*;
+
+/**
+ * Generator tool for creating the OpenCL capabilities classes
+ *
+ * @author Spasi
+ */
+public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
+
+ public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
+ public static final String PLATFORM_CAPS_CLASS_NAME = "CLPlatformCapabilities";
+ public static final String DEVICE_CAPS_CLASS_NAME = "CLDeviceCapabilities";
+
+ private static final String EXTENSION_PREFIX = "CL_";
+ private static final String CORE_PREFIX = "Open";
+
+ private static boolean first_round = true;
+
+ // Process any set of annotations
+ private static final Collection supportedAnnotations = unmodifiableCollection(Arrays.asList("*"));
+
+ public Collection supportedAnnotationTypes() {
+ return supportedAnnotations;
+ }
+
+ public Collection supportedOptions() {
+ return unmodifiableCollection(Arrays.asList("-Acontextspecific"));
+ }
+
+ public void roundComplete(RoundCompleteEvent event) {
+ first_round = false;
+ }
+
+ public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
+ // Only process the initial types, not the generated ones
+ if ( first_round ) {
+ env.addListener(this);
+ return new GeneratorProcessor(env);
+ } else
+ return AnnotationProcessors.NO_OP;
+ }
+
+ static String getExtensionName(String interface_name) {
+ if ( interface_name.startsWith("CL") )
+ return CORE_PREFIX + interface_name;
+ else
+ return EXTENSION_PREFIX + interface_name;
+ }
+
+ private static class GeneratorProcessor implements AnnotationProcessor {
+
+ private final AnnotationProcessorEnvironment env;
+
+ GeneratorProcessor(AnnotationProcessorEnvironment env) {
+ this.env = env;
+ }
+
+ public void process() {
+ try {
+ generateCLCapabilitiesSource();
+ generateCLPDCapabilitiesSource(CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
+ generateCLPDCapabilitiesSource(CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void printHeader(final PrintWriter writer) {
+ writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
+ writer.println();
+ writer.println("package org.lwjgl.opencl;");
+ writer.println();
+ writer.println("import java.util.*;");
+ writer.println();
+ }
+
+ private void generateCLCapabilitiesSource() throws IOException {
+ final PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opencl", new File(CLCAPS_CLASS_NAME + ".java"), null);
+ printHeader(writer);
+
+ CLCapabilitiesGenerator.generateClassPrologue(writer);
+
+ final Collection templates = DeclarationFilter.getFilter(InterfaceDeclaration.class).filter(env.getSpecifiedTypeDeclarations());
+
+ for ( final TypeDeclaration t : templates ) {
+ if ( t.getAnnotation(CLPlatformExtension.class) == null && t.getAnnotation(CLDeviceExtension.class) == null && !t.getSimpleName().startsWith("CL") )
+ throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + t.getSimpleName());
+
+ CLCapabilitiesGenerator.generateSymbolAddresses(writer, (InterfaceDeclaration)t);
+ }
+ writer.println();
+
+ CLCapabilitiesGenerator.generateConstructor(writer, templates);
+
+ CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
+
+ CLCapabilitiesGenerator.generateExtensionSupported(writer);
+
+ for ( final TypeDeclaration template : templates )
+ CLCapabilitiesGenerator.generateExtensionChecks(writer, (InterfaceDeclaration)template);
+
+ writer.println("}");
+ writer.close();
+ }
+
+ private void generateCLPDCapabilitiesSource(final Class extends Annotation> capsType, final String capsName, final Class extends PointerWrapper> objectType, final String objectName) throws IOException {
+ final PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opencl", new File(capsName + ".java"), null);
+ printHeader(writer);
+
+ CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
+
+ final Collection templates = DeclarationFilter.getFilter(InterfaceDeclaration.class).filter(env.getSpecifiedTypeDeclarations());
+
+ for ( final TypeDeclaration t : templates ) {
+ if ( t.getAnnotation(capsType) != null )
+ CLPDCapabilitiesGenerator.generateExtensions(writer, (InterfaceDeclaration)t);
+ }
+ writer.println();
+
+ CLPDCapabilitiesGenerator.generateConstructor(writer, templates, capsType, capsName, objectType, objectName);
+
+ CLPDCapabilitiesGenerator.generateGetters(writer);
+
+ CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType, capsName, objectType, objectName);
+
+ writer.println("}");
+ writer.close();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java
new file mode 100644
index 00000000..c697755b
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java
@@ -0,0 +1,147 @@
+/*
+ * 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.util.generator.opencl;
+
+import org.lwjgl.PointerWrapper;
+import org.lwjgl.util.generator.Private;
+
+import java.io.PrintWriter;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+
+/**
+ * CL platform/device capabilities generator.
+ *
+ * @author Spasi
+ */
+public class CLPDCapabilitiesGenerator {
+
+ // TODO: Add future versions here
+ private static final int[][] CL_VERSIONS = {
+ { 1 }, // OpenCL 1
+ };
+
+ static void generateClassPrologue(final PrintWriter writer, final String name) {
+ writer.println("public class " + name + " {");
+ writer.println();
+ writer.println("\tpublic final int majorVersion;");
+ writer.println("\tpublic final int minorVersion;");
+ writer.println();
+ for ( int major = 1; major <= CL_VERSIONS.length; major++ ) {
+ for ( final int minor : CL_VERSIONS[major - 1] )
+ writer.println("\tpublic final boolean OpenCL" + Integer.toString(major) + Integer.toString(minor) + ";");
+ }
+ writer.println();
+ }
+
+ static void generateExtensions(final PrintWriter writer, final InterfaceDeclaration d) {
+ writer.print("\t");
+
+ if ( d.getAnnotation(Private.class) == null )
+ writer.print("public ");
+
+ writer.println("final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
+ }
+
+ static void generateConstructor(final PrintWriter writer, final Collection templates,
+ final Class extends Annotation> capsType, final String capsName,
+ final Class extends PointerWrapper> objectType, final String objectName) {
+ writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {");
+
+ final String methodName = Character.toUpperCase(objectName.charAt(0)) + objectName.substring(1);
+ writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" +
+ "\t\tfinal String version = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_VERSION);\n" +
+ "\t\tif ( !version.startsWith(\"OpenCL \") )\n" +
+ "\t\t\tthrow new RuntimeException(\"Invalid OpenCL version string: \" + version);\n\n" +
+ "\t\ttry {\n" +
+ "\t\t\tfinal StringTokenizer tokenizer = new StringTokenizer(version.substring(7), \". \");\n" +
+ "\n" +
+ "\t\t\tmajorVersion = Integer.parseInt(tokenizer.nextToken());\n" +
+ "\t\t\tminorVersion = Integer.parseInt(tokenizer.nextToken());\n");
+
+ for ( int major = 1; major <= CL_VERSIONS.length; major++ ) {
+ for ( final int minor : CL_VERSIONS[major - 1] )
+ writer.println("\t\t\tOpenCL" + Integer.toString(major) + Integer.toString(minor) + " = " + major + " < majorVersion || (" + major + " == majorVersion && " + minor + " <= minorVersion);");
+ }
+
+ writer.println("\t\t} catch (RuntimeException e) {\n" +
+ "\t\t\tthrow new RuntimeException(\"The major and/or minor OpenCL version \\\"\" + version + \"\\\" is malformed: \" + e.getMessage());\n" +
+ "\t\t}\n");
+
+ writer.println("\t\tfinal Set extensions = APIUtil.getExtensions(extensionList);");
+
+ for ( final TypeDeclaration t : templates ) {
+ if ( t.getAnnotation(capsType) == null )
+ continue;
+
+ writer.print("\t\t" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()) + " = extensions.contains(\"" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()).toLowerCase() + "\")");
+ if ( !t.getMethods().isEmpty() )
+ writer.print(" && CLCapabilities.is" + t.getSimpleName() + "Supported()");
+ writer.println(";");
+ }
+
+ writer.println("\t}\n");
+ }
+
+ public static void generateGetters(final PrintWriter writer) {
+ writer.println("\tpublic int getMajorVersion() {");
+ writer.println("\t\treturn majorVersion;");
+ writer.println("\t}\n");
+
+ writer.println("\tpublic int getMinorVersion() {");
+ writer.println("\t\treturn minorVersion;");
+ writer.println("\t}\n");
+ }
+
+ public static void generateToString(final PrintWriter writer, final Collection templates, final Class extends Annotation> capsType, final String capsName, final Class extends PointerWrapper> objectType, final String objectName) {
+ writer.println("\tpublic String toString() {");
+ writer.println("\t\tfinal StringBuilder buf = new StringBuilder();\n");
+
+ writer.println("\t\tbuf.append(\"OpenCL \").append(majorVersion).append('.').append(minorVersion);");
+ writer.println();
+ writer.println("\t\tbuf.append(\" - Extensions: \");");
+ for ( final TypeDeclaration t : templates ) {
+ if ( t.getAnnotation(capsType) == null )
+ continue;
+
+ writer.println("\t\tif ( " + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()) + " ) buf.append(\"" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()).toLowerCase() + " \");");
+ }
+
+ writer.println("\n\t\treturn buf.toString();");
+ writer.println("\t}\n");
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLPlatformExtension.java b/src/java/org/lwjgl/util/generator/opencl/CLPlatformExtension.java
new file mode 100644
index 00000000..e8ddadc1
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLPlatformExtension.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/** Extension templates marked with @CLPlatformExtension will be considered CL platform extensions. */
+@Target(ElementType.TYPE)
+public @interface CLPlatformExtension {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java b/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java
new file mode 100644
index 00000000..6a2c13bb
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.lwjgl.util.generator.opencl;
+
+/**
+ *
+ * OpenCL specific generator behaviour
+ *
+ * @author Spasi
+ */
+
+import org.lwjgl.PointerBuffer;
+import org.lwjgl.util.generator.*;
+import org.lwjgl.util.generator.opengl.GLreturn;
+
+import java.io.PrintWriter;
+import java.lang.annotation.Annotation;
+import java.nio.*;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.type.PrimitiveType;
+
+public class CLTypeMap implements TypeMap {
+
+ private static final Map native_types_to_primitive;
+
+ static {
+ native_types_to_primitive = new HashMap();
+ native_types_to_primitive.put(cl_void.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(cl_byte.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(cl_char.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(cl_uchar.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(cl_short.class, PrimitiveType.Kind.SHORT);
+ native_types_to_primitive.put(cl_bool.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(cl_int.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(cl_uint.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(cl_long.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(size_t.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(cl_bitfield.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(cl_float.class, PrimitiveType.Kind.FLOAT);
+ native_types_to_primitive.put(cl_double.class, PrimitiveType.Kind.DOUBLE);
+ }
+
+ public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
+ PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
+ if ( kind == null )
+ throw new RuntimeException("Unsupported type " + native_type);
+ return kind;
+ }
+
+ public void printCapabilitiesInit(final PrintWriter writer) {
+ }
+
+ public String getCapabilities() {
+ return "CLCapabilities";
+ }
+
+ public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
+ final Check check = method.getAnnotation(Check.class);
+ if ( check != null ) // Get the error code from an IntBuffer output parameter
+ writer.println(tabs + "Util.checkCLError(" + check.value() + ".get(" + check.value() + ".position()));");
+ else {
+ final Class return_type = Utils.getJavaType(method.getReturnType());
+ if ( return_type == int.class )
+ writer.println(tabs + "Util.checkCLError(__result);");
+ else {
+ boolean hasErrCodeParam = false;
+ for ( final ParameterDeclaration param : method.getParameters() ) {
+ if ( "errcode_ret".equals(param.getSimpleName()) && Utils.getJavaType(param.getType()) == IntBuffer.class ) {
+ hasErrCodeParam = true;
+ break;
+ }
+ }
+ if ( hasErrCodeParam )
+ throw new RuntimeException("A method is missing the @Check annotation: " + method.toString());
+ }
+ }
+ }
+
+ public String getRegisterNativesFunctionName() {
+ return "extcl_InitializeClass";
+ }
+
+ public Signedness getSignednessFromType(Class type) {
+ if ( cl_uint.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( cl_int.class.equals(type) )
+ return Signedness.SIGNED;
+ else
+ return Signedness.NONE;
+ }
+
+ public String translateAnnotation(Class annotation_type) {
+ if ( annotation_type.equals(cl_uint.class) || annotation_type.equals(cl_int.class) )
+ return "i";
+ else if ( annotation_type.equals(cl_short.class) )
+ return "s";
+ else if ( annotation_type.equals(cl_byte.class) )
+ return "b";
+ else if ( annotation_type.equals(cl_float.class) )
+ return "f";
+ else if ( annotation_type.equals(cl_double.class) )
+ return "d";
+ else
+ throw new RuntimeException(annotation_type + " is not allowed");
+ }
+
+ public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
+ Class type;
+ switch ( kind ) {
+ case INT:
+ type = cl_int.class;
+ break;
+ case DOUBLE:
+ type = cl_double.class;
+ break;
+ case FLOAT:
+ type = cl_float.class;
+ break;
+ case SHORT:
+ type = cl_short.class;
+ break;
+ case BYTE:
+ type = cl_byte.class;
+ break;
+ case LONG:
+ type = cl_long.class;
+ break;
+ case BOOLEAN:
+ type = cl_bool.class;
+ break;
+ default:
+ throw new RuntimeException(kind + " is not allowed");
+ }
+ return type;
+ }
+
+ public Class extends Annotation> getVoidType() {
+ return cl_void.class;
+ }
+
+ public Class extends Annotation> getStringElementType() {
+ return cl_char.class;
+ }
+
+ public Class extends Annotation> getStringArrayType() {
+ return cl_char.class;
+ }
+
+ public Class extends Annotation> getByteBufferArrayType() {
+ return cl_uchar.class;
+ }
+
+ private static Class[] getValidBufferTypes(Class type) {
+ if ( type.equals(IntBuffer.class) )
+ return new Class[] { cl_int.class, cl_uint.class };
+ else if ( type.equals(FloatBuffer.class) )
+ return new Class[] { cl_float.class };
+ else if ( type.equals(ByteBuffer.class) )
+ return new Class[] { cl_byte.class, cl_char.class, cl_uchar.class, cl_void.class };
+ else if ( type.equals(ShortBuffer.class) )
+ return new Class[] { cl_short.class };
+ else if ( type.equals(DoubleBuffer.class) )
+ return new Class[] { cl_double.class };
+ else if ( type.equals(LongBuffer.class) )
+ return new Class[] { cl_long.class };
+ else if ( type.equals(PointerBuffer.class) )
+ return new Class[] { size_t.class };
+ else
+ return new Class[] { };
+ }
+
+ private static Class[] getValidPrimitiveTypes(Class type) {
+ if ( type.equals(long.class) )
+ return new Class[] { cl_long.class, size_t.class, cl_bitfield.class };
+ else if ( type.equals(int.class) )
+ return new Class[] { cl_int.class, cl_uint.class, cl_bool.class };
+ else if ( type.equals(double.class) )
+ return new Class[] { cl_double.class };
+ else if ( type.equals(float.class) )
+ return new Class[] { cl_float.class };
+ else if ( type.equals(short.class) )
+ return new Class[] { cl_short.class };
+ else if ( type.equals(byte.class) )
+ return new Class[] { cl_byte.class, cl_char.class, cl_uchar.class };
+ else if ( type.equals(boolean.class) )
+ return new Class[] { cl_bool.class };
+ else if ( type.equals(void.class) )
+ return new Class[] { cl_void.class };
+ else
+ return new Class[] { };
+ }
+
+ public String getTypedefPostfix() {
+ return "CL_API_ENTRY ";
+ }
+
+ public String getFunctionPrefix() {
+ return "CL_API_CALL";
+ }
+
+ public void printNativeIncludes(PrintWriter writer) {
+ writer.println("#include \"extcl.h\"");
+ }
+
+ public Class[] getValidAnnotationTypes(Class type) {
+ Class[] valid_types;
+ if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) )
+ valid_types = getValidBufferTypes(type);
+ else if ( type.isPrimitive() )
+ valid_types = getValidPrimitiveTypes(type);
+ else if ( String.class.equals(type) )
+ valid_types = new Class[] { cl_byte.class };
+ else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
+ valid_types = new Class[] { PointerWrapper.class };
+ else if ( ByteBuffer[].class == type )
+ valid_types = new Class[] { cl_char.class, cl_uchar.class };
+ else if ( void.class.equals(type) )
+ valid_types = new Class[] { GLreturn.class };
+ else
+ valid_types = new Class[] { };
+ return valid_types;
+ }
+
+ public Class extends Annotation> getInverseType(Class type) {
+ return null;
+ }
+
+ public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_bitfield.java b/src/java/org/lwjgl/util/generator/opencl/cl_bitfield.java
new file mode 100644
index 00000000..4b216512
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_bitfield.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface cl_bitfield {
+ String alias() default "";
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_bool.java b/src/java/org/lwjgl/util/generator/opencl/cl_bool.java
new file mode 100644
index 00000000..73792b67
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_bool.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface cl_bool {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_byte.java b/src/java/org/lwjgl/util/generator/opencl/cl_byte.java
new file mode 100644
index 00000000..28bc59e3
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_byte.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_byte {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_char.java b/src/java/org/lwjgl/util/generator/opencl/cl_char.java
new file mode 100644
index 00000000..c275db41
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_char.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface cl_char {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_double.java b/src/java/org/lwjgl/util/generator/opencl/cl_double.java
new file mode 100644
index 00000000..8459a87e
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_double.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_double {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_float.java b/src/java/org/lwjgl/util/generator/opencl/cl_float.java
new file mode 100644
index 00000000..44c9cb18
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_float.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_float {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_int.java b/src/java/org/lwjgl/util/generator/opencl/cl_int.java
new file mode 100644
index 00000000..b515e4e3
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_int.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_int {
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_long.java b/src/java/org/lwjgl/util/generator/opencl/cl_long.java
new file mode 100644
index 00000000..c34aa6a6
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_long.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface cl_long {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_short.java b/src/java/org/lwjgl/util/generator/opencl/cl_short.java
new file mode 100644
index 00000000..23ce10d6
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_short.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_short {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_uchar.java b/src/java/org/lwjgl/util/generator/opencl/cl_uchar.java
new file mode 100644
index 00000000..825a479e
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_uchar.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface cl_uchar {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_uint.java b/src/java/org/lwjgl/util/generator/opencl/cl_uint.java
new file mode 100644
index 00000000..50a335a3
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_uint.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_uint {
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/cl_void.java b/src/java/org/lwjgl/util/generator/opencl/cl_void.java
new file mode 100644
index 00000000..6cf56311
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/cl_void.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+import com.sun.mirror.type.PrimitiveType;
+
+@NativeType
+@Target({ ElementType.PARAMETER, ElementType.METHOD })
+public @interface cl_void {
+ PrimitiveType.Kind value() default PrimitiveType.Kind.BYTE;
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/opencl/size_t.java b/src/java/org/lwjgl/util/generator/opencl/size_t.java
new file mode 100644
index 00000000..b6bdeab7
--- /dev/null
+++ b/src/java/org/lwjgl/util/generator/opencl/size_t.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.util.generator.opencl;
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@NativeType
+@Target({ ElementType.PARAMETER })
+public @interface size_t {
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/ContextCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java
similarity index 91%
rename from src/java/org/lwjgl/util/generator/ContextCapabilitiesGenerator.java
rename to src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java
index 84146976..a3928327 100644
--- a/src/java/org/lwjgl/util/generator/ContextCapabilitiesGenerator.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java
@@ -1,319 +1,328 @@
-/*
- * 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.util.generator;
-
-import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.EnumSet;
-import java.util.Iterator;
-
-import com.sun.mirror.declaration.InterfaceDeclaration;
-import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.type.InterfaceType;
-
-/**
- * Generator visitor for the context capabilities generator tool
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-public class ContextCapabilitiesGenerator {
-
- private static final String STUBS_LOADED_NAME = "loaded_stubs";
- private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
- private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
- private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
- private static final String PROFILE_MASK_VAR_NAME = "profileMask";
- private static final String EXTENSION_PREFIX = "GL_";
- private static final String CORE_PREFIX = "Open";
-
- public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
- 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();
- if ( !context_specific ) {
- writer.println("\tprivate static boolean " + STUBS_LOADED_NAME + " = false;");
- }
- }
-
- public static void generateInitializerPrologue(PrintWriter writer) {
- writer.println("\t" + Utils.CONTEXT_CAPS_CLASS_NAME + "(boolean forwardCompatible) throws LWJGLException {");
- writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCompatible);");
- }
-
- private static String translateFieldName(String interface_name) {
- if ( interface_name.startsWith("GL") )
- return CORE_PREFIX + interface_name;
- else
- return EXTENSION_PREFIX + interface_name;
- }
-
- public static void generateSuperClassAdds(PrintWriter writer, InterfaceDeclaration d) {
- Collection super_interfaces = d.getSuperinterfaces();
- if ( super_interfaces.size() > 1 )
- throw new RuntimeException(d + " extends more than one other interface");
- if ( super_interfaces.size() == 1 ) {
- InterfaceType super_interface = super_interfaces.iterator().next();
- writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.println(translateFieldName(d.getSimpleName()) + "\"))");
- writer.print("\t\t\t");
- generateAddExtension(writer, super_interface.getDeclaration());
- }
- }
-
- public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
- String translated_field_name = translateFieldName(d.getSimpleName());
- writer.print("\t\tthis." + translated_field_name + " = ");
- writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.print(translated_field_name + "\")");
- Collection super_interfaces = d.getSuperinterfaces();
- if ( super_interfaces.size() > 1 )
- throw new RuntimeException(d + " extends more than one other interface");
- if ( super_interfaces.size() == 1 ) {
- InterfaceType super_interface = super_interfaces.iterator().next();
- writer.println();
- writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
- }
- Alias alias_annotation = d.getAnnotation(Alias.class);
- if ( alias_annotation != null ) {
- writer.println();
- writer.print("\t\t\t|| " + CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.print(translateFieldName(alias_annotation.value()) + "\")");
- }
- writer.println(";");
- }
-
- private static String getAddressesInitializerName(String class_name) {
- return class_name + POINTER_INITIALIZER_POSTFIX;
- }
-
- public static void generateInitStubsPrologue(PrintWriter writer, boolean context_specific) {
- writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "(boolean forwardCompatible) throws LWJGLException {");
-
- // Load the basic pointers we need to detect OpenGL version and supported extensions.
- writer.println("\t\tGL11_glGetError_pointer = GLContext.getFunctionAddress(\"glGetError\");");
- writer.println("\t\tGL11_glGetString_pointer = GLContext.getFunctionAddress(\"glGetString\");");
-
- // Initialize GL11.glGetIntegerv and GL30.glGetStringi here, in case we have created an OpenGL 3.0 context.
- // (they will be used in GLContext.getSupportedExtensions)
- writer.println("\t\tGL11_glGetIntegerv_pointer = GLContext.getFunctionAddress(\"glGetIntegerv\");");
- writer.println("\t\tGL30_glGetStringi_pointer = GLContext.getFunctionAddress(\"glGetStringi\");");
-
- // Get the supported extensions set.
- writer.println("\t\tGLContext.setCapabilities(this);");
- writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = new HashSet(256);");
- writer.println("\t\tint " + PROFILE_MASK_VAR_NAME + " = GLContext.getSupportedExtensions(" + CACHED_EXTS_VAR_NAME + ");");
-
- // Force forward compatible mode when OpenGL version is 3.1 or higher and ARB_compatibility is not available.
- writer.println("\t\tif ( supported_extensions.contains(\"OpenGL31\") && !(supported_extensions.contains(\"GL_ARB_compatibility\") || (profileMask & GL32.GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0) )");
- writer.println("\t\t\tforwardCompatible = true;");
-
- if ( !context_specific ) {
- writer.println("\t\tif (" + STUBS_LOADED_NAME + ")");
- writer.println("\t\t\treturn GLContext.getSupportedExtensions();");
- writer.println("\t\torg.lwjgl.opengl.GL11." + Utils.STUB_INITIALIZER_NAME + "();");
- } else {
- writer.println("\t\tif (!" + getAddressesInitializerName("GL11") + "(forwardCompatible))");
- writer.println("\t\t\tthrow new LWJGLException(\"GL11 not supported\");");
- }
- }
-
- public static void generateInitStubsEpilogue(PrintWriter writer, boolean context_specific) {
- if ( !context_specific ) {
- writer.println("\t\t" + STUBS_LOADED_NAME + " = true;");
- }
- writer.println("\t\treturn " + CACHED_EXTS_VAR_NAME + ";");
- writer.println("\t}");
- }
-
- public static void generateUnloadStubs(PrintWriter writer, InterfaceDeclaration d) {
- if ( d.getMethods().size() > 0 ) {
- writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
- writer.println(".class);");
- }
- }
-
- public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
- if ( d.getMethods().size() > 0 ) {
- if ( context_specific ) {
- final Alias alias_annotation = d.getAnnotation(Alias.class);
-
- if ( d.getAnnotation(ForceInit.class) != null )
- writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName()) + "\");");
- writer.print("\t\tif (");
- if ( alias_annotation != null )
- writer.print("(");
- writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.print(translateFieldName(d.getSimpleName()) + "\")");
- if ( alias_annotation != null ) {
- writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
- writer.print(translateFieldName(alias_annotation.value()) + "\"))");
- }
- writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
- if ( d.getAnnotation(DeprecatedGL.class) != null )
- writer.print("forwardCompatible");
- if ( d.getAnnotation(Dependent.class) != null ) {
- if ( d.getAnnotation(DeprecatedGL.class) != null )
- writer.print(",");
- writer.print("supported_extensions");
- }
- if ( alias_annotation != null ) {
- writer.println(")) {");
- writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
- writer.println(translateFieldName(alias_annotation.value()) + "\");");
- } else
- writer.println("))");
- writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
- writer.println(translateFieldName(d.getSimpleName()) + "\");");
- if ( alias_annotation != null )
- writer.println("\t\t}");
- } else {
- writer.print("\t\tGLContext." + Utils.STUB_INITIALIZER_NAME + "(" + Utils.getSimpleClassName(d));
- writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName()) + "\");");
- }
- }
- }
-
- private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
- writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
- writer.println(translateFieldName(d.getSimpleName()) + "\");");
- }
-
- public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
- Iterator extends MethodDeclaration> methods = d.getMethods().iterator();
- if ( !methods.hasNext() )
- return;
-
- writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
-
- boolean optional;
- boolean deprecated = d.getAnnotation(DeprecatedGL.class) != null;
- Dependent dependent = d.getAnnotation(Dependent.class);
- if ( deprecated )
- writer.print("boolean forwardCompatible");
- if ( dependent != null ) {
- if ( deprecated )
- writer.print(",");
- writer.print("Set supported_extensions");
- }
-
- Alias alias_annotation = d.getAnnotation(Alias.class);
- boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
-
- writer.println(") {");
- writer.println("\t\treturn ");
-
- boolean first = true;
- while ( methods.hasNext() ) {
- MethodDeclaration method = methods.next();
- if ( method.getAnnotation(Alternate.class) != null )
- continue;
-
- if ( !first )
- writer.println(" &");
- else
- first = false;
-
- optional = method.getAnnotation(Optional.class) != null;
- deprecated = method.getAnnotation(DeprecatedGL.class) != null;
- dependent = method.getAnnotation(Dependent.class);
-
- writer.print("\t\t\t(");
- if ( optional )
- writer.print('(');
- if ( deprecated )
- writer.print("forwardCompatible || ");
- if ( dependent != null ) {
- if ( dependent.value().indexOf(',') == -1 )
- writer.print("!supported_extensions.contains(\"" + dependent.value() + "\") || ");
- else {
- writer.print("!(false");
- for ( String extension : dependent.value().split(",") )
- writer.print(" || supported_extensions.contains(\"" + extension + "\")");
- writer.print(") || ");
- }
- }
- if ( deprecated || dependent != null )
- writer.print('(');
- writer.print(Utils.getFunctionAddressName(d, method) + " = ");
- PlatformDependent platform_dependent = method.getAnnotation(PlatformDependent.class);
- if ( platform_dependent != null ) {
- EnumSet platform_set = EnumSet.copyOf(Arrays.asList(platform_dependent.value()));
- writer.print("GLContext.getPlatformSpecificFunctionAddress(\"");
- writer.print(Platform.ALL.getPrefix() + "\", ");
- writer.print("new String[]{");
- Iterator platforms = platform_set.iterator();
- while ( platforms.hasNext() ) {
- writer.print("\"" + platforms.next().getOSPrefix() + "\"");
- if ( platforms.hasNext() )
- writer.print(", ");
- }
- writer.print("}, new String[]{");
- platforms = platform_set.iterator();
- while ( platforms.hasNext() ) {
- writer.print("\"" + platforms.next().getPrefix() + "\"");
- if ( platforms.hasNext() )
- writer.print(", ");
- }
- writer.print("}, ");
- } else if ( aliased ) {
- writer.print("GLContext.getFunctionAddress(new String[] {\"" + method.getSimpleName() + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"})) != 0");
- } else
- writer.print("GLContext.getFunctionAddress(");
- if ( !aliased )
- writer.print("\"" + method.getSimpleName() + "\")) != 0");
- if ( deprecated || dependent != null )
- writer.print(')');
- if ( optional )
- writer.print(" || true)");
- }
- writer.println(";");
- writer.println("\t}");
- writer.println();
- }
-
- public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
- for ( MethodDeclaration method : d.getMethods() ) {
- if ( method.getAnnotation(Alternate.class) == null )
- writer.println("\tlong " + Utils.getFunctionAddressName(d, method) + ";");
- }
- }
-
- public static void generateField(PrintWriter writer, InterfaceDeclaration d) {
- writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
- }
+/*
+ * 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.util.generator.opengl;
+
+import org.lwjgl.util.generator.*;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.Iterator;
+
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.InterfaceType;
+
+/**
+ * Generator visitor for the context capabilities generator tool
+ *
+ * @author elias_naur
+ * @version $Revision: 3355 $
+ * $Id: ContextCapabilitiesGenerator.java 3355 2010-05-27 22:56:29Z spasi $
+ */
+public class GLCapabilitiesGenerator {
+
+ private static final String STUBS_LOADED_NAME = "loaded_stubs";
+ private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
+ private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
+ private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
+ private static final String PROFILE_MASK_VAR_NAME = "profileMask";
+ private static final String EXTENSION_PREFIX = "GL_";
+ private static final String CORE_PREFIX = "Open";
+
+ public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
+ 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();
+ if ( !context_specific ) {
+ writer.println("\tprivate static boolean " + STUBS_LOADED_NAME + " = false;");
+ }
+ }
+
+ public static void generateInitializerPrologue(PrintWriter writer) {
+ writer.println("\t" + Utils.CONTEXT_CAPS_CLASS_NAME + "(boolean forwardCompatible) throws LWJGLException {");
+ writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCompatible);");
+ }
+
+ private static String translateFieldName(String interface_name) {
+ if ( interface_name.startsWith("GL") )
+ return CORE_PREFIX + interface_name;
+ else
+ return EXTENSION_PREFIX + interface_name;
+ }
+
+ public static void generateSuperClassAdds(PrintWriter writer, InterfaceDeclaration d) {
+ Collection super_interfaces = d.getSuperinterfaces();
+ if ( super_interfaces.size() > 1 )
+ throw new RuntimeException(d + " extends more than one other interface");
+ if ( super_interfaces.size() == 1 ) {
+ InterfaceType super_interface = super_interfaces.iterator().next();
+ writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.println(translateFieldName(d.getSimpleName()) + "\"))");
+ writer.print("\t\t\t");
+ generateAddExtension(writer, super_interface.getDeclaration());
+ }
+ }
+
+ public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
+ String translated_field_name = translateFieldName(d.getSimpleName());
+ writer.print("\t\tthis." + translated_field_name + " = ");
+ writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.print(translated_field_name + "\")");
+ Collection super_interfaces = d.getSuperinterfaces();
+ if ( super_interfaces.size() > 1 )
+ throw new RuntimeException(d + " extends more than one other interface");
+ if ( super_interfaces.size() == 1 ) {
+ InterfaceType super_interface = super_interfaces.iterator().next();
+ writer.println();
+ writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
+ }
+ Alias alias_annotation = d.getAnnotation(Alias.class);
+ if ( alias_annotation != null ) {
+ writer.println();
+ writer.print("\t\t\t|| " + CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.print(translateFieldName(alias_annotation.value()) + "\")");
+ }
+ writer.println(";");
+ }
+
+ private static String getAddressesInitializerName(String class_name) {
+ return class_name + POINTER_INITIALIZER_POSTFIX;
+ }
+
+ public static void generateInitStubsPrologue(PrintWriter writer, boolean context_specific) {
+ writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "(boolean forwardCompatible) throws LWJGLException {");
+
+ // Load the basic pointers we need to detect OpenGL version and supported extensions.
+ writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");");
+ writer.println("\t\tglGetString = GLContext.getFunctionAddress(\"glGetString\");");
+
+ // Initialize GL11.glGetIntegerv and GL30.glGetStringi here, in case we have created an OpenGL 3.0 context.
+ // (they will be used in GLContext.getSupportedExtensions)
+ writer.println("\t\tglGetIntegerv = GLContext.getFunctionAddress(\"glGetIntegerv\");");
+ writer.println("\t\tglGetStringi = GLContext.getFunctionAddress(\"glGetStringi\");");
+
+ // Get the supported extensions set.
+ writer.println("\t\tGLContext.setCapabilities(this);");
+ writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = new HashSet(256);");
+ writer.println("\t\tint " + PROFILE_MASK_VAR_NAME + " = GLContext.getSupportedExtensions(" + CACHED_EXTS_VAR_NAME + ");");
+
+ // Force forward compatible mode when OpenGL version is 3.1 or higher and ARB_compatibility is not available.
+ writer.println("\t\tif ( supported_extensions.contains(\"OpenGL31\") && !(supported_extensions.contains(\"GL_ARB_compatibility\") || (profileMask & GL32.GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0) )");
+ writer.println("\t\t\tforwardCompatible = true;");
+
+ if ( !context_specific ) {
+ writer.println("\t\tif (" + STUBS_LOADED_NAME + ")");
+ writer.println("\t\t\treturn GLContext.getSupportedExtensions();");
+ writer.println("\t\torg.lwjgl.opengl.GL11." + Utils.STUB_INITIALIZER_NAME + "();");
+ } else {
+ writer.println("\t\tif (!" + getAddressesInitializerName("GL11") + "(forwardCompatible))");
+ writer.println("\t\t\tthrow new LWJGLException(\"GL11 not supported\");");
+ }
+ }
+
+ public static void generateInitStubsEpilogue(PrintWriter writer, boolean context_specific) {
+ if ( !context_specific ) {
+ writer.println("\t\t" + STUBS_LOADED_NAME + " = true;");
+ }
+ writer.println("\t\treturn " + CACHED_EXTS_VAR_NAME + ";");
+ writer.println("\t}");
+ }
+
+ public static void generateUnloadStubs(PrintWriter writer, InterfaceDeclaration d) {
+ if ( d.getMethods().size() > 0 ) {
+ writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
+ writer.println(".class);");
+ }
+ }
+
+ public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
+ if ( d.getMethods().size() > 0 ) {
+ if ( context_specific ) {
+ final Alias alias_annotation = d.getAnnotation(Alias.class);
+
+ if ( d.getAnnotation(ForceInit.class) != null )
+ writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName()) + "\");");
+ writer.print("\t\tif (");
+ if ( alias_annotation != null )
+ writer.print("(");
+ writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.print(translateFieldName(d.getSimpleName()) + "\")");
+ if ( alias_annotation != null ) {
+ writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
+ writer.print(translateFieldName(alias_annotation.value()) + "\"))");
+ }
+ writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
+ if ( d.getAnnotation(DeprecatedGL.class) != null )
+ writer.print("forwardCompatible");
+ if ( d.getAnnotation(Dependent.class) != null ) {
+ if ( d.getAnnotation(DeprecatedGL.class) != null )
+ writer.print(",");
+ writer.print("supported_extensions");
+ }
+ if ( alias_annotation != null ) {
+ writer.println(")) {");
+ writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
+ writer.println(translateFieldName(alias_annotation.value()) + "\");");
+ } else
+ writer.println("))");
+ writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
+ writer.println(translateFieldName(d.getSimpleName()) + "\");");
+ if ( alias_annotation != null )
+ writer.println("\t\t}");
+ } else {
+ writer.print("\t\tGLContext." + Utils.STUB_INITIALIZER_NAME + "(" + Utils.getSimpleClassName(d));
+ writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName()) + "\");");
+ }
+ }
+ }
+
+ private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
+ writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
+ writer.println(translateFieldName(d.getSimpleName()) + "\");");
+ }
+
+ public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
+ Iterator extends MethodDeclaration> methods = d.getMethods().iterator();
+ if ( !methods.hasNext() )
+ return;
+
+ writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
+
+ boolean optional;
+ boolean deprecated = d.getAnnotation(DeprecatedGL.class) != null;
+ Dependent dependent = d.getAnnotation(Dependent.class);
+ if ( deprecated )
+ writer.print("boolean forwardCompatible");
+ if ( dependent != null ) {
+ if ( deprecated )
+ writer.print(",");
+ writer.print("Set supported_extensions");
+ }
+
+ Alias alias_annotation = d.getAnnotation(Alias.class);
+ boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
+
+ writer.println(") {");
+ writer.println("\t\treturn ");
+
+ boolean first = true;
+ while ( methods.hasNext() ) {
+ MethodDeclaration method = methods.next();
+ if ( method.getAnnotation(Alternate.class) != null )
+ continue;
+
+ if ( !first )
+ writer.println(" &");
+ else
+ first = false;
+
+ optional = method.getAnnotation(Optional.class) != null;
+ deprecated = method.getAnnotation(DeprecatedGL.class) != null;
+ dependent = method.getAnnotation(Dependent.class);
+
+ writer.print("\t\t\t(");
+ if ( optional )
+ writer.print('(');
+ if ( deprecated )
+ writer.print("forwardCompatible || ");
+ if ( dependent != null ) {
+ if ( dependent.value().indexOf(',') == -1 )
+ writer.print("!supported_extensions.contains(\"" + dependent.value() + "\") || ");
+ else {
+ writer.print("!(false");
+ for ( String extension : dependent.value().split(",") )
+ writer.print(" || supported_extensions.contains(\"" + extension + "\")");
+ writer.print(") || ");
+ }
+ }
+ if ( deprecated || dependent != null )
+ writer.print('(');
+ writer.print(Utils.getFunctionAddressName(d, method) + " = ");
+ PlatformDependent platform_dependent = method.getAnnotation(PlatformDependent.class);
+ if ( platform_dependent != null ) {
+ EnumSet platform_set = EnumSet.copyOf(Arrays.asList(platform_dependent.value()));
+ writer.print("GLContext.getPlatformSpecificFunctionAddress(\"");
+ writer.print(Platform.ALL.getPrefix() + "\", ");
+ writer.print("new String[]{");
+ Iterator platforms = platform_set.iterator();
+ while ( platforms.hasNext() ) {
+ writer.print("\"" + platforms.next().getOSPrefix() + "\"");
+ if ( platforms.hasNext() )
+ writer.print(", ");
+ }
+ writer.print("}, new String[]{");
+ platforms = platform_set.iterator();
+ while ( platforms.hasNext() ) {
+ writer.print("\"" + platforms.next().getPrefix() + "\"");
+ if ( platforms.hasNext() )
+ writer.print(", ");
+ }
+ writer.print("}, ");
+ } else if ( aliased ) {
+ writer.print("GLContext.getFunctionAddress(new String[] {\"" + method.getSimpleName() + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"})) != 0");
+ } else
+ writer.print("GLContext.getFunctionAddress(");
+ if ( !aliased )
+ writer.print("\"" + method.getSimpleName() + "\")) != 0");
+ if ( deprecated || dependent != null )
+ writer.print(')');
+ if ( optional )
+ writer.print(" || true)");
+ }
+ writer.println(";");
+ writer.println("\t}");
+ writer.println();
+ }
+
+ public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
+ boolean first = true;
+ for ( final MethodDeclaration method : d.getMethods() ) {
+ if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
+ continue;
+
+ if ( first ) {
+ writer.println("\t// " + d.getSimpleName());
+ first = false;
+ }
+ writer.println("\tlong " + Utils.getFunctionAddressName(d, method) + ";");
+ }
+ }
+
+ public static void generateField(PrintWriter writer, InterfaceDeclaration d) {
+ writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
+ }
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java
similarity index 83%
rename from src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java
rename to src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java
index 2ae7936c..6e5dbea4 100644
--- a/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java
@@ -1,189 +1,189 @@
-/*
- * 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.util.generator;
-
-import static java.util.Collections.unmodifiableCollection;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-import com.sun.mirror.apt.AnnotationProcessor;
-import com.sun.mirror.apt.AnnotationProcessorEnvironment;
-import com.sun.mirror.apt.AnnotationProcessorFactory;
-import com.sun.mirror.apt.AnnotationProcessors;
-import com.sun.mirror.apt.Filer;
-import com.sun.mirror.apt.RoundCompleteEvent;
-import com.sun.mirror.apt.RoundCompleteListener;
-import com.sun.mirror.declaration.AnnotationTypeDeclaration;
-import com.sun.mirror.declaration.InterfaceDeclaration;
-import com.sun.mirror.declaration.TypeDeclaration;
-import com.sun.mirror.util.DeclarationFilter;
-
-/**
- *
- * Generator tool for creating the ContexCapabilities class
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-public class ContextGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
- private static boolean first_round = true;
-
- // Process any set of annotations
- private static final Collection supportedAnnotations =
- unmodifiableCollection(Arrays.asList("*"));
-
- public Collection supportedAnnotationTypes() {
- return supportedAnnotations;
- }
-
- public Collection supportedOptions() {
- return unmodifiableCollection(Arrays.asList("-Acontextspecific", "-Ageneratechecks"));
- }
-
- public void roundComplete(RoundCompleteEvent event) {
- first_round = false;
- }
-
- public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
- // Only process the initial types, not the generated ones
- if (first_round) {
- env.addListener(this);
- return new GeneratorProcessor(env);
- } else
- return AnnotationProcessors.NO_OP;
- }
-
- private static class GeneratorProcessor implements AnnotationProcessor {
- private final AnnotationProcessorEnvironment env;
-
- GeneratorProcessor(AnnotationProcessorEnvironment env) {
- this.env = env;
- }
-
- public void process() {
- Map options = env.getOptions();
- boolean generate_error_checks = options.containsKey("-Ageneratechecks");
- boolean context_specific = options.containsKey("-Acontextspecific");
- try {
- generateContextCapabilitiesSource(context_specific, generate_error_checks);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void generateContextCapabilitiesSource(boolean context_specific, boolean generate_error_checks) throws IOException {
- PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(Utils.CONTEXT_CAPS_CLASS_NAME + ".java"), null);
- writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
- writer.println();
- writer.println("package org.lwjgl.opengl;");
- writer.println();
- writer.println("import org.lwjgl.LWJGLException;");
- writer.println("import org.lwjgl.LWJGLUtil;");
- writer.println("import org.lwjgl.BufferUtils;");
- writer.println("import java.util.Set;");
- writer.println("import java.util.HashSet;");
- writer.println("import java.nio.IntBuffer;");
- writer.println();
- ContextCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
- DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
- Collection interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- if (Utils.isFinal(interface_decl))
- ContextCapabilitiesGenerator.generateField(writer, interface_decl);
- }
- writer.println();
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- ContextCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl);
- }
- writer.println();
- if (context_specific) {
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- ContextCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl);
- }
- writer.println();
- }
-
- writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
- writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
- writer.println("\t\tsupported_extensions.remove(extension);");
- writer.println("\t}\n");
-
- ContextCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- ContextCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl);
- }
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- String simple_name = interface_decl.getSimpleName();
- if (simple_name.equals("GL11"))
- continue;
- ContextCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
- }
- ContextCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
- writer.println();
- writer.println("\tstatic void unloadAllStubs() {");
- if (!context_specific) {
- writer.println("\t\tif (!loaded_stubs)");
- writer.println("\t\t\treturn;");
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- ContextCapabilitiesGenerator.generateUnloadStubs(writer, interface_decl);
- }
- writer.println("\t\tloaded_stubs = false;");
- }
- writer.println("\t}");
- writer.println();
- ContextCapabilitiesGenerator.generateInitializerPrologue(writer);
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- if (Utils.isFinal(interface_decl))
- ContextCapabilitiesGenerator.generateInitializer(writer, interface_decl);
- }
- writer.println("\t\ttracker.init();");
- writer.println("\t}");
- writer.println("}");
- writer.close();
- }
- }
-}
+/*
+ * 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.util.generator.opengl;
+
+import org.lwjgl.util.generator.Utils;
+
+import static java.util.Collections.unmodifiableCollection;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.apt.AnnotationProcessors;
+import com.sun.mirror.apt.Filer;
+import com.sun.mirror.apt.RoundCompleteEvent;
+import com.sun.mirror.apt.RoundCompleteListener;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.util.DeclarationFilter;
+
+/**
+ *
+ * Generator tool for creating the ContexCapabilities class
+ *
+ * @author elias_naur
+ * @version $Revision: 3316 $
+ * $Id: ContextGeneratorProcessorFactory.java 3316 2010-04-09 23:57:40Z spasi $
+ */
+public class GLGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
+ private static boolean first_round = true;
+
+ // Process any set of annotations
+ private static final Collection supportedAnnotations =
+ unmodifiableCollection(Arrays.asList("*"));
+
+ public Collection supportedAnnotationTypes() {
+ return supportedAnnotations;
+ }
+
+ public Collection supportedOptions() {
+ return unmodifiableCollection(Arrays.asList("-Acontextspecific", "-Ageneratechecks"));
+ }
+
+ public void roundComplete(RoundCompleteEvent event) {
+ first_round = false;
+ }
+
+ public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
+ // Only process the initial types, not the generated ones
+ if (first_round) {
+ env.addListener(this);
+ return new GeneratorProcessor(env);
+ } else
+ return AnnotationProcessors.NO_OP;
+ }
+
+ private static class GeneratorProcessor implements AnnotationProcessor {
+ private final AnnotationProcessorEnvironment env;
+
+ GeneratorProcessor(AnnotationProcessorEnvironment env) {
+ this.env = env;
+ }
+
+ public void process() {
+ Map options = env.getOptions();
+ boolean generate_error_checks = options.containsKey("-Ageneratechecks");
+ boolean context_specific = options.containsKey("-Acontextspecific");
+ try {
+ generateContextCapabilitiesSource(context_specific, generate_error_checks);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void generateContextCapabilitiesSource(boolean context_specific, boolean generate_error_checks) throws IOException {
+ PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(Utils.CONTEXT_CAPS_CLASS_NAME + ".java"), null);
+ writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
+ writer.println();
+ writer.println("package org.lwjgl.opengl;");
+ writer.println();
+ writer.println("import org.lwjgl.LWJGLException;");
+ writer.println("import org.lwjgl.LWJGLUtil;");
+ writer.println("import java.util.Set;");
+ writer.println("import java.util.HashSet;");
+ writer.println();
+ GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
+ DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
+ Collection interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ if (Utils.isFinal(interface_decl))
+ GLCapabilitiesGenerator.generateField(writer, interface_decl);
+ }
+ writer.println();
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ GLCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl);
+ }
+ writer.println();
+ if (context_specific) {
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ GLCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl);
+ }
+ writer.println();
+ }
+
+ writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
+ writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
+ writer.println("\t\tsupported_extensions.remove(extension);");
+ writer.println("\t}\n");
+
+ GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl);
+ }
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ String simple_name = interface_decl.getSimpleName();
+ if (simple_name.equals("GL11"))
+ continue;
+ GLCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
+ }
+ GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
+ writer.println();
+ writer.println("\tstatic void unloadAllStubs() {");
+ if (!context_specific) {
+ writer.println("\t\tif (!loaded_stubs)");
+ writer.println("\t\t\treturn;");
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ GLCapabilitiesGenerator.generateUnloadStubs(writer, interface_decl);
+ }
+ writer.println("\t\tloaded_stubs = false;");
+ }
+ writer.println("\t}");
+ writer.println();
+ GLCapabilitiesGenerator.generateInitializerPrologue(writer);
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ if (Utils.isFinal(interface_decl))
+ GLCapabilitiesGenerator.generateInitializer(writer, interface_decl);
+ }
+ writer.println("\t\ttracker.init();");
+ writer.println("\t}");
+ writer.println("}");
+ writer.close();
+ }
+ }
+}
diff --git a/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java
similarity index 93%
rename from src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java
rename to src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java
index c1f9eee7..f306603e 100644
--- a/src/java/org/lwjgl/util/generator/ReferencesGeneratorProcessorFactory.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java
@@ -1,205 +1,208 @@
-/*
- * 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.util.generator;
-
-import static java.util.Collections.emptyList;
-import static java.util.Collections.unmodifiableCollection;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-
-import com.sun.mirror.apt.AnnotationProcessor;
-import com.sun.mirror.apt.AnnotationProcessorEnvironment;
-import com.sun.mirror.apt.AnnotationProcessorFactory;
-import com.sun.mirror.apt.AnnotationProcessors;
-import com.sun.mirror.apt.Filer;
-import com.sun.mirror.apt.RoundCompleteEvent;
-import com.sun.mirror.apt.RoundCompleteListener;
-import com.sun.mirror.declaration.AnnotationTypeDeclaration;
-import com.sun.mirror.declaration.InterfaceDeclaration;
-import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.ParameterDeclaration;
-import com.sun.mirror.declaration.TypeDeclaration;
-import com.sun.mirror.util.DeclarationFilter;
-
-/**
- *
- * Generator tool for creating the References class
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-public class ReferencesGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
- private final static String REFERENCES_CLASS_NAME = "References";
- private final static String REFERENCES_PARAMETER_NAME = "references";
-
- private static boolean first_round = true;
-
- // Process any set of annotations
- private static final Collection supportedAnnotations =
- unmodifiableCollection(Arrays.asList("*"));
-
- public Collection supportedAnnotationTypes() {
- return supportedAnnotations;
- }
-
- public Collection supportedOptions() {
- return emptyList();
- }
-
- public void roundComplete(RoundCompleteEvent event) {
- first_round = false;
- }
-
- public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
- // Only process the initial types, not the generated ones
- if (first_round) {
- env.addListener(this);
- return new GeneratorProcessor(env);
- } else
- return AnnotationProcessors.NO_OP;
- }
-
- private static class GeneratorProcessor implements AnnotationProcessor {
- private final AnnotationProcessorEnvironment env;
-
- GeneratorProcessor(AnnotationProcessorEnvironment env) {
- this.env = env;
- }
-
- public void process() {
- try {
- generateReferencesSource();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static void generateClearsFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
- for (ParameterDeclaration param : method.getParameters()) {
- CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
- if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
- Class nio_type = Utils.getNIOBufferType(param.getType());
- String reference_name = Utils.getReferenceName(interface_decl, method, param);
- writer.println("\t\tthis." + reference_name + " = null;");
- }
- }
- }
-
- private static void generateCopiesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
- for (ParameterDeclaration param : method.getParameters()) {
- CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
- if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
- Class nio_type = Utils.getNIOBufferType(param.getType());
- String reference_name = Utils.getReferenceName(interface_decl, method, param);
- writer.print("\t\t\tthis." + reference_name + " = ");
- writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";");
- }
- }
- }
-
- private static void generateClearsFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
- for (MethodDeclaration method : interface_decl.getMethods()) {
- generateClearsFromParameters(writer, interface_decl, method);
- }
- }
-
- private static void generateCopiesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
- for (MethodDeclaration method : interface_decl.getMethods()) {
- generateCopiesFromParameters(writer, interface_decl, method);
- }
- }
-
- private static void generateReferencesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
- for (ParameterDeclaration param : method.getParameters()) {
- CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
- if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
- Class nio_type = Utils.getNIOBufferType(param.getType());
- if (nio_type == null)
- throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
- + cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
- writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param));
- writer.println(";");
- }
- }
- }
-
- private static void generateReferencesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
- for (MethodDeclaration method : interface_decl.getMethods()) {
- generateReferencesFromParameters(writer, interface_decl, method);
- }
- }
-
- private void generateReferencesSource() throws IOException {
- PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(REFERENCES_CLASS_NAME + ".java"), null);
- writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
- writer.println();
- writer.println("package org.lwjgl.opengl;");
- writer.println();
- writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {");
- writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
- writer.println("\t\tsuper(caps);");
- writer.println("\t}");
- DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
- Collection interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- generateReferencesFromMethods(writer, interface_decl);
- }
- writer.println();
- writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
- writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
- writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- generateCopiesFromMethods(writer, interface_decl);
- }
- writer.println("\t\t}");
- writer.println("\t}");
- writer.println("\tvoid clear() {");
- writer.println("\t\tsuper.clear();");
- for (TypeDeclaration typedecl : interface_decls) {
- InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
- generateClearsFromMethods(writer, interface_decl);
- }
- writer.println("\t}");
- writer.println("}");
- writer.close();
- }
- }
-}
+/*
+ * 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.util.generator.opengl;
+
+import org.lwjgl.util.generator.CachedReference;
+import org.lwjgl.util.generator.Utils;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.unmodifiableCollection;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.apt.AnnotationProcessors;
+import com.sun.mirror.apt.Filer;
+import com.sun.mirror.apt.RoundCompleteEvent;
+import com.sun.mirror.apt.RoundCompleteListener;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.InterfaceDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.util.DeclarationFilter;
+
+/**
+ *
+ * Generator tool for creating the References class
+ *
+ * @author elias_naur
+ * @version $Revision: 3237 $
+ * $Id: ReferencesGeneratorProcessorFactory.java 3237 2009-09-08 15:07:15Z spasi $
+ */
+public class GLReferencesGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
+ private final static String REFERENCES_CLASS_NAME = "References";
+ private final static String REFERENCES_PARAMETER_NAME = "references";
+
+ private static boolean first_round = true;
+
+ // Process any set of annotations
+ private static final Collection supportedAnnotations =
+ unmodifiableCollection(Arrays.asList("*"));
+
+ public Collection supportedAnnotationTypes() {
+ return supportedAnnotations;
+ }
+
+ public Collection supportedOptions() {
+ return emptyList();
+ }
+
+ public void roundComplete(RoundCompleteEvent event) {
+ first_round = false;
+ }
+
+ public AnnotationProcessor getProcessorFor(Set atds, AnnotationProcessorEnvironment env) {
+ // Only process the initial types, not the generated ones
+ if (first_round) {
+ env.addListener(this);
+ return new GeneratorProcessor(env);
+ } else
+ return AnnotationProcessors.NO_OP;
+ }
+
+ private static class GeneratorProcessor implements AnnotationProcessor {
+ private final AnnotationProcessorEnvironment env;
+
+ GeneratorProcessor(AnnotationProcessorEnvironment env) {
+ this.env = env;
+ }
+
+ public void process() {
+ try {
+ generateReferencesSource();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void generateClearsFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
+ for (ParameterDeclaration param : method.getParameters()) {
+ CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
+ if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
+ Class nio_type = Utils.getNIOBufferType(param.getType());
+ String reference_name = Utils.getReferenceName(interface_decl, method, param);
+ writer.println("\t\tthis." + reference_name + " = null;");
+ }
+ }
+ }
+
+ private static void generateCopiesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
+ for (ParameterDeclaration param : method.getParameters()) {
+ CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
+ if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
+ Class nio_type = Utils.getNIOBufferType(param.getType());
+ String reference_name = Utils.getReferenceName(interface_decl, method, param);
+ writer.print("\t\t\tthis." + reference_name + " = ");
+ writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";");
+ }
+ }
+ }
+
+ private static void generateClearsFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
+ for (MethodDeclaration method : interface_decl.getMethods()) {
+ generateClearsFromParameters(writer, interface_decl, method);
+ }
+ }
+
+ private static void generateCopiesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
+ for (MethodDeclaration method : interface_decl.getMethods()) {
+ generateCopiesFromParameters(writer, interface_decl, method);
+ }
+ }
+
+ private static void generateReferencesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
+ for (ParameterDeclaration param : method.getParameters()) {
+ CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
+ if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
+ Class nio_type = Utils.getNIOBufferType(param.getType());
+ if (nio_type == null)
+ throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
+ + cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
+ writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param));
+ writer.println(";");
+ }
+ }
+ }
+
+ private static void generateReferencesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
+ for (MethodDeclaration method : interface_decl.getMethods()) {
+ generateReferencesFromParameters(writer, interface_decl, method);
+ }
+ }
+
+ private void generateReferencesSource() throws IOException {
+ PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(REFERENCES_CLASS_NAME + ".java"), null);
+ writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
+ writer.println();
+ writer.println("package org.lwjgl.opengl;");
+ writer.println();
+ writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {");
+ writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
+ writer.println("\t\tsuper(caps);");
+ writer.println("\t}");
+ DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
+ Collection interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ generateReferencesFromMethods(writer, interface_decl);
+ }
+ writer.println();
+ writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
+ writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
+ writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ generateCopiesFromMethods(writer, interface_decl);
+ }
+ writer.println("\t\t}");
+ writer.println("\t}");
+ writer.println("\tvoid clear() {");
+ writer.println("\t\tsuper.clear();");
+ for (TypeDeclaration typedecl : interface_decls) {
+ InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
+ generateClearsFromMethods(writer, interface_decl);
+ }
+ writer.println("\t}");
+ writer.println("}");
+ writer.close();
+ }
+ }
+}
diff --git a/src/java/org/lwjgl/util/generator/GLTypeMap.java b/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java
similarity index 86%
rename from src/java/org/lwjgl/util/generator/GLTypeMap.java
rename to src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java
index 7e466442..92f6df1f 100644
--- a/src/java/org/lwjgl/util/generator/GLTypeMap.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java
@@ -1,299 +1,324 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * OpenGL sepcific generator behaviour
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import org.lwjgl.opengl.PointerWrapper;
-
-import java.io.PrintWriter;
-import java.nio.*;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.sun.mirror.declaration.AnnotationMirror;
-import com.sun.mirror.type.PrimitiveType;
-
-public class GLTypeMap implements TypeMap {
-
- private static final Map native_types_to_primitive;
-
- static {
- native_types_to_primitive = new HashMap();
- native_types_to_primitive.put(GLbitfield.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLcharARB.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(GLclampf.class, PrimitiveType.Kind.FLOAT);
- native_types_to_primitive.put(GLfloat.class, PrimitiveType.Kind.FLOAT);
- native_types_to_primitive.put(GLint.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLshort.class, PrimitiveType.Kind.SHORT);
- native_types_to_primitive.put(GLsizeiptr.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLuint.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLboolean.class, PrimitiveType.Kind.BOOLEAN);
- native_types_to_primitive.put(GLchar.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(GLdouble.class, PrimitiveType.Kind.DOUBLE);
- native_types_to_primitive.put(GLhalf.class, PrimitiveType.Kind.SHORT);
- native_types_to_primitive.put(GLintptrARB.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLsizei.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLushort.class, PrimitiveType.Kind.SHORT);
- native_types_to_primitive.put(GLbyte.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(GLclampd.class, PrimitiveType.Kind.DOUBLE);
- native_types_to_primitive.put(GLenum.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLhandleARB.class, PrimitiveType.Kind.INT);
- native_types_to_primitive.put(GLintptr.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLsizeiptrARB.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLubyte.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(GLvoid.class, PrimitiveType.Kind.BYTE);
- native_types_to_primitive.put(GLint64EXT.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLuint64EXT.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLint64.class, PrimitiveType.Kind.LONG);
- native_types_to_primitive.put(GLuint64.class, PrimitiveType.Kind.LONG);
- }
-
- public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
- PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
- if ( kind == null )
- throw new RuntimeException("Unsupported type " + native_type);
- return kind;
- }
-
- public String getErrorCheckMethodName() {
- return "Util.checkGLError()";
- }
-
- public String getRegisterNativesFunctionName() {
- return "extgl_InitializeClass";
- }
-
- public Signedness getSignednessFromType(Class type) {
- if ( GLuint.class.equals(type) )
- return Signedness.UNSIGNED;
- else if ( GLint.class.equals(type) )
- return Signedness.SIGNED;
- else if ( GLushort.class.equals(type) )
- return Signedness.UNSIGNED;
- else if ( GLshort.class.equals(type) )
- return Signedness.SIGNED;
- else if ( GLubyte.class.equals(type) )
- return Signedness.UNSIGNED;
- else if ( GLbyte.class.equals(type) )
- return Signedness.SIGNED;
- else if ( GLuint64EXT.class.equals(type) )
- return Signedness.UNSIGNED;
- else if ( GLint64EXT.class.equals(type) )
- return Signedness.SIGNED;
- else if ( GLuint64.class.equals(type) )
- return Signedness.UNSIGNED;
- else if ( GLint64.class.equals(type) )
- return Signedness.SIGNED;
- else
- return Signedness.NONE;
- }
-
- public String translateAnnotation(Class annotation_type) {
- if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) )
- return "i";
- else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) )
- return "s";
- else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) )
- return "b";
- else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) )
- return "f";
- else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) )
- return "d";
- else if ( annotation_type.equals(GLhalf.class) )
- return "h";
- else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) )
- return "i64";
- else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) )
- return "";
- else
- throw new RuntimeException(annotation_type + " is not allowed");
- }
-
- public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
- Class type;
- switch ( kind ) {
- case INT:
- type = GLint.class;
- break;
- case DOUBLE:
- type = GLdouble.class;
- break;
- case FLOAT:
- type = GLfloat.class;
- break;
- case SHORT:
- type = GLshort.class;
- break;
- case BYTE:
- type = GLbyte.class;
- break;
- case LONG:
- type = GLint64EXT.class;
- break;
- case BOOLEAN:
- type = GLboolean.class;
- break;
- default:
- throw new RuntimeException(kind + " is not allowed");
- }
- return type;
- }
-
- public Class getVoidType() {
- return GLvoid.class;
- }
-
- public Class getStringElementType() {
- return GLubyte.class;
- }
-
- private static Class[] getValidBufferTypes(Class type) {
- if ( type.equals(IntBuffer.class) )
- return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
- GLsizei.class, GLuint.class, GLvoid.class };
- else if ( type.equals(FloatBuffer.class) )
- return new Class[] { GLclampf.class, GLfloat.class };
- else if ( type.equals(ByteBuffer.class) )
- return new Class[] { GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class };
- else if ( type.equals(ShortBuffer.class) )
- return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
- else if ( type.equals(DoubleBuffer.class) )
- return new Class[] { GLclampd.class, GLdouble.class };
- else if ( type.equals(LongBuffer.class) )
- return new Class[] { GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
- else
- return new Class[] { };
- }
-
- private static Class[] getValidPrimitiveTypes(Class type) {
- if ( type.equals(long.class) )
- return new Class[] { GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
- else if ( type.equals(int.class) )
- return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
- GLsizei.class };
- else if ( type.equals(double.class) )
- return new Class[] { GLclampd.class, GLdouble.class };
- else if ( type.equals(float.class) )
- return new Class[] { GLclampf.class, GLfloat.class };
- else if ( type.equals(short.class) )
- return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
- else if ( type.equals(byte.class) )
- return new Class[] { GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class };
- else if ( type.equals(boolean.class) )
- return new Class[] { GLboolean.class };
- else if ( type.equals(void.class) )
- return new Class[] { GLvoid.class, GLreturn.class };
- else
- return new Class[] { };
- }
-
- public String getTypedefPrefix() {
- return "APIENTRY";
- }
-
- public void printNativeIncludes(PrintWriter writer) {
- writer.println("#include \"extgl.h\"");
- }
-
- public Class[] getValidAnnotationTypes(Class type) {
- Class[] valid_types;
- if ( Buffer.class.isAssignableFrom(type) )
- valid_types = getValidBufferTypes(type);
- else if ( type.isPrimitive() )
- valid_types = getValidPrimitiveTypes(type);
- else if ( String.class.equals(type) )
- valid_types = new Class[] { GLubyte.class };
- else if ( PointerWrapper.class.isAssignableFrom(type) )
- valid_types = new Class[] { GLpointer.class };
- else if (void.class.equals(type) )
- valid_types = new Class[] { GLreturn.class };
- else
- valid_types = new Class[] { };
- return valid_types;
- }
-
- public Class getInverseType(Class type) {
- if ( GLuint.class.equals(type) )
- return GLint.class;
- else if ( GLint.class.equals(type) )
- return GLuint.class;
- else if ( GLushort.class.equals(type) )
- return GLshort.class;
- else if ( GLshort.class.equals(type) )
- return GLushort.class;
- else if ( GLubyte.class.equals(type) )
- return GLbyte.class;
- else if ( GLbyte.class.equals(type) )
- return GLubyte.class;
- else if ( GLuint64EXT.class.equals(type) )
- return GLint64EXT.class;
- else if ( GLint64EXT.class.equals(type) )
- return GLuint64EXT.class;
- else if ( GLuint64.class.equals(type) )
- return GLint64.class;
- else if ( GLint64.class.equals(type) )
- return GLuint64.class;
- else
- return null;
- }
-
- public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
- Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
- if ( annotation_class.equals(GLint.class) )
- return "GL11.GL_INT";
- else if ( annotation_class.equals(GLbyte.class) )
- return "GL11.GL_BYTE";
- else if ( annotation_class.equals(GLshort.class) )
- return "GL11.GL_SHORT";
- if ( annotation_class.equals(GLuint.class) )
- return "GL11.GL_UNSIGNED_INT";
- else if ( annotation_class.equals(GLubyte.class) )
- return "GL11.GL_UNSIGNED_BYTE";
- else if ( annotation_class.equals(GLushort.class) )
- return "GL11.GL_UNSIGNED_SHORT";
- else if ( annotation_class.equals(GLfloat.class) )
- return "GL11.GL_FLOAT";
- else if ( annotation_class.equals(GLdouble.class) )
- return "GL11.GL_DOUBLE";
- else
- return null;
- }
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * OpenGL sepcific generator behaviour
+ *
+ * @author elias_naur
+ * @version $Revision: 3392 $
+ * $Id: GLTypeMap.java 3392 2010-07-27 15:33:22Z spasi $
+ */
+
+import org.lwjgl.util.generator.NativeTypeTranslator;
+import org.lwjgl.util.generator.PointerWrapper;
+import org.lwjgl.util.generator.Signedness;
+import org.lwjgl.util.generator.TypeMap;
+
+import java.io.PrintWriter;
+import java.lang.annotation.Annotation;
+import java.nio.*;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.PrimitiveType;
+
+public class GLTypeMap implements TypeMap {
+
+ private static final Map native_types_to_primitive;
+
+ static {
+ native_types_to_primitive = new HashMap();
+ native_types_to_primitive.put(GLbitfield.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLcharARB.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(GLclampf.class, PrimitiveType.Kind.FLOAT);
+ native_types_to_primitive.put(GLfloat.class, PrimitiveType.Kind.FLOAT);
+ native_types_to_primitive.put(GLint.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLshort.class, PrimitiveType.Kind.SHORT);
+ native_types_to_primitive.put(GLsizeiptr.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLuint.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLboolean.class, PrimitiveType.Kind.BOOLEAN);
+ native_types_to_primitive.put(GLchar.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(GLdouble.class, PrimitiveType.Kind.DOUBLE);
+ native_types_to_primitive.put(GLhalf.class, PrimitiveType.Kind.SHORT);
+ native_types_to_primitive.put(GLintptrARB.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLsizei.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLushort.class, PrimitiveType.Kind.SHORT);
+ native_types_to_primitive.put(GLbyte.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(GLclampd.class, PrimitiveType.Kind.DOUBLE);
+ native_types_to_primitive.put(GLenum.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLhandleARB.class, PrimitiveType.Kind.INT);
+ native_types_to_primitive.put(GLintptr.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLsizeiptrARB.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLubyte.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(GLvoid.class, PrimitiveType.Kind.BYTE);
+ native_types_to_primitive.put(GLint64EXT.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLuint64EXT.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLint64.class, PrimitiveType.Kind.LONG);
+ native_types_to_primitive.put(GLuint64.class, PrimitiveType.Kind.LONG);
+ }
+
+ public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
+ PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
+ if ( kind == null )
+ throw new RuntimeException("Unsupported type " + native_type);
+ return kind;
+ }
+
+ public void printCapabilitiesInit(final PrintWriter writer) {
+ writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
+ }
+
+ public String getCapabilities() {
+ return "caps";
+ }
+
+ public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
+ writer.println(tabs + "Util.checkGLError();");
+ }
+
+ public String getRegisterNativesFunctionName() {
+ return "extgl_InitializeClass";
+ }
+
+ public Signedness getSignednessFromType(Class type) {
+ if ( GLuint.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( GLint.class.equals(type) )
+ return Signedness.SIGNED;
+ else if ( GLushort.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( GLshort.class.equals(type) )
+ return Signedness.SIGNED;
+ else if ( GLubyte.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( GLbyte.class.equals(type) )
+ return Signedness.SIGNED;
+ else if ( GLuint64EXT.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( GLint64EXT.class.equals(type) )
+ return Signedness.SIGNED;
+ else if ( GLuint64.class.equals(type) )
+ return Signedness.UNSIGNED;
+ else if ( GLint64.class.equals(type) )
+ return Signedness.SIGNED;
+ else
+ return Signedness.NONE;
+ }
+
+ public String translateAnnotation(Class annotation_type) {
+ if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) )
+ return "i";
+ else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) )
+ return "s";
+ else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) )
+ return "b";
+ else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) )
+ return "f";
+ else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) )
+ return "d";
+ else if ( annotation_type.equals(GLhalf.class) )
+ return "h";
+ else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) )
+ return "i64";
+ else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) )
+ return "";
+ else
+ throw new RuntimeException(annotation_type + " is not allowed");
+ }
+
+ public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
+ Class type;
+ switch ( kind ) {
+ case INT:
+ type = GLint.class;
+ break;
+ case DOUBLE:
+ type = GLdouble.class;
+ break;
+ case FLOAT:
+ type = GLfloat.class;
+ break;
+ case SHORT:
+ type = GLshort.class;
+ break;
+ case BYTE:
+ type = GLbyte.class;
+ break;
+ case LONG:
+ type = GLint64EXT.class;
+ break;
+ case BOOLEAN:
+ type = GLboolean.class;
+ break;
+ default:
+ throw new RuntimeException(kind + " is not allowed");
+ }
+ return type;
+ }
+
+ public Class extends Annotation> getVoidType() {
+ return GLvoid.class;
+ }
+
+ public Class extends Annotation> getStringElementType() {
+ return GLubyte.class;
+ }
+
+ public Class extends Annotation> getStringArrayType() {
+ return GLchar.class;
+ }
+
+ public Class extends Annotation> getByteBufferArrayType() {
+ return GLchar.class;
+ }
+
+ private static Class[] getValidBufferTypes(Class type) {
+ if ( type.equals(IntBuffer.class) )
+ return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
+ GLsizei.class, GLuint.class, GLvoid.class };
+ else if ( type.equals(FloatBuffer.class) )
+ return new Class[] { GLclampf.class, GLfloat.class };
+ else if ( type.equals(ByteBuffer.class) )
+ return new Class[] { GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class };
+ else if ( type.equals(ShortBuffer.class) )
+ return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
+ else if ( type.equals(DoubleBuffer.class) )
+ return new Class[] { GLclampd.class, GLdouble.class };
+ else if ( type.equals(LongBuffer.class) )
+ return new Class[] { GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
+ else
+ return new Class[] { };
+ }
+
+ private static Class[] getValidPrimitiveTypes(Class type) {
+ if ( type.equals(long.class) )
+ return new Class[] { GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
+ else if ( type.equals(int.class) )
+ return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
+ GLsizei.class };
+ else if ( type.equals(double.class) )
+ return new Class[] { GLclampd.class, GLdouble.class };
+ else if ( type.equals(float.class) )
+ return new Class[] { GLclampf.class, GLfloat.class };
+ else if ( type.equals(short.class) )
+ return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
+ else if ( type.equals(byte.class) )
+ return new Class[] { GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class };
+ else if ( type.equals(boolean.class) )
+ return new Class[] { GLboolean.class };
+ else if ( type.equals(void.class) )
+ return new Class[] { GLvoid.class, GLreturn.class };
+ else
+ return new Class[] { };
+ }
+
+ public String getTypedefPostfix() {
+ return "";
+ }
+
+ public String getFunctionPrefix() {
+ return "APIENTRY";
+ }
+
+ public void printNativeIncludes(PrintWriter writer) {
+ writer.println("#include \"extgl.h\"");
+ }
+
+ public Class[] getValidAnnotationTypes(Class type) {
+ Class[] valid_types;
+ if ( Buffer.class.isAssignableFrom(type) )
+ valid_types = getValidBufferTypes(type);
+ else if ( type.isPrimitive() )
+ valid_types = getValidPrimitiveTypes(type);
+ else if ( String.class.equals(type) )
+ valid_types = new Class[] { GLubyte.class };
+ else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
+ valid_types = new Class[] { PointerWrapper.class };
+ else if (void.class.equals(type) )
+ valid_types = new Class[] { GLreturn.class };
+ else
+ valid_types = new Class[] { };
+ return valid_types;
+ }
+
+ public Class extends Annotation> getInverseType(Class type) {
+ if ( GLuint.class.equals(type) )
+ return GLint.class;
+ else if ( GLint.class.equals(type) )
+ return GLuint.class;
+ else if ( GLushort.class.equals(type) )
+ return GLshort.class;
+ else if ( GLshort.class.equals(type) )
+ return GLushort.class;
+ else if ( GLubyte.class.equals(type) )
+ return GLbyte.class;
+ else if ( GLbyte.class.equals(type) )
+ return GLubyte.class;
+ else if ( GLuint64EXT.class.equals(type) )
+ return GLint64EXT.class;
+ else if ( GLint64EXT.class.equals(type) )
+ return GLuint64EXT.class;
+ else if ( GLuint64.class.equals(type) )
+ return GLint64.class;
+ else if ( GLint64.class.equals(type) )
+ return GLuint64.class;
+ else
+ return null;
+ }
+
+ public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
+ Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
+ if ( annotation_class.equals(GLint.class) )
+ return "GL11.GL_INT";
+ else if ( annotation_class.equals(GLbyte.class) )
+ return "GL11.GL_BYTE";
+ else if ( annotation_class.equals(GLshort.class) )
+ return "GL11.GL_SHORT";
+ if ( annotation_class.equals(GLuint.class) )
+ return "GL11.GL_UNSIGNED_INT";
+ else if ( annotation_class.equals(GLubyte.class) )
+ return "GL11.GL_UNSIGNED_BYTE";
+ else if ( annotation_class.equals(GLushort.class) )
+ return "GL11.GL_UNSIGNED_SHORT";
+ else if ( annotation_class.equals(GLfloat.class) )
+ return "GL11.GL_FLOAT";
+ else if ( annotation_class.equals(GLdouble.class) )
+ return "GL11.GL_DOUBLE";
+ else
+ return null;
+ }
+}
diff --git a/src/java/org/lwjgl/util/generator/GLbitfield.java b/src/java/org/lwjgl/util/generator/opengl/GLbitfield.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLbitfield.java
rename to src/java/org/lwjgl/util/generator/opengl/GLbitfield.java
index 9c49c558..6652f88f 100644
--- a/src/java/org/lwjgl/util/generator/GLbitfield.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLbitfield.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLbitfield {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLbitfield.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLbitfield {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLboolean.java b/src/java/org/lwjgl/util/generator/opengl/GLboolean.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLboolean.java
rename to src/java/org/lwjgl/util/generator/opengl/GLboolean.java
index bdacd842..f392283e 100644
--- a/src/java/org/lwjgl/util/generator/GLboolean.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLboolean.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLboolean {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLboolean.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLboolean {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLbyte.java b/src/java/org/lwjgl/util/generator/opengl/GLbyte.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLbyte.java
rename to src/java/org/lwjgl/util/generator/opengl/GLbyte.java
index 82e8bd83..6f4fcc51 100644
--- a/src/java/org/lwjgl/util/generator/GLbyte.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLbyte.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLbyte {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLbyte.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLbyte {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLchar.java b/src/java/org/lwjgl/util/generator/opengl/GLchar.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLchar.java
rename to src/java/org/lwjgl/util/generator/opengl/GLchar.java
index a5603ca3..a31bf425 100644
--- a/src/java/org/lwjgl/util/generator/GLchar.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLchar.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLchar {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLchar.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLchar {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLcharARB.java b/src/java/org/lwjgl/util/generator/opengl/GLcharARB.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLcharARB.java
rename to src/java/org/lwjgl/util/generator/opengl/GLcharARB.java
index a983f6da..25fe1f71 100644
--- a/src/java/org/lwjgl/util/generator/GLcharARB.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLcharARB.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLcharARB {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLcharARB.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLcharARB {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLclampd.java b/src/java/org/lwjgl/util/generator/opengl/GLclampd.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLclampd.java
rename to src/java/org/lwjgl/util/generator/opengl/GLclampd.java
index 90361bd7..21c85fbb 100644
--- a/src/java/org/lwjgl/util/generator/GLclampd.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLclampd.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLclampd {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLclampd.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLclampd {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLclampf.java b/src/java/org/lwjgl/util/generator/opengl/GLclampf.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLclampf.java
rename to src/java/org/lwjgl/util/generator/opengl/GLclampf.java
index 237bc37c..0027efbc 100644
--- a/src/java/org/lwjgl/util/generator/GLclampf.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLclampf.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLclampf {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLclampf.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLclampf {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLdouble.java b/src/java/org/lwjgl/util/generator/opengl/GLdouble.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLdouble.java
rename to src/java/org/lwjgl/util/generator/opengl/GLdouble.java
index 445c5dbb..10fdf389 100644
--- a/src/java/org/lwjgl/util/generator/GLdouble.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLdouble.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLdouble {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLdouble.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLdouble {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLenum.java b/src/java/org/lwjgl/util/generator/opengl/GLenum.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLenum.java
rename to src/java/org/lwjgl/util/generator/opengl/GLenum.java
index 7eef9d80..fecf2eb2 100644
--- a/src/java/org/lwjgl/util/generator/GLenum.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLenum.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLenum {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLenum.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLenum {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLfloat.java b/src/java/org/lwjgl/util/generator/opengl/GLfloat.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLfloat.java
rename to src/java/org/lwjgl/util/generator/opengl/GLfloat.java
index 5d47242e..ba90d6cc 100644
--- a/src/java/org/lwjgl/util/generator/GLfloat.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLfloat.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur
- * @version $Revision$
- * $Id$
- */
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-
-@NativeType
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-public @interface GLfloat {
-}
+/*
+ * 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.util.generator.opengl;
+
+/**
+ *
+ * @author elias_naur
+ * @version $Revision: 2983 $
+ * $Id: GLfloat.java 2983 2008-04-07 18:36:09Z matzon $
+ */
+
+import org.lwjgl.util.generator.NativeType;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@NativeType
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface GLfloat {
+}
diff --git a/src/java/org/lwjgl/util/generator/GLhalf.java b/src/java/org/lwjgl/util/generator/opengl/GLhalf.java
similarity index 89%
rename from src/java/org/lwjgl/util/generator/GLhalf.java
rename to src/java/org/lwjgl/util/generator/opengl/GLhalf.java
index 0039848b..dd77e6f0 100644
--- a/src/java/org/lwjgl/util/generator/GLhalf.java
+++ b/src/java/org/lwjgl/util/generator/opengl/GLhalf.java
@@ -1,47 +1,49 @@
-/*
- * 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.util.generator;
-
-/**
- *
- * @author elias_naur