From: <sp...@us...> - 2010-03-14 23:24:49
|
Revision: 3287 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3287&view=rev Author: spasi Date: 2010-03-14 23:24:40 +0000 (Sun, 14 Mar 2010) Log Message: ----------- Added support for single primitive input/output parameters. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/opengl/SyncTest.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java trunk/LWJGL/src/java/org/lwjgl/util/generator/Constant.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GLTypeMap.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/PostfixTranslator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_performance_monitor.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_buffer_object.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_draw_buffers.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_framebuffer_object.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_occlusion_query.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_program.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sampler_objects.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_objects.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_subroutine.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shading_language_include.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sync.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_timer_query.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback2.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback3.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_uniform_buffer_object.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_array_object.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ATI_draw_buffers.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_draw_buffers2.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_framebuffer_object.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_multi_draw_arrays.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_texture_integer.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_timer_query.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_transform_feedback.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL15.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL31.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL32.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL33.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL40.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GREMEDY_string_marker.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_explicit_multisample.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_occlusion_query.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_program.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_register_combiners.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_shader_buffer_load.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_transform_feedback.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_transform_feedback2.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_buffer_unified_memory.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtils.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GLreturn.java Removed Paths: ------------- trunk/LWJGL/src/java/org/lwjgl/opengl/StringUtils.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstring.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstringOffset.java Copied: trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtils.java (from rev 3286, trunk/LWJGL/src/java/org/lwjgl/opengl/StringUtils.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtils.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtils.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +import org.lwjgl.BufferUtils; + +import java.nio.*; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; + +/** @author spasi */ +final class APIUtils { + + 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 Object initialValue() { return new char[INITIAL_BUFFER_SIZE]; } + }; + + private static final ThreadLocal bufferTL = new ThreadLocal() { + protected Object initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); } + }; + + private static final ThreadLocal lengthsTL = new ThreadLocal() { + protected Object initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); } + }; + + private static final ThreadLocal infiniteSeqTL = new ThreadLocal() { + protected Object initialValue() { return new InfiniteCharSequence(); } + }; + + private static final ThreadLocal buffersTL = new ThreadLocal() { + protected Object initialValue() { return new Buffers(); } + }; + + private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); + + private APIUtils() { + } + + private static char[] getArray(final int size) { + char[] array = (char[])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 = (ByteBuffer)bufferTL.get(); + + if ( buffer.capacity() < size ) { + int sizeNew = buffer.capacity() << 1; + while ( sizeNew < size ) + sizeNew <<= 1; + + buffer = BufferUtils.createByteBuffer(size); + bufferTL.set(buffer); + } else + buffer.clear(); + + return buffer; + } + + private static ByteBuffer getBufferByteOffset(final int size) { + ByteBuffer buffer = (ByteBuffer)bufferTL.get(); + + if ( buffer.capacity() < size ) { + int sizeNew = buffer.capacity() << 1; + while ( sizeNew < size ) + sizeNew <<= 1; + + final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size); + bufferNew.put(buffer); + bufferTL.set(buffer = bufferNew); + } else { + buffer.position(buffer.limit()); + buffer.limit(buffer.capacity()); + } + + return buffer; + } + + static ShortBuffer getBufferShort() { return ((Buffers)buffersTL.get()).shorts; } + + static IntBuffer getBufferInt() { return ((Buffers)buffersTL.get()).ints; } + + static LongBuffer getBufferLong() { return ((Buffers)buffersTL.get()).longs; } + + static FloatBuffer getBufferFloat() { return ((Buffers)buffersTL.get()).floats; } + + static DoubleBuffer getBufferDouble() { return ((Buffers)buffersTL.get()).doubles; } + + static IntBuffer getLengths() { + return getLengths(1); + } + + static IntBuffer getLengths(final int size) { + IntBuffer lengths = (IntBuffer)lengthsTL.get(); + + if ( lengths.capacity() < size ) { + int sizeNew = lengths.capacity(); + while ( sizeNew < size ) + sizeNew <<= 1; + + lengths = BufferUtils.createIntBuffer(size); + lengthsTL.set(lengths); + } else + lengths.clear(); + + return lengths; + } + + private static InfiniteCharSequence getInfiniteSeq() { + return (InfiniteCharSequence)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); + } + + /** + * 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 an IntBuffer + */ + static IntBuffer getLengths(final CharSequence[] strings) { + IntBuffer buffer = getLengths(strings.length); + + for ( int i = 0; i < strings.length; i++ ) + buffer.put(strings[i].length()); + + buffer.flip(); + return buffer; + } + + /** + * 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 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 LongBuffer longs; + + final FloatBuffer floats; + final DoubleBuffer doubles; + + Buffers() { + shorts = BufferUtils.createShortBuffer(BUFFERS_SIZE); + ints = BufferUtils.createIntBuffer(BUFFERS_SIZE); + longs = BufferUtils.createLongBuffer(BUFFERS_SIZE); + + floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE); + doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE); + } + + } + +} \ No newline at end of file Deleted: trunk/LWJGL/src/java/org/lwjgl/opengl/StringUtils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/StringUtils.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/StringUtils.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl.opengl; - -import org.lwjgl.BufferUtils; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.IntBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; - -/** @author spasi */ -final class StringUtils { - - private static final int INITIAL_BUFFER_SIZE = 256; - private static final int INITIAL_LENGTHS_SIZE = 4; - - private static final ThreadLocal arrayTL = new ThreadLocal() { - protected Object initialValue() { - return new char[INITIAL_BUFFER_SIZE]; - } - }; - - private static final ThreadLocal bufferTL = new ThreadLocal() { - protected Object initialValue() { - return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); - } - }; - - private static final ThreadLocal lengthsTL = new ThreadLocal() { - protected Object initialValue() { - return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); - } - }; - - private static final ThreadLocal infiniteSeqTL = new ThreadLocal() { - protected Object initialValue() { - return new InfiniteCharSequence(); - } - }; - - private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); - - private StringUtils() { - } - - private static char[] getArray(final int size) { - char[] array = (char[])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 getBuffer(final int size) { - ByteBuffer buffer = (ByteBuffer)bufferTL.get(); - - if ( buffer.capacity() < size ) { - int sizeNew = buffer.capacity() << 1; - while ( sizeNew < size ) - sizeNew <<= 1; - - buffer = BufferUtils.createByteBuffer(size); - bufferTL.set(buffer); - } - - buffer.clear(); - return buffer; - } - - private static ByteBuffer getBufferOffset(final int size) { - ByteBuffer buffer = (ByteBuffer)bufferTL.get(); - - if ( buffer.capacity() < size ) { - int sizeNew = buffer.capacity() << 1; - while ( sizeNew < size ) - sizeNew <<= 1; - - final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size); - bufferNew.put(buffer); - bufferTL.set(buffer = bufferNew); - } else { - buffer.position(buffer.limit()); - buffer.limit(buffer.capacity()); - } - - return buffer; - } - - static IntBuffer getLengths(final int size) { - IntBuffer lengths = (IntBuffer)lengthsTL.get(); - - if ( lengths.capacity() < size ) { - int sizeNew = lengths.capacity(); - while ( sizeNew < size ) - sizeNew <<= 1; - - lengths = BufferUtils.createIntBuffer(size); - lengthsTL.set(lengths); - } - - lengths.clear(); - return lengths; - } - - static InfiniteCharSequence getInfiniteSeq() { - return (InfiniteCharSequence)infiniteSeqTL.get(); - } - - /** - * 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); - } - - private static void encode(final ByteBuffer buffer, final CharSequence string) { - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); - } - - /** - * 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 = getBuffer(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 getBufferOffset(final CharSequence string, final int offset) { - final ByteBuffer buffer = getBufferOffset(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 = getBuffer(string.length() + 1); - - encode(buffer, string); - - buffer.put((byte)0); - buffer.flip(); - return buffer; - } - - private 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 = getBuffer(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 = getBuffer(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 an IntBuffer - */ - static IntBuffer getLengths(final CharSequence[] strings) { - IntBuffer buffer = getLengths(strings.length); - - for ( int i = 0; i < strings.length; i++ ) - buffer.put(strings[i].length()); - - buffer.flip(); - return buffer; - } - - /** - * 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 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); - } - } - -} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/SyncTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/SyncTest.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/SyncTest.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -31,17 +31,13 @@ */ package org.lwjgl.test.opengl; -import org.lwjgl.BufferUtils; import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.opengl.*; -import java.nio.IntBuffer; import java.util.Random; -/** - * @author spasi <sp...@us...> - */ +/** @author spasi <sp...@us...> */ public final class SyncTest { private SyncTest() { @@ -131,9 +127,7 @@ System.out.println("Unexpected wait status: 0x" + Integer.toHexString(status)); } - IntBuffer property = BufferUtils.createIntBuffer(1); - GL32.glGetSync(sync, GL32.GL_SYNC_STATUS, null, property); - System.out.println("Sync Status: " + (property.get(0) == GL32.GL_UNSIGNALED ? "UNSIGNALED" : "SIGNALED")); + System.out.println("Sync Status: " + (GL32.glGetSync(sync, GL32.GL_SYNC_STATUS) == GL32.GL_UNSIGNALED ? "UNSIGNALED" : "SIGNALED")); GL32.glDeleteSync(sync); Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -44,7 +44,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; -import java.nio.IntBuffer; import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; @@ -191,9 +190,7 @@ System.out.println("ARB VBO not supported!"); System.exit(1); } - IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); - ARBBufferObject.glGenBuffersARB(int_buffer); - buffer_id = int_buffer.get(0); + buffer_id = ARBBufferObject.glGenBuffersARB(); ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id); vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50); @@ -206,9 +203,7 @@ * Cleanup */ private static void cleanup() { - IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); - int_buffer.put(0, buffer_id); - ARBBufferObject.glDeleteBuffersARB(int_buffer); + ARBBufferObject.glDeleteBuffersARB(buffer_id); Display.destroy(); } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -37,21 +37,18 @@ */ package org.lwjgl.test.opengl.shaders; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; - import org.lwjgl.BufferUtils; import org.lwjgl.opengl.ARBProgram; import org.lwjgl.opengl.ARBShaderObjects; import org.lwjgl.opengl.GL11; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + abstract class Shader { - private static final IntBuffer int_buffer = BufferUtils.createIntBuffer(16); - protected static IntBuffer programBuffer = BufferUtils.createIntBuffer(1); protected static ByteBuffer fileBuffer = BufferUtils.createByteBuffer(1024 * 10); protected Shader() { @@ -61,18 +58,6 @@ abstract void cleanup(); - /** - * Obtain a GL integer value from the driver - * - * @param gl_enum The GL value you want - * - * @return the integer value - */ - public static int glGetInteger(int gl_enum) { - GL11.glGetInteger(gl_enum, int_buffer); - return int_buffer.get(0); - } - protected static String getShaderText(String file) { String shader = null; @@ -107,7 +92,7 @@ protected static void checkProgramError(String programFile, String programSource) { if ( GL11.glGetError() == GL11.GL_INVALID_OPERATION ) { - final int errorPos = glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB); + final int errorPos = GL11.glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB); int lineStart = 0; int lineEnd = -1; for ( int i = 0; i < programSource.length(); i++ ) { @@ -140,9 +125,7 @@ } protected static void printShaderObjectInfoLog(String file, int ID) { - ARBShaderObjects.glGetObjectParameterARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB, programBuffer); - - final int logLength = programBuffer.get(0); + final int logLength = ARBShaderObjects.glGetObjectParameteriARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB); if ( logLength <= 1 ) return; @@ -153,9 +136,7 @@ } protected static void printShaderProgramInfoLog(int ID) { - ARBShaderObjects.glGetObjectParameterARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB, programBuffer); - - final int logLength = programBuffer.get(0); + final int logLength = ARBShaderObjects.glGetObjectParameteriARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB); if ( logLength <= 1 ) return; Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -60,10 +60,8 @@ vpFile = vpShaderFile; vpSource = getShaderText(vpShaderFile); - ARBProgram.glGenProgramsARB(programBuffer); + vpID = ARBProgram.glGenProgramsARB(); - vpID = programBuffer.get(0); - ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, vpID); ARBProgram.glProgramStringARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, vpSource); @@ -73,10 +71,8 @@ fpFile = fpShaderFile; fpSource = getShaderText(fpShaderFile); - ARBProgram.glGenProgramsARB(programBuffer); + fpID = ARBProgram.glGenProgramsARB(); - fpID = programBuffer.get(0); - ARBProgram.glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, fpID); ARBProgram.glProgramStringARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, fpSource); @@ -104,11 +100,8 @@ } void cleanup() { - programBuffer.put(0, vpID); - ARBProgram.glDeleteProgramsARB(programBuffer); - - programBuffer.put(0, fpID); - ARBProgram.glDeleteProgramsARB(programBuffer); + ARBProgram.glDeleteProgramsARB(vpID); + ARBProgram.glDeleteProgramsARB(fpID); } } \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -70,8 +70,7 @@ printShaderObjectInfoLog(this.vshFile, vshID); - ARBShaderObjects.glGetObjectParameterARB(vshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( ARBShaderObjects.glGetObjectParameteriARB(vshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE ) ShadersTest.kill("A compilation error occured in a vertex shader."); // Initialize the fragment shader. @@ -84,8 +83,7 @@ printShaderObjectInfoLog(this.fshFile, fshID); - ARBShaderObjects.glGetObjectParameterARB(fshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( ARBShaderObjects.glGetObjectParameteriARB(fshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE ) ShadersTest.kill("A compilation error occured in a fragment shader."); // Initialize the shader program. @@ -98,8 +96,7 @@ printShaderProgramInfoLog(programID); - ARBShaderObjects.glGetObjectParameterARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( ARBShaderObjects.glGetObjectParameteriARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE ) ShadersTest.kill("A linking error occured in a shader program."); uniformLocation = getUniformLocation(programID, "UNIFORMS"); Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -70,8 +70,7 @@ printShaderObjectInfoLog(file, shaderID); - GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE ) ShadersTest.kill("A compilation error occured in a vertex shader."); programID = GL20.glCreateProgram(); @@ -81,27 +80,19 @@ printShaderProgramInfoLog(programID); - GL20.glGetProgram(programID, GL20.GL_LINK_STATUS, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( GL20.glGetProgram(programID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE ) ShadersTest.kill("A linking error occured in a shader program."); final String[] uniformNames = { "uniformA", "uniformB" }; - IntBuffer indexes = BufferUtils.createIntBuffer(uniformNames.length); - IntBuffer params = BufferUtils.createIntBuffer(uniformNames.length); - IntBuffer getBuffer = BufferUtils.createIntBuffer(16); - IntBuffer buffers = BufferUtils.createIntBuffer(1); - // Get uniform block index and data size final int blockIndex = ARBUniformBufferObject.glGetUniformBlockIndex(programID, "test"); - ARBUniformBufferObject.glGetActiveUniformBlock(programID, blockIndex, ARBUniformBufferObject.GL_UNIFORM_BLOCK_DATA_SIZE, getBuffer); - final int blockSize = getBuffer.get(0); + final int blockSize = ARBUniformBufferObject.glGetActiveUniformBlock(programID, blockIndex, ARBUniformBufferObject.GL_UNIFORM_BLOCK_DATA_SIZE); System.out.println("blockSize = " + blockSize); // Create uniform buffer object and allocate a ByteBuffer - GL15.glGenBuffers(buffers); - bufferID = buffers.get(0); + bufferID = GL15.glGenBuffers(); GL15.glBindBuffer(ARBUniformBufferObject.GL_UNIFORM_BUFFER, bufferID); GL15.glBufferData(ARBUniformBufferObject.GL_UNIFORM_BUFFER, blockSize, GL15.GL_DYNAMIC_DRAW); buffer = BufferUtils.createFloatBuffer(blockSize); @@ -111,6 +102,9 @@ ARBUniformBufferObject.glUniformBlockBinding(programID, blockIndex, 0); // Get uniform information + IntBuffer indexes = BufferUtils.createIntBuffer(uniformNames.length); + IntBuffer params = BufferUtils.createIntBuffer(uniformNames.length); + ARBUniformBufferObject.glGetUniformIndices(programID, uniformNames, indexes); uniformA_index = indexes.get(0); uniformB_index = indexes.get(1); Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -53,10 +53,8 @@ file = shaderFile; source = getShaderText(shaderFile); - ARBProgram.glGenProgramsARB(programBuffer); + ID = ARBProgram.glGenProgramsARB(); - ID = programBuffer.get(0); - ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ID); ARBProgram.glProgramStringARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, source); @@ -76,8 +74,7 @@ } void cleanup() { - programBuffer.put(0, ID); - ARBProgram.glDeleteProgramsARB(programBuffer); + ARBProgram.glDeleteProgramsARB(ID); } } \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -38,8 +38,6 @@ package org.lwjgl.test.opengl.shaders; -import java.nio.ByteBuffer; - import org.lwjgl.opengl.ARBShaderObjects; import org.lwjgl.opengl.ARBVertexShader; import org.lwjgl.opengl.GL11; @@ -64,8 +62,7 @@ printShaderObjectInfoLog(file, shaderID); - ARBShaderObjects.glGetObjectParameterARB(shaderID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( ARBShaderObjects.glGetObjectParameteriARB(shaderID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE ) ShadersTest.kill("A compilation error occured in a vertex shader."); programID = ARBShaderObjects.glCreateProgramObjectARB(); @@ -75,8 +72,7 @@ printShaderProgramInfoLog(programID); - ARBShaderObjects.glGetObjectParameterARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB, programBuffer); - if ( programBuffer.get(0) == GL11.GL_FALSE ) + if ( ARBShaderObjects.glGetObjectParameteriARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE ) ShadersTest.kill("A linking error occured in a shader program."); uniformLocation = getUniformLocation(programID, "UNIFORMS"); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/Constant.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/Constant.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/Constant.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -44,4 +44,6 @@ @Target(ElementType.PARAMETER) public @interface Constant { String value(); + /** If true, the original parameter will not be removed from the method. */ + boolean keepParam() default false; } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GLTypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GLTypeMap.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GLTypeMap.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -220,7 +220,7 @@ else if ( type.equals(boolean.class) ) return new Class[] { GLboolean.class }; else if ( type.equals(void.class) ) - return new Class[] { GLvoid.class, GLstring.class }; + return new Class[] { GLvoid.class, GLreturn.class }; else return new Class[] { }; } @@ -244,7 +244,7 @@ else if ( PointerWrapper.class.isAssignableFrom(type) ) valid_types = new Class[] { GLpointer.class }; else if (void.class.equals(type) ) - valid_types = new Class[] { GLstring.class }; + valid_types = new Class[] { GLreturn.class }; else valid_types = new Class[] { }; return valid_types; Copied: trunk/LWJGL/src/java/org/lwjgl/util/generator/GLreturn.java (from rev 3281, trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstring.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GLreturn.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GLreturn.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -0,0 +1,55 @@ +/* + * 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; + +/** + * When a method is annonated with @GLreturn, the specified output Buffer parameter + * will be used to return a single value. The primitive type will match the Buffer type. + * String will be returned if the Buffer is a ByteBuffer annotated with @GLchar. + * + * @author spasi + */ +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@NativeType +@Target({ ElementType.METHOD }) +public @interface GLreturn { + /** The Buffer parameter to use as the method result. */ + String value(); + /** The argument that specifies the maximum number of bytes that may be read (String results only). */ + String maxLength() default ""; + /** If true, the maxLength value is going to be used when creating the String. */ + boolean forceMaxLength() default false; + ///** If we use the byte buffer for another parameter, an offset must be used. */ + //String offset() default ""; +} \ No newline at end of file Deleted: trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstring.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstring.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstring.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl.util.generator; - -/** - * Methods annotated with @GLstring will return a String instead of void. - * - * @author spasi - */ - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -@NativeType -@Target({ ElementType.METHOD }) -public @interface GLstring { - /** The ByteBuffer argument that will be used to retrieve the String bytes. */ - String string(); - /** The argument that specifies the maximum number of bytes that may be read. */ - String maxLength(); -} \ No newline at end of file Deleted: trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstringOffset.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstringOffset.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GLstringOffset.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl.util.generator; - -/** - * This annotation must be used when there are more than one CharSequence arguments in a method. - * TODO: Add support for CharSequence[] if/when we need it. - * - * @author spasi - */ - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -@Target({ ElementType.PARAMETER }) -public @interface GLstringOffset { - /** An expression that will specify the offset from which this String will be written to the ByteBuffer. */ - String value(); -} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -105,17 +105,19 @@ } if (typemap_classname == null) throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>"); + + TypeDeclaration lastFile = null; try { TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance()); for (TypeDeclaration typedecl : env.getSpecifiedTypeDeclarations()) { + lastFile = typedecl; typedecl.accept(getDeclarationScanner(new GeneratorVisitor(env, type_map, generate_error_checks, context_specific), NO_OP)); } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + } catch (Exception e) { + if ( lastFile == null ) + throw new RuntimeException(e); + else + throw new RuntimeException("\n-- Failed to process template: " + lastFile.getQualifiedName() + " --", e); } } } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -81,7 +81,7 @@ throw new RuntimeException("Method " + method.getSimpleName() + " throws checked exceptions"); validateParameters(method); StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class); - if (strip_annotation != null) { + if (strip_annotation != null && method.getAnnotation(Alternate.class) == null) { String postfix_param_name = strip_annotation.value(); ParameterDeclaration postfix_param = Utils.findParameter(method, postfix_param_name); if (Utils.isParameterMultiTyped(postfix_param)) @@ -142,9 +142,9 @@ if (!found_auto_size_param && param.getAnnotation(Result.class) == null && param.getAnnotation(Constant.class) == null - && !Utils.isReturnString(method, param) + && !Utils.isReturnParameter(method, param) ) - throw new RuntimeException(param + " has no Check, Result nor Constant annotation and no other parameters has" + + throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has" + " an @AutoSize annotation on it in method " + method); } if (param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null) @@ -249,10 +249,11 @@ } 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"); + try { // Skip this class if the output exists and the input has not been modified. - File input = d.getPosition().file(); - File output = new File(env.getOptions().get("-s") + '/' + d.getPackage().getQualifiedName().replace('.', '/'), Utils.getSimpleClassName(d) + ".java"); if ( output.exists() && input.lastModified() < output.lastModified() ) return; @@ -260,7 +261,14 @@ generateJavaSource(d); if (d.getMethods().size() > 0) generateNativeSource(d); - } catch (IOException e) { + } catch (Exception e) { + try { + // If anything goes wrong mid-gen, delete output to allow regen next time we run. + if ( output.exists() ) + output.delete(); + } catch (Exception e2) { + // ignore + } throw new RuntimeException(e); } } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -122,7 +122,7 @@ } } else if ( param.getAnnotation(Result.class) == null - && (native_stub || (param.getAnnotation(Constant.class) == null && !Utils.isReturnString(method, param))) + && (native_stub || ((param.getAnnotation(Constant.class) == null || param.getAnnotation(Constant.class).keepParam()) && !Utils.isReturnParameter(method, param))) && (getAutoTypeParameter(method, param) == null || mode != Mode.AUTOS) ) { @@ -237,12 +237,9 @@ if ( method.getAnnotation(GLpointer.class) != null ) writer.print("new " + method.getReturnType() + "("); } - GLstring string_annotation = method.getAnnotation(GLstring.class); - if ( string_annotation != null ) { + if ( method.getAnnotation(GLreturn.class) != null ) { has_result = true; - writer.println("IntBuffer " + string_annotation.string() + "_length = StringUtils.getLengths(1);"); - writer.println("\t\tByteBuffer " + string_annotation.string() + " = StringUtils.getBuffer(" + string_annotation.maxLength() + ");"); - writer.print("\t\t"); + Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class)); } writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific)); if (mode == Mode.BUFFEROBJECT) @@ -262,12 +259,10 @@ // DISABLED: indirect buffer support //printNondirectParameterCopies(writer, method, mode); if (has_result) { - if ( string_annotation == null ) + if ( method.getAnnotation(GLreturn.class) == null ) writer.println("\t\treturn " + Utils.RESULT_VAR_NAME + ";"); - else { - writer.println("\t\t" + string_annotation.string() + ".limit(" + string_annotation.string() + "_length.get(0));"); - writer.println("\t\treturn StringUtils.getString(" + string_annotation.string() + ");"); - } + else + Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class)); } writer.println("\t}"); } @@ -403,22 +398,20 @@ if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) { writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX); } else { + Class type = typeinfos_instance.get(param).getType(); boolean hide_buffer = mode == Mode.AUTOS && getAutoTypeParameter(method, param) != null; if (hide_buffer) writer.print("null"); else { - Class type = typeinfos_instance.get(param).getType(); if ( type == CharSequence.class || type == CharSequence[].class ) { - GLstringOffset offset_annotation = param.getAnnotation(GLstringOffset.class); + final String offset = Utils.getStringOffset(method, param); - writer.print("StringUtils.getBuffer"); - if ( offset_annotation != null ) - writer.print("Offset"); + writer.print("APIUtils.getBuffer"); if ( param.getAnnotation(NullTerminated.class) != null ) writer.print("NT"); writer.print("(" + param.getSimpleName()); - if ( offset_annotation != null ) - writer.print(", " + offset_annotation.value()); + if ( offset != null ) + writer.print(", " + offset); writer.print(")"); hide_buffer = true; } else @@ -443,9 +436,10 @@ writer.print(" << " + shifting); if (check_annotation != null && check_annotation.canBeNull()) writer.print(" : 0"); - } else if ( param.getAnnotation(GLstringOffset.class) != null ) - writer.print(param.getAnnotation(GLstringOffset.class).value()); - else + } else if ( type == CharSequence.class || type == CharSequence[].class ) { + final String offset = Utils.getStringOffset(method, param); + writer.print(offset == null ? "0" : offset); + } else writer.print("0"); } else if ( param.getAnnotation(GLpointer.class) != null ) { writer.print(".getPointer()"); @@ -531,7 +525,7 @@ (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) && (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) && param.getAnnotation(Result.class) == null && - !Utils.isReturnString(method, param) ) { + !Utils.isReturnParameter(method, param) ) { String check_value = null; boolean can_be_null = false; Check check_annotation = param.getAnnotation(Check.class); @@ -589,8 +583,8 @@ 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(GLstring.class) != null ) - writer.print("String"); + 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()); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -62,34 +62,31 @@ throw new RuntimeException(t + " is not allowed"); } - public void visitPrimitiveType(PrimitiveType t) { - switch (t.getKind()) { + public static Class getPrimitiveClassFromKind(PrimitiveType.Kind kind) { + switch ( kind ) { case LONG: - type = long.class; - break; + return long.class; case INT: - type = int.class; - break; + return int.class; case DOUBLE: - type = double.class; - break; + return double.class; case FLOAT: - type = float.class; - break; + return float.class; case SHORT: - type = short.class; - break; + return short.class; case BYTE: - type = byte.class; - break; + return byte.class; case BOOLEAN: - type = boolean.class; - break; + return boolean.class; default: - throw new RuntimeException(t.getKind() + " is not allowed"); + throw new RuntimeException(kind + " is not allowed"); } } + public void visitPrimitiveType(PrimitiveType t) { + type = getPrimitiveClassFromKind(t.getKind()); + } + public void visitDeclaredType(DeclaredType t) { throw new RuntimeException(t + " is not allowed"); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/PostfixTranslator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/PostfixTranslator.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/PostfixTranslator.java 2010-03-14 23:24:40 UTC (rev 3287) @@ -71,17 +71,17 @@ } private static PrimitiveType.Kind getPrimitiveKindFromBufferClass(Class c) { - if (IntBuffer.class.equals(c)) + if (IntBuffer.class.equals(c) || int.class.equals(c) ) return PrimitiveType.Kind.INT; - else if (DoubleBuffer.class.equals(c)) + else if (DoubleBuffer.class.equals(c) || double.class.equals(c) ) return PrimitiveType.Kind.DOUBLE; - else if (ShortBuffer.class.equals(c)) + else if (ShortBuffer.class.equals(c) || short.class.equals(c) ) return PrimitiveType.Kind.SHORT; - else if (ByteBuffer.class.equals(c)) + else if (ByteBuffer.class.equals(c) || byte.class.equals(c) ) return PrimitiveType.Kind.BYTE; - else if (FloatBuffer.class.equals(c)) + else if (FloatBuffer.class.equals(c) || float.class.equals(c)) return PrimitiveType.Kind.FLOAT; - else if (LongBuffer.class.equals(c)) + else if (LongBuffer.class.equals(c) || long.class.equals(c) ) return PrimitiveType.Kind.LONG; else throw new RuntimeException(c + " is not allowed"); @@ -127,7 +127,7 @@ } public void visitPrimitiveType(PrimitiveType t) { - throw new RuntimeException(t + " is not allowed"); + visitPrimitiveTypeKind(t.getKind()); } private void visitPrimitiveTypeKind(PrimitiveType.Kind kind) { Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2010-03-14 00:19:48 UTC (rev 3286) +++ trunk/LWJ... [truncated message content] |