lwjgl2 build
This commit is contained in:
parent
c04cd191ff
commit
08bfe8fda6
|
@ -0,0 +1,27 @@
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'org.lwjgl'
|
||||||
|
|
||||||
|
configurations.default.setCanBeResolved(true)
|
||||||
|
|
||||||
|
jar{
|
||||||
|
archiveFileName = 'lwjgl.jar'
|
||||||
|
manifest {
|
||||||
|
attributes 'Manifest-Version': '2.9.3'
|
||||||
|
}
|
||||||
|
destinationDirectory.set(file("../FCL/src/main/assets/app_runtime/lwjgl2"))
|
||||||
|
File versionFile = file("../FCL/src/main/assets/app_runtime/lwjgl2/version")
|
||||||
|
versionFile.write(String.valueOf(new Date().getTime()))
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,286 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A class to check buffer boundaries in general. If there is unsufficient space
|
||||||
|
* in the buffer when the call is made then a buffer overflow would otherwise
|
||||||
|
* occur and cause unexpected behaviour, a crash, or worse, a security risk.
|
||||||
|
*
|
||||||
|
* Internal class, don't use.
|
||||||
|
* </p>
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class BufferChecks {
|
||||||
|
/** Static methods only! */
|
||||||
|
private BufferChecks() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper methods to ensure a function pointer is not-null (0)
|
||||||
|
*/
|
||||||
|
public static void checkFunctionAddress(long pointer) {
|
||||||
|
if (LWJGLUtil.CHECKS && pointer == 0) {
|
||||||
|
throw new IllegalStateException("Function is not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper methods to ensure a ByteBuffer is null-terminated
|
||||||
|
*/
|
||||||
|
public static void checkNullTerminated(ByteBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0) {
|
||||||
|
throw new IllegalArgumentException("Missing null termination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNullTerminated(ByteBuffer buf, int count) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
int nullFound = 0;
|
||||||
|
for ( int i = buf.position(); i < buf.limit(); i++ ) {
|
||||||
|
if ( buf.get(i) == 0 )
|
||||||
|
nullFound++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( nullFound < count )
|
||||||
|
throw new IllegalArgumentException("Missing null termination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper method to ensure an IntBuffer is null-terminated */
|
||||||
|
public static void checkNullTerminated(IntBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) {
|
||||||
|
throw new IllegalArgumentException("Missing null termination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper method to ensure a LongBuffer is null-terminated */
|
||||||
|
public static void checkNullTerminated(LongBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) {
|
||||||
|
throw new IllegalArgumentException("Missing null termination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper method to ensure a PointerBuffer is null-terminated */
|
||||||
|
public static void checkNullTerminated(PointerBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) {
|
||||||
|
throw new IllegalArgumentException("Missing null termination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNotNull(Object o) {
|
||||||
|
if ( LWJGLUtil.CHECKS && o == null)
|
||||||
|
throw new IllegalArgumentException("Null argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper methods to ensure a buffer is direct (and, implicitly, non-null).
|
||||||
|
*/
|
||||||
|
public static void checkDirect(ByteBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("ByteBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(ShortBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("ShortBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(IntBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("IntBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(LongBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("LongBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(FloatBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("FloatBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(DoubleBuffer buf) {
|
||||||
|
if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
|
||||||
|
throw new IllegalArgumentException("DoubleBuffer is not direct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkDirect(PointerBuffer buf) {
|
||||||
|
// NO-OP, PointerBuffer is always direct.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkArray(Object[] array) {
|
||||||
|
if ( LWJGLUtil.CHECKS && (array == null || array.length == 0) )
|
||||||
|
throw new IllegalArgumentException("Invalid array");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a separate call to help inline checkBufferSize.
|
||||||
|
*/
|
||||||
|
private static void throwBufferSizeException(Buffer buf, int size) {
|
||||||
|
throw new IllegalArgumentException("Number of remaining buffer elements is " + buf.remaining() + ", must be at least " + size + ". Because at most " + size + " elements can be returned, a buffer with at least " + size + " elements is required, regardless of actual returned element count");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwBufferSizeException(PointerBuffer buf, int size) {
|
||||||
|
throw new IllegalArgumentException("Number of remaining pointer buffer elements is " + buf.remaining() + ", must be at least " + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwArraySizeException(Object[] array, int size) {
|
||||||
|
throw new IllegalArgumentException("Number of array elements is " + array.length + ", must be at least " + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwArraySizeException(long[] array, int size) {
|
||||||
|
throw new IllegalArgumentException("Number of array elements is " + array.length + ", must be at least " + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to ensure a buffer is big enough to receive data from a
|
||||||
|
* glGet* operation.
|
||||||
|
*
|
||||||
|
* @param buf
|
||||||
|
* The buffer to check
|
||||||
|
* @param size
|
||||||
|
* The minimum buffer size
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
*/
|
||||||
|
public static void checkBufferSize(Buffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.remaining() < size) {
|
||||||
|
throwBufferSizeException(buf, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects the buffer type and performs the corresponding check
|
||||||
|
* and also returns the buffer position in bytes.
|
||||||
|
*
|
||||||
|
* @param buffer the buffer to check
|
||||||
|
* @param size the size to check
|
||||||
|
*
|
||||||
|
* @return the buffer position in bytes
|
||||||
|
*/
|
||||||
|
public static int checkBuffer(final Buffer buffer, final int size) {
|
||||||
|
final int posShift;
|
||||||
|
if ( buffer instanceof ByteBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((ByteBuffer)buffer, size);
|
||||||
|
posShift = 0;
|
||||||
|
} else if ( buffer instanceof ShortBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((ShortBuffer)buffer, size);
|
||||||
|
posShift = 1;
|
||||||
|
} else if ( buffer instanceof IntBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((IntBuffer)buffer, size);
|
||||||
|
posShift = 2;
|
||||||
|
} else if ( buffer instanceof LongBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((LongBuffer)buffer, size);
|
||||||
|
posShift = 4;
|
||||||
|
} else if ( buffer instanceof FloatBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((FloatBuffer)buffer, size);
|
||||||
|
posShift = 2;
|
||||||
|
} else if ( buffer instanceof DoubleBuffer ) {
|
||||||
|
BufferChecks.checkBuffer((DoubleBuffer)buffer, size);
|
||||||
|
posShift = 4;
|
||||||
|
} else
|
||||||
|
throw new IllegalArgumentException("Unsupported Buffer type specified: " + buffer.getClass());
|
||||||
|
|
||||||
|
return buffer.position() << posShift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(ByteBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(ShortBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(IntBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(LongBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(FloatBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(DoubleBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS ) {
|
||||||
|
checkBufferSize(buf, size);
|
||||||
|
checkDirect(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkBuffer(PointerBuffer buf, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS && buf.remaining() < size ) {
|
||||||
|
throwBufferSizeException(buf, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkArray(Object[] array, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS && array.length < size )
|
||||||
|
throwArraySizeException(array, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkArray(long[] array, int size) {
|
||||||
|
if ( LWJGLUtil.CHECKS && array.length < size )
|
||||||
|
throwArraySizeException(array, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,205 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.DoubleBuffer;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.nio.LongBuffer;
|
||||||
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some often-used Buffer code for creating native buffers of the appropriate size.
|
||||||
|
*
|
||||||
|
* @author $Author$
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
public final class BufferUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-ordered bytebuffer with the specified size.
|
||||||
|
* @param size The size, in bytes
|
||||||
|
* @return a ByteBuffer
|
||||||
|
*/
|
||||||
|
public static ByteBuffer createByteBuffer(int size) {
|
||||||
|
return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order shortbuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in shorts
|
||||||
|
* @return a ShortBuffer
|
||||||
|
*/
|
||||||
|
public static ShortBuffer createShortBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 1).asShortBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order charbuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in chars
|
||||||
|
* @return an CharBuffer
|
||||||
|
*/
|
||||||
|
public static CharBuffer createCharBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 1).asCharBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order intbuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in ints
|
||||||
|
* @return an IntBuffer
|
||||||
|
*/
|
||||||
|
public static IntBuffer createIntBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 2).asIntBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order longbuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in longs
|
||||||
|
* @return an LongBuffer
|
||||||
|
*/
|
||||||
|
public static LongBuffer createLongBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 3).asLongBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order floatbuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in floats
|
||||||
|
* @return a FloatBuffer
|
||||||
|
*/
|
||||||
|
public static FloatBuffer createFloatBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 2).asFloatBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a direct native-order doublebuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in floats
|
||||||
|
* @return a FloatBuffer
|
||||||
|
*/
|
||||||
|
public static DoubleBuffer createDoubleBuffer(int size) {
|
||||||
|
return createByteBuffer(size << 3).asDoubleBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a PointerBuffer with the specified number
|
||||||
|
* of elements.
|
||||||
|
* @param size The size, in memory addresses
|
||||||
|
* @return a PointerBuffer
|
||||||
|
*/
|
||||||
|
public static PointerBuffer createPointerBuffer(int size) {
|
||||||
|
return PointerBuffer.allocateDirect(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return n, where buffer_element_size=2^n.
|
||||||
|
*/
|
||||||
|
public static int getElementSizeExponent(Buffer buf) {
|
||||||
|
if (buf instanceof ByteBuffer)
|
||||||
|
return 0;
|
||||||
|
else if (buf instanceof ShortBuffer || buf instanceof CharBuffer)
|
||||||
|
return 1;
|
||||||
|
else if (buf instanceof FloatBuffer || buf instanceof IntBuffer)
|
||||||
|
return 2;
|
||||||
|
else if (buf instanceof LongBuffer || buf instanceof DoubleBuffer)
|
||||||
|
return 3;
|
||||||
|
else
|
||||||
|
throw new IllegalStateException("Unsupported buffer type: " + buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function which is used to get the byte offset in an arbitrary buffer
|
||||||
|
* based on its position
|
||||||
|
* @return the position of the buffer, in BYTES
|
||||||
|
*/
|
||||||
|
public static int getOffset(Buffer buffer) {
|
||||||
|
return buffer.position() << getElementSizeExponent(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(ByteBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position(), b.remaining());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(ShortBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(CharBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(IntBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(FloatBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(LongBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
public static void zeroBuffer(DoubleBuffer b) {
|
||||||
|
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fill buffer with zeros from position to remaining */
|
||||||
|
private static native void zeroBuffer0(Buffer b, long off, long size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the memory address of the specified buffer.
|
||||||
|
*
|
||||||
|
* @param buffer the buffer
|
||||||
|
*
|
||||||
|
* @return the memory address
|
||||||
|
*/
|
||||||
|
static native long getBufferAddress(Buffer buffer);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
abstract class DefaultSysImplementation implements SysImplementation {
|
||||||
|
public native int getJNIVersion();
|
||||||
|
public native int getPointerSize();
|
||||||
|
public native void setDebug(boolean debug);
|
||||||
|
|
||||||
|
public long getTimerResolution() {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has64Bit() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract long getTime();
|
||||||
|
public abstract void alert(String title, String message);
|
||||||
|
public abstract String getClipboard();
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.lang.UnsatisfiedLinkError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Tungsten
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
final class FCLSysImplementation extends J2SESysImplementation {
|
||||||
|
private static final int JNI_VERSION = 23;
|
||||||
|
|
||||||
|
public int getRequiredJNIVersion() {
|
||||||
|
return JNI_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean openURL(final String url) {
|
||||||
|
// Seems to have failed
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has64Bit() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A SysImplementation which delegates as much as it can to J2SE.
|
||||||
|
* <p>
|
||||||
|
* @author $Author$
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
abstract class J2SESysImplementation extends DefaultSysImplementation {
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void alert(String title, String message) {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
} catch(Exception e) {
|
||||||
|
LWJGLUtil.log("Caught exception while setting LAF: " + e);
|
||||||
|
}
|
||||||
|
JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClipboard() {
|
||||||
|
try {
|
||||||
|
java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
java.awt.datatransfer.Transferable transferable = clipboard.getContents(null);
|
||||||
|
if (transferable.isDataFlavorSupported(java.awt.datatransfer.DataFlavor.stringFlavor)) {
|
||||||
|
return (String)transferable.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LWJGLUtil.log("Exception while getting clipboard: " + e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* This exception is supplied to make exception handling more generic for LWJGL
|
||||||
|
* specific exceptions
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class LWJGLException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plain c'tor
|
||||||
|
*/
|
||||||
|
public LWJGLException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new LWJGLException
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* String identifier for exception
|
||||||
|
*/
|
||||||
|
public LWJGLException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
* @param cause
|
||||||
|
*/
|
||||||
|
public LWJGLException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cause
|
||||||
|
*/
|
||||||
|
public LWJGLException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,639 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Internal library methods
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class LWJGLUtil {
|
||||||
|
public static final int PLATFORM_LINUX = 1;
|
||||||
|
public static final int PLATFORM_MACOSX = 2;
|
||||||
|
public static final int PLATFORM_WINDOWS = 3;
|
||||||
|
public static final int PLATFORM_FCL = 1728;
|
||||||
|
public static final String PLATFORM_LINUX_NAME = "linux";
|
||||||
|
public static final String PLATFORM_MACOSX_NAME = "macosx";
|
||||||
|
public static final String PLATFORM_WINDOWS_NAME = "windows";
|
||||||
|
public static final String PLATFORM_FCL_NAME = "fcl";
|
||||||
|
|
||||||
|
private static final String LWJGL_ICON_DATA_16x16 =
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\376\377\377\377\302\327\350\377" +
|
||||||
|
"\164\244\313\377\120\213\275\377\124\216\277\377\206\257\322\377" +
|
||||||
|
"\347\357\366\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\365\365\365\377\215\217\221\377\166\202\215\377" +
|
||||||
|
"\175\215\233\377\204\231\252\377\224\267\325\377\072\175\265\377" +
|
||||||
|
"\110\206\272\377\332\347\361\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\364\370\373\377\234\236\240\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\344\344\344\377\204\255\320\377" +
|
||||||
|
"\072\175\265\377\133\222\301\377\374\375\376\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\221\266\325\377\137\137\137\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\042\042\042\377\377\377\377\377\350\360\366\377" +
|
||||||
|
"\071\174\265\377\072\175\265\377\304\330\351\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\306\331\351\377" +
|
||||||
|
"\201\253\316\377\035\035\035\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\146\146\146\377\377\377\377\377\320\340\355\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\215\264\324\377\377\377\377\377" +
|
||||||
|
"\362\362\362\377\245\245\245\377\337\337\337\377\242\301\334\377" +
|
||||||
|
"\260\305\326\377\012\012\012\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\250\250\250\377\377\377\377\377\227\272\330\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\161\241\312\377\377\377\377\377" +
|
||||||
|
"\241\241\241\377\000\000\000\377\001\001\001\377\043\043\043\377" +
|
||||||
|
"\314\314\314\377\320\320\320\377\245\245\245\377\204\204\204\377" +
|
||||||
|
"\134\134\134\377\357\357\357\377\377\377\377\377\140\226\303\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\155\236\310\377\377\377\377\377" +
|
||||||
|
"\136\136\136\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\317\317\317\377\037\037\037\377\003\003\003\377\053\053\053\377" +
|
||||||
|
"\154\154\154\377\306\306\306\377\372\374\375\377\236\277\332\377" +
|
||||||
|
"\167\245\314\377\114\211\274\377\174\250\316\377\377\377\377\377" +
|
||||||
|
"\033\033\033\377\000\000\000\377\000\000\000\377\027\027\027\377" +
|
||||||
|
"\326\326\326\377\001\001\001\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\122\122\122\377\345\345\345\377\075\075\075\377" +
|
||||||
|
"\150\150\150\377\246\246\247\377\332\336\341\377\377\377\377\377" +
|
||||||
|
"\164\164\164\377\016\016\016\377\000\000\000\377\131\131\131\377" +
|
||||||
|
"\225\225\225\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\221\221\221\377\233\233\233\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\002\002\002\377\103\103\103\377" +
|
||||||
|
"\377\377\377\377\356\356\356\377\214\214\214\377\277\277\277\377" +
|
||||||
|
"\126\126\126\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\323\323\323\377\130\130\130\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\063\063\063\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\374\375\376\377\377\377\377\377" +
|
||||||
|
"\300\300\300\377\100\100\100\377\002\002\002\377\000\000\000\377" +
|
||||||
|
"\033\033\033\377\373\373\373\377\027\027\027\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\170\170\170\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\322\341\356\377\176\251\316\377" +
|
||||||
|
"\340\352\363\377\377\377\377\377\324\324\324\377\155\155\155\377" +
|
||||||
|
"\204\204\204\377\323\323\323\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\275\275\275\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\376\376\376\377\146\232\305\377" +
|
||||||
|
"\075\177\266\377\202\254\320\377\344\355\365\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\345\345\345\377\055\055\055\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\014\014\014\377\366\366\366\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\342\354\364\377" +
|
||||||
|
"\115\211\274\377\072\175\265\377\076\200\266\377\207\260\322\377" +
|
||||||
|
"\347\357\366\377\377\377\377\377\376\376\376\377\274\274\274\377" +
|
||||||
|
"\117\117\117\377\003\003\003\377\112\112\112\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\353\362\370\377\214\263\324\377\126\220\300\377\120\214\275\377" +
|
||||||
|
"\167\245\314\377\355\363\370\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\337\337\337\377\346\346\346\377\377\377\377\377";
|
||||||
|
|
||||||
|
private static final String LWJGL_ICON_DATA_32x32 =
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\372\374\375\377" +
|
||||||
|
"\313\335\354\377\223\267\326\377\157\240\311\377\134\223\302\377\140\226\303\377\172\247\315\377\254\310\340\377\355\363\370\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\374\375\376\377\265\316\343\377\132\222\301\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\105\205\271\377" +
|
||||||
|
"\241\301\334\377\374\375\376\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\374\374\374\377\342\352\361\377\270\317\343\377\256\311\340\377" +
|
||||||
|
"\243\302\334\377\230\272\330\377\214\263\323\377\201\254\317\377\156\237\310\377\075\177\266\377\072\175\265\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\162\242\312\377\365\370\373\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\330\330\330\377\061\061\061\377\044\044\044\377\061\061\061\377\100\100\100\377" +
|
||||||
|
"\122\122\122\377\145\145\145\377\164\164\164\377\217\217\217\377\367\370\370\377\254\310\337\377\073\175\265\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\171\247\315\377\374\375\376\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\376\376\376\377\150\150\150\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\266\266\266\377\376\376\376\377\206\256\321\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\256\312\341\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\323\342\356\377\341\352\362\377\050\050\050\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\002\002\002\377\336\336\336\377\377\377\377\377\365\370\373\377\133\222\301\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\110\206\272\377\364\370\373\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\354\363\370\377\144\231\305\377\327\331\333\377\005\005\005\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\044\044\044\377\376\376\376\377\377\377\377\377\377\377\377\377\300\325\347\377" +
|
||||||
|
"\071\174\265\377\072\175\265\377\072\175\265\377\072\175\265\377\253\310\340\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\376\377\377\377" +
|
||||||
|
"\170\246\314\377\173\247\315\377\236\236\236\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\145\145\145\377\377\377\377\377\377\377\377\377\377\377\377\377\342\354\364\377" +
|
||||||
|
"\067\173\264\377\072\175\265\377\072\175\265\377\072\175\265\377\146\232\305\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\303\327\350\377" +
|
||||||
|
"\071\175\265\377\262\314\341\377\130\130\130\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\251\251\251\377\377\377\377\377\377\377\377\377\377\377\377\377\274\322\345\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\100\201\267\377\356\364\371\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\372\374\375\377\132\222\301\377" +
|
||||||
|
"\075\177\266\377\335\345\355\377\034\034\034\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\007\007\007\377\347\347\347\377\377\377\377\377\377\377\377\377\377\377\377\377\205\256\321\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\071\175\265\377\314\336\354\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\376\376\376\377\377\377\377\377\377\377\377\377\377\377\377\377\272\322\345\377\072\175\265\377" +
|
||||||
|
"\127\220\277\377\320\321\321\377\003\003\003\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\063\063\063\377\375\375\375\377\377\377\377\377\377\377\377\377\373\374\375\377\120\213\275\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\071\175\265\377\261\314\342\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\312\312\312\377\067\067\067\377\141\141\141\377\242\242\242\377\335\335\335\377\344\354\363\377\261\313\341\377" +
|
||||||
|
"\264\315\342\377\346\346\346\377\043\043\043\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\162\162\162\377\377\377\377\377\377\377\377\377\377\377\377\377\330\345\360\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\240\300\333\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\146\146\146\377\000\000\000\377\000\000\000\377\000\000\000\377\006\006\006\377\047\047\047\377\146\146\146\377" +
|
||||||
|
"\324\324\324\377\377\377\377\377\366\366\366\377\320\320\320\377\227\227\227\377\136\136\136\377\047\047\047\377\004\004\004\377" +
|
||||||
|
"\000\000\000\377\003\003\003\377\300\300\300\377\377\377\377\377\377\377\377\377\377\377\377\377\242\301\333\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\236\277\332\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\373\373\373\377\045\045\045\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\134\134\134\377\377\377\377\377\352\352\352\377\217\217\217\377\265\265\265\377\351\351\351\377\375\375\375\377\347\347\347\377" +
|
||||||
|
"\262\262\262\377\275\275\275\377\376\376\376\377\377\377\377\377\377\377\377\377\377\377\377\377\153\235\307\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\241\301\334\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\333\333\333\377\003\003\003\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\203\203\203\377\377\377\377\377\137\137\137\377\000\000\000\377\000\000\000\377\013\013\013\377\067\067\067\377\166\166\166\377" +
|
||||||
|
"\267\267\267\377\360\360\360\377\377\377\377\377\377\377\377\377\377\377\377\377\360\365\371\377\113\210\273\377\075\177\266\377" +
|
||||||
|
"\071\174\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\262\314\342\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\232\232\232\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\305\305\305\377\367\367\367\377\035\035\035\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\007\007\007\377\074\074\074\377\337\337\337\377\377\377\377\377\373\374\375\377\374\375\376\377\363\367\372\377" +
|
||||||
|
"\314\335\353\377\236\276\332\377\162\241\311\377\114\211\273\377\072\175\265\377\311\334\353\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\126\126\126\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\017\017\017\377" +
|
||||||
|
"\371\371\371\377\321\321\321\377\003\003\003\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\216\216\216\377\377\377\377\377\371\371\371\377\204\204\204\377\160\160\160\377" +
|
||||||
|
"\260\260\260\377\352\352\352\377\377\377\377\377\371\373\374\377\334\350\362\377\366\371\374\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\025\025\025\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\116\116\116\377" +
|
||||||
|
"\377\377\377\377\221\221\221\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\273\273\273\377\377\377\377\377\236\236\236\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\004\004\004\377\057\057\057\377\160\160\160\377\260\260\260\377\346\346\346\377\376\376\376\377\377\377\377\377" +
|
||||||
|
"\071\071\071\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\220\220\220\377" +
|
||||||
|
"\377\377\377\377\115\115\115\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\020\020\020\377\360\360\360\377\377\377\377\377\132\132\132\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\011\011\011\377\062\062\062\377\261\261\261\377" +
|
||||||
|
"\366\366\366\377\241\241\241\377\065\065\065\377\002\002\002\377\000\000\000\377\000\000\000\377\002\002\002\377\321\321\321\377" +
|
||||||
|
"\365\365\365\377\023\023\023\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\105\105\105\377\376\376\376\377\370\370\370\377\035\035\035\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\053\053\053\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\374\374\374\377\276\276\276\377\120\120\120\377\005\005\005\377\045\045\045\377\371\371\371\377" +
|
||||||
|
"\302\302\302\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\206\206\206\377\377\377\377\377\322\322\322\377\001\001\001\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\103\103\103\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377\334\334\334\377\340\340\340\377\377\377\377\377" +
|
||||||
|
"\225\225\225\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\001\001\001\377\310\310\310\377\377\377\377\377\216\216\216\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\210\210\210\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\337\337\337\377\051\051\051\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\030\030\030\377\365\365\365\377\377\377\377\377\112\112\112\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\317\317\317\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\361\366\372\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\371\371\371\377\265\265\265\377\113\113\113\377\006\006\006\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\122\122\122\377\377\377\377\377\370\370\370\377\020\020\020\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\034\034\034\377\370\370\370\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\206\257\321\377\220\265\325\377\352\361\367\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\333\333\333\377\170\170\170\377\033\033\033\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\226\226\226\377\377\377\377\377\306\306\306\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\132\132\132\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\303\330\351\377\072\175\265\377\103\203\270\377" +
|
||||||
|
"\224\270\326\377\355\363\370\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\364\364\364\377\247\247\247\377" +
|
||||||
|
"\205\205\205\377\364\364\364\377\377\377\377\377\206\206\206\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\235\235\235\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\372\373\375\377\135\224\302\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\106\205\271\377\230\273\330\377\357\364\371\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\233\233\233\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\005\005\005\377\335\335\335\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\305\331\351\377\073\176\266\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\110\206\272\377\236\276\332\377\362\366\372\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\373\373\373\377\216\216\216\377\045\045\045\377\001\001\001\377\000\000\000\377" +
|
||||||
|
"\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\054\054\054\377\374\374\374\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\217\265\325\377" +
|
||||||
|
"\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\112\207\273\377\243\302\334\377\363\367\372\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\372\372\372\377\260\260\260\377\105\105\105\377" +
|
||||||
|
"\004\004\004\377\000\000\000\377\000\000\000\377\000\000\000\377\000\000\000\377\156\156\156\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\374\375\376\377" +
|
||||||
|
"\205\257\321\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\115\211\274\377" +
|
||||||
|
"\250\305\336\377\366\371\374\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377" +
|
||||||
|
"\322\322\322\377\150\150\150\377\016\016\016\377\000\000\000\377\001\001\001\377\270\270\270\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\376\376\377\377\261\313\342\377\114\211\274\377\071\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377\072\175\265\377" +
|
||||||
|
"\072\175\265\377\115\211\274\377\277\324\347\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\354\354\354\377\223\223\223\377\233\233\233\377\375\375\375\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\363\367\372\377\265\316\343\377\201\254\320\377\145\231\305\377\141\227\304\377\154\236\310\377" +
|
||||||
|
"\217\265\325\377\305\331\351\377\367\372\374\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" +
|
||||||
|
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377";
|
||||||
|
|
||||||
|
/** LWJGL Logo - 16 by 16 pixels */
|
||||||
|
public static final ByteBuffer LWJGLIcon16x16 = loadIcon(LWJGL_ICON_DATA_16x16);
|
||||||
|
|
||||||
|
/** LWJGL Logo - 32 by 32 pixels */
|
||||||
|
public static final ByteBuffer LWJGLIcon32x32 = loadIcon(LWJGL_ICON_DATA_32x32);
|
||||||
|
|
||||||
|
/** Debug flag. */
|
||||||
|
public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug");
|
||||||
|
|
||||||
|
public static final boolean CHECKS = !getPrivilegedBoolean("org.lwjgl.util.NoChecks");
|
||||||
|
|
||||||
|
private static final int PLATFORM;
|
||||||
|
|
||||||
|
static {
|
||||||
|
final String osName = getPrivilegedProperty("os.name");
|
||||||
|
if ( osName.startsWith("Windows") )
|
||||||
|
PLATFORM = PLATFORM_WINDOWS;
|
||||||
|
else if ( osName.startsWith("Linux") || osName.startsWith("FreeBSD") || osName.startsWith("OpenBSD") || osName.startsWith("SunOS") || osName.startsWith("Unix") ) {
|
||||||
|
if (getPrivilegedProperty("lwjgl.platform").startsWith("FCL"))
|
||||||
|
PLATFORM = PLATFORM_FCL;
|
||||||
|
else
|
||||||
|
PLATFORM = PLATFORM_LINUX;
|
||||||
|
}
|
||||||
|
else if ( osName.startsWith("Mac OS X") || osName.startsWith("Darwin") )
|
||||||
|
PLATFORM = PLATFORM_MACOSX;
|
||||||
|
else
|
||||||
|
throw new LinkageError("Unknown platform: " + osName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ByteBuffer loadIcon(String data) {
|
||||||
|
int len = data.length();
|
||||||
|
ByteBuffer bb = BufferUtils.createByteBuffer(len);
|
||||||
|
for(int i=0 ; i<len ; i++) {
|
||||||
|
bb.put(i, (byte)data.charAt(i));
|
||||||
|
}
|
||||||
|
return bb.asReadOnlyBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #PLATFORM_WINDOWS
|
||||||
|
* @see #PLATFORM_LINUX
|
||||||
|
* @see #PLATFORM_MACOSX
|
||||||
|
* @see #PLATFORM_FCL
|
||||||
|
* @return the current platform type
|
||||||
|
*/
|
||||||
|
public static int getPlatform() {
|
||||||
|
return PLATFORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #PLATFORM_WINDOWS_NAME
|
||||||
|
* @see #PLATFORM_LINUX_NAME
|
||||||
|
* @see #PLATFORM_MACOSX_NAME
|
||||||
|
* @see #PLATFORM_FCL_NAME
|
||||||
|
* @return current platform name
|
||||||
|
*/
|
||||||
|
public static String getPlatformName() {
|
||||||
|
switch (LWJGLUtil.getPlatform()) {
|
||||||
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
|
return PLATFORM_LINUX_NAME;
|
||||||
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
|
return PLATFORM_MACOSX_NAME;
|
||||||
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
|
return PLATFORM_WINDOWS_NAME;
|
||||||
|
case LWJGLUtil.PLATFORM_FCL:
|
||||||
|
return PLATFORM_FCL_NAME;
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps {@link System#mapLibraryName}. On OS X with JDK 6, the .jnilib file
|
||||||
|
* extension will be replaced with .dylib.
|
||||||
|
*
|
||||||
|
* @param name the name of the library.
|
||||||
|
*
|
||||||
|
* @return a platform-dependent native library name.
|
||||||
|
*/
|
||||||
|
public static String mapLibraryName(String name) {
|
||||||
|
String libName = System.mapLibraryName(name);
|
||||||
|
return LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX && libName.endsWith(".jnilib")
|
||||||
|
? libName.substring(0, libName.length() - ".jnilib".length()) + ".dylib"
|
||||||
|
: libName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locates the paths required by a library.
|
||||||
|
*
|
||||||
|
* @param libname Local Library Name to search the classloader with ("openal").
|
||||||
|
* @param platform_lib_name The native library name ("libopenal.so")
|
||||||
|
* @param classloader The classloader to ask for library paths
|
||||||
|
* @return Paths to located libraries, if any
|
||||||
|
*/
|
||||||
|
public static String[] getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) {
|
||||||
|
return getLibraryPaths(libname, new String[]{platform_lib_name}, classloader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locates the paths required by a library.
|
||||||
|
*
|
||||||
|
* @param libname Local Library Name to search the classloader with ("openal").
|
||||||
|
* @param platform_lib_names The list of possible library names ("libopenal.so")
|
||||||
|
* @param classloader The classloader to ask for library paths
|
||||||
|
* @return Paths to located libraries, if any
|
||||||
|
*/
|
||||||
|
public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) {
|
||||||
|
// need to pass path of possible locations of library to native side
|
||||||
|
List<String> possible_paths = new ArrayList<String>();
|
||||||
|
|
||||||
|
String classloader_path = getPathFromClassLoader(libname, classloader);
|
||||||
|
if (classloader_path != null) {
|
||||||
|
log("getPathFromClassLoader: Path found: " + classloader_path);
|
||||||
|
possible_paths.add(classloader_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( String platform_lib_name : platform_lib_names ) {
|
||||||
|
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader);
|
||||||
|
if ( lwjgl_classloader_path != null ) {
|
||||||
|
log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path);
|
||||||
|
possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator))
|
||||||
|
+ File.separator + platform_lib_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add Installer path
|
||||||
|
String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath");
|
||||||
|
if ( alternative_path != null ) {
|
||||||
|
possible_paths.add(alternative_path + File.separator + platform_lib_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add all possible paths from java.library.path
|
||||||
|
String java_library_path = getPrivilegedProperty("java.library.path");
|
||||||
|
|
||||||
|
StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator);
|
||||||
|
while ( st.hasMoreTokens() ) {
|
||||||
|
String path = st.nextToken();
|
||||||
|
possible_paths.add(path + File.separator + platform_lib_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//add current path
|
||||||
|
String current_dir = getPrivilegedProperty("user.dir");
|
||||||
|
possible_paths.add(current_dir + File.separator + platform_lib_name);
|
||||||
|
|
||||||
|
//add pure library (no path, let OS search)
|
||||||
|
possible_paths.add(platform_lib_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//create needed string array
|
||||||
|
return possible_paths.toArray(new String[possible_paths.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void execPrivileged(final String[] cmd_array) throws Exception {
|
||||||
|
try {
|
||||||
|
Process process = AccessController.doPrivileged(new PrivilegedExceptionAction<Process>() {
|
||||||
|
public Process run() throws Exception {
|
||||||
|
return Runtime.getRuntime().exec(cmd_array);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Close unused streams to make sure the child process won't hang
|
||||||
|
process.getInputStream().close();
|
||||||
|
process.getOutputStream().close();
|
||||||
|
process.getErrorStream().close();
|
||||||
|
} catch (PrivilegedActionException e) {
|
||||||
|
throw (Exception)e.getCause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPrivilegedProperty(final String property_name) {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||||
|
public String run() {
|
||||||
|
return System.getProperty(property_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to locate named library from the current ClassLoader
|
||||||
|
* This method exists because native libraries are loaded from native code, and as such
|
||||||
|
* is exempt from ClassLoader library loading rutines. It therefore always fails.
|
||||||
|
* We therefore invoke the protected method of the ClassLoader to see if it can
|
||||||
|
* locate it.
|
||||||
|
*
|
||||||
|
* @param libname Name of library to search for
|
||||||
|
* @param classloader Classloader to use
|
||||||
|
* @return Absolute path to library if found, otherwise null
|
||||||
|
*/
|
||||||
|
private static String getPathFromClassLoader(final String libname, final ClassLoader classloader) {
|
||||||
|
Class<?> c = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
log("getPathFromClassLoader: searching for: " + libname);
|
||||||
|
c = classloader.getClass();
|
||||||
|
while (c != null) {
|
||||||
|
final Class<?> clazz = c;
|
||||||
|
try {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
|
||||||
|
public String run() throws Exception {
|
||||||
|
Method findLibrary = clazz.getDeclaredMethod("findLibrary", String.class);
|
||||||
|
findLibrary.setAccessible(true);
|
||||||
|
String path = (String)findLibrary.invoke(classloader, libname);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (PrivilegedActionException e) {
|
||||||
|
log("Failed to locate findLibrary method: " + e.getCause());
|
||||||
|
c = c.getSuperclass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log("Failure locating " + e + " using classloader:" + c);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a boolean property as a privileged action.
|
||||||
|
*/
|
||||||
|
public static boolean getPrivilegedBoolean(final String property_name) {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||||
|
public Boolean run() {
|
||||||
|
return Boolean.getBoolean(property_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an integer property as a privileged action.
|
||||||
|
*
|
||||||
|
* @param property_name the integer property name
|
||||||
|
*
|
||||||
|
* @return the property value
|
||||||
|
*/
|
||||||
|
public static Integer getPrivilegedInteger(final String property_name) {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||||
|
public Integer run() {
|
||||||
|
return Integer.getInteger(property_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an integer property as a privileged action.
|
||||||
|
*
|
||||||
|
* @param property_name the integer property name
|
||||||
|
* @param default_val the default value to use if the property is not defined
|
||||||
|
*
|
||||||
|
* @return the property value
|
||||||
|
*/
|
||||||
|
public static Integer getPrivilegedInteger(final String property_name, final int default_val) {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||||
|
public Integer run() {
|
||||||
|
return Integer.getInteger(property_name, default_val);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native void nLog(String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param msg Message to print
|
||||||
|
*/
|
||||||
|
public static void log(CharSequence msg) {
|
||||||
|
if (DEBUG) {
|
||||||
|
nLog("[LWJGL] " + msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to determine if the current system is running a version of
|
||||||
|
* Mac OS X better than the given version. This is only useful for Mac OS X
|
||||||
|
* specific code and will not work for any other platform.
|
||||||
|
*/
|
||||||
|
public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) {
|
||||||
|
String os_version = getPrivilegedProperty("os.version");
|
||||||
|
StringTokenizer version_tokenizer = new StringTokenizer(os_version, ".");
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
try {
|
||||||
|
String major_str = version_tokenizer.nextToken();
|
||||||
|
String minor_str = version_tokenizer.nextToken();
|
||||||
|
major = Integer.parseInt(major_str);
|
||||||
|
minor = Integer.parseInt(minor_str);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LWJGLUtil.log("Exception occurred while trying to determine OS version: " + e);
|
||||||
|
// Best guess, no
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return major > major_required || (major == major_required && minor >= minor_required);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of public static final integer fields in the specified classes, to their String representations.
|
||||||
|
* An optional filter can be specified to only include specific fields. The target map may be null, in which
|
||||||
|
* case a new map is allocated and returned.
|
||||||
|
* <p>
|
||||||
|
* This method is useful when debugging to quickly identify values returned from the AL/GL/CL APIs.
|
||||||
|
*
|
||||||
|
* @param filter the filter to use (optional)
|
||||||
|
* @param target the target map (optional)
|
||||||
|
* @param tokenClasses an array of classes to get tokens from
|
||||||
|
*
|
||||||
|
* @return the token map
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Map<Integer, String> getClassTokens(final TokenFilter filter, final Map<Integer, String> target, final Class ... tokenClasses) {
|
||||||
|
return getClassTokens(filter, target, Arrays.asList(tokenClasses));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of public static final integer fields in the specified classes, to their String representations.
|
||||||
|
* An optional filter can be specified to only include specific fields. The target map may be null, in which
|
||||||
|
* case a new map is allocated and returned.
|
||||||
|
* <p>
|
||||||
|
* This method is useful when debugging to quickly identify values returned from the AL/GL/CL APIs.
|
||||||
|
*
|
||||||
|
* @param filter the filter to use (optional)
|
||||||
|
* @param target the target map (optional)
|
||||||
|
* @param tokenClasses the classes to get tokens from
|
||||||
|
*
|
||||||
|
* @return the token map
|
||||||
|
*/
|
||||||
|
public static Map<Integer, String> getClassTokens(final TokenFilter filter, Map<Integer, String> target, final Iterable<Class> tokenClasses) {
|
||||||
|
if ( target == null )
|
||||||
|
target = new HashMap<Integer, String>();
|
||||||
|
|
||||||
|
final int TOKEN_MODIFIERS = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
|
||||||
|
|
||||||
|
for ( final Class tokenClass : tokenClasses ) {
|
||||||
|
for ( final Field field : tokenClass.getDeclaredFields() ) {
|
||||||
|
// Get only <public static final int> 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, toHexString(value));
|
||||||
|
else
|
||||||
|
target.put(value, field.getName());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the integer argument as an
|
||||||
|
* unsigned integer in base 16. The string will be uppercase
|
||||||
|
* and will have a leading '0x'.
|
||||||
|
*
|
||||||
|
* @param value the integer value
|
||||||
|
*
|
||||||
|
* @return the hex string representation
|
||||||
|
*/
|
||||||
|
public static String toHexString(final int value) {
|
||||||
|
return "0x" + Integer.toHexString(value).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Simple interface for Field filtering. */
|
||||||
|
public interface TokenFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should return true if the specified Field passes the filter.
|
||||||
|
*
|
||||||
|
* @param field the Field to test
|
||||||
|
* @param value the integer value of the field
|
||||||
|
*
|
||||||
|
* @return true if the Field is accepted
|
||||||
|
*/
|
||||||
|
boolean accept(Field field, int value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.lang.UnsatisfiedLinkError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
final class LinuxSysImplementation extends J2SESysImplementation {
|
||||||
|
private static final int JNI_VERSION = 19;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Load libawt.so and libmawt.so, needed for libjawt.so
|
||||||
|
java.awt.Toolkit.getDefaultToolkit();
|
||||||
|
|
||||||
|
// manually load libjawt.so into vm, needed since Java 7
|
||||||
|
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||||
|
public Object run() {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("jawt");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
// catch and ignore an already loaded in another classloader
|
||||||
|
// exception, as vm already has it loaded
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredJNIVersion() {
|
||||||
|
return JNI_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean openURL(final String url) {
|
||||||
|
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
|
||||||
|
// right anyway.
|
||||||
|
|
||||||
|
String[] browsers = {"sensible-browser", "xdg-open", "google-chrome", "chromium", "firefox", "iceweasel", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
|
||||||
|
|
||||||
|
for ( final String browser : browsers ) {
|
||||||
|
try {
|
||||||
|
LWJGLUtil.execPrivileged(new String[] { browser, url });
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seems to have failed
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has64Bit() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.apple.eio.FileManager;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.lang.UnsatisfiedLinkError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
final class MacOSXSysImplementation extends J2SESysImplementation {
|
||||||
|
private static final int JNI_VERSION = 25;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Manually start the AWT Application Loop
|
||||||
|
java.awt.Toolkit.getDefaultToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredJNIVersion() {
|
||||||
|
return JNI_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean openURL(String url) {
|
||||||
|
try {
|
||||||
|
FileManager.openURL(url);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,430 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.nio.*;
|
||||||
|
import java.nio.charset.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [INTERNAL USE ONLY]
|
||||||
|
* <p/>
|
||||||
|
* This class provides utility methods for passing buffers to JNI API calls.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class MemoryUtil {
|
||||||
|
|
||||||
|
private static final Charset ascii;
|
||||||
|
private static final Charset utf8;
|
||||||
|
private static final Charset utf16;
|
||||||
|
|
||||||
|
static {
|
||||||
|
ascii = Charset.forName("ISO-8859-1");
|
||||||
|
utf8 = Charset.forName("UTF-8");
|
||||||
|
utf16 = Charset.forName("UTF-16LE");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Accessor memUtil;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Accessor util;
|
||||||
|
try {
|
||||||
|
// Depends on java.nio.Buffer#address and sun.misc.Unsafe
|
||||||
|
util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorUnsafe");
|
||||||
|
} catch (Exception e0) {
|
||||||
|
try {
|
||||||
|
// Depends on java.nio.Buffer#address and sun.reflect.FieldAccessor
|
||||||
|
util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorReflectFast");
|
||||||
|
} catch (Exception e1) {
|
||||||
|
try {
|
||||||
|
// Depends on java.nio.Buffer#address
|
||||||
|
util = new AccessorReflect();
|
||||||
|
} catch (Exception e2) {
|
||||||
|
LWJGLUtil.log("Unsupported JVM detected, this will likely result in low performance. Please inform LWJGL developers.");
|
||||||
|
util = new AccessorJNI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LWJGLUtil.log("MemoryUtil Accessor: " + util.getClass().getSimpleName());
|
||||||
|
memUtil = util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
BENCHMARK RESULTS - Oracle Server VM:
|
||||||
|
|
||||||
|
Unsafe: 4ns
|
||||||
|
ReflectFast: 8ns
|
||||||
|
Reflect: 10ns
|
||||||
|
JNI: 82ns
|
||||||
|
|
||||||
|
BENCHMARK RESULTS - Oracle Client VM:
|
||||||
|
|
||||||
|
Unsafe: 5ns
|
||||||
|
ReflectFast: 81ns
|
||||||
|
Reflect: 85ns
|
||||||
|
JNI: 87ns
|
||||||
|
|
||||||
|
On non-Oracle VMs, Unsafe should be the fastest implementation as well. In the absence
|
||||||
|
of Unsafe, performance will depend on how reflection and JNI are implemented. For now
|
||||||
|
we'll go with what we see on the Oracle VM (that is, we'll prefer reflection over JNI).
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private MemoryUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the memory address of the specified buffer. [INTERNAL USE ONLY]
|
||||||
|
*
|
||||||
|
* @param buffer the buffer
|
||||||
|
*
|
||||||
|
* @return the memory address
|
||||||
|
*/
|
||||||
|
public static long getAddress0(Buffer buffer) { return memUtil.getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddress0Safe(Buffer buffer) { return buffer == null ? 0L : memUtil.getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddress0(PointerBuffer buffer) { return memUtil.getAddress(buffer.getBuffer()); }
|
||||||
|
|
||||||
|
public static long getAddress0Safe(PointerBuffer buffer) { return buffer == null ? 0L : memUtil.getAddress(buffer.getBuffer()); }
|
||||||
|
|
||||||
|
// --- [ API utilities ] ---
|
||||||
|
|
||||||
|
public static long getAddress(ByteBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(ByteBuffer buffer, int position) { return getAddress0(buffer) + position; }
|
||||||
|
|
||||||
|
public static long getAddress(ShortBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(ShortBuffer buffer, int position) { return getAddress0(buffer) + (position << 1); }
|
||||||
|
|
||||||
|
public static long getAddress(CharBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(CharBuffer buffer, int position) { return getAddress0(buffer) + (position << 1); }
|
||||||
|
|
||||||
|
public static long getAddress(IntBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(IntBuffer buffer, int position) { return getAddress0(buffer) + (position << 2); }
|
||||||
|
|
||||||
|
public static long getAddress(FloatBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(FloatBuffer buffer, int position) { return getAddress0(buffer) + (position << 2); }
|
||||||
|
|
||||||
|
public static long getAddress(LongBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(LongBuffer buffer, int position) { return getAddress0(buffer) + (position << 3); }
|
||||||
|
|
||||||
|
public static long getAddress(DoubleBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(DoubleBuffer buffer, int position) { return getAddress0(buffer) + (position << 3); }
|
||||||
|
|
||||||
|
public static long getAddress(PointerBuffer buffer) { return getAddress(buffer, buffer.position()); }
|
||||||
|
|
||||||
|
public static long getAddress(PointerBuffer buffer, int position) { return getAddress0(buffer) + (position * PointerBuffer.getPointerSize()); }
|
||||||
|
|
||||||
|
// --- [ API utilities - Safe ] ---
|
||||||
|
|
||||||
|
public static long getAddressSafe(ByteBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(ByteBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(ShortBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(ShortBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(CharBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(CharBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(IntBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(IntBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(FloatBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(FloatBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(LongBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(LongBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(DoubleBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(DoubleBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(PointerBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
|
||||||
|
|
||||||
|
public static long getAddressSafe(PointerBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
|
||||||
|
|
||||||
|
// --- [ String utilities ] ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a ByteBuffer containing the specified text ASCII encoded and null-terminated.
|
||||||
|
* If text is null, null is returned.
|
||||||
|
*
|
||||||
|
* @param text the text to encode
|
||||||
|
*
|
||||||
|
* @return the encoded text or null
|
||||||
|
*
|
||||||
|
* @see String#getBytes()
|
||||||
|
*/
|
||||||
|
public static ByteBuffer encodeASCII(final CharSequence text) {
|
||||||
|
return encode(text, ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a ByteBuffer containing the specified text UTF-8 encoded and null-terminated.
|
||||||
|
* If text is null, null is returned.
|
||||||
|
*
|
||||||
|
* @param text the text to encode
|
||||||
|
*
|
||||||
|
* @return the encoded text or null
|
||||||
|
*
|
||||||
|
* @see String#getBytes()
|
||||||
|
*/
|
||||||
|
public static ByteBuffer encodeUTF8(final CharSequence text) {
|
||||||
|
return encode(text, utf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a ByteBuffer containing the specified text UTF-16LE encoded and null-terminated.
|
||||||
|
* If text is null, null is returned.
|
||||||
|
*
|
||||||
|
* @param text the text to encode
|
||||||
|
*
|
||||||
|
* @return the encoded text
|
||||||
|
*/
|
||||||
|
public static ByteBuffer encodeUTF16(final CharSequence text) {
|
||||||
|
return encode(text, utf16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps the specified text in a null-terminated CharBuffer and encodes it using the specified Charset.
|
||||||
|
*
|
||||||
|
* @param text the text to encode
|
||||||
|
* @param charset the charset to use for encoding
|
||||||
|
*
|
||||||
|
* @return the encoded text
|
||||||
|
*/
|
||||||
|
private static ByteBuffer encode(final CharSequence text, final Charset charset) {
|
||||||
|
if ( text == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return encode(CharBuffer.wrap(new CharSequenceNT(text)), charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link CharsetEncoder#encode(CharBuffer)} implementation that uses {@link BufferUtils#createByteBuffer(int)}
|
||||||
|
* instead of {@link ByteBuffer#allocate(int)}.
|
||||||
|
*
|
||||||
|
* @see CharsetEncoder#encode(CharBuffer)
|
||||||
|
*/
|
||||||
|
private static ByteBuffer encode(final CharBuffer in, final Charset charset) {
|
||||||
|
final CharsetEncoder encoder = charset.newEncoder(); // encoders are not thread-safe, create a new one on every call
|
||||||
|
|
||||||
|
int n = (int)(in.remaining() * encoder.averageBytesPerChar());
|
||||||
|
ByteBuffer out = BufferUtils.createByteBuffer(n);
|
||||||
|
|
||||||
|
if ( n == 0 && in.remaining() == 0 )
|
||||||
|
return out;
|
||||||
|
|
||||||
|
encoder.reset();
|
||||||
|
while ( true ) {
|
||||||
|
CoderResult cr = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
|
||||||
|
if ( cr.isUnderflow() )
|
||||||
|
cr = encoder.flush(out);
|
||||||
|
|
||||||
|
if ( cr.isUnderflow() )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( cr.isOverflow() ) {
|
||||||
|
n = 2 * n + 1; // Ensure progress; n might be 0!
|
||||||
|
ByteBuffer o = BufferUtils.createByteBuffer(n);
|
||||||
|
out.flip();
|
||||||
|
o.put(out);
|
||||||
|
out = o;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
cr.throwException();
|
||||||
|
} catch (CharacterCodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.flip();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decodeASCII(final ByteBuffer buffer) {
|
||||||
|
return decode(buffer, ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decodeUTF8(final ByteBuffer buffer) {
|
||||||
|
return decode(buffer, utf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decodeUTF16(final ByteBuffer buffer) {
|
||||||
|
return decode(buffer, utf16);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String decode(final ByteBuffer buffer, final Charset charset) {
|
||||||
|
if ( buffer == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return decodeImpl(buffer, charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String decodeImpl(final ByteBuffer in, final Charset charset) {
|
||||||
|
final CharsetDecoder decoder = charset.newDecoder(); // decoders are not thread-safe, create a new one on every call
|
||||||
|
|
||||||
|
int n = (int)(in.remaining() * decoder.averageCharsPerByte());
|
||||||
|
CharBuffer out = BufferUtils.createCharBuffer(n);
|
||||||
|
|
||||||
|
if ( (n == 0) && (in.remaining() == 0) )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
decoder.reset();
|
||||||
|
for (; ; ) {
|
||||||
|
CoderResult cr = in.hasRemaining() ? decoder.decode(in, out, true) : CoderResult.UNDERFLOW;
|
||||||
|
if ( cr.isUnderflow() )
|
||||||
|
cr = decoder.flush(out);
|
||||||
|
|
||||||
|
if ( cr.isUnderflow() )
|
||||||
|
break;
|
||||||
|
if ( cr.isOverflow() ) {
|
||||||
|
n = 2 * n + 1; // Ensure progress; n might be 0!
|
||||||
|
CharBuffer o = BufferUtils.createCharBuffer(n);
|
||||||
|
out.flip();
|
||||||
|
o.put(out);
|
||||||
|
out = o;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cr.throwException();
|
||||||
|
} catch (CharacterCodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.flip();
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A null-terminated CharSequence. */
|
||||||
|
private static class CharSequenceNT implements CharSequence {
|
||||||
|
|
||||||
|
final CharSequence source;
|
||||||
|
|
||||||
|
CharSequenceNT(CharSequence source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int length() {
|
||||||
|
return source.length() + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public char charAt(final int index) {
|
||||||
|
return index == source.length() ? '\0' : source.charAt(index);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CharSequence subSequence(final int start, final int end) {
|
||||||
|
return new CharSequenceNT(source.subSequence(start, Math.min(end, source.length())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Accessor {
|
||||||
|
|
||||||
|
long getAddress(Buffer buffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Accessor loadAccessor(final String className) throws Exception {
|
||||||
|
return (Accessor)Class.forName(className).newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Default implementation. */
|
||||||
|
private static class AccessorJNI implements Accessor {
|
||||||
|
|
||||||
|
public long getAddress(final Buffer buffer) {
|
||||||
|
return BufferUtils.getBufferAddress(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Implementation using reflection on ByteBuffer. */
|
||||||
|
private static class AccessorReflect implements Accessor {
|
||||||
|
|
||||||
|
private final Field address;
|
||||||
|
|
||||||
|
AccessorReflect() {
|
||||||
|
try {
|
||||||
|
address = getAddressField();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
|
address.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAddress(final Buffer buffer) {
|
||||||
|
try {
|
||||||
|
return address.getLong(buffer);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// cannot happen
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static Field getAddressField() throws NoSuchFieldException {
|
||||||
|
return getDeclaredFieldRecursive(ByteBuffer.class, "address");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Field getDeclaredFieldRecursive(final Class<?> root, final String fieldName) throws NoSuchFieldException {
|
||||||
|
Class<?> type = root;
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
return type.getDeclaredField(fieldName);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
type = type.getSuperclass();
|
||||||
|
}
|
||||||
|
} while ( type != null );
|
||||||
|
|
||||||
|
throw new NoSuchFieldException(fieldName + " does not exist in " + root.getSimpleName() + " or any of its superclasses.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
|
||||||
|
import sun.misc.Unsafe;
|
||||||
|
import sun.reflect.FieldAccessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MemoryUtil.Accessor implementations that depend on sun.misc.
|
||||||
|
* We use reflection to grab these, so that we can compile on JDKs
|
||||||
|
* that do not support sun.misc.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
final class MemoryUtilSun {
|
||||||
|
|
||||||
|
private MemoryUtilSun() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Implementation using sun.misc.Unsafe. */
|
||||||
|
private static class AccessorUnsafe implements MemoryUtil.Accessor {
|
||||||
|
|
||||||
|
private final Unsafe unsafe;
|
||||||
|
private final long address;
|
||||||
|
|
||||||
|
AccessorUnsafe() {
|
||||||
|
try {
|
||||||
|
unsafe = getUnsafeInstance();
|
||||||
|
address = unsafe.objectFieldOffset(MemoryUtil.getAddressField());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAddress(final Buffer buffer) {
|
||||||
|
return unsafe.getLong(buffer, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Unsafe getUnsafeInstance() {
|
||||||
|
final Field[] fields = Unsafe.class.getDeclaredFields();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Different runtimes use different names for the Unsafe singleton,
|
||||||
|
so we cannot use .getDeclaredField and we scan instead. For example:
|
||||||
|
|
||||||
|
Oracle: theUnsafe
|
||||||
|
PERC : m_unsafe_instance
|
||||||
|
Android: THE_ONE
|
||||||
|
*/
|
||||||
|
for ( Field field : fields ) {
|
||||||
|
if ( !field.getType().equals(Unsafe.class) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final int modifiers = field.getModifiers();
|
||||||
|
if ( !(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
try {
|
||||||
|
return (Unsafe)field.get(null);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Implementation using reflection on ByteBuffer, FieldAccessor is used directly. */
|
||||||
|
private static class AccessorReflectFast implements MemoryUtil.Accessor {
|
||||||
|
|
||||||
|
private final FieldAccessor addressAccessor;
|
||||||
|
|
||||||
|
AccessorReflectFast() {
|
||||||
|
Field address;
|
||||||
|
try {
|
||||||
|
address = MemoryUtil.getAddressField();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
|
address.setAccessible(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Method m = Field.class.getDeclaredMethod("acquireFieldAccessor", boolean.class);
|
||||||
|
m.setAccessible(true);
|
||||||
|
addressAccessor = (FieldAccessor)m.invoke(address, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAddress(final Buffer buffer) {
|
||||||
|
return addressAccessor.getLong(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,960 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a container for architecture independent pointer data.
|
||||||
|
* The interface mirrors the NIO LongBuffer API for convenience.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public class PointerBuffer implements Comparable {
|
||||||
|
|
||||||
|
private static final boolean is64Bit;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Use reflection so that we can compile this class for the Generator.
|
||||||
|
boolean is64 = false;
|
||||||
|
try {
|
||||||
|
Method m = Class.forName("org.lwjgl.Sys").getDeclaredMethod("is64Bit", (Class[])null);
|
||||||
|
is64 = (Boolean)m.invoke(null, (Object[])null);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// ignore
|
||||||
|
} finally {
|
||||||
|
is64Bit = is64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final ByteBuffer pointers;
|
||||||
|
|
||||||
|
protected final Buffer view;
|
||||||
|
protected final IntBuffer view32;
|
||||||
|
protected final LongBuffer view64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PointerBuffer with the specified capacity.
|
||||||
|
*
|
||||||
|
* @param capacity the PointerBuffer size, in number of pointers
|
||||||
|
*/
|
||||||
|
public PointerBuffer(final int capacity) {
|
||||||
|
this(BufferUtils.createByteBuffer(capacity * getPointerSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PointerBuffer using the specified ByteBuffer as its pointer
|
||||||
|
* data source. This is useful for users that do their own memory management
|
||||||
|
* over a big ByteBuffer, instead of allocating many small ones.
|
||||||
|
*
|
||||||
|
* @param source the source buffer
|
||||||
|
*/
|
||||||
|
public PointerBuffer(final ByteBuffer source) {
|
||||||
|
if ( LWJGLUtil.CHECKS )
|
||||||
|
checkSource(source);
|
||||||
|
|
||||||
|
pointers = source.slice().order(source.order());
|
||||||
|
|
||||||
|
if ( is64Bit ) {
|
||||||
|
view32 = null;
|
||||||
|
view = view64 = pointers.asLongBuffer();
|
||||||
|
} else {
|
||||||
|
view = view32 = pointers.asIntBuffer();
|
||||||
|
view64 = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkSource(final ByteBuffer source) {
|
||||||
|
if ( !source.isDirect() )
|
||||||
|
throw new IllegalArgumentException("The source buffer is not direct.");
|
||||||
|
|
||||||
|
final int alignment = is64Bit ? 8 : 4;
|
||||||
|
if ( (MemoryUtil.getAddress0(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 )
|
||||||
|
throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ByteBuffer that backs this PointerBuffer.
|
||||||
|
*
|
||||||
|
* @return the pointer ByteBuffer
|
||||||
|
*/
|
||||||
|
public ByteBuffer getBuffer() {
|
||||||
|
return pointers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if the underlying architecture is 64bit. */
|
||||||
|
public static boolean is64Bit() {
|
||||||
|
return is64Bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the pointer size in bytes, based on the underlying architecture.
|
||||||
|
*
|
||||||
|
* @return The pointer size in bytes
|
||||||
|
*/
|
||||||
|
public static int getPointerSize() {
|
||||||
|
return is64Bit ? 8 : 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this buffer's capacity. </p>
|
||||||
|
*
|
||||||
|
* @return The capacity of this buffer
|
||||||
|
*/
|
||||||
|
public final int capacity() {
|
||||||
|
return view.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this buffer's position. </p>
|
||||||
|
*
|
||||||
|
* @return The position of this buffer
|
||||||
|
*/
|
||||||
|
public final int position() {
|
||||||
|
return view.position();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this buffer's position, in bytes. </p>
|
||||||
|
*
|
||||||
|
* @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. </p>
|
||||||
|
*
|
||||||
|
* @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 <tt>newPosition</tt> do not hold
|
||||||
|
*/
|
||||||
|
public final PointerBuffer position(int newPosition) {
|
||||||
|
view.position(newPosition);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this buffer's limit. </p>
|
||||||
|
*
|
||||||
|
* @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. </p>
|
||||||
|
*
|
||||||
|
* @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 <tt>newLimit</tt> do not hold
|
||||||
|
*/
|
||||||
|
public final PointerBuffer limit(int newLimit) {
|
||||||
|
view.limit(newLimit);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets this buffer's mark at its position. </p>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*/
|
||||||
|
public final PointerBuffer mark() {
|
||||||
|
view.mark();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets this buffer's position to the previously-marked position.
|
||||||
|
* <p/>
|
||||||
|
* <p> Invoking this method neither changes nor discards the mark's
|
||||||
|
* value. </p>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*
|
||||||
|
* @throws 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> Invoke this method before using a sequence of channel-read or
|
||||||
|
* <i>put</i> operations to fill this buffer. For example:
|
||||||
|
* <p/>
|
||||||
|
* <blockquote><pre>
|
||||||
|
* buf.clear(); // Prepare buffer for reading
|
||||||
|
* in.read(buf); // Read data</pre></blockquote>
|
||||||
|
* <p/>
|
||||||
|
* <p> 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. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> After a sequence of channel-read or <i>put</i> operations, invoke
|
||||||
|
* this method to prepare for a sequence of channel-write or relative
|
||||||
|
* <i>get</i> operations. For example:
|
||||||
|
* <p/>
|
||||||
|
* <blockquote><pre>
|
||||||
|
* 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</pre></blockquote>
|
||||||
|
* <p/>
|
||||||
|
* <p> This method is often used in conjunction with the {@link
|
||||||
|
* ByteBuffer#compact compact} method when transferring data from
|
||||||
|
* one place to another. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> Invoke this method before a sequence of channel-write or <i>get</i>
|
||||||
|
* operations, assuming that the limit has already been set
|
||||||
|
* appropriately. For example:
|
||||||
|
* <p/>
|
||||||
|
* <blockquote><pre>
|
||||||
|
* out.write(buf); // Write remaining data
|
||||||
|
* buf.rewind(); // Rewind buffer
|
||||||
|
* buf.get(array); // Copy data into array</pre></blockquote>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*/
|
||||||
|
public final PointerBuffer rewind() {
|
||||||
|
view.rewind();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of elements between the current position and the
|
||||||
|
* limit. </p>
|
||||||
|
*
|
||||||
|
* @return The number of elements remaining in this buffer
|
||||||
|
*/
|
||||||
|
public final int remaining() {
|
||||||
|
return view.remaining();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of bytes between the current position and the
|
||||||
|
* limit. </p>
|
||||||
|
*
|
||||||
|
* @return The number of bytes remaining in this buffer
|
||||||
|
*/
|
||||||
|
public final int remainingByte() {
|
||||||
|
return remaining() * getPointerSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether there are any elements between the current position and
|
||||||
|
* the limit. </p>
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> The new buffer's position will be zero, its limit will be its
|
||||||
|
* capacity, and its mark will be undefined. </p>
|
||||||
|
*
|
||||||
|
* @param capacity The new buffer's capacity, in pointers
|
||||||
|
*
|
||||||
|
* @return The new pointer buffer
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException If the <tt>capacity</tt> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> The new buffer's capacity, limit and position will be
|
||||||
|
* identical to those of this buffer.
|
||||||
|
* <p/>
|
||||||
|
* <p> If this buffer is itself read-only then this method behaves in
|
||||||
|
* exactly the same way as the {@link #duplicate duplicate} method. </p>
|
||||||
|
*
|
||||||
|
* @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 <i>get</i> method. Reads the long at this buffer's
|
||||||
|
* current position, and then increments the position. </p>
|
||||||
|
*
|
||||||
|
* @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 <i>put</i> method <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> Writes the given long into this buffer at the current
|
||||||
|
* position, and then increments the position. </p>
|
||||||
|
*
|
||||||
|
* @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 <i>get</i> method. Reads the long at the given
|
||||||
|
* index. </p>
|
||||||
|
*
|
||||||
|
* @param index The index from which the long will be read
|
||||||
|
*
|
||||||
|
* @return The long at the given index
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException If <tt>index</tt> 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 <i>put</i> method <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> Writes the given long into this buffer at the given
|
||||||
|
* index. </p>
|
||||||
|
*
|
||||||
|
* @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 <tt>index</tt> 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, l);
|
||||||
|
else
|
||||||
|
target.putInt(index, (int)l);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Bulk get operations --
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative bulk <i>get</i> method.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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
|
||||||
|
* <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
|
||||||
|
* longs are transferred and a {@link BufferUnderflowException} is
|
||||||
|
* thrown.
|
||||||
|
* <p/>
|
||||||
|
* <p> Otherwise, this method copies <tt>length</tt> 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 <tt>length</tt>.
|
||||||
|
* <p/>
|
||||||
|
* <p> In other words, an invocation of this method of the form
|
||||||
|
* <tt>src.get(dst, off, len)</tt> has exactly the same effect as
|
||||||
|
* the loop
|
||||||
|
* <p/>
|
||||||
|
* <pre>
|
||||||
|
* for (int i = off; i < off + len; i++)
|
||||||
|
* dst[i] = src.get(); </pre>
|
||||||
|
* <p/>
|
||||||
|
* except that it first checks that there are sufficient longs in
|
||||||
|
* this buffer and it is potentially much more efficient. </p>
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* <tt>dst.length</tt>
|
||||||
|
* @param length The maximum number of longs to be written to the given
|
||||||
|
* array; must be non-negative and no larger than
|
||||||
|
* <tt>dst.length - offset</tt>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*
|
||||||
|
* @throws BufferUnderflowException If there are fewer than <tt>length</tt> longs
|
||||||
|
* remaining in this buffer
|
||||||
|
* @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and <tt>length</tt>
|
||||||
|
* 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 <i>get</i> method.
|
||||||
|
* <p/>
|
||||||
|
* <p> This method transfers longs from this buffer into the given
|
||||||
|
* destination array. An invocation of this method of the form
|
||||||
|
* <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
|
||||||
|
* <p/>
|
||||||
|
* <pre>
|
||||||
|
* src.get(a, 0, a.length) </pre>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*
|
||||||
|
* @throws BufferUnderflowException If there are fewer than <tt>length</tt> longs
|
||||||
|
* remaining in this buffer
|
||||||
|
*/
|
||||||
|
public PointerBuffer get(long[] dst) {
|
||||||
|
return get(dst, 0, dst.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative bulk <i>put</i> method <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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
|
||||||
|
* <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>,
|
||||||
|
* then no longs are transferred and a {@link
|
||||||
|
* BufferOverflowException} is thrown.
|
||||||
|
* <p/>
|
||||||
|
* <p> Otherwise, this method copies
|
||||||
|
* <i>n</i> = <tt>src.remaining()</tt> longs from the given
|
||||||
|
* buffer into this buffer, starting at each buffer's current position.
|
||||||
|
* The positions of both buffers are then incremented by <i>n</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> In other words, an invocation of this method of the form
|
||||||
|
* <tt>dst.put(src)</tt> has exactly the same effect as the loop
|
||||||
|
* <p/>
|
||||||
|
* <pre>
|
||||||
|
* while (src.hasRemaining())
|
||||||
|
* dst.put(src.get()); </pre>
|
||||||
|
* <p/>
|
||||||
|
* except that it first checks that there is sufficient space in this
|
||||||
|
* buffer and it is potentially much more efficient. </p>
|
||||||
|
*
|
||||||
|
* @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 <i>put</i> method <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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
|
||||||
|
* <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
|
||||||
|
* longs are transferred and a {@link BufferOverflowException} is
|
||||||
|
* thrown.
|
||||||
|
* <p/>
|
||||||
|
* <p> Otherwise, this method copies <tt>length</tt> 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 <tt>length</tt>.
|
||||||
|
* <p/>
|
||||||
|
* <p> In other words, an invocation of this method of the form
|
||||||
|
* <tt>dst.put(src, off, len)</tt> has exactly the same effect as
|
||||||
|
* the loop
|
||||||
|
* <p/>
|
||||||
|
* <pre>
|
||||||
|
* for (int i = off; i < off + len; i++)
|
||||||
|
* dst.put(a[i]); </pre>
|
||||||
|
* <p/>
|
||||||
|
* except that it first checks that there is sufficient space in this
|
||||||
|
* buffer and it is potentially much more efficient. </p>
|
||||||
|
*
|
||||||
|
* @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 <tt>array.length</tt>
|
||||||
|
* @param length The number of longs to be read from the given array;
|
||||||
|
* must be non-negative and no larger than
|
||||||
|
* <tt>array.length - offset</tt>
|
||||||
|
*
|
||||||
|
* @return This buffer
|
||||||
|
*
|
||||||
|
* @throws BufferOverflowException If there is insufficient space in this buffer
|
||||||
|
* @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and <tt>length</tt>
|
||||||
|
* 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 <i>put</i> method <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> This method transfers the entire content of the given source
|
||||||
|
* long array into this buffer. An invocation of this method of the
|
||||||
|
* form <tt>dst.put(a)</tt> behaves in exactly the same way as the
|
||||||
|
* invocation
|
||||||
|
* <p/>
|
||||||
|
* <pre>
|
||||||
|
* dst.put(a, 0, a.length) </pre>
|
||||||
|
*
|
||||||
|
* @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 <i>(optional operation)</i>.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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 <i>p</i> = <tt>position()</tt> is copied
|
||||||
|
* to index zero, the long at index <i>p</i> + 1 is copied
|
||||||
|
* to index one, and so forth until the long at index
|
||||||
|
* <tt>limit()</tt> - 1 is copied to index
|
||||||
|
* <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>.
|
||||||
|
* The buffer's position is then set to <i>n+1</i> and its limit is set to
|
||||||
|
* its capacity. The mark, if defined, is discarded.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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 <i>put</i>
|
||||||
|
* method. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> The byte order of a pointer buffer created by allocation or by
|
||||||
|
* wrapping an existing <tt>long</tt> array is the {@link
|
||||||
|
* ByteOrder#nativeOrder </code>native order<code>} of the underlying
|
||||||
|
* hardware. The byte order of a pointer buffer created as a <a
|
||||||
|
* href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
|
||||||
|
* byte buffer at the moment that the view is created. </p>
|
||||||
|
*
|
||||||
|
* @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. </p>
|
||||||
|
*
|
||||||
|
* @return A summary string
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder(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.
|
||||||
|
* <p/>
|
||||||
|
* <p> The hash code of a pointer buffer depends only upon its remaining
|
||||||
|
* elements; that is, upon the elements from <tt>position()</tt> up to, and
|
||||||
|
* including, the element at <tt>limit()</tt> - <tt>1</tt>.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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. </p>
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p/>
|
||||||
|
* <p> Two pointer buffers are equal if, and only if,
|
||||||
|
* <p/>
|
||||||
|
* <p><ol>
|
||||||
|
* <p/>
|
||||||
|
* <li><p> They have the same element type, </p></li>
|
||||||
|
* <p/>
|
||||||
|
* <li><p> They have the same number of remaining elements, and
|
||||||
|
* </p></li>
|
||||||
|
* <p/>
|
||||||
|
* <li><p> The two sequences of remaining elements, considered
|
||||||
|
* independently of their starting positions, are pointwise equal.
|
||||||
|
* </p></li>
|
||||||
|
* <p/>
|
||||||
|
* </ol>
|
||||||
|
* <p/>
|
||||||
|
* <p> A pointer buffer is not equal to any other type of object. </p>
|
||||||
|
*
|
||||||
|
* @param ob The object to which this buffer is to be compared
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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.
|
||||||
|
* <p/>
|
||||||
|
* <p> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A common interface for classes that wrap pointer addresses.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public interface PointerWrapper {
|
||||||
|
|
||||||
|
long getPointer();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this object represents a valid pointer.
|
||||||
|
* The pointer might be invalid because it is NULL or because
|
||||||
|
* some other action has deleted the object that this pointer
|
||||||
|
* represents.
|
||||||
|
*
|
||||||
|
* @return true if the pointer is valid
|
||||||
|
*/
|
||||||
|
public boolean isValid() {
|
||||||
|
return pointer != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the pointer is valid and throws an IllegalStateException if
|
||||||
|
* it is not. This method is a NO-OP, unless the org.lwjgl.util.Debug
|
||||||
|
* property has been set to true.
|
||||||
|
*/
|
||||||
|
public final void checkValid() {
|
||||||
|
if ( LWJGLUtil.DEBUG && !isValid() )
|
||||||
|
throw new IllegalStateException("This " + getClass().getSimpleName() + " pointer is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public final long getPointer() {
|
||||||
|
checkValid();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() + " pointer (0x" + Long.toHexString(pointer).toUpperCase() + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,274 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* System class (named Sys so as not to conflict with java.lang.System)
|
||||||
|
* </p>
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class Sys {
|
||||||
|
/** The native library name */
|
||||||
|
private static final String JNI_LIBRARY_NAME = "lwjgl2";
|
||||||
|
|
||||||
|
/** Current version of library */
|
||||||
|
private static final String VERSION = "2.9.3";
|
||||||
|
|
||||||
|
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 static void doLoadLibrary(final String lib_name) {
|
||||||
|
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||||
|
public Object run() {
|
||||||
|
String library_path = System.getProperty("org.lwjgl.librarypath");
|
||||||
|
if (library_path != null) {
|
||||||
|
System.load(library_path + File.separator + LWJGLUtil.mapLibraryName(lib_name));
|
||||||
|
} else {
|
||||||
|
System.loadLibrary(lib_name);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadLibrary(final String lib_name) {
|
||||||
|
// actively try to load 64bit libs on 64bit architectures first
|
||||||
|
String osArch = System.getProperty("os.arch");
|
||||||
|
boolean try64First = LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX && ("amd64".equals(osArch) || "x86_64".equals(osArch));
|
||||||
|
|
||||||
|
Error err = null;
|
||||||
|
if ( try64First ) {
|
||||||
|
try {
|
||||||
|
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||||
|
return;
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to loading the "old way"
|
||||||
|
try {
|
||||||
|
doLoadLibrary(lib_name);
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
if ( try64First )
|
||||||
|
throw err;
|
||||||
|
|
||||||
|
if (implementation.has64Bit()) {
|
||||||
|
try {
|
||||||
|
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||||
|
return;
|
||||||
|
} catch (UnsatisfiedLinkError e2) {
|
||||||
|
LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Throw original error
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
implementation = createImplementation();
|
||||||
|
loadLibrary(JNI_LIBRARY_NAME);
|
||||||
|
is64Bit = implementation.getPointerSize() == 8;
|
||||||
|
|
||||||
|
int native_jni_version = implementation.getJNIVersion();
|
||||||
|
int required_version = implementation.getRequiredJNIVersion();
|
||||||
|
if (native_jni_version != required_version)
|
||||||
|
throw new LinkageError("Version mismatch: jar version is '" + required_version +
|
||||||
|
"', native library version is '" + native_jni_version + "'");
|
||||||
|
implementation.setDebug(LWJGLUtil.DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SysImplementation createImplementation() {
|
||||||
|
switch (LWJGLUtil.getPlatform()) {
|
||||||
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
|
return new LinuxSysImplementation();
|
||||||
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
|
return new WindowsSysImplementation();
|
||||||
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
|
return new MacOSXSysImplementation();
|
||||||
|
case LWJGLUtil.PLATFORM_FCL:
|
||||||
|
return new FCLSysImplementation();
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unsupported platform");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No constructor for Sys.
|
||||||
|
*/
|
||||||
|
private Sys() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version of the core LWJGL libraries as a String.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @return timer resolution in ticks per second or 0 if no timer is present.
|
||||||
|
*/
|
||||||
|
public static long getTimerResolution() {
|
||||||
|
return implementation.getTimerResolution();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current value of the hires timer, in ticks. When the Sys class is first loaded
|
||||||
|
* the hires timer is reset to 0. If no hires timer is present then this method will always
|
||||||
|
* return 0.<p><strong>NOTEZ BIEN</strong> that the hires timer WILL wrap around.
|
||||||
|
*
|
||||||
|
* @return the current hires time, in ticks (always >= 0)
|
||||||
|
*/
|
||||||
|
public static long getTime() {
|
||||||
|
return implementation.getTime() & 0x7FFFFFFFFFFFFFFFL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to display a modal alert to the user. This method should be used
|
||||||
|
* when a game fails to initialize properly or crashes out losing its display
|
||||||
|
* in the process. It is provided because AWT may not be available on the target
|
||||||
|
* platform, although on Mac and Linux and other platforms supporting AWT we
|
||||||
|
* delegate the task to AWT instead of doing it ourselves.
|
||||||
|
* <p>
|
||||||
|
* The alert should display the title and the message and then the current
|
||||||
|
* thread should block until the user dismisses the alert - typically with an
|
||||||
|
* OK button click.
|
||||||
|
* <p>
|
||||||
|
* It may be that the user's system has no windowing system installed for some
|
||||||
|
* reason, in which case this method may do nothing at all, or attempt to provide
|
||||||
|
* some console output.
|
||||||
|
*
|
||||||
|
* @param title The title of the alert. We suggest using the title of your game.
|
||||||
|
* @param message The message text for the alert.
|
||||||
|
*/
|
||||||
|
public static void alert(String title, String message) {
|
||||||
|
boolean grabbed = Mouse.isGrabbed();
|
||||||
|
if (grabbed) {
|
||||||
|
Mouse.setGrabbed(false);
|
||||||
|
}
|
||||||
|
if (title == null)
|
||||||
|
title = "";
|
||||||
|
if (message == null)
|
||||||
|
message = "";
|
||||||
|
implementation.alert(title, message);
|
||||||
|
if (grabbed) {
|
||||||
|
Mouse.setGrabbed(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the system web browser and point it at the specified URL. It is recommended
|
||||||
|
* that this not be called whilst your game is running, but on application exit in
|
||||||
|
* a shutdown hook, as the screen resolution will not be reset when the browser is
|
||||||
|
* brought into view.
|
||||||
|
* <p>
|
||||||
|
* There is no guarantee that this will work, nor that we can detect if it has
|
||||||
|
* failed - hence we don't return success code or throw an Exception. This is just a
|
||||||
|
* best attempt at opening the URL given - don't rely on it to work!
|
||||||
|
* <p>
|
||||||
|
* @param url The URL. Ensure that the URL is properly encoded.
|
||||||
|
* @return false if we are CERTAIN the call has failed
|
||||||
|
*/
|
||||||
|
public static boolean openURL(String url) {
|
||||||
|
// Attempt to use Webstart if we have it available
|
||||||
|
try {
|
||||||
|
// Lookup the javax.jnlp.BasicService object
|
||||||
|
final Class<?> serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
|
||||||
|
Method lookupMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||||
|
public Method run() throws Exception {
|
||||||
|
return serviceManagerClass.getMethod("lookup", String.class);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"});
|
||||||
|
final Class<?> basicServiceClass = Class.forName("javax.jnlp.BasicService");
|
||||||
|
Method showDocumentMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||||
|
public Method run() throws Exception {
|
||||||
|
return basicServiceClass.getMethod("showDocument", URL.class);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
Boolean ret = (Boolean)showDocumentMethod.invoke(basicService, new URL(url));
|
||||||
|
return ret;
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception ue) {
|
||||||
|
return implementation.openURL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the contents of the system clipboard. The system might not have a
|
||||||
|
* clipboard (particularly if it doesn't even have a keyboard) in which case
|
||||||
|
* we return null. Otherwise we return a String, which may be the empty
|
||||||
|
* string "".
|
||||||
|
*
|
||||||
|
* @return a String, or null if there is no system clipboard.
|
||||||
|
*/
|
||||||
|
public static String getClipboard() {
|
||||||
|
return implementation.getClipboard();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* System class platform specific method interface
|
||||||
|
*
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
interface SysImplementation {
|
||||||
|
/**
|
||||||
|
* Return the required version of the native library
|
||||||
|
*/
|
||||||
|
int getRequiredJNIVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version of the native library
|
||||||
|
*/
|
||||||
|
int getJNIVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the platform's pointer size in bytes
|
||||||
|
*/
|
||||||
|
int getPointerSize();
|
||||||
|
|
||||||
|
void setDebug(boolean debug);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the number of ticks that the hires timer does in a second.
|
||||||
|
*
|
||||||
|
* @return timer resolution in ticks per second or 0 if no timer is present.
|
||||||
|
*/
|
||||||
|
long getTimerResolution();
|
||||||
|
|
||||||
|
long getTime();
|
||||||
|
|
||||||
|
void alert(String title, String message);
|
||||||
|
|
||||||
|
boolean openURL(String url);
|
||||||
|
|
||||||
|
String getClipboard();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true there exists a separate 64 bit library
|
||||||
|
* on the platform
|
||||||
|
*/
|
||||||
|
boolean has64Bit();
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* @author $Author$
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
final class WindowsSysImplementation extends DefaultSysImplementation {
|
||||||
|
private static final int JNI_VERSION = 24;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Sys.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredJNIVersion() {
|
||||||
|
return JNI_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimerResolution() {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return nGetTime();
|
||||||
|
}
|
||||||
|
private static native long nGetTime();
|
||||||
|
|
||||||
|
public boolean has64Bit() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long getHwnd() {
|
||||||
|
if (!Display.isCreated())
|
||||||
|
return 0;
|
||||||
|
/* Use reflection since we can't make Display.getImplementation
|
||||||
|
* public
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedExceptionAction<Long>() {
|
||||||
|
public Long run() throws Exception {
|
||||||
|
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||||
|
getImplementation_method.setAccessible(true);
|
||||||
|
Object display_impl = getImplementation_method.invoke(null);
|
||||||
|
Class<?> WindowsDisplay_class = Class.forName("org.lwjgl.opengl.WindowsDisplay");
|
||||||
|
Method getHwnd_method = WindowsDisplay_class.getDeclaredMethod("getHwnd");
|
||||||
|
getHwnd_method.setAccessible(true);
|
||||||
|
return (Long)getHwnd_method.invoke(display_impl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (PrivilegedActionException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void alert(String title, String message) {
|
||||||
|
if(!Display.isCreated()) {
|
||||||
|
initCommonControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
LWJGLUtil.log(String.format("*** Alert *** %s\n%s\n", title, message));
|
||||||
|
|
||||||
|
final ByteBuffer titleText = MemoryUtil.encodeUTF16(title);
|
||||||
|
final ByteBuffer messageText = MemoryUtil.encodeUTF16(message);
|
||||||
|
nAlert(getHwnd(), MemoryUtil.getAddress(titleText), MemoryUtil.getAddress(messageText));
|
||||||
|
}
|
||||||
|
private static native void nAlert(long parent_hwnd, long title, long message);
|
||||||
|
private static native void initCommonControls();
|
||||||
|
|
||||||
|
public boolean openURL(final String url) {
|
||||||
|
try {
|
||||||
|
LWJGLUtil.execPrivileged(new String[]{"rundll32", "url.dll,FileProtocolHandler", url});
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LWJGLUtil.log("Failed to open url (" + url + "): " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClipboard() {
|
||||||
|
return nGetClipboard();
|
||||||
|
}
|
||||||
|
private static native String nGetClipboard();
|
||||||
|
}
|
|
@ -0,0 +1,290 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A game controller of some sort that will provide input. The controller
|
||||||
|
* presents buttons and axes. Buttons are either pressed or not pressed. Axis
|
||||||
|
* provide analogue values.
|
||||||
|
*
|
||||||
|
* @author Kevin Glass
|
||||||
|
*/
|
||||||
|
public interface Controller {
|
||||||
|
/**
|
||||||
|
* Get the name assigned to this controller.
|
||||||
|
*
|
||||||
|
* @return The name assigned to this controller
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the index of this controller in the collection
|
||||||
|
*
|
||||||
|
* @return The index of this controller in the collection
|
||||||
|
*/
|
||||||
|
int getIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the number of buttons available on this controller
|
||||||
|
*
|
||||||
|
* @return The number of butotns available on this controller
|
||||||
|
*/
|
||||||
|
int getButtonCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the specified button. Be warned, often this is
|
||||||
|
* as exciting as "Button X"
|
||||||
|
*
|
||||||
|
* @param index The index of the button whose name should be retrieved
|
||||||
|
* @return The name of the button requested
|
||||||
|
*/
|
||||||
|
String getButtonName(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a button is currently pressed
|
||||||
|
*
|
||||||
|
* @param index The button to check
|
||||||
|
* @return True if the button is currently pressed
|
||||||
|
*/
|
||||||
|
boolean isButtonPressed(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Poll the controller for new data. This will also update
|
||||||
|
* events
|
||||||
|
*/
|
||||||
|
void poll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the X-Axis value of the POV on this controller
|
||||||
|
*
|
||||||
|
* @return The X-Axis value of the POV on this controller
|
||||||
|
*/
|
||||||
|
float getPovX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Y-Axis value of the POV on this controller
|
||||||
|
*
|
||||||
|
* @return The Y-Axis value of the POV on this controller
|
||||||
|
*/
|
||||||
|
float getPovY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for a specified axis
|
||||||
|
*
|
||||||
|
* @param index The index of the axis for which to retrieve the dead zone
|
||||||
|
* @return The dead zone for the specified axis
|
||||||
|
*/
|
||||||
|
float getDeadZone(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the specified axis
|
||||||
|
*
|
||||||
|
* @param index The index of hte axis for which to set the dead zone
|
||||||
|
* @param zone The dead zone to use for the specified axis
|
||||||
|
*/
|
||||||
|
void setDeadZone(int index,float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the number of axes available on this controller.
|
||||||
|
*
|
||||||
|
* @return The number of axes available on this controller.
|
||||||
|
*/
|
||||||
|
int getAxisCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name that's given to the specified axis
|
||||||
|
*
|
||||||
|
* @param index The index of the axis whose name should be retrieved
|
||||||
|
* @return The name of the specified axis.
|
||||||
|
*/
|
||||||
|
String getAxisName(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the value thats currently available on a specified axis. The
|
||||||
|
* value will always be between 1.0 and -1.0 and will calibrate as values
|
||||||
|
* are passed read. It may be useful to get the player to wiggle the joystick
|
||||||
|
* from side to side to get the calibration right.
|
||||||
|
*
|
||||||
|
* @param index The index of axis to be read
|
||||||
|
* @return The value from the specified axis.
|
||||||
|
*/
|
||||||
|
float getAxisValue(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the X axis if there is one. If no X axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the X axis
|
||||||
|
*/
|
||||||
|
float getXAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the X axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the X axis
|
||||||
|
*/
|
||||||
|
float getXAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the X axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the X axis
|
||||||
|
*/
|
||||||
|
void setXAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the Y axis if there is one. If no Y axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the Y axis
|
||||||
|
*/
|
||||||
|
float getYAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the Y axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the Y axis
|
||||||
|
*/
|
||||||
|
float getYAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the Y axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the Y axis
|
||||||
|
*/
|
||||||
|
void setYAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the Z axis if there is one. If no Z axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the Z axis
|
||||||
|
*/
|
||||||
|
float getZAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the Z axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the Z axis
|
||||||
|
*/
|
||||||
|
float getZAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the Z axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the Z axis
|
||||||
|
*/
|
||||||
|
void setZAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the RX axis if there is one. If no RX axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the RX axis
|
||||||
|
*/
|
||||||
|
float getRXAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the RX axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the RX axis
|
||||||
|
*/
|
||||||
|
float getRXAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the RX axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the RX axis
|
||||||
|
*/
|
||||||
|
void setRXAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the RY axis if there is one. If no RY axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the RY axis
|
||||||
|
*/
|
||||||
|
float getRYAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the RY axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the RY axis
|
||||||
|
*/
|
||||||
|
float getRYAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the RY axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the RY axis
|
||||||
|
*/
|
||||||
|
void setRYAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from the RZ axis if there is one. If no RZ axis is
|
||||||
|
* defined a zero value will be returned.
|
||||||
|
*
|
||||||
|
* @return The value from the RZ axis
|
||||||
|
*/
|
||||||
|
float getRZAxisValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dead zone for the RZ axis.
|
||||||
|
*
|
||||||
|
* @return The dead zone for the RZ axis
|
||||||
|
*/
|
||||||
|
float getRZAxisDeadZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dead zone for the RZ axis
|
||||||
|
*
|
||||||
|
* @param zone The dead zone to use for the RZ axis
|
||||||
|
*/
|
||||||
|
void setRZAxisDeadZone(float zone);
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the number of rumblers this controller supports */
|
||||||
|
int getRumblerCount();
|
||||||
|
|
||||||
|
/** Returns the name of the specified rumbler
|
||||||
|
*
|
||||||
|
* @param index The rumbler index
|
||||||
|
*/
|
||||||
|
String getRumblerName(int index);
|
||||||
|
|
||||||
|
/** Sets the vibration strength of the specified rumbler
|
||||||
|
*
|
||||||
|
* @param index The index of the rumbler
|
||||||
|
* @param strength The strength to vibrate at
|
||||||
|
*/
|
||||||
|
void setRumblerStrength(int index, float strength);
|
||||||
|
}
|
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event occuring on a controller.
|
||||||
|
*
|
||||||
|
* @author Kevin Glass
|
||||||
|
*/
|
||||||
|
class ControllerEvent {
|
||||||
|
/** Indicates the event was caused by a button */
|
||||||
|
public static final int BUTTON = 1;
|
||||||
|
/** Indicates the event was caused by a axis */
|
||||||
|
public static final int AXIS = 2;
|
||||||
|
/** Indicates the event was caused by a pov X */
|
||||||
|
public static final int POVX = 3;
|
||||||
|
/** Indicates the event was caused by a pov Y */
|
||||||
|
public static final int POVY = 4;
|
||||||
|
|
||||||
|
/** The controller generating the event */
|
||||||
|
private Controller source;
|
||||||
|
/** The index of the input (axis or button) that generated the event */
|
||||||
|
private int index;
|
||||||
|
/** Type of control that generated the event */
|
||||||
|
private int type;
|
||||||
|
/** True when a button is pressed, if this event was caused by the button */
|
||||||
|
private boolean buttonState;
|
||||||
|
/** True if this event was caused by the x axis */
|
||||||
|
private boolean xaxis;
|
||||||
|
/** True if this event was caused by the y axis */
|
||||||
|
private boolean yaxis;
|
||||||
|
/** The time stamp of this event */
|
||||||
|
private long timeStamp;
|
||||||
|
/** The value on a specified axis, if this event was caused by the x-axis */
|
||||||
|
private float xaxisValue;
|
||||||
|
/** The value on a specified axis, if this event was caused by the y-axis */
|
||||||
|
private float yaxisValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event
|
||||||
|
*
|
||||||
|
* @param source The source of the event
|
||||||
|
* @param timeStamp The time stamp given for this event
|
||||||
|
* @param type The type of control generating this event
|
||||||
|
* @param index The index of the input that generated the event
|
||||||
|
* @param xaxis True if this event was caused by the x-axis
|
||||||
|
* @param yaxis True if this event was caused by the y-axis
|
||||||
|
*/
|
||||||
|
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
|
||||||
|
this(source, timeStamp, type, index, false, xaxis, yaxis, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event
|
||||||
|
*
|
||||||
|
* @param source The source of the event
|
||||||
|
* @param timeStamp The time stamp given for this event
|
||||||
|
* @param type The type of control generating this event
|
||||||
|
* @param index The index of the input that generated the event
|
||||||
|
* @param buttonState True when a button is pressed, if this event was caused by the button
|
||||||
|
* @param xaxis True if this event was caused by the x-axis
|
||||||
|
* @param yaxis True if this event was caused by the y-axis
|
||||||
|
* @param xaxisValue The value on a specified axis, if this event was caused by the x-axis
|
||||||
|
* @param yaxisValue The value on a specified axis, if this event was caused by the y-axis
|
||||||
|
*/
|
||||||
|
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean buttonState,boolean xaxis,boolean yaxis,float xaxisValue,float yaxisValue) {
|
||||||
|
this.source = source;
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
this.type = type;
|
||||||
|
this.index = index;
|
||||||
|
this.buttonState = buttonState;
|
||||||
|
this.xaxis = xaxis;
|
||||||
|
this.yaxis = yaxis;
|
||||||
|
this.xaxisValue = xaxisValue;
|
||||||
|
this.yaxisValue = yaxisValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time stamp given for this event. As with nanoTime()
|
||||||
|
* this value means nothing other than giving ordering
|
||||||
|
*
|
||||||
|
* @return The time stamp given for this event
|
||||||
|
*/
|
||||||
|
public long getTimeStamp() {
|
||||||
|
return timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the controller that generated this event
|
||||||
|
*
|
||||||
|
* @return The controller that generated this event
|
||||||
|
*/
|
||||||
|
public Controller getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the index of the control generating this event
|
||||||
|
*
|
||||||
|
* @return The index of the control generating this event
|
||||||
|
*/
|
||||||
|
public int getControlIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this event was generated by a button
|
||||||
|
*
|
||||||
|
* @return True if this event was generated by a button
|
||||||
|
*/
|
||||||
|
public boolean isButton() {
|
||||||
|
return type == BUTTON;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the button is pressed or not, when this event was caused
|
||||||
|
*
|
||||||
|
* @return True when a button is pressed, if this event was caused by the button
|
||||||
|
*/
|
||||||
|
public boolean getButtonState() {
|
||||||
|
return buttonState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this event was generated by a axis
|
||||||
|
*
|
||||||
|
* @return True if this event was generated by a axis
|
||||||
|
*/
|
||||||
|
public boolean isAxis() {
|
||||||
|
return type == AXIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this event was generated by a pov
|
||||||
|
*
|
||||||
|
* @return True if this event was generated by a pov
|
||||||
|
*/
|
||||||
|
public boolean isPovY() {
|
||||||
|
return type == POVY;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Check if this event was generated by a pov
|
||||||
|
*
|
||||||
|
* @return True if this event was generated by a pov
|
||||||
|
*/
|
||||||
|
public boolean isPovX() {
|
||||||
|
return type == POVX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this event was caused by the X axis
|
||||||
|
*
|
||||||
|
* @return True if this event was caused by the X axis
|
||||||
|
*/
|
||||||
|
public boolean isXAxis() {
|
||||||
|
return xaxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this event was caused by the Y axis
|
||||||
|
*
|
||||||
|
* @return True if this event was caused by the Y axis
|
||||||
|
*/
|
||||||
|
public boolean isYAxis() {
|
||||||
|
return yaxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value on an X axis when this event was caused
|
||||||
|
*
|
||||||
|
* @return The value on a specified axis, if this event was caused by the x-axis
|
||||||
|
*/
|
||||||
|
public float getXAxisValue() {
|
||||||
|
return xaxisValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value on an Y axis when this event was caused
|
||||||
|
*
|
||||||
|
* @return The value on a specified axis, if this event was caused by the y-axis
|
||||||
|
*/
|
||||||
|
public float getYAxisValue() {
|
||||||
|
return yaxisValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return "["+source+" type="+type+" xaxis="+xaxis+" yaxis="+yaxis+"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,308 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.java.games.input.ControllerEnvironment;
|
||||||
|
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The collection of controllers currently connected.
|
||||||
|
*
|
||||||
|
* @author Kevin Glass
|
||||||
|
*/
|
||||||
|
public class Controllers {
|
||||||
|
/** The controllers available */
|
||||||
|
private static ArrayList<JInputController> controllers = new ArrayList<JInputController>();
|
||||||
|
/** The number of controllers */
|
||||||
|
private static int controllerCount;
|
||||||
|
|
||||||
|
/** The current list of events */
|
||||||
|
private static ArrayList<ControllerEvent> events = new ArrayList<ControllerEvent>();
|
||||||
|
/** The current event */
|
||||||
|
private static ControllerEvent event;
|
||||||
|
|
||||||
|
/** Whether controllers were created */
|
||||||
|
private static boolean created;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the controllers collection
|
||||||
|
*
|
||||||
|
* @throws LWJGLException Indicates a failure to initialise the controller library.
|
||||||
|
*/
|
||||||
|
public static void create() throws LWJGLException {
|
||||||
|
if (created)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment();
|
||||||
|
|
||||||
|
net.java.games.input.Controller[] found = env.getControllers();
|
||||||
|
ArrayList<net.java.games.input.Controller> lollers = new ArrayList<net.java.games.input.Controller>();
|
||||||
|
for ( net.java.games.input.Controller c : found ) {
|
||||||
|
if ( (!c.getType().equals(net.java.games.input.Controller.Type.KEYBOARD)) &&
|
||||||
|
(!c.getType().equals(net.java.games.input.Controller.Type.MOUSE)) ) {
|
||||||
|
lollers.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( net.java.games.input.Controller c : lollers ) {
|
||||||
|
createController(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
created = true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new LWJGLException("Failed to initialise controllers",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility to create a controller based on its potential sub-controllers
|
||||||
|
*
|
||||||
|
* @param c The controller to add
|
||||||
|
*/
|
||||||
|
private static void createController(net.java.games.input.Controller c) {
|
||||||
|
net.java.games.input.Controller[] subControllers = c.getControllers();
|
||||||
|
if (subControllers.length == 0) {
|
||||||
|
JInputController controller = new JInputController(controllerCount,c);
|
||||||
|
|
||||||
|
controllers.add(controller);
|
||||||
|
controllerCount++;
|
||||||
|
} else {
|
||||||
|
for ( net.java.games.input.Controller sub : subControllers ) {
|
||||||
|
createController(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a controller from the collection
|
||||||
|
*
|
||||||
|
* @param index The index of the controller to retrieve
|
||||||
|
* @return The controller requested
|
||||||
|
*/
|
||||||
|
public static Controller getController(int index) {
|
||||||
|
return controllers.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a count of the number of controllers
|
||||||
|
*
|
||||||
|
* @return The number of controllers available
|
||||||
|
*/
|
||||||
|
public static int getControllerCount() {
|
||||||
|
return controllers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Poll the controllers available. This will both update their state
|
||||||
|
* and generate events that must be cleared.
|
||||||
|
*/
|
||||||
|
public static void poll() {
|
||||||
|
for (int i=0;i<controllers.size();i++) {
|
||||||
|
getController(i).poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear any events stored for the controllers in this set
|
||||||
|
*/
|
||||||
|
public static void clearEvents() {
|
||||||
|
events.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to the next event that has been stored.
|
||||||
|
*
|
||||||
|
* @return True if there is still an event to process
|
||||||
|
*/
|
||||||
|
public static boolean next() {
|
||||||
|
if (events.size() == 0) {
|
||||||
|
event = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
event = events.remove(0);
|
||||||
|
|
||||||
|
return event != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if Controllers has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys any resources used by the controllers
|
||||||
|
*/
|
||||||
|
public static void destroy() {
|
||||||
|
// FIXME! not currently possible to destroy a controller
|
||||||
|
|
||||||
|
// if (!created)
|
||||||
|
// return;
|
||||||
|
// created = false;
|
||||||
|
//
|
||||||
|
// // nuke each controller
|
||||||
|
// for (int i=0;i<controllers.size();i++) {
|
||||||
|
// //
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // cleanup
|
||||||
|
// event = null;
|
||||||
|
// events.clear();
|
||||||
|
// controllers.clear();
|
||||||
|
// controllerCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the source of the current event
|
||||||
|
*
|
||||||
|
* @return The source of the current event
|
||||||
|
*/
|
||||||
|
public static Controller getEventSource() {
|
||||||
|
return event.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the index of the control that caused the current event
|
||||||
|
*
|
||||||
|
* @return The index of the control that cause the current event
|
||||||
|
*/
|
||||||
|
public static int getEventControlIndex() {
|
||||||
|
return event.getControlIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was caused by a button
|
||||||
|
*
|
||||||
|
* @return True if the current event was caused by a button
|
||||||
|
*/
|
||||||
|
public static boolean isEventButton() {
|
||||||
|
return event.isButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was caused by a axis
|
||||||
|
*
|
||||||
|
* @return True if the current event was caused by a axis
|
||||||
|
*/
|
||||||
|
public static boolean isEventAxis() {
|
||||||
|
return event.isAxis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was caused by movement on the x-axis
|
||||||
|
*
|
||||||
|
* @return True if the current event was cause by movement on the x-axis
|
||||||
|
*/
|
||||||
|
public static boolean isEventXAxis() {
|
||||||
|
return event.isXAxis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was caused by movement on the y-axis
|
||||||
|
*
|
||||||
|
* @return True if the current event was caused by movement on the y-axis
|
||||||
|
*/
|
||||||
|
public static boolean isEventYAxis() {
|
||||||
|
return event.isYAxis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was cause by the POV x-axis
|
||||||
|
*
|
||||||
|
* @return True if the current event was caused by the POV x-axis
|
||||||
|
*/
|
||||||
|
public static boolean isEventPovX() {
|
||||||
|
return event.isPovX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current event was cause by the POV x-axis
|
||||||
|
*
|
||||||
|
* @return True if the current event was caused by the POV x-axis
|
||||||
|
*/
|
||||||
|
public static boolean isEventPovY() {
|
||||||
|
return event.isPovY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp assigned to the current event
|
||||||
|
*
|
||||||
|
* @return The timestamp assigned to the current event
|
||||||
|
*/
|
||||||
|
public static long getEventNanoseconds() {
|
||||||
|
return event.getTimeStamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the state of the button that generated the current event
|
||||||
|
*
|
||||||
|
* @return True if button was down, or false if released
|
||||||
|
*/
|
||||||
|
public static boolean getEventButtonState() {
|
||||||
|
return event.getButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value on an X axis of the current event
|
||||||
|
*
|
||||||
|
* @return The value on a x axis of the current event
|
||||||
|
*/
|
||||||
|
public static float getEventXAxisValue() {
|
||||||
|
return event.getXAxisValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value on an Y axis of the current event
|
||||||
|
*
|
||||||
|
* @return The value on a y axis of the current event
|
||||||
|
*/
|
||||||
|
public static float getEventYAxisValue() {
|
||||||
|
return event.getYAxisValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an event to the stack of events that have been caused
|
||||||
|
*
|
||||||
|
* @param event The event to add to the list
|
||||||
|
*/
|
||||||
|
static void addEvent(ControllerEvent event) {
|
||||||
|
if (event != null) {
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,366 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferChecks;
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* A class representing a native cursor. Instances of this
|
||||||
|
* class can be used with Mouse.setCursor(), if available.
|
||||||
|
*
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Cursor {
|
||||||
|
/** 1 bit transparency for native cursor */
|
||||||
|
public static final int CURSOR_ONE_BIT_TRANSPARENCY = 1;
|
||||||
|
|
||||||
|
/** 8 bit alhpa native cursor */
|
||||||
|
public static final int CURSOR_8_BIT_ALPHA = 2;
|
||||||
|
|
||||||
|
/** animation native cursor */
|
||||||
|
public static final int CURSOR_ANIMATION = 4;
|
||||||
|
|
||||||
|
/** First element to display */
|
||||||
|
private final CursorElement[] cursors;
|
||||||
|
|
||||||
|
/** Index into list of cursors */
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
private boolean destroyed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create
|
||||||
|
* Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported.
|
||||||
|
* So to maximize portability, lwjgl applications should only create cursor images with 0x00 or 0xff as alpha values.
|
||||||
|
* The constructor will copy the images and delays, so there's no need to keep them around.
|
||||||
|
*
|
||||||
|
* @param width cursor image width
|
||||||
|
* @param height cursor image height
|
||||||
|
* @param xHotspot the x coordinate of the cursor hotspot
|
||||||
|
* @param yHotspot the y coordinate of the cursor hotspot
|
||||||
|
* @param numImages number of cursor images specified. Must be 1 if animations are not supported.
|
||||||
|
* @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL.
|
||||||
|
* @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null
|
||||||
|
* @throws LWJGLException if the cursor could not be created for any reason
|
||||||
|
*/
|
||||||
|
public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if ((getCapabilities() & CURSOR_ONE_BIT_TRANSPARENCY) == 0)
|
||||||
|
throw new LWJGLException("Native cursors not supported");
|
||||||
|
BufferChecks.checkBufferSize(images, width*height*numImages);
|
||||||
|
if (delays != null)
|
||||||
|
BufferChecks.checkBufferSize(delays, numImages);
|
||||||
|
if (!Mouse.isCreated())
|
||||||
|
throw new IllegalStateException("Mouse must be created before creating cursor objects");
|
||||||
|
if (width*height*numImages > images.remaining())
|
||||||
|
throw new IllegalArgumentException("width*height*numImages > images.remaining()");
|
||||||
|
if (xHotspot >= width || xHotspot < 0)
|
||||||
|
throw new IllegalArgumentException("xHotspot > width || xHotspot < 0");
|
||||||
|
if (yHotspot >= height || yHotspot < 0)
|
||||||
|
throw new IllegalArgumentException("yHotspot > height || yHotspot < 0");
|
||||||
|
|
||||||
|
Sys.initialize();
|
||||||
|
|
||||||
|
// Hmm
|
||||||
|
yHotspot = height - 1 - yHotspot;
|
||||||
|
|
||||||
|
// create cursor (or cursors if multiple images supplied)
|
||||||
|
cursors = createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the minimum size of a native cursor. Can only be called if
|
||||||
|
* The Mouse is created and cursor caps includes at least
|
||||||
|
* CURSOR_ONE_BIT_TRANSPARANCY.
|
||||||
|
*
|
||||||
|
* @return the maximum size of a native cursor
|
||||||
|
*/
|
||||||
|
public static int getMinCursorSize() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!Mouse.isCreated())
|
||||||
|
throw new IllegalStateException("Mouse must be created.");
|
||||||
|
return Mouse.getImplementation().getMinCursorSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the maximum size of a native cursor. Can only be called if
|
||||||
|
* The Mouse is created and cursor caps includes at least
|
||||||
|
* CURSOR_ONE_BIT_TRANSPARANCY.
|
||||||
|
*
|
||||||
|
* @return the maximum size of a native cursor
|
||||||
|
*/
|
||||||
|
public static int getMaxCursorSize() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!Mouse.isCreated())
|
||||||
|
throw new IllegalStateException("Mouse must be created.");
|
||||||
|
return Mouse.getImplementation().getMaxCursorSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the capabilities of the native cursor. Return a bit mask of the native cursor capabilities.
|
||||||
|
* The CURSOR_ONE_BIT_TRANSPARANCY indicates support for cursors with one bit transparancy,
|
||||||
|
* the CURSOR_8_BIT_ALPHA indicates support for 8 bit alpha and CURSOR_ANIMATION indicates
|
||||||
|
* support for cursor animations.
|
||||||
|
*
|
||||||
|
* @return A bit mask with native cursor capabilities.
|
||||||
|
*/
|
||||||
|
public static int getCapabilities() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (Mouse.getImplementation() != null)
|
||||||
|
return Mouse.getImplementation().getNativeCursorCapabilities();
|
||||||
|
else
|
||||||
|
return OpenGLPackageAccess.createImplementation().getNativeCursorCapabilities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the actual cursor, using a platform specific class
|
||||||
|
*/
|
||||||
|
private static CursorElement[] createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
|
||||||
|
// create copy and flip images to match ogl
|
||||||
|
IntBuffer images_copy = BufferUtils.createIntBuffer(images.remaining());
|
||||||
|
flipImages(width, height, numImages, images, images_copy);
|
||||||
|
|
||||||
|
// Mac and Windows doesn't (afaik) allow for animation based cursors, except in the .ani
|
||||||
|
// format on Windows, which we don't support.
|
||||||
|
// The cursor animation was therefor developed using java side time tracking.
|
||||||
|
// unfortunately X flickers when changing cursor. We therefore check for either
|
||||||
|
// Windows, Mac or X and do accordingly.
|
||||||
|
// we might want to split it into a X/Win/Mac cursor if it gets too cluttered
|
||||||
|
|
||||||
|
CursorElement[] cursors;
|
||||||
|
switch (LWJGLUtil.getPlatform()) {
|
||||||
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
|
|
||||||
|
// OS X requires the image format to be in ABGR format
|
||||||
|
convertARGBtoABGR(images_copy);
|
||||||
|
|
||||||
|
// create our cursor elements
|
||||||
|
cursors = new CursorElement[numImages];
|
||||||
|
for(int i=0; i<numImages; i++) {
|
||||||
|
Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
|
||||||
|
long delay = (delays != null) ? delays.get(i) : 0;
|
||||||
|
long timeout = System.currentTimeMillis();
|
||||||
|
cursors[i] = new CursorElement(handle, delay, timeout);
|
||||||
|
|
||||||
|
// offset to next image
|
||||||
|
images_copy.position(width*height*(i+1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
|
// create our cursor elements
|
||||||
|
cursors = new CursorElement[numImages];
|
||||||
|
for(int i=0; i<numImages; i++) {
|
||||||
|
|
||||||
|
// iterate through the images, and make sure that the pixels are either 0xffxxxxxx or 0x00000000
|
||||||
|
int size = width * height;
|
||||||
|
for(int j=0; j<size; j++) {
|
||||||
|
int index = j + (i*size);
|
||||||
|
int alpha = images_copy.get(index) >> 24 & 0xff;
|
||||||
|
if(alpha != 0xff) {
|
||||||
|
images_copy.put(index, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
|
||||||
|
long delay = (delays != null) ? delays.get(i) : 0;
|
||||||
|
long timeout = System.currentTimeMillis();
|
||||||
|
cursors[i] = new CursorElement(handle, delay, timeout);
|
||||||
|
|
||||||
|
// offset to next image
|
||||||
|
images_copy.position(width*height*(i+1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
|
case LWJGLUtil.PLATFORM_FCL:
|
||||||
|
// create our cursor elements
|
||||||
|
Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays);
|
||||||
|
CursorElement cursor_element = new CursorElement(handle, -1, -1);
|
||||||
|
cursors = new CursorElement[]{cursor_element};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unknown OS");
|
||||||
|
}
|
||||||
|
return cursors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an IntBuffer image of ARGB format into ABGR
|
||||||
|
*
|
||||||
|
* @param imageBuffer image to convert
|
||||||
|
*/
|
||||||
|
private static void convertARGBtoABGR(IntBuffer imageBuffer) {
|
||||||
|
for (int i = 0; i < imageBuffer.limit(); i++) {
|
||||||
|
int argbColor = imageBuffer.get(i);
|
||||||
|
|
||||||
|
byte alpha = (byte)(argbColor >>> 24);
|
||||||
|
byte blue = (byte)(argbColor >>> 16);
|
||||||
|
byte green = (byte)(argbColor >>> 8);
|
||||||
|
byte red = (byte)argbColor;
|
||||||
|
|
||||||
|
int abgrColor = ((alpha & 0xff) << 24 ) + ((red & 0xff) << 16 ) + ((green & 0xff) << 8 ) + ((blue & 0xff) );
|
||||||
|
|
||||||
|
imageBuffer.put(i, abgrColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flips the images so they're oriented according to opengl
|
||||||
|
*
|
||||||
|
* @param width Width of image
|
||||||
|
* @param height Height of images
|
||||||
|
* @param numImages How many images to flip
|
||||||
|
* @param images Source images
|
||||||
|
* @param images_copy Destination images
|
||||||
|
*/
|
||||||
|
private static void flipImages(int width, int height, int numImages, IntBuffer images, IntBuffer images_copy) {
|
||||||
|
for (int i = 0; i < numImages; i++) {
|
||||||
|
int start_index = i*width*height;
|
||||||
|
flipImage(width, height, start_index, images, images_copy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param width Width of image
|
||||||
|
* @param height Height of images
|
||||||
|
* @param start_index index into source buffer to copy to
|
||||||
|
* @param images Source images
|
||||||
|
* @param images_copy Destination images
|
||||||
|
*/
|
||||||
|
private static void flipImage(int width, int height, int start_index, IntBuffer images, IntBuffer images_copy) {
|
||||||
|
for (int y = 0; y < height>>1; y++) {
|
||||||
|
int index_y_1 = y*width + start_index;
|
||||||
|
int index_y_2 = (height - y - 1)*width + start_index;
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
int index1 = index_y_1 + x;
|
||||||
|
int index2 = index_y_2 + x;
|
||||||
|
int temp_pixel = images.get(index1 + images.position());
|
||||||
|
images_copy.put(index1, images.get(index2 + images.position()));
|
||||||
|
images_copy.put(index2, temp_pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the native handle associated with the cursor object.
|
||||||
|
*/
|
||||||
|
Object getHandle() {
|
||||||
|
checkValid();
|
||||||
|
return cursors[index].cursorHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkValid() {
|
||||||
|
if (destroyed)
|
||||||
|
throw new IllegalStateException("The cursor is destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the native cursor. If the cursor is current,
|
||||||
|
* the current native cursor is set to null (the default
|
||||||
|
* OS cursor)
|
||||||
|
*/
|
||||||
|
public void destroy() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (destroyed)
|
||||||
|
return;
|
||||||
|
if (Mouse.getNativeCursor() == this) {
|
||||||
|
try {
|
||||||
|
Mouse.setNativeCursor(null);
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ( CursorElement cursor : cursors ) {
|
||||||
|
Mouse.getImplementation().destroyCursor(cursor.cursorHandle);
|
||||||
|
}
|
||||||
|
destroyed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the timout property to the time it should be changed
|
||||||
|
*/
|
||||||
|
protected void setTimeout() {
|
||||||
|
checkValid();
|
||||||
|
cursors[index].timeout = System.currentTimeMillis() + cursors[index].delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this cursor has timed out
|
||||||
|
* @return true if the this cursor has timed out, false if not
|
||||||
|
*/
|
||||||
|
protected boolean hasTimedOut() {
|
||||||
|
checkValid();
|
||||||
|
return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes to the next cursor
|
||||||
|
*/
|
||||||
|
protected void nextCursor() {
|
||||||
|
checkValid();
|
||||||
|
index = ++index % cursors.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single cursor element, used when animating
|
||||||
|
*/
|
||||||
|
private static class CursorElement {
|
||||||
|
/** Handle to cursor */
|
||||||
|
final Object cursorHandle;
|
||||||
|
|
||||||
|
/** How long a delay this element should have */
|
||||||
|
final long delay;
|
||||||
|
|
||||||
|
/** Absolute time this element times out */
|
||||||
|
long timeout;
|
||||||
|
|
||||||
|
CursorElement(Object cursorHandle, long delay, long timeout) {
|
||||||
|
this.cursorHandle = cursorHandle;
|
||||||
|
this.delay = delay;
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,537 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.java.games.input.Component;
|
||||||
|
import net.java.games.input.Component.Identifier.Axis;
|
||||||
|
import net.java.games.input.Component.Identifier.Button;
|
||||||
|
import net.java.games.input.Event;
|
||||||
|
import net.java.games.input.EventQueue;
|
||||||
|
import net.java.games.input.Rumbler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper round a JInput controller that attempts to make the interface
|
||||||
|
* more useable.
|
||||||
|
*
|
||||||
|
* @author Kevin Glass
|
||||||
|
*/
|
||||||
|
class JInputController implements Controller {
|
||||||
|
/** The JInput controller this class is wrapping */
|
||||||
|
private net.java.games.input.Controller target;
|
||||||
|
/** The index that has been assigned to this controller */
|
||||||
|
private int index;
|
||||||
|
/** The Buttons that have been detected on the JInput controller */
|
||||||
|
private ArrayList<Component> buttons = new ArrayList<Component>();
|
||||||
|
/** The Axes that have been detected on the JInput controller */
|
||||||
|
private ArrayList<Component> axes = new ArrayList<Component>();
|
||||||
|
/** The POVs that have been detected on the JInput controller */
|
||||||
|
private ArrayList<Component> pov = new ArrayList<Component>();
|
||||||
|
/** The rumblers exposed by the controller */
|
||||||
|
private Rumbler[] rumblers;
|
||||||
|
/** The state of the buttons last check */
|
||||||
|
private boolean[] buttonState;
|
||||||
|
/** The values that were read from the pov last check */
|
||||||
|
private float[] povValues;
|
||||||
|
/** The values that were read from the axes last check */
|
||||||
|
private float[] axesValue;
|
||||||
|
/** The maximum values read for each axis */
|
||||||
|
private float[] axesMax;
|
||||||
|
/** The dead zones for each axis */
|
||||||
|
private float[] deadZones;
|
||||||
|
/** The index of the X axis or -1 if no X axis is defined */
|
||||||
|
private int xaxis = -1;
|
||||||
|
/** The index of the Y axis or -1 if no Y axis is defined */
|
||||||
|
private int yaxis = -1;
|
||||||
|
/** The index of the X axis or -1 if no Z axis is defined */
|
||||||
|
private int zaxis = -1;
|
||||||
|
/** The index of the RX axis or -1 if no RX axis is defined */
|
||||||
|
private int rxaxis = -1;
|
||||||
|
/** The index of the RY axis or -1 if no RY axis is defined */
|
||||||
|
private int ryaxis = -1;
|
||||||
|
/** The index of the RZ axis or -1 if no RZ axis is defined */
|
||||||
|
private int rzaxis = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller that wraps round a JInput controller and hopefully
|
||||||
|
* makes it easier to use.
|
||||||
|
*
|
||||||
|
* @param index The index this controller has been assigned to
|
||||||
|
* @param target The target JInput controller this class is wrapping
|
||||||
|
*/
|
||||||
|
JInputController(int index, net.java.games.input.Controller target) {
|
||||||
|
this.target = target;
|
||||||
|
this.index = index;
|
||||||
|
|
||||||
|
Component[] sourceAxes = target.getComponents();
|
||||||
|
|
||||||
|
for ( Component sourceAxis : sourceAxes ) {
|
||||||
|
if ( sourceAxis.getIdentifier() instanceof Button ) {
|
||||||
|
buttons.add(sourceAxis);
|
||||||
|
} else if ( sourceAxis.getIdentifier().equals(Axis.POV) ) {
|
||||||
|
pov.add(sourceAxis);
|
||||||
|
} else {
|
||||||
|
axes.add(sourceAxis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonState = new boolean[buttons.size()];
|
||||||
|
povValues = new float[pov.size()];
|
||||||
|
axesValue = new float[axes.size()];
|
||||||
|
int buttonsCount = 0;
|
||||||
|
int axesCount = 0;
|
||||||
|
|
||||||
|
// initialise the state
|
||||||
|
for ( Component sourceAxis : sourceAxes ) {
|
||||||
|
if ( sourceAxis.getIdentifier() instanceof Button ) {
|
||||||
|
buttonState[buttonsCount] = sourceAxis.getPollData() != 0;
|
||||||
|
buttonsCount++;
|
||||||
|
} else if ( sourceAxis.getIdentifier().equals(Axis.POV) ) {
|
||||||
|
// no account for POV yet
|
||||||
|
// pov.add(sourceAxes[i]);
|
||||||
|
} else {
|
||||||
|
axesValue[axesCount] = sourceAxis.getPollData();
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.X) ) {
|
||||||
|
xaxis = axesCount;
|
||||||
|
}
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.Y) ) {
|
||||||
|
yaxis = axesCount;
|
||||||
|
}
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.Z) ) {
|
||||||
|
zaxis = axesCount;
|
||||||
|
}
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.RX) ) {
|
||||||
|
rxaxis = axesCount;
|
||||||
|
}
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.RY) ) {
|
||||||
|
ryaxis = axesCount;
|
||||||
|
}
|
||||||
|
if ( sourceAxis.getIdentifier().equals(Axis.RZ) ) {
|
||||||
|
rzaxis = axesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
axesCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
axesMax = new float[axes.size()];
|
||||||
|
deadZones = new float[axes.size()];
|
||||||
|
|
||||||
|
for (int i=0;i<axesMax.length;i++) {
|
||||||
|
axesMax[i] = 1.0f;
|
||||||
|
deadZones[i] = 0.05f;
|
||||||
|
}
|
||||||
|
|
||||||
|
rumblers = target.getRumblers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
String name = target.getName();
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getIndex()
|
||||||
|
*/
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getButtonCount()
|
||||||
|
*/
|
||||||
|
public int getButtonCount() {
|
||||||
|
return buttons.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getButtonName(int)
|
||||||
|
*/
|
||||||
|
public String getButtonName(int index) {
|
||||||
|
return buttons.get(index).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#isButtonPressed(int)
|
||||||
|
*/
|
||||||
|
public boolean isButtonPressed(int index) {
|
||||||
|
return buttonState[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#poll()
|
||||||
|
*/
|
||||||
|
public void poll() {
|
||||||
|
target.poll();
|
||||||
|
|
||||||
|
Event event = new Event();
|
||||||
|
EventQueue queue = target.getEventQueue();
|
||||||
|
|
||||||
|
while (queue.getNextEvent(event)) {
|
||||||
|
// handle button event
|
||||||
|
if (buttons.contains(event.getComponent())) {
|
||||||
|
Component button = event.getComponent();
|
||||||
|
int buttonIndex = buttons.indexOf(button);
|
||||||
|
buttonState[buttonIndex] = event.getValue() != 0;
|
||||||
|
|
||||||
|
// fire button pressed event
|
||||||
|
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,
|
||||||
|
buttonState[buttonIndex],false,false,0,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle pov events
|
||||||
|
if (pov.contains(event.getComponent())) {
|
||||||
|
Component povComponent = event.getComponent();
|
||||||
|
int povIndex = pov.indexOf(povComponent);
|
||||||
|
float prevX = getPovX();
|
||||||
|
float prevY = getPovY();
|
||||||
|
povValues[povIndex] = event.getValue();
|
||||||
|
|
||||||
|
if (prevX != getPovX()) {
|
||||||
|
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVX,0,false,false));
|
||||||
|
}
|
||||||
|
if (prevY != getPovY()) {
|
||||||
|
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVY,0,false,false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle axis updates
|
||||||
|
if (axes.contains(event.getComponent())) {
|
||||||
|
Component axis = event.getComponent();
|
||||||
|
int axisIndex = axes.indexOf(axis);
|
||||||
|
float value = axis.getPollData();
|
||||||
|
float xaxisValue = 0;
|
||||||
|
float yaxisValue = 0;
|
||||||
|
|
||||||
|
// fixed dead zone since most axis don't report it :(
|
||||||
|
if (Math.abs(value) < deadZones[axisIndex]) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
if (Math.abs(value) < axis.getDeadZone()) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
if (Math.abs(value) > axesMax[axisIndex]) {
|
||||||
|
axesMax[axisIndex] = Math.abs(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize the value based on maximum value read in the past
|
||||||
|
value /= axesMax[axisIndex];
|
||||||
|
|
||||||
|
if (axisIndex == xaxis) {
|
||||||
|
xaxisValue = value;
|
||||||
|
}
|
||||||
|
if (axisIndex == yaxis) {
|
||||||
|
yaxisValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fire event
|
||||||
|
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,false,
|
||||||
|
axisIndex == xaxis,axisIndex == yaxis,xaxisValue,yaxisValue));
|
||||||
|
axesValue[axisIndex] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getAxisCount()
|
||||||
|
*/
|
||||||
|
public int getAxisCount() {
|
||||||
|
return axes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getAxisName(int)
|
||||||
|
*/
|
||||||
|
public String getAxisName(int index) {
|
||||||
|
return axes.get(index).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getAxisValue(int)
|
||||||
|
*/
|
||||||
|
public float getAxisValue(int index) {
|
||||||
|
return axesValue[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getXAxisValue()
|
||||||
|
*/
|
||||||
|
public float getXAxisValue() {
|
||||||
|
if (xaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(xaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getYAxisValue()
|
||||||
|
*/
|
||||||
|
public float getYAxisValue() {
|
||||||
|
if (yaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(yaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getXAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getXAxisDeadZone() {
|
||||||
|
if (xaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(xaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getYAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getYAxisDeadZone() {
|
||||||
|
if (yaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(yaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setXAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setXAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(xaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setYAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setYAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(yaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getDeadZone(int)
|
||||||
|
*/
|
||||||
|
public float getDeadZone(int index) {
|
||||||
|
return deadZones[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setDeadZone(int, float)
|
||||||
|
*/
|
||||||
|
public void setDeadZone(int index, float zone) {
|
||||||
|
deadZones[index] = zone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getZAxisValue()
|
||||||
|
*/
|
||||||
|
public float getZAxisValue() {
|
||||||
|
if (zaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(zaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getZAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getZAxisDeadZone() {
|
||||||
|
if (zaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(zaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setZAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setZAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(zaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRXAxisValue()
|
||||||
|
*/
|
||||||
|
public float getRXAxisValue() {
|
||||||
|
if (rxaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(rxaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRXAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getRXAxisDeadZone() {
|
||||||
|
if (rxaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(rxaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setRXAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setRXAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(rxaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRYAxisValue()
|
||||||
|
*/
|
||||||
|
public float getRYAxisValue() {
|
||||||
|
if (ryaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(ryaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRYAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getRYAxisDeadZone() {
|
||||||
|
if (ryaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(ryaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setRYAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setRYAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(ryaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRZAxisValue()
|
||||||
|
*/
|
||||||
|
public float getRZAxisValue() {
|
||||||
|
if (rzaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAxisValue(rzaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getRZAxisDeadZone()
|
||||||
|
*/
|
||||||
|
public float getRZAxisDeadZone() {
|
||||||
|
if (rzaxis == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDeadZone(rzaxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#setRZAxisDeadZone(float)
|
||||||
|
*/
|
||||||
|
public void setRZAxisDeadZone(float zone) {
|
||||||
|
setDeadZone(rzaxis,zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getPovX()
|
||||||
|
*/
|
||||||
|
public float getPovX() {
|
||||||
|
if (pov.size() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = povValues[0];
|
||||||
|
|
||||||
|
if ((value == Component.POV.DOWN_LEFT) ||
|
||||||
|
(value == Component.POV.UP_LEFT) ||
|
||||||
|
(value == Component.POV.LEFT)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((value == Component.POV.DOWN_RIGHT) ||
|
||||||
|
(value == Component.POV.UP_RIGHT) ||
|
||||||
|
(value == Component.POV.RIGHT)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.lwjgl.input.Controller#getPovY()
|
||||||
|
*/
|
||||||
|
public float getPovY() {
|
||||||
|
if (pov.size() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = povValues[0];
|
||||||
|
|
||||||
|
if ((value == Component.POV.DOWN_LEFT) ||
|
||||||
|
(value == Component.POV.DOWN_RIGHT) ||
|
||||||
|
(value == Component.POV.DOWN)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ((value == Component.POV.UP_LEFT) ||
|
||||||
|
(value == Component.POV.UP_RIGHT) ||
|
||||||
|
(value == Component.POV.UP)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRumblerCount() {
|
||||||
|
return rumblers.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRumblerName(int index) {
|
||||||
|
return rumblers[index].getAxisName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRumblerStrength(int index, float strength) {
|
||||||
|
rumblers[index].rumble(strength);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,610 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.Sys;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
import org.lwjgl.opengl.InputImplementation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <br>
|
||||||
|
* A raw Keyboard interface. This can be used to poll the current state of the
|
||||||
|
* keys, or read all the keyboard presses / releases since the last read.
|
||||||
|
*
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class Keyboard {
|
||||||
|
/** Internal use - event size in bytes */
|
||||||
|
public static final int EVENT_SIZE = 4 + 1 + 4 + 8 + 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The special character meaning that no
|
||||||
|
* character was translated for the event.
|
||||||
|
*/
|
||||||
|
public static final int CHAR_NONE = '\0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The special keycode meaning that only the
|
||||||
|
* translated character is valid.
|
||||||
|
*/
|
||||||
|
public static final int KEY_NONE = 0x00;
|
||||||
|
|
||||||
|
public static final int KEY_ESCAPE = 0x01;
|
||||||
|
public static final int KEY_1 = 0x02;
|
||||||
|
public static final int KEY_2 = 0x03;
|
||||||
|
public static final int KEY_3 = 0x04;
|
||||||
|
public static final int KEY_4 = 0x05;
|
||||||
|
public static final int KEY_5 = 0x06;
|
||||||
|
public static final int KEY_6 = 0x07;
|
||||||
|
public static final int KEY_7 = 0x08;
|
||||||
|
public static final int KEY_8 = 0x09;
|
||||||
|
public static final int KEY_9 = 0x0A;
|
||||||
|
public static final int KEY_0 = 0x0B;
|
||||||
|
public static final int KEY_MINUS = 0x0C; /* - on main keyboard */
|
||||||
|
public static final int KEY_EQUALS = 0x0D;
|
||||||
|
public static final int KEY_BACK = 0x0E; /* backspace */
|
||||||
|
public static final int KEY_TAB = 0x0F;
|
||||||
|
public static final int KEY_Q = 0x10;
|
||||||
|
public static final int KEY_W = 0x11;
|
||||||
|
public static final int KEY_E = 0x12;
|
||||||
|
public static final int KEY_R = 0x13;
|
||||||
|
public static final int KEY_T = 0x14;
|
||||||
|
public static final int KEY_Y = 0x15;
|
||||||
|
public static final int KEY_U = 0x16;
|
||||||
|
public static final int KEY_I = 0x17;
|
||||||
|
public static final int KEY_O = 0x18;
|
||||||
|
public static final int KEY_P = 0x19;
|
||||||
|
public static final int KEY_LBRACKET = 0x1A;
|
||||||
|
public static final int KEY_RBRACKET = 0x1B;
|
||||||
|
public static final int KEY_RETURN = 0x1C; /* Enter on main keyboard */
|
||||||
|
public static final int KEY_LCONTROL = 0x1D;
|
||||||
|
public static final int KEY_A = 0x1E;
|
||||||
|
public static final int KEY_S = 0x1F;
|
||||||
|
public static final int KEY_D = 0x20;
|
||||||
|
public static final int KEY_F = 0x21;
|
||||||
|
public static final int KEY_G = 0x22;
|
||||||
|
public static final int KEY_H = 0x23;
|
||||||
|
public static final int KEY_J = 0x24;
|
||||||
|
public static final int KEY_K = 0x25;
|
||||||
|
public static final int KEY_L = 0x26;
|
||||||
|
public static final int KEY_SEMICOLON = 0x27;
|
||||||
|
public static final int KEY_APOSTROPHE = 0x28;
|
||||||
|
public static final int KEY_GRAVE = 0x29; /* accent grave */
|
||||||
|
public static final int KEY_LSHIFT = 0x2A;
|
||||||
|
public static final int KEY_BACKSLASH = 0x2B;
|
||||||
|
public static final int KEY_Z = 0x2C;
|
||||||
|
public static final int KEY_X = 0x2D;
|
||||||
|
public static final int KEY_C = 0x2E;
|
||||||
|
public static final int KEY_V = 0x2F;
|
||||||
|
public static final int KEY_B = 0x30;
|
||||||
|
public static final int KEY_N = 0x31;
|
||||||
|
public static final int KEY_M = 0x32;
|
||||||
|
public static final int KEY_COMMA = 0x33;
|
||||||
|
public static final int KEY_PERIOD = 0x34; /* . on main keyboard */
|
||||||
|
public static final int KEY_SLASH = 0x35; /* / on main keyboard */
|
||||||
|
public static final int KEY_RSHIFT = 0x36;
|
||||||
|
public static final int KEY_MULTIPLY = 0x37; /* * on numeric keypad */
|
||||||
|
public static final int KEY_LMENU = 0x38; /* left Alt */
|
||||||
|
public static final int KEY_SPACE = 0x39;
|
||||||
|
public static final int KEY_CAPITAL = 0x3A;
|
||||||
|
public static final int KEY_F1 = 0x3B;
|
||||||
|
public static final int KEY_F2 = 0x3C;
|
||||||
|
public static final int KEY_F3 = 0x3D;
|
||||||
|
public static final int KEY_F4 = 0x3E;
|
||||||
|
public static final int KEY_F5 = 0x3F;
|
||||||
|
public static final int KEY_F6 = 0x40;
|
||||||
|
public static final int KEY_F7 = 0x41;
|
||||||
|
public static final int KEY_F8 = 0x42;
|
||||||
|
public static final int KEY_F9 = 0x43;
|
||||||
|
public static final int KEY_F10 = 0x44;
|
||||||
|
public static final int KEY_NUMLOCK = 0x45;
|
||||||
|
public static final int KEY_SCROLL = 0x46; /* Scroll Lock */
|
||||||
|
public static final int KEY_NUMPAD7 = 0x47;
|
||||||
|
public static final int KEY_NUMPAD8 = 0x48;
|
||||||
|
public static final int KEY_NUMPAD9 = 0x49;
|
||||||
|
public static final int KEY_SUBTRACT = 0x4A; /* - on numeric keypad */
|
||||||
|
public static final int KEY_NUMPAD4 = 0x4B;
|
||||||
|
public static final int KEY_NUMPAD5 = 0x4C;
|
||||||
|
public static final int KEY_NUMPAD6 = 0x4D;
|
||||||
|
public static final int KEY_ADD = 0x4E; /* + on numeric keypad */
|
||||||
|
public static final int KEY_NUMPAD1 = 0x4F;
|
||||||
|
public static final int KEY_NUMPAD2 = 0x50;
|
||||||
|
public static final int KEY_NUMPAD3 = 0x51;
|
||||||
|
public static final int KEY_NUMPAD0 = 0x52;
|
||||||
|
public static final int KEY_DECIMAL = 0x53; /* . on numeric keypad */
|
||||||
|
public static final int KEY_F11 = 0x57;
|
||||||
|
public static final int KEY_F12 = 0x58;
|
||||||
|
public static final int KEY_F13 = 0x64; /* (NEC PC98) */
|
||||||
|
public static final int KEY_F14 = 0x65; /* (NEC PC98) */
|
||||||
|
public static final int KEY_F15 = 0x66; /* (NEC PC98) */
|
||||||
|
public static final int KEY_F16 = 0x67; /* Extended Function keys - (Mac) */
|
||||||
|
public static final int KEY_F17 = 0x68;
|
||||||
|
public static final int KEY_F18 = 0x69;
|
||||||
|
public static final int KEY_KANA = 0x70; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_F19 = 0x71; /* Extended Function keys - (Mac) */
|
||||||
|
public static final int KEY_CONVERT = 0x79; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_NOCONVERT = 0x7B; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_YEN = 0x7D; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */
|
||||||
|
public static final int KEY_CIRCUMFLEX = 0x90; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_AT = 0x91; /* (NEC PC98) */
|
||||||
|
public static final int KEY_COLON = 0x92; /* (NEC PC98) */
|
||||||
|
public static final int KEY_UNDERLINE = 0x93; /* (NEC PC98) */
|
||||||
|
public static final int KEY_KANJI = 0x94; /* (Japanese keyboard) */
|
||||||
|
public static final int KEY_STOP = 0x95; /* (NEC PC98) */
|
||||||
|
public static final int KEY_AX = 0x96; /* (Japan AX) */
|
||||||
|
public static final int KEY_UNLABELED = 0x97; /* (J3100) */
|
||||||
|
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
|
||||||
|
public static final int KEY_RCONTROL = 0x9D;
|
||||||
|
public static final int KEY_SECTION = 0xA7; /* Section symbol (Mac) */
|
||||||
|
public static final int KEY_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
|
||||||
|
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
|
||||||
|
public static final int KEY_SYSRQ = 0xB7;
|
||||||
|
public static final int KEY_RMENU = 0xB8; /* right Alt */
|
||||||
|
public static final int KEY_FUNCTION = 0xC4; /* Function (Mac) */
|
||||||
|
public static final int KEY_PAUSE = 0xC5; /* Pause */
|
||||||
|
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
|
||||||
|
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
|
||||||
|
public static final int KEY_PRIOR = 0xC9; /* PgUp on arrow keypad */
|
||||||
|
public static final int KEY_LEFT = 0xCB; /* LeftArrow on arrow keypad */
|
||||||
|
public static final int KEY_RIGHT = 0xCD; /* RightArrow on arrow keypad */
|
||||||
|
public static final int KEY_END = 0xCF; /* End on arrow keypad */
|
||||||
|
public static final int KEY_DOWN = 0xD0; /* DownArrow on arrow keypad */
|
||||||
|
public static final int KEY_NEXT = 0xD1; /* PgDn on arrow keypad */
|
||||||
|
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
|
||||||
|
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
|
||||||
|
public static final int KEY_CLEAR = 0xDA; /* Clear key (Mac) */
|
||||||
|
public static final int KEY_LMETA = 0xDB; /* Left Windows/Option key */
|
||||||
|
/**
|
||||||
|
* The left windows key, mapped to KEY_LMETA
|
||||||
|
*
|
||||||
|
* @deprecated Use KEY_LMETA instead
|
||||||
|
*/
|
||||||
|
public static final int KEY_LWIN = KEY_LMETA; /* Left Windows key */
|
||||||
|
public static final int KEY_RMETA = 0xDC; /* Right Windows/Option key */
|
||||||
|
/**
|
||||||
|
* The right windows key, mapped to KEY_RMETA
|
||||||
|
*
|
||||||
|
* @deprecated Use KEY_RMETA instead
|
||||||
|
*/
|
||||||
|
public static final int KEY_RWIN = KEY_RMETA; /* Right Windows key */
|
||||||
|
public static final int KEY_APPS = 0xDD; /* AppMenu key */
|
||||||
|
public static final int KEY_POWER = 0xDE;
|
||||||
|
public static final int KEY_SLEEP = 0xDF;
|
||||||
|
|
||||||
|
/* public static final int STATE_ON = 0;
|
||||||
|
public static final int STATE_OFF = 1;
|
||||||
|
public static final int STATE_UNKNOWN = 2;
|
||||||
|
*/
|
||||||
|
public static final int KEYBOARD_SIZE = 256;
|
||||||
|
|
||||||
|
/** Buffer size in events */
|
||||||
|
private static final int BUFFER_SIZE = 50;
|
||||||
|
|
||||||
|
/** Key names */
|
||||||
|
private static final String[] keyName = new String[KEYBOARD_SIZE];
|
||||||
|
private static final Map<String, Integer> keyMap = new HashMap<String, Integer>(253);
|
||||||
|
private static int counter;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Use reflection to find out key names
|
||||||
|
Field[] fields = Keyboard.class.getFields();
|
||||||
|
try {
|
||||||
|
for ( Field field : fields ) {
|
||||||
|
if ( Modifier.isStatic(field.getModifiers())
|
||||||
|
&& Modifier.isPublic(field.getModifiers())
|
||||||
|
&& Modifier.isFinal(field.getModifiers())
|
||||||
|
&& field.getType().equals(int.class)
|
||||||
|
&& field.getName().startsWith("KEY_")
|
||||||
|
&& !field.getName().endsWith("WIN") ) { /* Don't use deprecated names */
|
||||||
|
|
||||||
|
int key = field.getInt(null);
|
||||||
|
String name = field.getName().substring(4);
|
||||||
|
keyName[key] = name;
|
||||||
|
keyMap.put(name, key);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The number of keys supported */
|
||||||
|
private static final int keyCount = counter;
|
||||||
|
|
||||||
|
/** Has the keyboard been created? */
|
||||||
|
private static boolean created;
|
||||||
|
|
||||||
|
/** Are repeat events enabled? */
|
||||||
|
private static boolean repeat_enabled;
|
||||||
|
|
||||||
|
/** The keys status from the last poll */
|
||||||
|
private static final ByteBuffer keyDownBuffer = BufferUtils.createByteBuffer(KEYBOARD_SIZE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key events from the last read: a sequence of pairs of key number,
|
||||||
|
* followed by state. The state is followed by
|
||||||
|
* a 4 byte code point representing the translated character.
|
||||||
|
*/
|
||||||
|
private static ByteBuffer readBuffer;
|
||||||
|
|
||||||
|
/** current event */
|
||||||
|
private static KeyEvent current_event = new KeyEvent();
|
||||||
|
|
||||||
|
/** scratch event */
|
||||||
|
private static KeyEvent tmp_event = new KeyEvent();
|
||||||
|
|
||||||
|
/** One time initialization */
|
||||||
|
private static boolean initialized;
|
||||||
|
|
||||||
|
private static InputImplementation implementation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keyboard cannot be constructed.
|
||||||
|
*/
|
||||||
|
private Keyboard() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static initialization
|
||||||
|
*/
|
||||||
|
private static void initialize() {
|
||||||
|
if (initialized)
|
||||||
|
return;
|
||||||
|
Sys.initialize();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Create" the keyboard with the given implementation. This is used
|
||||||
|
* reflectively from AWTInputAdapter.
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if the keyboard could not be created for any reason
|
||||||
|
*/
|
||||||
|
private static void create(InputImplementation impl) throws LWJGLException {
|
||||||
|
if (created)
|
||||||
|
return;
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
|
implementation = impl;
|
||||||
|
implementation.createKeyboard();
|
||||||
|
created = true;
|
||||||
|
readBuffer = ByteBuffer.allocate(EVENT_SIZE*BUFFER_SIZE);
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Create" the keyboard. The display must first have been created. The
|
||||||
|
* reason for this is so the keyboard has a window to "focus" in.
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if the keyboard could not be created for any reason
|
||||||
|
*/
|
||||||
|
public static void create() throws LWJGLException {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!Display.isCreated()) throw new IllegalStateException("Display must be created.");
|
||||||
|
|
||||||
|
create(OpenGLPackageAccess.createImplementation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void reset() {
|
||||||
|
readBuffer.limit(0);
|
||||||
|
for (int i = 0; i < keyDownBuffer.remaining(); i++)
|
||||||
|
keyDownBuffer.put(i, (byte)0);
|
||||||
|
current_event.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the keyboard has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Destroy" the keyboard
|
||||||
|
*/
|
||||||
|
public static void destroy() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created)
|
||||||
|
return;
|
||||||
|
created = false;
|
||||||
|
implementation.destroyKeyboard();
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polls the keyboard for its current state. Access the polled values using the
|
||||||
|
* <code>isKeyDown</code> method.
|
||||||
|
* By using this method, it is possible to "miss" keyboard keys if you don't
|
||||||
|
* poll fast enough.
|
||||||
|
*
|
||||||
|
* To use buffered values, you have to call <code>next</code> for each event you
|
||||||
|
* want to read. You can query which key caused the event by using
|
||||||
|
* <code>getEventKey</code>. To get the state of that key, for that event, use
|
||||||
|
* <code>getEventKeyState</code> - finally use <code>getEventCharacter</code> to get the
|
||||||
|
* character for that event.
|
||||||
|
*
|
||||||
|
* NOTE: This method does not query the operating system for new events. To do that,
|
||||||
|
* Display.processMessages() (or Display.update()) must be called first.
|
||||||
|
*
|
||||||
|
* @see Keyboard#isKeyDown(int key)
|
||||||
|
* @see Keyboard#next()
|
||||||
|
* @see Keyboard#getEventKey()
|
||||||
|
* @see Keyboard#getEventKeyState()
|
||||||
|
* @see Keyboard#getEventCharacter()
|
||||||
|
*/
|
||||||
|
public static void poll() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created)
|
||||||
|
throw new IllegalStateException("Keyboard must be created before you can poll the device");
|
||||||
|
implementation.pollKeyboard(keyDownBuffer);
|
||||||
|
read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read() {
|
||||||
|
readBuffer.compact();
|
||||||
|
implementation.readKeyboard(readBuffer);
|
||||||
|
readBuffer.flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a key is down.
|
||||||
|
* @param key Keycode to check
|
||||||
|
* @return true if the key is down according to the last poll()
|
||||||
|
*/
|
||||||
|
public static boolean isKeyDown(int key) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created)
|
||||||
|
throw new IllegalStateException("Keyboard must be created before you can query key state");
|
||||||
|
return keyDownBuffer.get(key) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether one of the state keys are "active"
|
||||||
|
*
|
||||||
|
* @param key State key to test (KEY_CAPITAL | KEY_NUMLOCK | KEY_SYSRQ)
|
||||||
|
* @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
|
||||||
|
*/
|
||||||
|
/* public static int isStateKeySet(int key) {
|
||||||
|
if (!created)
|
||||||
|
throw new IllegalStateException("Keyboard must be created before you can query key state");
|
||||||
|
return implementation.isStateKeySet(key);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Gets a key's name
|
||||||
|
* @param key The key
|
||||||
|
* @return a String with the key's human readable name in it or null if the key is unnamed
|
||||||
|
*/
|
||||||
|
public static synchronized String getKeyName(int key) {
|
||||||
|
return keyName[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's a key's index. If the key is unrecognised then KEY_NONE is returned.
|
||||||
|
* @param keyName The key name
|
||||||
|
*/
|
||||||
|
public static synchronized int getKeyIndex(String keyName) {
|
||||||
|
Integer ret = keyMap.get(keyName);
|
||||||
|
if (ret == null)
|
||||||
|
return KEY_NONE;
|
||||||
|
else
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of keyboard events waiting after doing a buffer enabled poll().
|
||||||
|
* @return the number of keyboard events
|
||||||
|
*/
|
||||||
|
public static int getNumKeyboardEvents() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created)
|
||||||
|
throw new IllegalStateException("Keyboard must be created before you can read events");
|
||||||
|
int old_position = readBuffer.position();
|
||||||
|
int num_events = 0;
|
||||||
|
while (readNext(tmp_event) && (!tmp_event.repeat || repeat_enabled))
|
||||||
|
num_events++;
|
||||||
|
readBuffer.position(old_position);
|
||||||
|
return num_events;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the next keyboard event. You can query which key caused the event by using
|
||||||
|
* <code>getEventKey</code>. To get the state of that key, for that event, use
|
||||||
|
* <code>getEventKeyState</code> - finally use <code>getEventCharacter</code> to get the
|
||||||
|
* character for that event.
|
||||||
|
*
|
||||||
|
* @see Keyboard#getEventKey()
|
||||||
|
* @see Keyboard#getEventKeyState()
|
||||||
|
* @see Keyboard#getEventCharacter()
|
||||||
|
* @return true if a keyboard event was read, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean next() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created)
|
||||||
|
throw new IllegalStateException("Keyboard must be created before you can read events");
|
||||||
|
|
||||||
|
boolean result;
|
||||||
|
while ((result = readNext(current_event)) && current_event.repeat && !repeat_enabled)
|
||||||
|
;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether repeat events are reported or not. If repeat events
|
||||||
|
* are enabled, key down events are reported when a key is pressed and held for
|
||||||
|
* a OS dependent amount of time. To distinguish a repeat event from a normal event,
|
||||||
|
* use isRepeatEvent().
|
||||||
|
*
|
||||||
|
* @see Keyboard#getEventKey()
|
||||||
|
*/
|
||||||
|
public static void enableRepeatEvents(boolean enable) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
repeat_enabled = enable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether repeat events are currently reported or not.
|
||||||
|
*
|
||||||
|
* @return true is repeat events are reported, false if not.
|
||||||
|
* @see Keyboard#getEventKey()
|
||||||
|
*/
|
||||||
|
public static boolean areRepeatEventsEnabled() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return repeat_enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean readNext(KeyEvent event) {
|
||||||
|
if (readBuffer.hasRemaining()) {
|
||||||
|
event.key = readBuffer.getInt() & 0xFF;
|
||||||
|
event.state = readBuffer.get() != 0;
|
||||||
|
event.character = readBuffer.getInt();
|
||||||
|
event.nanos = readBuffer.getLong();
|
||||||
|
event.repeat = readBuffer.get() == 1;
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Number of keys on this keyboard
|
||||||
|
*/
|
||||||
|
public static int getKeyCount() {
|
||||||
|
return keyCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The character from the current event
|
||||||
|
*/
|
||||||
|
public static char getEventCharacter() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return (char)current_event.character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Please note that the key code returned is NOT valid against the
|
||||||
|
* current keyboard layout. To get the actual character pressed call
|
||||||
|
* getEventCharacter
|
||||||
|
*
|
||||||
|
* @return The key from the current event
|
||||||
|
*/
|
||||||
|
public static int getEventKey() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return current_event.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the state of the key that generated the
|
||||||
|
* current event
|
||||||
|
*
|
||||||
|
* @return True if key was down, or false if released
|
||||||
|
*/
|
||||||
|
public static boolean getEventKeyState() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return current_event.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time in nanoseconds of the current event.
|
||||||
|
* Only useful for relative comparisons with other
|
||||||
|
* Keyboard events, as the absolute time has no defined
|
||||||
|
* origin.
|
||||||
|
* @return The time in nanoseconds of the current event
|
||||||
|
*/
|
||||||
|
public static long getEventNanoseconds() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return current_event.nanos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Keyboard#enableRepeatEvents(boolean)
|
||||||
|
* @return true if the current event is a repeat event, false if
|
||||||
|
* the current event is not a repeat even or if repeat events are disabled.
|
||||||
|
*/
|
||||||
|
public static boolean isRepeatEvent() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return current_event.repeat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class KeyEvent {
|
||||||
|
/** The current keyboard character being examined */
|
||||||
|
private int character;
|
||||||
|
|
||||||
|
/** The current keyboard event key being examined */
|
||||||
|
private int key;
|
||||||
|
|
||||||
|
/** The current state of the key being examined in the event queue */
|
||||||
|
private boolean state;
|
||||||
|
|
||||||
|
/** The current event time */
|
||||||
|
private long nanos;
|
||||||
|
|
||||||
|
/** Is the current event a repeated event? */
|
||||||
|
private boolean repeat;
|
||||||
|
|
||||||
|
private void reset() {
|
||||||
|
character = 0;
|
||||||
|
key = 0;
|
||||||
|
state = false;
|
||||||
|
repeat = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,712 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
import org.lwjgl.Sys;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
import org.lwjgl.opengl.InputImplementation;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <br>
|
||||||
|
* A raw Mouse interface. This can be used to poll the current state of the
|
||||||
|
* mouse buttons, and determine the mouse movement delta since the last poll.
|
||||||
|
*
|
||||||
|
* n buttons supported, n being a native limit. A scrolly wheel is also
|
||||||
|
* supported, if one such is available. Movement is reported as delta from
|
||||||
|
* last position or as an absolute position. If the window has been created
|
||||||
|
* the absolute position will be clamped to 0 - width | height.
|
||||||
|
*
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class Mouse {
|
||||||
|
/** Internal use - event size in bytes */
|
||||||
|
public static final int EVENT_SIZE = 1 + 1 + 4 + 4 + 4 + 8;
|
||||||
|
|
||||||
|
/** Has the mouse been created? */
|
||||||
|
private static boolean created;
|
||||||
|
|
||||||
|
/** The mouse buttons status from the last poll */
|
||||||
|
private static ByteBuffer buttons;
|
||||||
|
|
||||||
|
/** Mouse absolute X position in pixels */
|
||||||
|
private static int x;
|
||||||
|
|
||||||
|
/** Mouse absolute Y position in pixels */
|
||||||
|
private static int y;
|
||||||
|
|
||||||
|
/** Mouse absolute X position in pixels without any clipping */
|
||||||
|
private static int absolute_x;
|
||||||
|
|
||||||
|
/** Mouse absolute Y position in pixels without any clipping */
|
||||||
|
private static int absolute_y;
|
||||||
|
|
||||||
|
/** Buffer to hold the deltas dx, dy and dwheel */
|
||||||
|
private static IntBuffer coord_buffer;
|
||||||
|
|
||||||
|
/** Delta X */
|
||||||
|
private static int dx;
|
||||||
|
|
||||||
|
/** Delta Y */
|
||||||
|
private static int dy;
|
||||||
|
|
||||||
|
/** Delta Z */
|
||||||
|
private static int dwheel;
|
||||||
|
|
||||||
|
/** Number of buttons supported by the mouse */
|
||||||
|
private static int buttonCount = -1;
|
||||||
|
|
||||||
|
/** Does this mouse support a scroll wheel */
|
||||||
|
private static boolean hasWheel;
|
||||||
|
|
||||||
|
/** The current native cursor, if any */
|
||||||
|
private static Cursor currentCursor;
|
||||||
|
|
||||||
|
/** Button names. These are set upon create(), to names like BUTTON0, BUTTON1, etc. */
|
||||||
|
private static String[] buttonName;
|
||||||
|
|
||||||
|
/** hashmap of button names, for fast lookup */
|
||||||
|
private static final Map<String, Integer> buttonMap = new HashMap<String, Integer>(16);
|
||||||
|
|
||||||
|
/** Lazy initialization */
|
||||||
|
private static boolean initialized;
|
||||||
|
|
||||||
|
/** The mouse button events from the last read */
|
||||||
|
private static ByteBuffer readBuffer;
|
||||||
|
|
||||||
|
/** The current mouse event button being examined */
|
||||||
|
private static int eventButton;
|
||||||
|
|
||||||
|
/** The current state of the button being examined in the event queue */
|
||||||
|
private static boolean eventState;
|
||||||
|
|
||||||
|
/** The current delta of the mouse in the event queue */
|
||||||
|
private static int event_dx;
|
||||||
|
private static int event_dy;
|
||||||
|
private static int event_dwheel;
|
||||||
|
/** The current absolute position of the mouse in the event queue */
|
||||||
|
private static int event_x;
|
||||||
|
private static int event_y;
|
||||||
|
private static long event_nanos;
|
||||||
|
/** The position of the mouse it was grabbed at */
|
||||||
|
private static int grab_x;
|
||||||
|
private static int grab_y;
|
||||||
|
/** The last absolute mouse event position (before clipping) for delta computation */
|
||||||
|
private static int last_event_raw_x;
|
||||||
|
private static int last_event_raw_y;
|
||||||
|
|
||||||
|
/** Buffer size in events */
|
||||||
|
private static final int BUFFER_SIZE = 50;
|
||||||
|
|
||||||
|
private static boolean isGrabbed;
|
||||||
|
|
||||||
|
private static InputImplementation implementation;
|
||||||
|
|
||||||
|
/** Whether we need cursor animation emulation */
|
||||||
|
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS ||
|
||||||
|
LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX;
|
||||||
|
|
||||||
|
private static boolean clipMouseCoordinatesToWindow = !getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mouse cannot be constructed.
|
||||||
|
*/
|
||||||
|
private Mouse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the currently bound native cursor, if any.
|
||||||
|
*
|
||||||
|
* @return the currently bound native cursor, if any.
|
||||||
|
*/
|
||||||
|
public static Cursor getNativeCursor() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return currentCursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a native cursor. If the cursor argument is null, any
|
||||||
|
* currently bound native cursor is disabled, and the cursor reverts
|
||||||
|
* to the default operating system supplied cursor.
|
||||||
|
*
|
||||||
|
* NOTE: The native cursor is not constrained to the window, but
|
||||||
|
* relative events will not be generated if the cursor is outside.
|
||||||
|
*
|
||||||
|
* @param cursor the native cursor object to bind. May be null.
|
||||||
|
* @return The previous Cursor object set, or null.
|
||||||
|
* @throws LWJGLException if the cursor could not be set for any reason
|
||||||
|
*/
|
||||||
|
public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0)
|
||||||
|
throw new IllegalStateException("Mouse doesn't support native cursors");
|
||||||
|
Cursor oldCursor = currentCursor;
|
||||||
|
currentCursor = cursor;
|
||||||
|
if (isCreated()) {
|
||||||
|
if (currentCursor != null) {
|
||||||
|
implementation.setNativeCursor(currentCursor.getHandle());
|
||||||
|
currentCursor.setTimeout();
|
||||||
|
} else {
|
||||||
|
implementation.setNativeCursor(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oldCursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isClipMouseCoordinatesToWindow() {
|
||||||
|
return clipMouseCoordinatesToWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setClipMouseCoordinatesToWindow(boolean clip) {
|
||||||
|
clipMouseCoordinatesToWindow = clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the position of the cursor. If the cursor is not grabbed,
|
||||||
|
* the native cursor is moved to the new position.
|
||||||
|
*
|
||||||
|
* @param new_x The x coordinate of the new cursor position in OpenGL coordinates relative
|
||||||
|
* to the window origin.
|
||||||
|
* @param new_y The y coordinate of the new cursor position in OpenGL coordinates relative
|
||||||
|
* to the window origin.
|
||||||
|
*/
|
||||||
|
public static void setCursorPosition(int new_x, int new_y) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!isCreated())
|
||||||
|
throw new IllegalStateException("Mouse is not created");
|
||||||
|
x = event_x = new_x;
|
||||||
|
y = event_y = new_y;
|
||||||
|
if (!isGrabbed() && (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) {
|
||||||
|
implementation.setCursorPosition(x, y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
grab_x = new_x;
|
||||||
|
grab_y = new_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static initialization
|
||||||
|
*/
|
||||||
|
private static void initialize() {
|
||||||
|
Sys.initialize();
|
||||||
|
|
||||||
|
// Assign names to all the buttons
|
||||||
|
buttonName = new String[16];
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
buttonName[i] = "BUTTON" + i;
|
||||||
|
buttonMap.put(buttonName[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetMouse() {
|
||||||
|
dx = dy = dwheel = 0;
|
||||||
|
readBuffer.position(readBuffer.limit());
|
||||||
|
}
|
||||||
|
|
||||||
|
static InputImplementation getImplementation() {
|
||||||
|
return implementation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Create" the mouse with the given custom implementation. This is used
|
||||||
|
* reflectively by AWTInputAdapter.
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if the mouse could not be created for any reason
|
||||||
|
*/
|
||||||
|
private static void create(InputImplementation impl) throws LWJGLException {
|
||||||
|
if (created)
|
||||||
|
return;
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
|
implementation = impl;
|
||||||
|
implementation.createMouse();
|
||||||
|
hasWheel = implementation.hasWheel();
|
||||||
|
created = true;
|
||||||
|
|
||||||
|
// set mouse buttons
|
||||||
|
buttonCount = implementation.getButtonCount();
|
||||||
|
buttons = BufferUtils.createByteBuffer(buttonCount);
|
||||||
|
coord_buffer = BufferUtils.createIntBuffer(3);
|
||||||
|
if (currentCursor != null && implementation.getNativeCursorCapabilities() != 0)
|
||||||
|
setNativeCursor(currentCursor);
|
||||||
|
readBuffer = ByteBuffer.allocate(EVENT_SIZE * BUFFER_SIZE);
|
||||||
|
readBuffer.limit(0);
|
||||||
|
setGrabbed(isGrabbed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Create" the mouse. The display must first have been created.
|
||||||
|
* Initially, the mouse is not grabbed and the delta values are reported
|
||||||
|
* with respect to the center of the display.
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if the mouse could not be created for any reason
|
||||||
|
*/
|
||||||
|
public static void create() throws LWJGLException {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!Display.isCreated()) throw new IllegalStateException("Display must be created.");
|
||||||
|
|
||||||
|
create(OpenGLPackageAccess.createImplementation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the mouse has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Destroy" the mouse.
|
||||||
|
*/
|
||||||
|
public static void destroy() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created) return;
|
||||||
|
created = false;
|
||||||
|
buttons = null;
|
||||||
|
coord_buffer = null;
|
||||||
|
|
||||||
|
implementation.destroyMouse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polls the mouse for its current state. Access the polled values using the
|
||||||
|
* get<value> methods.
|
||||||
|
* By using this method, it is possible to "miss" mouse click events if you don't
|
||||||
|
* poll fast enough.
|
||||||
|
*
|
||||||
|
* To use buffered values, you have to call <code>next</code> for each event you
|
||||||
|
* want to read. You can query which button caused the event by using
|
||||||
|
* <code>getEventButton</code>. To get the state of that button, for that event, use
|
||||||
|
* <code>getEventButtonState</code>.
|
||||||
|
*
|
||||||
|
* NOTE: This method does not query the operating system for new events. To do that,
|
||||||
|
* Display.processMessages() (or Display.update()) must be called first.
|
||||||
|
*
|
||||||
|
* @see Mouse#next()
|
||||||
|
* @see Mouse#getEventButton()
|
||||||
|
* @see Mouse#getEventButtonState()
|
||||||
|
* @see Mouse#isButtonDown(int button)
|
||||||
|
* @see Mouse#getX()
|
||||||
|
* @see Mouse#getY()
|
||||||
|
* @see Mouse#getDX()
|
||||||
|
* @see Mouse#getDY()
|
||||||
|
* @see Mouse#getDWheel()
|
||||||
|
*/
|
||||||
|
public static void poll() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created) throw new IllegalStateException("Mouse must be created before you can poll it");
|
||||||
|
implementation.pollMouse(coord_buffer, buttons);
|
||||||
|
|
||||||
|
/* If we're grabbed, poll returns mouse deltas, if not it returns absolute coordinates */
|
||||||
|
int poll_coord1 = coord_buffer.get(0);
|
||||||
|
int poll_coord2 = coord_buffer.get(1);
|
||||||
|
/* The wheel is always relative */
|
||||||
|
int poll_dwheel = coord_buffer.get(2);
|
||||||
|
|
||||||
|
if (isGrabbed()) {
|
||||||
|
dx += poll_coord1;
|
||||||
|
dy += poll_coord2;
|
||||||
|
x += poll_coord1;
|
||||||
|
y += poll_coord2;
|
||||||
|
absolute_x += poll_coord1;
|
||||||
|
absolute_y += poll_coord2;
|
||||||
|
} else {
|
||||||
|
dx = poll_coord1 - absolute_x;
|
||||||
|
dy = poll_coord2 - absolute_y;
|
||||||
|
absolute_x = x = poll_coord1;
|
||||||
|
absolute_y = y = poll_coord2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(clipMouseCoordinatesToWindow) {
|
||||||
|
x = Math.min(Display.getWidth() - 1, Math.max(0, x));
|
||||||
|
y = Math.min(Display.getHeight() - 1, Math.max(0, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
dwheel += poll_dwheel;
|
||||||
|
read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read() {
|
||||||
|
readBuffer.compact();
|
||||||
|
implementation.readMouse(readBuffer);
|
||||||
|
readBuffer.flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See if a particular mouse button is down.
|
||||||
|
*
|
||||||
|
* @param button The index of the button you wish to test (0..getButtonCount-1)
|
||||||
|
* @return true if the specified button is down
|
||||||
|
*/
|
||||||
|
public static boolean isButtonDown(int button) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created) throw new IllegalStateException("Mouse must be created before you can poll the button state");
|
||||||
|
if (button >= buttonCount || button < 0)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return buttons.get(button) == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a button's name
|
||||||
|
* @param button The button
|
||||||
|
* @return a String with the button's human readable name in it or null if the button is unnamed
|
||||||
|
*/
|
||||||
|
public static String getButtonName(int button) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (button >= buttonName.length || button < 0)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return buttonName[button];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's a button's index. If the button is unrecognised then -1 is returned.
|
||||||
|
* @param buttonName The button name
|
||||||
|
*/
|
||||||
|
public static int getButtonIndex(String buttonName) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
Integer ret = buttonMap.get(buttonName);
|
||||||
|
if (ret == null)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the next mouse event. You can query which button caused the event by using
|
||||||
|
* <code>getEventButton()</code> (if any). To get the state of that key, for that event, use
|
||||||
|
* <code>getEventButtonState</code>. To get the current mouse delta values use <code>getEventDX()</code>
|
||||||
|
* and <code>getEventDY()</code>.
|
||||||
|
* @see Mouse#getEventButton()
|
||||||
|
* @see Mouse#getEventButtonState()
|
||||||
|
* @return true if a mouse event was read, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean next() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (!created) throw new IllegalStateException("Mouse must be created before you can read events");
|
||||||
|
if (readBuffer.hasRemaining()) {
|
||||||
|
eventButton = readBuffer.get();
|
||||||
|
eventState = readBuffer.get() != 0;
|
||||||
|
if (isGrabbed()) {
|
||||||
|
event_dx = readBuffer.getInt();
|
||||||
|
event_dy = readBuffer.getInt();
|
||||||
|
event_x += event_dx;
|
||||||
|
event_y += event_dy;
|
||||||
|
last_event_raw_x = event_x;
|
||||||
|
last_event_raw_y = event_y;
|
||||||
|
} else {
|
||||||
|
int new_event_x = readBuffer.getInt();
|
||||||
|
int new_event_y = readBuffer.getInt();
|
||||||
|
event_dx = new_event_x - last_event_raw_x;
|
||||||
|
event_dy = new_event_y - last_event_raw_y;
|
||||||
|
event_x = new_event_x;
|
||||||
|
event_y = new_event_y;
|
||||||
|
last_event_raw_x = new_event_x;
|
||||||
|
last_event_raw_y = new_event_y;
|
||||||
|
}
|
||||||
|
if(clipMouseCoordinatesToWindow) {
|
||||||
|
event_x = Math.min(Display.getWidth() - 1, Math.max(0, event_x));
|
||||||
|
event_y = Math.min(Display.getHeight() - 1, Math.max(0, event_y));
|
||||||
|
}
|
||||||
|
event_dwheel = readBuffer.getInt();
|
||||||
|
event_nanos = readBuffer.getLong();
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events button. Returns -1 if no button state was changed
|
||||||
|
*/
|
||||||
|
public static int getEventButton() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return eventButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current events button state.
|
||||||
|
* @return Current events button state.
|
||||||
|
*/
|
||||||
|
public static boolean getEventButtonState() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return eventState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events delta x.
|
||||||
|
*/
|
||||||
|
public static int getEventDX() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_dx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events delta y.
|
||||||
|
*/
|
||||||
|
public static int getEventDY() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events absolute x.
|
||||||
|
*/
|
||||||
|
public static int getEventX() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events absolute y.
|
||||||
|
*/
|
||||||
|
public static int getEventY() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Current events delta z
|
||||||
|
*/
|
||||||
|
public static int getEventDWheel() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_dwheel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time in nanoseconds of the current event.
|
||||||
|
* Only useful for relative comparisons with other
|
||||||
|
* Mouse events, as the absolute time has no defined
|
||||||
|
* origin.
|
||||||
|
*
|
||||||
|
* @return The time in nanoseconds of the current event
|
||||||
|
*/
|
||||||
|
public static long getEventNanoseconds() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return event_nanos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the absolute position. It will be clamped to
|
||||||
|
* 0...width-1.
|
||||||
|
*
|
||||||
|
* @return Absolute x axis position of mouse
|
||||||
|
*/
|
||||||
|
public static int getX() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the absolute position. It will be clamped to
|
||||||
|
* 0...height-1.
|
||||||
|
*
|
||||||
|
* @return Absolute y axis position of mouse
|
||||||
|
*/
|
||||||
|
public static int getY() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Movement on the x axis since last time getDX() was called.
|
||||||
|
*/
|
||||||
|
public static int getDX() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
int result = dx;
|
||||||
|
dx = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Movement on the y axis since last time getDY() was called.
|
||||||
|
*/
|
||||||
|
public static int getDY() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
int result = dy;
|
||||||
|
dy = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Movement of the wheel since last time getDWheel() was called
|
||||||
|
*/
|
||||||
|
public static int getDWheel() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
int result = dwheel;
|
||||||
|
dwheel = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Number of buttons on this mouse
|
||||||
|
*/
|
||||||
|
public static int getButtonCount() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return buttonCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether or not this mouse has wheel support
|
||||||
|
*/
|
||||||
|
public static boolean hasWheel() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return hasWheel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether or not the mouse has grabbed the cursor
|
||||||
|
*/
|
||||||
|
public static boolean isGrabbed() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
return isGrabbed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not the mouse has grabbed the cursor
|
||||||
|
* (and thus hidden). If grab is false, the getX() and getY()
|
||||||
|
* will return delta movement in pixels clamped to the display
|
||||||
|
* dimensions, from the center of the display.
|
||||||
|
*
|
||||||
|
* @param grab whether the mouse should be grabbed
|
||||||
|
*/
|
||||||
|
public static void setGrabbed(boolean grab) {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
boolean grabbed = isGrabbed;
|
||||||
|
isGrabbed = grab;
|
||||||
|
if (isCreated()) {
|
||||||
|
if (grab && !grabbed) {
|
||||||
|
// store location mouse was grabbed
|
||||||
|
grab_x = x;
|
||||||
|
grab_y = y;
|
||||||
|
}
|
||||||
|
else if (!grab && grabbed) {
|
||||||
|
// move mouse back to location it was grabbed before ungrabbing
|
||||||
|
if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0)
|
||||||
|
implementation.setCursorPosition(grab_x, grab_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
implementation.grabMouse(grab);
|
||||||
|
// Get latest values from native side
|
||||||
|
poll();
|
||||||
|
event_x = x;
|
||||||
|
event_y = y;
|
||||||
|
last_event_raw_x = x;
|
||||||
|
last_event_raw_y = y;
|
||||||
|
resetMouse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the cursor, so that animation can be changed if needed.
|
||||||
|
* This method is called automatically by the window on its update, and
|
||||||
|
* shouldn't be called otherwise
|
||||||
|
*/
|
||||||
|
public static void updateCursor() {
|
||||||
|
synchronized (OpenGLPackageAccess.global_lock) {
|
||||||
|
if (emulateCursorAnimation && currentCursor != null && currentCursor.hasTimedOut() && Mouse.isInsideWindow()) {
|
||||||
|
currentCursor.nextCursor();
|
||||||
|
try {
|
||||||
|
setNativeCursor(currentCursor);
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
if (LWJGLUtil.DEBUG) e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets a boolean property as a privileged action. */
|
||||||
|
static boolean getPrivilegedBoolean(final String property_name) {
|
||||||
|
Boolean value = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||||
|
public Boolean run() {
|
||||||
|
return Boolean.getBoolean(property_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves whether or not the mouse cursor is within the bounds of the window.
|
||||||
|
* If the mouse cursor was moved outside the display during a drag, then the result of calling
|
||||||
|
* this method will be true until the button is released.
|
||||||
|
* @return true if mouse is inside display, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isInsideWindow() {
|
||||||
|
return implementation.isInsideWindow();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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.input;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.InputImplementation;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains utilities for accessing the org.lwjgl.opengl
|
||||||
|
* package through (privileged) reflection.
|
||||||
|
*/
|
||||||
|
final class OpenGLPackageAccess {
|
||||||
|
static final Object global_lock;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||||
|
public Object run() throws Exception {
|
||||||
|
Field lock_field = Class.forName("org.lwjgl.opengl.GlobalLock").getDeclaredField("lock");
|
||||||
|
lock_field.setAccessible(true);
|
||||||
|
return lock_field.get(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (PrivilegedActionException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static InputImplementation createImplementation() {
|
||||||
|
/* Use reflection since we can't make Display.getImplementation
|
||||||
|
* public
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
return AccessController.doPrivileged(new PrivilegedExceptionAction<InputImplementation>() {
|
||||||
|
public InputImplementation run() throws Exception {
|
||||||
|
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||||
|
getImplementation_method.setAccessible(true);
|
||||||
|
return (InputImplementation)getImplementation_method.invoke(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (PrivilegedActionException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,252 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* The AL class implements the actual creation code for linking to the native library
|
||||||
|
* OpenAL.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class AL {
|
||||||
|
/** ALCdevice instance. */
|
||||||
|
static ALCdevice device;
|
||||||
|
|
||||||
|
/** Current ALCcontext. */
|
||||||
|
static ALCcontext context;
|
||||||
|
|
||||||
|
/** Have we been created? */
|
||||||
|
private static boolean created;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Sys.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AL() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native method to create AL instance
|
||||||
|
*
|
||||||
|
* @param oalPath Path to search for OpenAL library
|
||||||
|
*/
|
||||||
|
private static native void nCreate(String oalPath) throws LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native method to create AL instance from the Mac OS X 10.4 OpenAL framework.
|
||||||
|
* It is only defined in the Mac OS X native library.
|
||||||
|
*/
|
||||||
|
private static native void nCreateDefault() throws LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native method the destroy the AL
|
||||||
|
*/
|
||||||
|
private static native void nDestroy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if AL has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an OpenAL instance. Using this constructor will cause OpenAL to
|
||||||
|
* open the device using supplied device argument, and create a context using the context values
|
||||||
|
* supplied.
|
||||||
|
*
|
||||||
|
* @param deviceArguments Arguments supplied to native device
|
||||||
|
* @param contextFrequency Frequency for mixing output buffer, in units of Hz (Common values include 11025, 22050, and 44100).
|
||||||
|
* @param contextRefresh Refresh intervalls, in units of Hz.
|
||||||
|
* @param contextSynchronized Flag, indicating a synchronous context.*
|
||||||
|
*/
|
||||||
|
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized)
|
||||||
|
throws LWJGLException {
|
||||||
|
create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param openDevice Whether to automatically open the device
|
||||||
|
* @see #create(String, int, int, boolean)
|
||||||
|
*/
|
||||||
|
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice)
|
||||||
|
throws LWJGLException {
|
||||||
|
|
||||||
|
if (created)
|
||||||
|
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
||||||
|
String libname;
|
||||||
|
String[] library_names;
|
||||||
|
switch (LWJGLUtil.getPlatform()) {
|
||||||
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
|
if ( Sys.is64Bit() ) {
|
||||||
|
libname = "OpenAL64";
|
||||||
|
library_names = new String[]{"OpenAL64.dll"};
|
||||||
|
} else {
|
||||||
|
libname = "OpenAL32";
|
||||||
|
library_names = new String[]{"OpenAL32.dll"};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
|
libname = "openal";
|
||||||
|
library_names = new String[]{"libopenal64.so", "libopenal.so", "libopenal.so.0"};
|
||||||
|
break;
|
||||||
|
case LWJGLUtil.PLATFORM_FCL:
|
||||||
|
libname = "openal";
|
||||||
|
library_names = new String[]{"libopenal.so"};
|
||||||
|
break;
|
||||||
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
|
libname = "openal";
|
||||||
|
library_names = new String[]{"openal.dylib"};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
||||||
|
}
|
||||||
|
String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
|
||||||
|
LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths");
|
||||||
|
for ( String oalPath : oalPaths ) {
|
||||||
|
try {
|
||||||
|
nCreate(oalPath);
|
||||||
|
created = true;
|
||||||
|
init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
|
||||||
|
break;
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Failed to load " + oalPath + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!created && LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
|
||||||
|
// Try to load OpenAL from the framework instead
|
||||||
|
nCreateDefault();
|
||||||
|
created = true;
|
||||||
|
init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
|
||||||
|
}
|
||||||
|
if (!created)
|
||||||
|
throw new LWJGLException("Could not locate OpenAL library.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void init(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice) throws LWJGLException {
|
||||||
|
try {
|
||||||
|
AL10.initNativeStubs();
|
||||||
|
ALC10.initNativeStubs();
|
||||||
|
|
||||||
|
if(openDevice) {
|
||||||
|
device = ALC10.alcOpenDevice(deviceArguments);
|
||||||
|
if (device == null) {
|
||||||
|
throw new LWJGLException("Could not open ALC device");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contextFrequency == -1) {
|
||||||
|
context = ALC10.alcCreateContext(device, null);
|
||||||
|
} else {
|
||||||
|
context = ALC10.alcCreateContext(device,
|
||||||
|
ALCcontext.createAttributeList(contextFrequency, contextRefresh,
|
||||||
|
contextSynchronized ? ALC10.ALC_TRUE : ALC10.ALC_FALSE));
|
||||||
|
}
|
||||||
|
ALC10.alcMakeContextCurrent(context);
|
||||||
|
}
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
destroy();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALC11.initialize();
|
||||||
|
|
||||||
|
// Load EFX10 native stubs if ALC_EXT_EFX is supported.
|
||||||
|
// Is there any situation where the current device supports ALC_EXT_EFX and one
|
||||||
|
// later created by the user does not?
|
||||||
|
// Do we have to call resetNativeStubs(EFX10.class); somewhere? Not done for AL11
|
||||||
|
// either.
|
||||||
|
// This can either be here or in ALC11, since ALC_EXT_EFX indirectly requires AL 1.1
|
||||||
|
// for functions like alSource3i.
|
||||||
|
if (ALC10.alcIsExtensionPresent(device, EFX10.ALC_EXT_EFX_NAME)){
|
||||||
|
EFX10.initNativeStubs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an OpenAL instance. The empty create will cause OpenAL to
|
||||||
|
* open the default device, and create a context using default values.
|
||||||
|
* This method used to use default values that the OpenAL implementation
|
||||||
|
* chose but this produces unexpected results on some systems; so now
|
||||||
|
* it defaults to 44100Hz mixing @ 60Hz refresh.
|
||||||
|
*/
|
||||||
|
public static void create() throws LWJGLException {
|
||||||
|
create(null, 44100, 60, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit cleanly by calling destroy.
|
||||||
|
*/
|
||||||
|
public static void destroy() {
|
||||||
|
if (context != null) {
|
||||||
|
ALC10.alcMakeContextCurrent(null);
|
||||||
|
ALC10.alcDestroyContext(context);
|
||||||
|
context = null;
|
||||||
|
}
|
||||||
|
if (device != null) {
|
||||||
|
boolean result = ALC10.alcCloseDevice(device);
|
||||||
|
device = null;
|
||||||
|
}
|
||||||
|
resetNativeStubs(AL10.class);
|
||||||
|
resetNativeStubs(AL11.class);
|
||||||
|
resetNativeStubs(ALC10.class);
|
||||||
|
resetNativeStubs(ALC11.class);
|
||||||
|
resetNativeStubs(EFX10.class);
|
||||||
|
|
||||||
|
if (created)
|
||||||
|
nDestroy();
|
||||||
|
created = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void resetNativeStubs(Class clazz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return handle to the default AL context.
|
||||||
|
*/
|
||||||
|
public static ALCcontext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return handle to the default AL device.
|
||||||
|
*/
|
||||||
|
public static ALCdevice getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,289 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.openal;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <br>
|
||||||
|
* This is the core OpenAL class. This class implements
|
||||||
|
* AL.h version 1.1
|
||||||
|
* <p>
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision: 2286 $
|
||||||
|
* $Id: AL10.java 2286 2006-03-23 19:32:21Z matzon $
|
||||||
|
*/
|
||||||
|
public final class AL11 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source buffer position information in seconds
|
||||||
|
*/
|
||||||
|
public static final int AL_SEC_OFFSET = 0x1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source buffer position information in samples
|
||||||
|
*/
|
||||||
|
public static final int AL_SAMPLE_OFFSET = 0x1025;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source buffer position information in bytes
|
||||||
|
*/
|
||||||
|
public static final int AL_BYTE_OFFSET = 0x1026;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of source: Buffer has been attached using AL_BUFFER
|
||||||
|
*/
|
||||||
|
public static final int AL_STATIC = 0x1028;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of source: if one or more Buffers have been attached using alSourceQueueBuffers
|
||||||
|
*/
|
||||||
|
public static final int AL_STREAMING = 0x1029;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of source: when it has the NULL buffer attached
|
||||||
|
*/
|
||||||
|
public static final int AL_UNDETERMINED = 0x1030;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AL10#AL_INVALID_OPERATION
|
||||||
|
*/
|
||||||
|
public static final int AL_ILLEGAL_COMMAND = 0xA004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speed of Sound in units per second
|
||||||
|
*/
|
||||||
|
public static final int AL_SPEED_OF_SOUND = 0xC003,
|
||||||
|
AL_LINEAR_DISTANCE = 0xD003,
|
||||||
|
AL_LINEAR_DISTANCE_CLAMPED = 0xD004,
|
||||||
|
AL_EXPONENT_DISTANCE = 0xD005,
|
||||||
|
AL_EXPONENT_DISTANCE_CLAMPED = 0xD006;
|
||||||
|
|
||||||
|
private AL11() {}
|
||||||
|
|
||||||
|
static native void initNativeStubs() throws LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener attributes are changed using the Listener group of commands.
|
||||||
|
* <p>
|
||||||
|
* @param pname name of the attribute to be set
|
||||||
|
* @param v1 value value 1
|
||||||
|
* @param v2 value value 2
|
||||||
|
* @param v3 value value 3
|
||||||
|
*/
|
||||||
|
public static void alListener3i(int pname, int v1, int v2, int v3) {
|
||||||
|
nalListener3i(pname, v1, v2, v3);
|
||||||
|
}
|
||||||
|
static native void nalListener3i(int pname, int v1, int v2, int v3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener state is maintained inside the AL implementation and can be queried in
|
||||||
|
* full.
|
||||||
|
* <p>
|
||||||
|
* @param pname name of the attribute to be retrieved
|
||||||
|
* @param intdata Buffer to write ints to
|
||||||
|
*/
|
||||||
|
public static void alGetListeneri(int pname, FloatBuffer intdata) {
|
||||||
|
BufferChecks.checkBuffer(intdata, 1);
|
||||||
|
nalGetListeneriv(pname, MemoryUtil.getAddress(intdata));
|
||||||
|
}
|
||||||
|
static native void nalGetListeneriv(int pname, long intdata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the position and other properties as taken into account during
|
||||||
|
* sound processing.
|
||||||
|
* <p>
|
||||||
|
* @param source Source to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param v1 value 1 of property
|
||||||
|
* @param v2 value 2 of property
|
||||||
|
* @param v3 value 3 of property
|
||||||
|
*/
|
||||||
|
public static void alSource3i(int source, int pname, int v1, int v2, int v3) {
|
||||||
|
nalSource3i(source, pname, v1, v2, v3);
|
||||||
|
}
|
||||||
|
static native void nalSource3i(int source, int pname, int v1, int v2, int v3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the position and other properties as taken into account during
|
||||||
|
* sound processing.
|
||||||
|
* <p>
|
||||||
|
* @param source Source to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param value IntBuffer containing value of property
|
||||||
|
*/
|
||||||
|
public static void alSource(int source, int pname, IntBuffer value) {
|
||||||
|
BufferChecks.checkBuffer(value, 1);
|
||||||
|
nalSourceiv(source, pname, MemoryUtil.getAddress(value));
|
||||||
|
}
|
||||||
|
static native void nalSourceiv(int source, int pname, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets a floating point property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param value value of property
|
||||||
|
*/
|
||||||
|
public static void alBufferf(int buffer, int pname, float value) {
|
||||||
|
nalBufferf(buffer, pname, value);
|
||||||
|
}
|
||||||
|
static native void nalBufferf(int buffer, int pname, float value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets a floating point property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param v1 value of property
|
||||||
|
* @param v2 value of property
|
||||||
|
* @param v3 value of property
|
||||||
|
*/
|
||||||
|
public static void alBuffer3f(int buffer, int pname, float v1, float v2, float v3) {
|
||||||
|
nalBuffer3f(buffer, pname, v1, v2, v3);
|
||||||
|
}
|
||||||
|
static native void nalBuffer3f(int buffer, int pname, float v1, float v2, float v3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets a floating point property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param value FloatBuffer containing value of property
|
||||||
|
*/
|
||||||
|
public static void alBuffer(int buffer, int pname, FloatBuffer value) {
|
||||||
|
BufferChecks.checkBuffer(value, 1);
|
||||||
|
nalBufferfv(buffer, pname, MemoryUtil.getAddress(value));
|
||||||
|
}
|
||||||
|
static native void nalBufferfv(int buffer, int pname, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets an integer property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param value value of property
|
||||||
|
*/
|
||||||
|
public static void alBufferi(int buffer, int pname, int value) {
|
||||||
|
nalBufferi(buffer, pname, value);
|
||||||
|
}
|
||||||
|
static native void nalBufferi(int buffer, int pname, int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets an integer property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param v1 value of property
|
||||||
|
* @param v2 value of property
|
||||||
|
* @param v3 value of property
|
||||||
|
*/
|
||||||
|
public static void alBuffer3i(int buffer, int pname, int v1, int v2, int v3) {
|
||||||
|
nalBuffer3i(buffer, pname, v1, v2, v3);
|
||||||
|
}
|
||||||
|
static native void nalBuffer3i(int buffer, int pname, int v1, int v2, int v3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets an integer property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to set property on
|
||||||
|
* @param pname property to set
|
||||||
|
* @param value IntBuffer containing value of property
|
||||||
|
*/
|
||||||
|
public static void alBuffer(int buffer, int pname, IntBuffer value) {
|
||||||
|
BufferChecks.checkBuffer(value, 1);
|
||||||
|
nalBufferiv(buffer, pname, MemoryUtil.getAddress(value));
|
||||||
|
}
|
||||||
|
static native void nalBufferiv(int buffer, int pname, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function retrieves an integer property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to get property from
|
||||||
|
* @param pname name of property
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static int alGetBufferi(int buffer, int pname) {
|
||||||
|
int __result = nalGetBufferi(buffer, pname);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGetBufferi(int buffer, int pname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function retrieves an integer property of a buffer.
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to get property from
|
||||||
|
* @param pname name of property
|
||||||
|
*/
|
||||||
|
public static void alGetBuffer(int buffer, int pname, IntBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalGetBufferiv(buffer, pname, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalGetBufferiv(int buffer, int pname, long values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function retrieves a floating point property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to get property from
|
||||||
|
* @param pname name of property
|
||||||
|
* @return floating point property
|
||||||
|
*/
|
||||||
|
public static float alGetBufferf(int buffer, int pname) {
|
||||||
|
float __result = nalGetBufferf(buffer, pname);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native float nalGetBufferf(int buffer, int pname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function retrieves a floating point property of a buffer.
|
||||||
|
* <i>note: There are no relevant buffer properties defined in OpenAL 1.1 which can be affected by
|
||||||
|
* this call, but this function may be used by OpenAL extensions.</i>
|
||||||
|
* <p>
|
||||||
|
* @param buffer Buffer to get property from
|
||||||
|
* @param pname name of property
|
||||||
|
*/
|
||||||
|
public static void alGetBuffer(int buffer, int pname, FloatBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalGetBufferfv(buffer, pname, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalGetBufferfv(int buffer, int pname, long values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* AL_SPEED_OF_SOUND allows the application to change the reference (propagation)
|
||||||
|
* speed used in the Doppler calculation. The source and listener velocities should be
|
||||||
|
* expressed in the same units as the speed of sound.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* A negative or zero value will result in an AL_INVALID_VALUE error, and the
|
||||||
|
* command is ignored. The default value is 343.3 (appropriate for velocity units of meters
|
||||||
|
* and air as the propagation medium). The current setting can be queried using
|
||||||
|
* alGetFloat{v} and AL_SPEED_OF_SOUND.
|
||||||
|
* Distance and velocity units are completely independent of one another (so you could use
|
||||||
|
* different units for each if desired).
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* @param value distance model to be set
|
||||||
|
*/
|
||||||
|
public static void alSpeedOfSound(float value) {
|
||||||
|
nalSpeedOfSound(value);
|
||||||
|
}
|
||||||
|
static native void nalSpeedOfSound(float value);
|
||||||
|
}
|
|
@ -0,0 +1,439 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferChecks;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.MemoryUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* ALC introduces the notion of a Device. A Device can be, depending on the
|
||||||
|
* implementation, a hardware device, or a daemon/OS service/actual server. This
|
||||||
|
* mechanism also permits different drivers (and hardware) to coexist within the same
|
||||||
|
* system, as well as allowing several applications to share system resources for audio,
|
||||||
|
* including a single hardware output device. The details are left to the
|
||||||
|
* implementation, which has to map the available backends to unique device
|
||||||
|
* specifiers (represented as strings).
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision: 2286 $
|
||||||
|
* $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $
|
||||||
|
*/
|
||||||
|
public final class ALC10 {
|
||||||
|
|
||||||
|
/** List of active contexts */
|
||||||
|
static final HashMap<Long, ALCcontext> contexts = new HashMap<Long, ALCcontext>();
|
||||||
|
|
||||||
|
/** List of active devices */
|
||||||
|
static final HashMap<Long, ALCdevice> devices = new HashMap<Long, ALCdevice>();
|
||||||
|
|
||||||
|
/** Bad value */
|
||||||
|
public static final int ALC_INVALID = 0;
|
||||||
|
|
||||||
|
/** Boolean False */
|
||||||
|
public static final int ALC_FALSE = 0;
|
||||||
|
|
||||||
|
/** Boolean True */
|
||||||
|
public static final int ALC_TRUE = 1;
|
||||||
|
|
||||||
|
/** Errors: No Error */
|
||||||
|
public static final int ALC_NO_ERROR = ALC_FALSE;
|
||||||
|
|
||||||
|
/** Major version query. */
|
||||||
|
public static final int ALC_MAJOR_VERSION = 0x1000;
|
||||||
|
|
||||||
|
/** Minor version query. */
|
||||||
|
public static final int ALC_MINOR_VERSION = 0x1001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size required for the zero-terminated attributes list, for the current context.
|
||||||
|
**/
|
||||||
|
public static final int ALC_ATTRIBUTES_SIZE = 0x1002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expects a destination of ALC_CURRENT_ATTRIBUTES_SIZE,
|
||||||
|
* and provides the attribute list for the current context of the specified device.
|
||||||
|
*/
|
||||||
|
public static final int ALC_ALL_ATTRIBUTES = 0x1003;
|
||||||
|
|
||||||
|
/** The specifier string for the default device */
|
||||||
|
public static final int ALC_DEFAULT_DEVICE_SPECIFIER = 0x1004;
|
||||||
|
|
||||||
|
/** The specifier string for the device */
|
||||||
|
public static final int ALC_DEVICE_SPECIFIER = 0x1005;
|
||||||
|
|
||||||
|
/** The extensions string for diagnostics and printing */
|
||||||
|
public static final int ALC_EXTENSIONS = 0x1006;
|
||||||
|
|
||||||
|
/** Frequency for mixing output buffer, in units of Hz. */
|
||||||
|
public static final int ALC_FREQUENCY = 0x1007;
|
||||||
|
|
||||||
|
/** Refresh intervalls, in units of Hz. */
|
||||||
|
public static final int ALC_REFRESH = 0x1008;
|
||||||
|
|
||||||
|
/** Flag, indicating a synchronous context. */
|
||||||
|
public static final int ALC_SYNC = 0x1009;
|
||||||
|
|
||||||
|
/** The device argument does not name a valid device */
|
||||||
|
public static final int ALC_INVALID_DEVICE = 0xA001;
|
||||||
|
|
||||||
|
/** The context argument does not name a valid context */
|
||||||
|
public static final int ALC_INVALID_CONTEXT = 0xA002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function was called at inappropriate time, or in an inappropriate way,
|
||||||
|
* causing an illegal state. This can be an incompatible ALenum, object ID,
|
||||||
|
* and/or function.
|
||||||
|
*/
|
||||||
|
public static final int ALC_INVALID_ENUM = 0xA003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Illegal value passed as an argument to an AL call.
|
||||||
|
* Applies to parameter values, but not to enumerations.
|
||||||
|
*/
|
||||||
|
public static final int ALC_INVALID_VALUE = 0xA004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function could not be completed, because there is not enough
|
||||||
|
* memory available.
|
||||||
|
*/
|
||||||
|
public static final int ALC_OUT_OF_MEMORY = 0xA005;
|
||||||
|
|
||||||
|
static native void initNativeStubs() throws LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application can obtain certain strings from ALC.
|
||||||
|
*
|
||||||
|
* <code>ALC_DEFAULT_DEVICE_SPECIFIER</code> - The specifer string for the default device
|
||||||
|
* <code>ALC_DEVICE_SPECIFIER</code> - The specifer string for the device
|
||||||
|
* <code>ALC_EXTENSIONS</code> - The extensions string for diagnostics and printing.
|
||||||
|
*
|
||||||
|
* In addition, printable error message strings are provided for all valid error tokens,
|
||||||
|
* including <code>ALC_NO_ERROR</code>,<code>ALC_INVALID_DEVICE</code>, <code>ALC_INVALID_CONTEXT</code>,
|
||||||
|
* <code>ALC_INVALID_ENUM</code>, <code>ALC_INVALID_VALUE</code>.
|
||||||
|
*
|
||||||
|
* @param pname Property to get
|
||||||
|
* @return String property from device
|
||||||
|
*/
|
||||||
|
public static String alcGetString(ALCdevice device, int pname) {
|
||||||
|
ByteBuffer buffer = nalcGetString(getDevice(device), pname);
|
||||||
|
Util.checkALCError(device);
|
||||||
|
return MemoryUtil.decodeUTF8(buffer);
|
||||||
|
}
|
||||||
|
static native ByteBuffer nalcGetString(long device, int pname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application can query ALC for information using an integer query function.
|
||||||
|
* For some tokens, <code>null</code> is a legal deviceHandle. In other cases, specifying a <code>null</code>
|
||||||
|
* device will generate an <code>ALC_INVALID_DEVICE</code> error. The application has to
|
||||||
|
* specify the size of the destination buffer provided. A <code>null</code> destination or a zero
|
||||||
|
* size parameter will cause ALC to ignore the query.
|
||||||
|
*
|
||||||
|
* <code>ALC_MAJOR_VERSION</code> - Major version query.
|
||||||
|
* <code>ALC_MINOR_VERSION</code> - Minor version query.
|
||||||
|
* <code>ALC_ATTRIBUTES_SIZE</code> - The size required for the zero-terminated attributes list,
|
||||||
|
* for the current context. <code>null</code> is an invalid device. <code>null</code> (no current context
|
||||||
|
* for the specified device) is legal.
|
||||||
|
* <code>ALC_ALL_ATTRIBUTES</code> - Expects a destination of <code>ALC_CURRENT_ATTRIBUTES_SIZE</code>,
|
||||||
|
* and provides the attribute list for the current context of the specified device.
|
||||||
|
* <code>null</code> is an invalid device. <code>null</code> (no current context for the specified device)
|
||||||
|
* will return the default attributes defined by the specified device.
|
||||||
|
*
|
||||||
|
* @param pname Property to get
|
||||||
|
* @param integerdata ByteBuffer to write integers to
|
||||||
|
*/
|
||||||
|
public static void alcGetInteger(ALCdevice device, int pname, IntBuffer integerdata) {
|
||||||
|
BufferChecks.checkDirect(integerdata);
|
||||||
|
nalcGetIntegerv(getDevice(device), pname, integerdata.remaining(), MemoryUtil.getAddress(integerdata));
|
||||||
|
Util.checkALCError(device);
|
||||||
|
}
|
||||||
|
static native void nalcGetIntegerv(long device, int pname, int size, long integerdata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <code>alcOpenDevice</code> function allows the application (i.e. the client program) to
|
||||||
|
* connect to a device (i.e. the server).
|
||||||
|
*
|
||||||
|
* If the function returns <code>null</code>, then no sound driver/device has been found. The
|
||||||
|
* argument is a null terminated string that requests a certain device or device
|
||||||
|
* configuration. If <code>null</code> is specified, the implementation will provide an
|
||||||
|
* implementation specific default.
|
||||||
|
*
|
||||||
|
* @param devicename name of device to open
|
||||||
|
* @return opened device, or null
|
||||||
|
*/
|
||||||
|
public static ALCdevice alcOpenDevice(String devicename) {
|
||||||
|
ByteBuffer buffer = MemoryUtil.encodeUTF8(devicename);
|
||||||
|
long device_address = nalcOpenDevice(MemoryUtil.getAddressSafe(buffer));
|
||||||
|
if(device_address != 0) {
|
||||||
|
ALCdevice device = new ALCdevice(device_address);
|
||||||
|
synchronized (ALC10.devices) {
|
||||||
|
devices.put(device_address, device);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
static native long nalcOpenDevice(long devicename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <code>alcCloseDevice</code> function allows the application (i.e. the client program) to
|
||||||
|
* disconnect from a device (i.e. the server).
|
||||||
|
*
|
||||||
|
* If deviceHandle is <code>null</code> or invalid, an <code>ALC_INVALID_DEVICE</code> error will be
|
||||||
|
* generated. Once closed, a deviceHandle is invalid.
|
||||||
|
*
|
||||||
|
* @param device address of native device to close
|
||||||
|
*/
|
||||||
|
public static boolean alcCloseDevice(ALCdevice device) {
|
||||||
|
boolean result = nalcCloseDevice(getDevice(device));
|
||||||
|
synchronized (devices) {
|
||||||
|
device.setInvalid();
|
||||||
|
devices.remove(new Long(device.device));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
static native boolean nalcCloseDevice(long device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A context is created using <code>alcCreateContext</code>. The device parameter has to be a valid
|
||||||
|
* device. The attribute list can be <code>null</code>, or a zero terminated list of integer pairs
|
||||||
|
* composed of valid ALC attribute tokens and requested values.
|
||||||
|
*
|
||||||
|
* Context creation will fail if the application requests attributes that, by themselves,
|
||||||
|
* can not be provided. Context creation will fail if the combination of specified
|
||||||
|
* attributes can not be provided. Context creation will fail if a specified attribute, or
|
||||||
|
* the combination of attributes, does not match the default values for unspecified
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param device address of device to associate context to
|
||||||
|
* @param attrList Buffer to read attributes from
|
||||||
|
* @return New context, or null if creation failed
|
||||||
|
*/
|
||||||
|
public static ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrList) {
|
||||||
|
long context_address = nalcCreateContext(getDevice(device), MemoryUtil.getAddressSafe(attrList));
|
||||||
|
Util.checkALCError(device);
|
||||||
|
|
||||||
|
if(context_address != 0) {
|
||||||
|
ALCcontext context = new ALCcontext(context_address);
|
||||||
|
synchronized (ALC10.contexts) {
|
||||||
|
contexts.put(context_address, context);
|
||||||
|
device.addContext(context);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
static native long nalcCreateContext(long device, long attrList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To make a Context current with respect to AL Operation (state changes by issueing
|
||||||
|
* commands), <code>alcMakeContextCurrent</code> is used. The context parameter can be <code>null</code>
|
||||||
|
* or a valid context pointer. The operation will apply to the device that the context
|
||||||
|
* was created for.
|
||||||
|
*
|
||||||
|
* For each OS process (usually this means for each application), only one context can
|
||||||
|
* be current at any given time. All AL commands apply to the current context.
|
||||||
|
* Commands that affect objects shared among contexts (e.g. buffers) have side effects
|
||||||
|
* on other contexts.
|
||||||
|
*
|
||||||
|
* @param context address of context to make current
|
||||||
|
* @return true if successfull, false if not
|
||||||
|
*/
|
||||||
|
public static int alcMakeContextCurrent(ALCcontext context) {
|
||||||
|
return nalcMakeContextCurrent(getContext(context));
|
||||||
|
}
|
||||||
|
static native int nalcMakeContextCurrent(long context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current context is the only context accessible to state changes by AL commands
|
||||||
|
* (aside from state changes affecting shared objects). However, multiple contexts can
|
||||||
|
* be processed at the same time. To indicate that a context should be processed (i.e.
|
||||||
|
* that internal execution state like offset increments are supposed to be performed),
|
||||||
|
* the application has to use <code>alcProcessContext</code>.
|
||||||
|
*
|
||||||
|
* Repeated calls to <code>alcProcessContext</code> are legal, and do not affect a context that is
|
||||||
|
* already marked as processing. The default state of a context created by
|
||||||
|
* alcCreateContext is that it is not marked as processing.
|
||||||
|
*/
|
||||||
|
public static void alcProcessContext(ALCcontext context) {
|
||||||
|
nalcProcessContext(getContext(context));
|
||||||
|
}
|
||||||
|
static native void nalcProcessContext(long context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application can query for, and obtain an handle to, the current context for the
|
||||||
|
* application. If there is no current context, <code>null</code> is returned.
|
||||||
|
*
|
||||||
|
* @return Current ALCcontext
|
||||||
|
*/
|
||||||
|
public static ALCcontext alcGetCurrentContext() {
|
||||||
|
ALCcontext context = null;
|
||||||
|
long context_address = nalcGetCurrentContext();
|
||||||
|
if(context_address != 0) {
|
||||||
|
synchronized (ALC10.contexts) {
|
||||||
|
context = ALC10.contexts.get(context_address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
static native long nalcGetCurrentContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application can query for, and obtain an handle to, the device of a given context.
|
||||||
|
*
|
||||||
|
* @param context address of context to get device for
|
||||||
|
*/
|
||||||
|
public static ALCdevice alcGetContextsDevice(ALCcontext context) {
|
||||||
|
ALCdevice device = null;
|
||||||
|
long device_address = nalcGetContextsDevice(getContext(context));
|
||||||
|
if (device_address != 0) {
|
||||||
|
synchronized (ALC10.devices) {
|
||||||
|
device = ALC10.devices.get(device_address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
static native long nalcGetContextsDevice(long context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application can suspend any context from processing (including the current
|
||||||
|
* one). To indicate that a context should be suspended from processing (i.e. that
|
||||||
|
* internal execution state like offset increments is not supposed to be changed), the
|
||||||
|
* application has to use <code>alcSuspendContext</code>.
|
||||||
|
*
|
||||||
|
* Repeated calls to <code>alcSuspendContext</code> are legal, and do not affect a context that is
|
||||||
|
* already marked as suspended. The default state of a context created by
|
||||||
|
* <code>alcCreateContext</code> is that it is marked as suspended.
|
||||||
|
*
|
||||||
|
* @param context address of context to suspend
|
||||||
|
*/
|
||||||
|
public static void alcSuspendContext(ALCcontext context) {
|
||||||
|
nalcSuspendContext(getContext(context));
|
||||||
|
}
|
||||||
|
static native void nalcSuspendContext(long context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The correct way to destroy a context is to first release it using <code>alcMakeCurrent</code> and
|
||||||
|
* <code>null</code>. Applications should not attempt to destroy a current context.
|
||||||
|
*
|
||||||
|
* @param context address of context to Destroy
|
||||||
|
*/
|
||||||
|
public static void alcDestroyContext(ALCcontext context) {
|
||||||
|
synchronized(ALC10.contexts) {
|
||||||
|
ALCdevice device = alcGetContextsDevice(context);
|
||||||
|
nalcDestroyContext(getContext(context));
|
||||||
|
device.removeContext(context);
|
||||||
|
context.setInvalid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native void nalcDestroyContext(long context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ALC uses the same conventions and mechanisms as AL for error handling. In
|
||||||
|
* particular, ALC does not use conventions derived from X11 (GLX) or Windows
|
||||||
|
* (WGL). The <code>alcGetError</code> function can be used to query ALC errors.
|
||||||
|
*
|
||||||
|
* Error conditions are specific to the device.
|
||||||
|
*
|
||||||
|
* ALC_NO_ERROR - The device handle or specifier does name an accessible driver/server.
|
||||||
|
* <code>ALC_INVALID_DEVICE</code> - The Context argument does not name a valid context.
|
||||||
|
* <code>ALC_INVALID_CONTEXT</code> - The Context argument does not name a valid context.
|
||||||
|
* <code>ALC_INVALID_ENUM</code> - A token used is not valid, or not applicable.
|
||||||
|
* <code>ALC_INVALID_VALUE</code> - An value (e.g. attribute) is not valid, or not applicable.
|
||||||
|
*
|
||||||
|
* @return Errorcode from ALC statemachine
|
||||||
|
*/
|
||||||
|
public static int alcGetError(ALCdevice device) {
|
||||||
|
return nalcGetError(getDevice(device));
|
||||||
|
}
|
||||||
|
static native int nalcGetError(long device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify that a given extension is available for the current context and the device it
|
||||||
|
* is associated with.
|
||||||
|
* A <code>null</code> name argument returns <code>ALC_FALSE</code>, as do invalid and unsupported string
|
||||||
|
* tokens.
|
||||||
|
*
|
||||||
|
* @param extName name of extension to find
|
||||||
|
* @return true if extension is available, false if not
|
||||||
|
*/
|
||||||
|
public static boolean alcIsExtensionPresent(ALCdevice device, String extName) {
|
||||||
|
ByteBuffer buffer = MemoryUtil.encodeASCII(extName);
|
||||||
|
boolean result = nalcIsExtensionPresent(getDevice(device), MemoryUtil.getAddress(buffer));
|
||||||
|
Util.checkALCError(device);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private static native boolean nalcIsExtensionPresent(long device, long extName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration/token values are device independend, but tokens defined for
|
||||||
|
* extensions might not be present for a given device. But only the tokens defined
|
||||||
|
* by the AL core are guaranteed. Availability of extension tokens dependends on the ALC extension.
|
||||||
|
*
|
||||||
|
* Specifying a <code>null</code> name parameter will cause an <code>ALC_INVALID_VALUE</code> error.
|
||||||
|
*
|
||||||
|
* @param enumName name of enum to find
|
||||||
|
* @return value of enumeration
|
||||||
|
*/
|
||||||
|
public static int alcGetEnumValue(ALCdevice device, String enumName) {
|
||||||
|
ByteBuffer buffer = MemoryUtil.encodeASCII(enumName);
|
||||||
|
int result = nalcGetEnumValue(getDevice(device), MemoryUtil.getAddress(buffer));
|
||||||
|
Util.checkALCError(device);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private static native int nalcGetEnumValue(long device, long enumName);
|
||||||
|
|
||||||
|
static long getDevice(ALCdevice device) {
|
||||||
|
if(device != null) {
|
||||||
|
Util.checkALCValidDevice(device);
|
||||||
|
return device.device;
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long getContext(ALCcontext context) {
|
||||||
|
if(context != null) {
|
||||||
|
Util.checkALCValidContext(context);
|
||||||
|
return context.context;
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,201 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
import org.lwjgl.MemoryUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* The ALC11 class implements features in OpenAL 1.1, specifically
|
||||||
|
* ALC methods and properties.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @see ALC10
|
||||||
|
* @version $Revision: 2286 $
|
||||||
|
* $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $
|
||||||
|
*/
|
||||||
|
public final class ALC11 {
|
||||||
|
|
||||||
|
public static final int ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012;
|
||||||
|
public static final int ALC_ALL_DEVICES_SPECIFIER = 0x1013;
|
||||||
|
|
||||||
|
public static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310;
|
||||||
|
public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311;
|
||||||
|
public static final int ALC_CAPTURE_SAMPLES = 0x312;
|
||||||
|
|
||||||
|
public static final int ALC_MONO_SOURCES = 0x1010;
|
||||||
|
public static final int ALC_STEREO_SOURCES = 0x1011;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The alcCaptureOpenDevice function allows the application to connect to a capture
|
||||||
|
* device. To obtain a list of all available capture devices, use getCaptureDevices a list of all
|
||||||
|
* capture devices will be returned. Retrieving ALC_CAPTURE_DEVICE_SPECIFIER with a valid capture device specified will result
|
||||||
|
* in the name of that device being returned as a single string.
|
||||||
|
*
|
||||||
|
* If the function returns null, then no sound driver/device has been found, or the
|
||||||
|
* requested format could not be fulfilled.
|
||||||
|
* The "deviceName" argument is a string that requests a certain device or
|
||||||
|
* device configuration. If null is specified, the implementation will provide an
|
||||||
|
* implementation specific default. The "frequency" and "format" arguments specify the format that
|
||||||
|
* audio data will be presented to the application, and match the values that can be passed to
|
||||||
|
* alBufferData. The implementation is expected to convert and resample to this format on
|
||||||
|
* behalf of the application. The "buffersize" argument specifies the number of sample frames
|
||||||
|
* to buffer in the AL, for example, requesting a format of AL_FORMAT_STEREO16 and
|
||||||
|
* a buffer size of 1024 would require the AL to store up to 1024 * 4 bytes of audio data.
|
||||||
|
* Note that the implementation may use a larger buffer than requested if it needs to, but the
|
||||||
|
* implementation will set up a buffer of at least the requested size.
|
||||||
|
* Specifying a compressed or extension-supplied format may result in failure, even if the
|
||||||
|
* extension is supplied for rendering.
|
||||||
|
*
|
||||||
|
* <i>LWJGL SPECIFIC: the actual created device is managed internally in lwjgl</i>
|
||||||
|
*
|
||||||
|
* @param devicename Name of device to open for capture
|
||||||
|
* @param frequency Frequency of samples to capture
|
||||||
|
* @param format Format of samples to capture
|
||||||
|
* @param buffersize Size of buffer to capture to
|
||||||
|
* @return ALCdevice if it was possible to open a device
|
||||||
|
*/
|
||||||
|
public static ALCdevice alcCaptureOpenDevice(String devicename, int frequency, int format, int buffersize) {
|
||||||
|
ByteBuffer buffer = MemoryUtil.encodeASCII(devicename);
|
||||||
|
long device_address = nalcCaptureOpenDevice(MemoryUtil.getAddressSafe(buffer), frequency, format, buffersize);
|
||||||
|
if(device_address != 0) {
|
||||||
|
ALCdevice device = new ALCdevice(device_address);
|
||||||
|
synchronized (ALC10.devices) {
|
||||||
|
ALC10.devices.put(device_address, device);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private static native long nalcCaptureOpenDevice(long devicename, int frequency, int format, int buffersize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The alcCaptureCloseDevice function allows the application to disconnect from a capture
|
||||||
|
* device.
|
||||||
|
*
|
||||||
|
* The return code will be true or false, indicating success or failure. If
|
||||||
|
* the device is null or invalid, an ALC_INVALID_DEVICE error will be generated.
|
||||||
|
* Once closed, a capture device is invalid.
|
||||||
|
* @return true if device was successfully closed
|
||||||
|
*/
|
||||||
|
public static boolean alcCaptureCloseDevice(ALCdevice device) {
|
||||||
|
boolean result = nalcCaptureCloseDevice(ALC10.getDevice(device));
|
||||||
|
synchronized (ALC10.devices) {
|
||||||
|
device.setInvalid();
|
||||||
|
ALC10.devices.remove(new Long(device.device));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
static native boolean nalcCaptureCloseDevice(long device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Once a capture device has been opened via alcCaptureOpenDevice, it is made to start
|
||||||
|
* recording audio via the alcCaptureStart entry point:
|
||||||
|
*
|
||||||
|
* Once started, the device will record audio to an internal ring buffer, the size of which was
|
||||||
|
* specified when opening the device.
|
||||||
|
* The application may query the capture device to discover how much data is currently
|
||||||
|
* available via the alcGetInteger with the ALC_CAPTURE_SAMPLES token. This will
|
||||||
|
* report the number of sample frames currently available.
|
||||||
|
*/
|
||||||
|
public static void alcCaptureStart(ALCdevice device) {
|
||||||
|
nalcCaptureStart(ALC10.getDevice(device));
|
||||||
|
}
|
||||||
|
static native void nalcCaptureStart(long device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the application doesn't need to capture more audio for an amount of time, they can halt
|
||||||
|
* the device without closing it via the alcCaptureStop entry point.
|
||||||
|
* The implementation is encouraged to optimize for this case. The amount of audio
|
||||||
|
* samples available after restarting a stopped capture device is reset to zero. The
|
||||||
|
* application does not need to stop the capture device to read from it.
|
||||||
|
*/
|
||||||
|
public static void alcCaptureStop(ALCdevice device) {
|
||||||
|
nalcCaptureStop(ALC10.getDevice(device));
|
||||||
|
}
|
||||||
|
static native void nalcCaptureStop(long device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the application feels there are enough samples available to process, it can obtain
|
||||||
|
* them from the AL via the alcCaptureSamples entry point.
|
||||||
|
*
|
||||||
|
* The "buffer" argument specifies an application-allocated buffer that can contain at least
|
||||||
|
* "samples" sample frames. The implementation may defer conversion and resampling until
|
||||||
|
* this point. Requesting more sample frames than are currently available is an error.
|
||||||
|
*
|
||||||
|
* @param buffer Buffer to store samples in
|
||||||
|
* @param samples Number of samples to request
|
||||||
|
*/
|
||||||
|
public static void alcCaptureSamples(ALCdevice device, ByteBuffer buffer, int samples ) {
|
||||||
|
nalcCaptureSamples(ALC10.getDevice(device), MemoryUtil.getAddress(buffer), samples);
|
||||||
|
}
|
||||||
|
static native void nalcCaptureSamples(long device, long buffer, int samples );
|
||||||
|
|
||||||
|
static native void initNativeStubs() throws LWJGLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes ALC11, including any extensions
|
||||||
|
* @return true if initialization was successfull
|
||||||
|
*/
|
||||||
|
static boolean initialize() {
|
||||||
|
try {
|
||||||
|
IntBuffer ib = BufferUtils.createIntBuffer(2);
|
||||||
|
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib);
|
||||||
|
ib.position(1);
|
||||||
|
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, ib);
|
||||||
|
|
||||||
|
int major = ib.get(0);
|
||||||
|
int minor = ib.get(1);
|
||||||
|
|
||||||
|
// checking for version 1.x+
|
||||||
|
if(major >= 1) {
|
||||||
|
|
||||||
|
// checking for version 1.1+
|
||||||
|
if(major > 1 || minor >= 1) {
|
||||||
|
ALC11.initNativeStubs();
|
||||||
|
AL11.initNativeStubs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (LWJGLException le) {
|
||||||
|
LWJGLUtil.log("failed to initialize ALC11: " + le);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ALCcontext class represents a context opened in OpenAL space.
|
||||||
|
*
|
||||||
|
* All operations of the AL core API affect a current AL context. Within the scope of AL,
|
||||||
|
* the ALC is implied - it is not visible as a handle or function parameter. Only one AL
|
||||||
|
* Context per process can be current at a time. Applications maintaining multiple AL
|
||||||
|
* Contexts, whether threaded or not, have to set the current context accordingly.
|
||||||
|
* Applications can have multiple threads that share one more or contexts. In other words,
|
||||||
|
* AL and ALC are threadsafe.
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class ALCcontext {
|
||||||
|
|
||||||
|
/** Address of actual context */
|
||||||
|
final long context;
|
||||||
|
|
||||||
|
/** Whether this context is valid */
|
||||||
|
private boolean valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of ALCcontext
|
||||||
|
*
|
||||||
|
* @param context address of actual context
|
||||||
|
*/
|
||||||
|
ALCcontext(long context) {
|
||||||
|
this.context = context;
|
||||||
|
this.valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public boolean equals(Object context) {
|
||||||
|
if(context instanceof ALCcontext) {
|
||||||
|
return ((ALCcontext)context).context == this.context;
|
||||||
|
}
|
||||||
|
return super.equals(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an attribute list in a ByteBuffer
|
||||||
|
* @param contextFrequency Frequency to add
|
||||||
|
* @param contextRefresh Refresh rate to add
|
||||||
|
* @param contextSynchronized Whether to synchronize the context
|
||||||
|
* @return attribute list
|
||||||
|
*/
|
||||||
|
static IntBuffer createAttributeList(int contextFrequency, int contextRefresh, int contextSynchronized) {
|
||||||
|
IntBuffer attribList = BufferUtils.createIntBuffer(7);
|
||||||
|
|
||||||
|
attribList.put(ALC10.ALC_FREQUENCY);
|
||||||
|
attribList.put(contextFrequency);
|
||||||
|
attribList.put(ALC10.ALC_REFRESH);
|
||||||
|
attribList.put(contextRefresh);
|
||||||
|
attribList.put(ALC10.ALC_SYNC);
|
||||||
|
attribList.put(contextSynchronized);
|
||||||
|
attribList.put(0); //terminating int
|
||||||
|
|
||||||
|
return attribList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks this context as invalid
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void setInvalid() {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this context is still valid
|
||||||
|
*/
|
||||||
|
public boolean isValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ALCdevice class represents a device opened in OpenAL space.
|
||||||
|
*
|
||||||
|
* ALC introduces the notion of a Device. A Device can be, depending on the
|
||||||
|
* implementation, a hardware device, or a daemon/OS service/actual server. This
|
||||||
|
* mechanism also permits different drivers (and hardware) to coexist within the same
|
||||||
|
* system, as well as allowing several applications to share system resources for audio,
|
||||||
|
* including a single hardware output device. The details are left to the implementation,
|
||||||
|
* which has to map the available backends to unique device specifiers.
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class ALCdevice {
|
||||||
|
|
||||||
|
/** Address of actual device */
|
||||||
|
final long device;
|
||||||
|
|
||||||
|
/** Whether this device is valid */
|
||||||
|
private boolean valid;
|
||||||
|
|
||||||
|
/** List of contexts belonging to the device */
|
||||||
|
private final HashMap<Long, ALCcontext> contexts = new HashMap<Long, ALCcontext>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of ALCdevice
|
||||||
|
*
|
||||||
|
* @param device address of actual device
|
||||||
|
*/
|
||||||
|
ALCdevice(long device) {
|
||||||
|
this.device = device;
|
||||||
|
this.valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public boolean equals(Object device) {
|
||||||
|
if(device instanceof ALCdevice) {
|
||||||
|
return ((ALCdevice)device).device == this.device;
|
||||||
|
}
|
||||||
|
return super.equals(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a context to the device
|
||||||
|
*
|
||||||
|
* @param context context to add to the list of contexts for this device
|
||||||
|
*/
|
||||||
|
void addContext(ALCcontext context) {
|
||||||
|
synchronized (contexts) {
|
||||||
|
contexts.put(context.context, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove context associated with device
|
||||||
|
*
|
||||||
|
* @param context Context to disassociate with device
|
||||||
|
*/
|
||||||
|
void removeContext(ALCcontext context) {
|
||||||
|
synchronized (contexts) {
|
||||||
|
contexts.remove(context.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks this device and all of its contexts invalid
|
||||||
|
*/
|
||||||
|
void setInvalid() {
|
||||||
|
valid = false;
|
||||||
|
synchronized (contexts) {
|
||||||
|
for ( ALCcontext context : contexts.values() )
|
||||||
|
context.setInvalid();
|
||||||
|
}
|
||||||
|
contexts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this device is still valid
|
||||||
|
*/
|
||||||
|
public boolean isValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,757 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.openal;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the OpenAL extension ALC_EXT_EFX (version 1.0). Contains necessary fields,
|
||||||
|
* methods and a range of supplementary fields containing minimum, maximum and default values of
|
||||||
|
* the former fields.
|
||||||
|
* <p>
|
||||||
|
* On top of regular functions defined in the ALC_EXT_EFX, there are also several convenience
|
||||||
|
* functions. Namely alGen... and alDelete... which do not take a Java buffer parameter and
|
||||||
|
* automatically create or delete a single object, without the overhead of using a buffer.
|
||||||
|
* <p>
|
||||||
|
* For comments and specification of functions and fields, refer to the "Effects Extension Guide"
|
||||||
|
* which is part of the OpenAL SDK and can be downloaded from:
|
||||||
|
* http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx
|
||||||
|
* <p>
|
||||||
|
* @author Ciardhubh <ciardhubh[at]ciardhubh.de>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class EFX10 {
|
||||||
|
|
||||||
|
public static final String ALC_EXT_EFX_NAME = "ALC_EXT_EFX";
|
||||||
|
|
||||||
|
public static final int ALC_EFX_MAJOR_VERSION = 0x20001,
|
||||||
|
ALC_EFX_MINOR_VERSION = 0x20002,
|
||||||
|
ALC_MAX_AUXILIARY_SENDS = 0x20003,
|
||||||
|
AL_METERS_PER_UNIT = 0x20004,
|
||||||
|
AL_DIRECT_FILTER = 0x20005,
|
||||||
|
AL_AUXILIARY_SEND_FILTER = 0x20006,
|
||||||
|
AL_AIR_ABSORPTION_FACTOR = 0x20007,
|
||||||
|
AL_ROOM_ROLLOFF_FACTOR = 0x20008,
|
||||||
|
AL_CONE_OUTER_GAINHF = 0x20009,
|
||||||
|
AL_DIRECT_FILTER_GAINHF_AUTO = 0x2000A,
|
||||||
|
AL_AUXILIARY_SEND_FILTER_GAIN_AUTO = 0x2000B,
|
||||||
|
AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO = 0x2000C,
|
||||||
|
AL_EFFECTSLOT_EFFECT = 0x1,
|
||||||
|
AL_EFFECTSLOT_GAIN = 0x2,
|
||||||
|
AL_EFFECTSLOT_AUXILIARY_SEND_AUTO = 0x3,
|
||||||
|
AL_EFFECTSLOT_NULL = 0x0,
|
||||||
|
AL_REVERB_DENSITY = 0x1,
|
||||||
|
AL_REVERB_DIFFUSION = 0x2,
|
||||||
|
AL_REVERB_GAIN = 0x3,
|
||||||
|
AL_REVERB_GAINHF = 0x4,
|
||||||
|
AL_REVERB_DECAY_TIME = 0x5,
|
||||||
|
AL_REVERB_DECAY_HFRATIO = 0x6,
|
||||||
|
AL_REVERB_REFLECTIONS_GAIN = 0x7,
|
||||||
|
AL_REVERB_REFLECTIONS_DELAY = 0x8,
|
||||||
|
AL_REVERB_LATE_REVERB_GAIN = 0x9,
|
||||||
|
AL_REVERB_LATE_REVERB_DELAY = 0xA,
|
||||||
|
AL_REVERB_AIR_ABSORPTION_GAINHF = 0xB,
|
||||||
|
AL_REVERB_ROOM_ROLLOFF_FACTOR = 0xC,
|
||||||
|
AL_REVERB_DECAY_HFLIMIT = 0xD,
|
||||||
|
AL_EAXREVERB_DENSITY = 0x1,
|
||||||
|
AL_EAXREVERB_DIFFUSION = 0x2,
|
||||||
|
AL_EAXREVERB_GAIN = 0x3,
|
||||||
|
AL_EAXREVERB_GAINHF = 0x4,
|
||||||
|
AL_EAXREVERB_GAINLF = 0x5,
|
||||||
|
AL_EAXREVERB_DECAY_TIME = 0x6,
|
||||||
|
AL_EAXREVERB_DECAY_HFRATIO = 0x7,
|
||||||
|
AL_EAXREVERB_DECAY_LFRATIO = 0x8,
|
||||||
|
AL_EAXREVERB_REFLECTIONS_GAIN = 0x9,
|
||||||
|
AL_EAXREVERB_REFLECTIONS_DELAY = 0xA,
|
||||||
|
AL_EAXREVERB_REFLECTIONS_PAN = 0xB,
|
||||||
|
AL_EAXREVERB_LATE_REVERB_GAIN = 0xC,
|
||||||
|
AL_EAXREVERB_LATE_REVERB_DELAY = 0xD,
|
||||||
|
AL_EAXREVERB_LATE_REVERB_PAN = 0xE,
|
||||||
|
AL_EAXREVERB_ECHO_TIME = 0xF,
|
||||||
|
AL_EAXREVERB_ECHO_DEPTH = 0x10,
|
||||||
|
AL_EAXREVERB_MODULATION_TIME = 0x11,
|
||||||
|
AL_EAXREVERB_MODULATION_DEPTH = 0x12,
|
||||||
|
AL_EAXREVERB_AIR_ABSORPTION_GAINHF = 0x13,
|
||||||
|
AL_EAXREVERB_HFREFERENCE = 0x14,
|
||||||
|
AL_EAXREVERB_LFREFERENCE = 0x15,
|
||||||
|
AL_EAXREVERB_ROOM_ROLLOFF_FACTOR = 0x16,
|
||||||
|
AL_EAXREVERB_DECAY_HFLIMIT = 0x17,
|
||||||
|
AL_CHORUS_WAVEFORM = 0x1,
|
||||||
|
AL_CHORUS_PHASE = 0x2,
|
||||||
|
AL_CHORUS_RATE = 0x3,
|
||||||
|
AL_CHORUS_DEPTH = 0x4,
|
||||||
|
AL_CHORUS_FEEDBACK = 0x5,
|
||||||
|
AL_CHORUS_DELAY = 0x6,
|
||||||
|
AL_DISTORTION_EDGE = 0x1,
|
||||||
|
AL_DISTORTION_GAIN = 0x2,
|
||||||
|
AL_DISTORTION_LOWPASS_CUTOFF = 0x3,
|
||||||
|
AL_DISTORTION_EQCENTER = 0x4,
|
||||||
|
AL_DISTORTION_EQBANDWIDTH = 0x5,
|
||||||
|
AL_ECHO_DELAY = 0x1,
|
||||||
|
AL_ECHO_LRDELAY = 0x2,
|
||||||
|
AL_ECHO_DAMPING = 0x3,
|
||||||
|
AL_ECHO_FEEDBACK = 0x4,
|
||||||
|
AL_ECHO_SPREAD = 0x5,
|
||||||
|
AL_FLANGER_WAVEFORM = 0x1,
|
||||||
|
AL_FLANGER_PHASE = 0x2,
|
||||||
|
AL_FLANGER_RATE = 0x3,
|
||||||
|
AL_FLANGER_DEPTH = 0x4,
|
||||||
|
AL_FLANGER_FEEDBACK = 0x5,
|
||||||
|
AL_FLANGER_DELAY = 0x6,
|
||||||
|
AL_FREQUENCY_SHIFTER_FREQUENCY = 0x1,
|
||||||
|
AL_FREQUENCY_SHIFTER_LEFT_DIRECTION = 0x2,
|
||||||
|
AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION = 0x3,
|
||||||
|
AL_VOCAL_MORPHER_PHONEMEA = 0x1,
|
||||||
|
AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING = 0x2,
|
||||||
|
AL_VOCAL_MORPHER_PHONEMEB = 0x3,
|
||||||
|
AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING = 0x4,
|
||||||
|
AL_VOCAL_MORPHER_WAVEFORM = 0x5,
|
||||||
|
AL_VOCAL_MORPHER_RATE = 0x6,
|
||||||
|
AL_PITCH_SHIFTER_COARSE_TUNE = 0x1,
|
||||||
|
AL_PITCH_SHIFTER_FINE_TUNE = 0x2,
|
||||||
|
AL_RING_MODULATOR_FREQUENCY = 0x1,
|
||||||
|
AL_RING_MODULATOR_HIGHPASS_CUTOFF = 0x2,
|
||||||
|
AL_RING_MODULATOR_WAVEFORM = 0x3,
|
||||||
|
AL_AUTOWAH_ATTACK_TIME = 0x1,
|
||||||
|
AL_AUTOWAH_RELEASE_TIME = 0x2,
|
||||||
|
AL_AUTOWAH_RESONANCE = 0x3,
|
||||||
|
AL_AUTOWAH_PEAK_GAIN = 0x4,
|
||||||
|
AL_COMPRESSOR_ONOFF = 0x1,
|
||||||
|
AL_EQUALIZER_LOW_GAIN = 0x1,
|
||||||
|
AL_EQUALIZER_LOW_CUTOFF = 0x2,
|
||||||
|
AL_EQUALIZER_MID1_GAIN = 0x3,
|
||||||
|
AL_EQUALIZER_MID1_CENTER = 0x4,
|
||||||
|
AL_EQUALIZER_MID1_WIDTH = 0x5,
|
||||||
|
AL_EQUALIZER_MID2_GAIN = 0x6,
|
||||||
|
AL_EQUALIZER_MID2_CENTER = 0x7,
|
||||||
|
AL_EQUALIZER_MID2_WIDTH = 0x8,
|
||||||
|
AL_EQUALIZER_HIGH_GAIN = 0x9,
|
||||||
|
AL_EQUALIZER_HIGH_CUTOFF = 0xA,
|
||||||
|
AL_EFFECT_FIRST_PARAMETER = 0x0,
|
||||||
|
AL_EFFECT_LAST_PARAMETER = 0x8000,
|
||||||
|
AL_EFFECT_TYPE = 0x8001,
|
||||||
|
AL_EFFECT_NULL = 0x0,
|
||||||
|
AL_EFFECT_REVERB = 0x1,
|
||||||
|
AL_EFFECT_CHORUS = 0x2,
|
||||||
|
AL_EFFECT_DISTORTION = 0x3,
|
||||||
|
AL_EFFECT_ECHO = 0x4,
|
||||||
|
AL_EFFECT_FLANGER = 0x5,
|
||||||
|
AL_EFFECT_FREQUENCY_SHIFTER = 0x6,
|
||||||
|
AL_EFFECT_VOCAL_MORPHER = 0x7,
|
||||||
|
AL_EFFECT_PITCH_SHIFTER = 0x8,
|
||||||
|
AL_EFFECT_RING_MODULATOR = 0x9,
|
||||||
|
AL_EFFECT_AUTOWAH = 0xA,
|
||||||
|
AL_EFFECT_COMPRESSOR = 0xB,
|
||||||
|
AL_EFFECT_EQUALIZER = 0xC,
|
||||||
|
AL_EFFECT_EAXREVERB = 0x8000,
|
||||||
|
AL_LOWPASS_GAIN = 0x1,
|
||||||
|
AL_LOWPASS_GAINHF = 0x2,
|
||||||
|
AL_HIGHPASS_GAIN = 0x1,
|
||||||
|
AL_HIGHPASS_GAINLF = 0x2,
|
||||||
|
AL_BANDPASS_GAIN = 0x1,
|
||||||
|
AL_BANDPASS_GAINLF = 0x2,
|
||||||
|
AL_BANDPASS_GAINHF = 0x3,
|
||||||
|
AL_FILTER_FIRST_PARAMETER = 0x0,
|
||||||
|
AL_FILTER_LAST_PARAMETER = 0x8000,
|
||||||
|
AL_FILTER_TYPE = 0x8001,
|
||||||
|
AL_FILTER_NULL = 0x0,
|
||||||
|
AL_FILTER_LOWPASS = 0x1,
|
||||||
|
AL_FILTER_HIGHPASS = 0x2,
|
||||||
|
AL_FILTER_BANDPASS = 0x3;
|
||||||
|
|
||||||
|
public static final float AL_MIN_AIR_ABSORPTION_FACTOR = 0.0f,
|
||||||
|
AL_MAX_AIR_ABSORPTION_FACTOR = 10.0f,
|
||||||
|
AL_DEFAULT_AIR_ABSORPTION_FACTOR = 0.0f,
|
||||||
|
AL_MIN_ROOM_ROLLOFF_FACTOR = 0.0f,
|
||||||
|
AL_MAX_ROOM_ROLLOFF_FACTOR = 10.0f,
|
||||||
|
AL_DEFAULT_ROOM_ROLLOFF_FACTOR = 0.0f,
|
||||||
|
AL_MIN_CONE_OUTER_GAINHF = 0.0f,
|
||||||
|
AL_MAX_CONE_OUTER_GAINHF = 1.0f,
|
||||||
|
AL_DEFAULT_CONE_OUTER_GAINHF = 1.0f;
|
||||||
|
|
||||||
|
public static final int AL_MIN_DIRECT_FILTER_GAINHF_AUTO = 0x0,
|
||||||
|
AL_MAX_DIRECT_FILTER_GAINHF_AUTO = 0x1,
|
||||||
|
AL_DEFAULT_DIRECT_FILTER_GAINHF_AUTO = 0x1,
|
||||||
|
AL_MIN_AUXILIARY_SEND_FILTER_GAIN_AUTO = 0x0,
|
||||||
|
AL_MAX_AUXILIARY_SEND_FILTER_GAIN_AUTO = 0x1,
|
||||||
|
AL_DEFAULT_AUXILIARY_SEND_FILTER_GAIN_AUTO = 0x1,
|
||||||
|
AL_MIN_AUXILIARY_SEND_FILTER_GAINHF_AUTO = 0x0,
|
||||||
|
AL_MAX_AUXILIARY_SEND_FILTER_GAINHF_AUTO = 0x1,
|
||||||
|
AL_DEFAULT_AUXILIARY_SEND_FILTER_GAINHF_AUTO = 0x1;
|
||||||
|
|
||||||
|
public static final float AL_MIN_METERS_PER_UNIT = 1.4E-45f,
|
||||||
|
AL_MAX_METERS_PER_UNIT = 3.4028235E38f,
|
||||||
|
AL_DEFAULT_METERS_PER_UNIT = 1.0f,
|
||||||
|
AL_REVERB_MIN_DENSITY = 0.0f,
|
||||||
|
AL_REVERB_MAX_DENSITY = 1.0f,
|
||||||
|
AL_REVERB_DEFAULT_DENSITY = 1.0f,
|
||||||
|
AL_REVERB_MIN_DIFFUSION = 0.0f,
|
||||||
|
AL_REVERB_MAX_DIFFUSION = 1.0f,
|
||||||
|
AL_REVERB_DEFAULT_DIFFUSION = 1.0f,
|
||||||
|
AL_REVERB_MIN_GAIN = 0.0f,
|
||||||
|
AL_REVERB_MAX_GAIN = 1.0f,
|
||||||
|
AL_REVERB_DEFAULT_GAIN = 0.32f,
|
||||||
|
AL_REVERB_MIN_GAINHF = 0.0f,
|
||||||
|
AL_REVERB_MAX_GAINHF = 1.0f,
|
||||||
|
AL_REVERB_DEFAULT_GAINHF = 0.89f,
|
||||||
|
AL_REVERB_MIN_DECAY_TIME = 0.1f,
|
||||||
|
AL_REVERB_MAX_DECAY_TIME = 20.0f,
|
||||||
|
AL_REVERB_DEFAULT_DECAY_TIME = 1.49f,
|
||||||
|
AL_REVERB_MIN_DECAY_HFRATIO = 0.1f,
|
||||||
|
AL_REVERB_MAX_DECAY_HFRATIO = 2.0f,
|
||||||
|
AL_REVERB_DEFAULT_DECAY_HFRATIO = 0.83f,
|
||||||
|
AL_REVERB_MIN_REFLECTIONS_GAIN = 0.0f,
|
||||||
|
AL_REVERB_MAX_REFLECTIONS_GAIN = 3.16f,
|
||||||
|
AL_REVERB_DEFAULT_REFLECTIONS_GAIN = 0.05f,
|
||||||
|
AL_REVERB_MIN_REFLECTIONS_DELAY = 0.0f,
|
||||||
|
AL_REVERB_MAX_REFLECTIONS_DELAY = 0.3f,
|
||||||
|
AL_REVERB_DEFAULT_REFLECTIONS_DELAY = 0.007f,
|
||||||
|
AL_REVERB_MIN_LATE_REVERB_GAIN = 0.0f,
|
||||||
|
AL_REVERB_MAX_LATE_REVERB_GAIN = 10.0f,
|
||||||
|
AL_REVERB_DEFAULT_LATE_REVERB_GAIN = 1.26f,
|
||||||
|
AL_REVERB_MIN_LATE_REVERB_DELAY = 0.0f,
|
||||||
|
AL_REVERB_MAX_LATE_REVERB_DELAY = 0.1f,
|
||||||
|
AL_REVERB_DEFAULT_LATE_REVERB_DELAY = 0.011f,
|
||||||
|
AL_REVERB_MIN_AIR_ABSORPTION_GAINHF = 0.892f,
|
||||||
|
AL_REVERB_MAX_AIR_ABSORPTION_GAINHF = 1.0f,
|
||||||
|
AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF = 0.994f,
|
||||||
|
AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR = 0.0f,
|
||||||
|
AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR = 10.0f,
|
||||||
|
AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR = 0.0f;
|
||||||
|
|
||||||
|
public static final int AL_REVERB_MIN_DECAY_HFLIMIT = 0x0,
|
||||||
|
AL_REVERB_MAX_DECAY_HFLIMIT = 0x1,
|
||||||
|
AL_REVERB_DEFAULT_DECAY_HFLIMIT = 0x1;
|
||||||
|
|
||||||
|
public static final float AL_EAXREVERB_MIN_DENSITY = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_DENSITY = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_DENSITY = 1.0f,
|
||||||
|
AL_EAXREVERB_MIN_DIFFUSION = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_DIFFUSION = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_DIFFUSION = 1.0f,
|
||||||
|
AL_EAXREVERB_MIN_GAIN = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_GAIN = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_GAIN = 0.32f,
|
||||||
|
AL_EAXREVERB_MIN_GAINHF = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_GAINHF = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_GAINHF = 0.89f,
|
||||||
|
AL_EAXREVERB_MIN_GAINLF = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_GAINLF = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_GAINLF = 1.0f,
|
||||||
|
AL_EAXREVERB_MIN_DECAY_TIME = 0.1f,
|
||||||
|
AL_EAXREVERB_MAX_DECAY_TIME = 20.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_DECAY_TIME = 1.49f,
|
||||||
|
AL_EAXREVERB_MIN_DECAY_HFRATIO = 0.1f,
|
||||||
|
AL_EAXREVERB_MAX_DECAY_HFRATIO = 2.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_DECAY_HFRATIO = 0.83f,
|
||||||
|
AL_EAXREVERB_MIN_DECAY_LFRATIO = 0.1f,
|
||||||
|
AL_EAXREVERB_MAX_DECAY_LFRATIO = 2.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_DECAY_LFRATIO = 1.0f,
|
||||||
|
AL_EAXREVERB_MIN_REFLECTIONS_GAIN = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_REFLECTIONS_GAIN = 3.16f,
|
||||||
|
AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN = 0.05f,
|
||||||
|
AL_EAXREVERB_MIN_REFLECTIONS_DELAY = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_REFLECTIONS_DELAY = 0.3f,
|
||||||
|
AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY = 0.007f,
|
||||||
|
AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ = 0.0f,
|
||||||
|
AL_EAXREVERB_MIN_LATE_REVERB_GAIN = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_LATE_REVERB_GAIN = 10.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN = 1.26f,
|
||||||
|
AL_EAXREVERB_MIN_LATE_REVERB_DELAY = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_LATE_REVERB_DELAY = 0.1f,
|
||||||
|
AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY = 0.011f,
|
||||||
|
AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ = 0.0f,
|
||||||
|
AL_EAXREVERB_MIN_ECHO_TIME = 0.075f,
|
||||||
|
AL_EAXREVERB_MAX_ECHO_TIME = 0.25f,
|
||||||
|
AL_EAXREVERB_DEFAULT_ECHO_TIME = 0.25f,
|
||||||
|
AL_EAXREVERB_MIN_ECHO_DEPTH = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_ECHO_DEPTH = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_ECHO_DEPTH = 0.0f,
|
||||||
|
AL_EAXREVERB_MIN_MODULATION_TIME = 0.04f,
|
||||||
|
AL_EAXREVERB_MAX_MODULATION_TIME = 4.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_MODULATION_TIME = 0.25f,
|
||||||
|
AL_EAXREVERB_MIN_MODULATION_DEPTH = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_MODULATION_DEPTH = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_MODULATION_DEPTH = 0.0f,
|
||||||
|
AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF = 0.892f,
|
||||||
|
AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF = 1.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF = 0.994f,
|
||||||
|
AL_EAXREVERB_MIN_HFREFERENCE = 1000.0f,
|
||||||
|
AL_EAXREVERB_MAX_HFREFERENCE = 20000.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_HFREFERENCE = 5000.0f,
|
||||||
|
AL_EAXREVERB_MIN_LFREFERENCE = 20.0f,
|
||||||
|
AL_EAXREVERB_MAX_LFREFERENCE = 1000.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_LFREFERENCE = 250.0f,
|
||||||
|
AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR = 0.0f,
|
||||||
|
AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR = 10.0f,
|
||||||
|
AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR = 0.0f;
|
||||||
|
|
||||||
|
public static final int AL_EAXREVERB_MIN_DECAY_HFLIMIT = 0x0,
|
||||||
|
AL_EAXREVERB_MAX_DECAY_HFLIMIT = 0x1,
|
||||||
|
AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT = 0x1,
|
||||||
|
AL_CHORUS_WAVEFORM_SINUSOID = 0x0,
|
||||||
|
AL_CHORUS_WAVEFORM_TRIANGLE = 0x1,
|
||||||
|
AL_CHORUS_MIN_WAVEFORM = 0x0,
|
||||||
|
AL_CHORUS_MAX_WAVEFORM = 0x1,
|
||||||
|
AL_CHORUS_DEFAULT_WAVEFORM = 0x1,
|
||||||
|
AL_CHORUS_MIN_PHASE = 0xFFFFFF4C,
|
||||||
|
AL_CHORUS_MAX_PHASE = 0xB4,
|
||||||
|
AL_CHORUS_DEFAULT_PHASE = 0x5A;
|
||||||
|
|
||||||
|
public static final float AL_CHORUS_MIN_RATE = 0.0f,
|
||||||
|
AL_CHORUS_MAX_RATE = 10.0f,
|
||||||
|
AL_CHORUS_DEFAULT_RATE = 1.1f,
|
||||||
|
AL_CHORUS_MIN_DEPTH = 0.0f,
|
||||||
|
AL_CHORUS_MAX_DEPTH = 1.0f,
|
||||||
|
AL_CHORUS_DEFAULT_DEPTH = 0.1f,
|
||||||
|
AL_CHORUS_MIN_FEEDBACK = -1.0f,
|
||||||
|
AL_CHORUS_MAX_FEEDBACK = 1.0f,
|
||||||
|
AL_CHORUS_DEFAULT_FEEDBACK = 0.25f,
|
||||||
|
AL_CHORUS_MIN_DELAY = 0.0f,
|
||||||
|
AL_CHORUS_MAX_DELAY = 0.016f,
|
||||||
|
AL_CHORUS_DEFAULT_DELAY = 0.016f,
|
||||||
|
AL_DISTORTION_MIN_EDGE = 0.0f,
|
||||||
|
AL_DISTORTION_MAX_EDGE = 1.0f,
|
||||||
|
AL_DISTORTION_DEFAULT_EDGE = 0.2f,
|
||||||
|
AL_DISTORTION_MIN_GAIN = 0.01f,
|
||||||
|
AL_DISTORTION_MAX_GAIN = 1.0f,
|
||||||
|
AL_DISTORTION_DEFAULT_GAIN = 0.05f,
|
||||||
|
AL_DISTORTION_MIN_LOWPASS_CUTOFF = 80.0f,
|
||||||
|
AL_DISTORTION_MAX_LOWPASS_CUTOFF = 24000.0f,
|
||||||
|
AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF = 8000.0f,
|
||||||
|
AL_DISTORTION_MIN_EQCENTER = 80.0f,
|
||||||
|
AL_DISTORTION_MAX_EQCENTER = 24000.0f,
|
||||||
|
AL_DISTORTION_DEFAULT_EQCENTER = 3600.0f,
|
||||||
|
AL_DISTORTION_MIN_EQBANDWIDTH = 80.0f,
|
||||||
|
AL_DISTORTION_MAX_EQBANDWIDTH = 24000.0f,
|
||||||
|
AL_DISTORTION_DEFAULT_EQBANDWIDTH = 3600.0f,
|
||||||
|
AL_ECHO_MIN_DELAY = 0.0f,
|
||||||
|
AL_ECHO_MAX_DELAY = 0.207f,
|
||||||
|
AL_ECHO_DEFAULT_DELAY = 0.1f,
|
||||||
|
AL_ECHO_MIN_LRDELAY = 0.0f,
|
||||||
|
AL_ECHO_MAX_LRDELAY = 0.404f,
|
||||||
|
AL_ECHO_DEFAULT_LRDELAY = 0.1f,
|
||||||
|
AL_ECHO_MIN_DAMPING = 0.0f,
|
||||||
|
AL_ECHO_MAX_DAMPING = 0.99f,
|
||||||
|
AL_ECHO_DEFAULT_DAMPING = 0.5f,
|
||||||
|
AL_ECHO_MIN_FEEDBACK = 0.0f,
|
||||||
|
AL_ECHO_MAX_FEEDBACK = 1.0f,
|
||||||
|
AL_ECHO_DEFAULT_FEEDBACK = 0.5f,
|
||||||
|
AL_ECHO_MIN_SPREAD = -1.0f,
|
||||||
|
AL_ECHO_MAX_SPREAD = 1.0f,
|
||||||
|
AL_ECHO_DEFAULT_SPREAD = -1.0f;
|
||||||
|
|
||||||
|
public static final int AL_FLANGER_WAVEFORM_SINUSOID = 0x0,
|
||||||
|
AL_FLANGER_WAVEFORM_TRIANGLE = 0x1,
|
||||||
|
AL_FLANGER_MIN_WAVEFORM = 0x0,
|
||||||
|
AL_FLANGER_MAX_WAVEFORM = 0x1,
|
||||||
|
AL_FLANGER_DEFAULT_WAVEFORM = 0x1,
|
||||||
|
AL_FLANGER_MIN_PHASE = 0xFFFFFF4C,
|
||||||
|
AL_FLANGER_MAX_PHASE = 0xB4,
|
||||||
|
AL_FLANGER_DEFAULT_PHASE = 0x0;
|
||||||
|
|
||||||
|
public static final float AL_FLANGER_MIN_RATE = 0.0f,
|
||||||
|
AL_FLANGER_MAX_RATE = 10.0f,
|
||||||
|
AL_FLANGER_DEFAULT_RATE = 0.27f,
|
||||||
|
AL_FLANGER_MIN_DEPTH = 0.0f,
|
||||||
|
AL_FLANGER_MAX_DEPTH = 1.0f,
|
||||||
|
AL_FLANGER_DEFAULT_DEPTH = 1.0f,
|
||||||
|
AL_FLANGER_MIN_FEEDBACK = -1.0f,
|
||||||
|
AL_FLANGER_MAX_FEEDBACK = 1.0f,
|
||||||
|
AL_FLANGER_DEFAULT_FEEDBACK = -0.5f,
|
||||||
|
AL_FLANGER_MIN_DELAY = 0.0f,
|
||||||
|
AL_FLANGER_MAX_DELAY = 0.004f,
|
||||||
|
AL_FLANGER_DEFAULT_DELAY = 0.002f,
|
||||||
|
AL_FREQUENCY_SHIFTER_MIN_FREQUENCY = 0.0f,
|
||||||
|
AL_FREQUENCY_SHIFTER_MAX_FREQUENCY = 24000.0f,
|
||||||
|
AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY = 0.0f;
|
||||||
|
|
||||||
|
public static final int AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION = 0x0,
|
||||||
|
AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION = 0x2,
|
||||||
|
AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION = 0x0,
|
||||||
|
AL_FREQUENCY_SHIFTER_DIRECTION_DOWN = 0x0,
|
||||||
|
AL_FREQUENCY_SHIFTER_DIRECTION_UP = 0x1,
|
||||||
|
AL_FREQUENCY_SHIFTER_DIRECTION_OFF = 0x2,
|
||||||
|
AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION = 0x0,
|
||||||
|
AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION = 0x2,
|
||||||
|
AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MIN_PHONEMEA = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MAX_PHONEMEA = 0x1D,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_PHONEMEA = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING = 0xFFFFFFE8,
|
||||||
|
AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING = 0x18,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MIN_PHONEMEB = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MAX_PHONEMEB = 0x1D,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_PHONEMEB = 0xA,
|
||||||
|
AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING = 0xFFFFFFE8,
|
||||||
|
AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING = 0x18,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_A = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_E = 0x1,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_I = 0x2,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_O = 0x3,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_U = 0x4,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_AA = 0x5,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_AE = 0x6,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_AH = 0x7,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_AO = 0x8,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_EH = 0x9,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_ER = 0xA,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_IH = 0xB,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_IY = 0xC,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_UH = 0xD,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_UW = 0xE,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_B = 0xF,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_D = 0x10,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_F = 0x11,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_G = 0x12,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_J = 0x13,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_K = 0x14,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_L = 0x15,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_M = 0x16,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_N = 0x17,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_P = 0x18,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_R = 0x19,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_S = 0x1A,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_T = 0x1B,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_V = 0x1C,
|
||||||
|
AL_VOCAL_MORPHER_PHONEME_Z = 0x1D,
|
||||||
|
AL_VOCAL_MORPHER_WAVEFORM_SINUSOID = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE = 0x1,
|
||||||
|
AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH = 0x2,
|
||||||
|
AL_VOCAL_MORPHER_MIN_WAVEFORM = 0x0,
|
||||||
|
AL_VOCAL_MORPHER_MAX_WAVEFORM = 0x2,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_WAVEFORM = 0x0;
|
||||||
|
|
||||||
|
public static final float AL_VOCAL_MORPHER_MIN_RATE = 0.0f,
|
||||||
|
AL_VOCAL_MORPHER_MAX_RATE = 10.0f,
|
||||||
|
AL_VOCAL_MORPHER_DEFAULT_RATE = 1.41f;
|
||||||
|
|
||||||
|
public static final int AL_PITCH_SHIFTER_MIN_COARSE_TUNE = 0xFFFFFFF4,
|
||||||
|
AL_PITCH_SHIFTER_MAX_COARSE_TUNE = 0xC,
|
||||||
|
AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE = 0xC,
|
||||||
|
AL_PITCH_SHIFTER_MIN_FINE_TUNE = 0xFFFFFFCE,
|
||||||
|
AL_PITCH_SHIFTER_MAX_FINE_TUNE = 0x32,
|
||||||
|
AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE = 0x0;
|
||||||
|
|
||||||
|
public static final float AL_RING_MODULATOR_MIN_FREQUENCY = 0.0f,
|
||||||
|
AL_RING_MODULATOR_MAX_FREQUENCY = 8000.0f,
|
||||||
|
AL_RING_MODULATOR_DEFAULT_FREQUENCY = 440.0f,
|
||||||
|
AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF = 0.0f,
|
||||||
|
AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF = 24000.0f,
|
||||||
|
AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF = 800.0f;
|
||||||
|
|
||||||
|
public static final int AL_RING_MODULATOR_SINUSOID = 0x0,
|
||||||
|
AL_RING_MODULATOR_SAWTOOTH = 0x1,
|
||||||
|
AL_RING_MODULATOR_SQUARE = 0x2,
|
||||||
|
AL_RING_MODULATOR_MIN_WAVEFORM = 0x0,
|
||||||
|
AL_RING_MODULATOR_MAX_WAVEFORM = 0x2,
|
||||||
|
AL_RING_MODULATOR_DEFAULT_WAVEFORM = 0x0;
|
||||||
|
|
||||||
|
public static final float AL_AUTOWAH_MIN_ATTACK_TIME = 1.0E-4f,
|
||||||
|
AL_AUTOWAH_MAX_ATTACK_TIME = 1.0f,
|
||||||
|
AL_AUTOWAH_DEFAULT_ATTACK_TIME = 0.06f,
|
||||||
|
AL_AUTOWAH_MIN_RELEASE_TIME = 1.0E-4f,
|
||||||
|
AL_AUTOWAH_MAX_RELEASE_TIME = 1.0f,
|
||||||
|
AL_AUTOWAH_DEFAULT_RELEASE_TIME = 0.06f,
|
||||||
|
AL_AUTOWAH_MIN_RESONANCE = 2.0f,
|
||||||
|
AL_AUTOWAH_MAX_RESONANCE = 1000.0f,
|
||||||
|
AL_AUTOWAH_DEFAULT_RESONANCE = 1000.0f,
|
||||||
|
AL_AUTOWAH_MIN_PEAK_GAIN = 3.0E-5f,
|
||||||
|
AL_AUTOWAH_MAX_PEAK_GAIN = 31621.0f,
|
||||||
|
AL_AUTOWAH_DEFAULT_PEAK_GAIN = 11.22f;
|
||||||
|
|
||||||
|
public static final int AL_COMPRESSOR_MIN_ONOFF = 0x0,
|
||||||
|
AL_COMPRESSOR_MAX_ONOFF = 0x1,
|
||||||
|
AL_COMPRESSOR_DEFAULT_ONOFF = 0x1;
|
||||||
|
|
||||||
|
public static final float AL_EQUALIZER_MIN_LOW_GAIN = 0.126f,
|
||||||
|
AL_EQUALIZER_MAX_LOW_GAIN = 7.943f,
|
||||||
|
AL_EQUALIZER_DEFAULT_LOW_GAIN = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_LOW_CUTOFF = 50.0f,
|
||||||
|
AL_EQUALIZER_MAX_LOW_CUTOFF = 800.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_LOW_CUTOFF = 200.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID1_GAIN = 0.126f,
|
||||||
|
AL_EQUALIZER_MAX_MID1_GAIN = 7.943f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID1_GAIN = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID1_CENTER = 200.0f,
|
||||||
|
AL_EQUALIZER_MAX_MID1_CENTER = 3000.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID1_CENTER = 500.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID1_WIDTH = 0.01f,
|
||||||
|
AL_EQUALIZER_MAX_MID1_WIDTH = 1.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID1_WIDTH = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID2_GAIN = 0.126f,
|
||||||
|
AL_EQUALIZER_MAX_MID2_GAIN = 7.943f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID2_GAIN = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID2_CENTER = 1000.0f,
|
||||||
|
AL_EQUALIZER_MAX_MID2_CENTER = 8000.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID2_CENTER = 3000.0f,
|
||||||
|
AL_EQUALIZER_MIN_MID2_WIDTH = 0.01f,
|
||||||
|
AL_EQUALIZER_MAX_MID2_WIDTH = 1.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_MID2_WIDTH = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_HIGH_GAIN = 0.126f,
|
||||||
|
AL_EQUALIZER_MAX_HIGH_GAIN = 7.943f,
|
||||||
|
AL_EQUALIZER_DEFAULT_HIGH_GAIN = 1.0f,
|
||||||
|
AL_EQUALIZER_MIN_HIGH_CUTOFF = 4000.0f,
|
||||||
|
AL_EQUALIZER_MAX_HIGH_CUTOFF = 16000.0f,
|
||||||
|
AL_EQUALIZER_DEFAULT_HIGH_CUTOFF = 6000.0f,
|
||||||
|
LOWPASS_MIN_GAIN = 0.0f,
|
||||||
|
LOWPASS_MAX_GAIN = 1.0f,
|
||||||
|
LOWPASS_DEFAULT_GAIN = 1.0f,
|
||||||
|
LOWPASS_MIN_GAINHF = 0.0f,
|
||||||
|
LOWPASS_MAX_GAINHF = 1.0f,
|
||||||
|
LOWPASS_DEFAULT_GAINHF = 1.0f,
|
||||||
|
HIGHPASS_MIN_GAIN = 0.0f,
|
||||||
|
HIGHPASS_MAX_GAIN = 1.0f,
|
||||||
|
HIGHPASS_DEFAULT_GAIN = 1.0f,
|
||||||
|
HIGHPASS_MIN_GAINLF = 0.0f,
|
||||||
|
HIGHPASS_MAX_GAINLF = 1.0f,
|
||||||
|
HIGHPASS_DEFAULT_GAINLF = 1.0f,
|
||||||
|
BANDPASS_MIN_GAIN = 0.0f,
|
||||||
|
BANDPASS_MAX_GAIN = 1.0f,
|
||||||
|
BANDPASS_DEFAULT_GAIN = 1.0f,
|
||||||
|
BANDPASS_MIN_GAINHF = 0.0f,
|
||||||
|
BANDPASS_MAX_GAINHF = 1.0f,
|
||||||
|
BANDPASS_DEFAULT_GAINHF = 1.0f,
|
||||||
|
BANDPASS_MIN_GAINLF = 0.0f,
|
||||||
|
BANDPASS_MAX_GAINLF = 1.0f,
|
||||||
|
BANDPASS_DEFAULT_GAINLF = 1.0f;
|
||||||
|
|
||||||
|
private EFX10() {}
|
||||||
|
|
||||||
|
static native void initNativeStubs() throws LWJGLException;
|
||||||
|
|
||||||
|
public static void alGenAuxiliaryEffectSlots(IntBuffer auxiliaryeffectslots) {
|
||||||
|
BufferChecks.checkDirect(auxiliaryeffectslots);
|
||||||
|
nalGenAuxiliaryEffectSlots(auxiliaryeffectslots.remaining(), MemoryUtil.getAddress(auxiliaryeffectslots));
|
||||||
|
}
|
||||||
|
static native void nalGenAuxiliaryEffectSlots(int auxiliaryeffectslots_n, long auxiliaryeffectslots);
|
||||||
|
|
||||||
|
/** Overloads alGenAuxiliaryEffectSlots. */
|
||||||
|
public static int alGenAuxiliaryEffectSlots() {
|
||||||
|
int __result = nalGenAuxiliaryEffectSlots2(1);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGenAuxiliaryEffectSlots2(int n);
|
||||||
|
|
||||||
|
public static void alDeleteAuxiliaryEffectSlots(IntBuffer auxiliaryeffectslots) {
|
||||||
|
BufferChecks.checkDirect(auxiliaryeffectslots);
|
||||||
|
nalDeleteAuxiliaryEffectSlots(auxiliaryeffectslots.remaining(), MemoryUtil.getAddress(auxiliaryeffectslots));
|
||||||
|
}
|
||||||
|
static native void nalDeleteAuxiliaryEffectSlots(int auxiliaryeffectslots_n, long auxiliaryeffectslots);
|
||||||
|
|
||||||
|
/** Overloads alDeleteAuxiliaryEffectSlots. */
|
||||||
|
public static void alDeleteAuxiliaryEffectSlots(int auxiliaryeffectslot) {
|
||||||
|
nalDeleteAuxiliaryEffectSlots2(1, auxiliaryeffectslot);
|
||||||
|
}
|
||||||
|
static native void nalDeleteAuxiliaryEffectSlots2(int n, int auxiliaryeffectslot);
|
||||||
|
|
||||||
|
public static boolean alIsAuxiliaryEffectSlot(int auxiliaryeffectslot) {
|
||||||
|
boolean __result = nalIsAuxiliaryEffectSlot(auxiliaryeffectslot);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native boolean nalIsAuxiliaryEffectSlot(int auxiliaryeffectslot);
|
||||||
|
|
||||||
|
public static void alAuxiliaryEffectSloti(int auxiliaryeffectslot, int param, int value) {
|
||||||
|
nalAuxiliaryEffectSloti(auxiliaryeffectslot, param, value);
|
||||||
|
}
|
||||||
|
static native void nalAuxiliaryEffectSloti(int auxiliaryeffectslot, int param, int value);
|
||||||
|
|
||||||
|
public static void alAuxiliaryEffectSlot(int auxiliaryeffectslot, int param, IntBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalAuxiliaryEffectSlotiv(auxiliaryeffectslot, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalAuxiliaryEffectSlotiv(int auxiliaryeffectslot, int param, long values);
|
||||||
|
|
||||||
|
public static void alAuxiliaryEffectSlotf(int auxiliaryeffectslot, int param, float value) {
|
||||||
|
nalAuxiliaryEffectSlotf(auxiliaryeffectslot, param, value);
|
||||||
|
}
|
||||||
|
static native void nalAuxiliaryEffectSlotf(int auxiliaryeffectslot, int param, float value);
|
||||||
|
|
||||||
|
public static void alAuxiliaryEffectSlot(int auxiliaryeffectslot, int param, FloatBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalAuxiliaryEffectSlotfv(auxiliaryeffectslot, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalAuxiliaryEffectSlotfv(int auxiliaryeffectslot, int param, long values);
|
||||||
|
|
||||||
|
public static int alGetAuxiliaryEffectSloti(int auxiliaryeffectslot, int param) {
|
||||||
|
int __result = nalGetAuxiliaryEffectSloti(auxiliaryeffectslot, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGetAuxiliaryEffectSloti(int auxiliaryeffectslot, int param);
|
||||||
|
|
||||||
|
public static void alGetAuxiliaryEffectSlot(int auxiliaryeffectslot, int param, IntBuffer intdata) {
|
||||||
|
BufferChecks.checkBuffer(intdata, 1);
|
||||||
|
nalGetAuxiliaryEffectSlotiv(auxiliaryeffectslot, param, MemoryUtil.getAddress(intdata));
|
||||||
|
}
|
||||||
|
static native void nalGetAuxiliaryEffectSlotiv(int auxiliaryeffectslot, int param, long intdata);
|
||||||
|
|
||||||
|
public static float alGetAuxiliaryEffectSlotf(int auxiliaryeffectslot, int param) {
|
||||||
|
float __result = nalGetAuxiliaryEffectSlotf(auxiliaryeffectslot, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native float nalGetAuxiliaryEffectSlotf(int auxiliaryeffectslot, int param);
|
||||||
|
|
||||||
|
public static void alGetAuxiliaryEffectSlot(int auxiliaryeffectslot, int param, FloatBuffer floatdata) {
|
||||||
|
BufferChecks.checkBuffer(floatdata, 1);
|
||||||
|
nalGetAuxiliaryEffectSlotfv(auxiliaryeffectslot, param, MemoryUtil.getAddress(floatdata));
|
||||||
|
}
|
||||||
|
static native void nalGetAuxiliaryEffectSlotfv(int auxiliaryeffectslot, int param, long floatdata);
|
||||||
|
|
||||||
|
public static void alGenEffects(IntBuffer effects) {
|
||||||
|
BufferChecks.checkDirect(effects);
|
||||||
|
nalGenEffects(effects.remaining(), MemoryUtil.getAddress(effects));
|
||||||
|
}
|
||||||
|
static native void nalGenEffects(int effects_n, long effects);
|
||||||
|
|
||||||
|
/** Overloads alGenEffects. */
|
||||||
|
public static int alGenEffects() {
|
||||||
|
int __result = nalGenEffects2(1);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGenEffects2(int n);
|
||||||
|
|
||||||
|
public static void alDeleteEffects(IntBuffer effects) {
|
||||||
|
BufferChecks.checkDirect(effects);
|
||||||
|
nalDeleteEffects(effects.remaining(), MemoryUtil.getAddress(effects));
|
||||||
|
}
|
||||||
|
static native void nalDeleteEffects(int effects_n, long effects);
|
||||||
|
|
||||||
|
/** Overloads alDeleteEffects. */
|
||||||
|
public static void alDeleteEffects(int effect) {
|
||||||
|
nalDeleteEffects2(1, effect);
|
||||||
|
}
|
||||||
|
static native void nalDeleteEffects2(int n, int effect);
|
||||||
|
|
||||||
|
public static boolean alIsEffect(int effect) {
|
||||||
|
boolean __result = nalIsEffect(effect);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native boolean nalIsEffect(int effect);
|
||||||
|
|
||||||
|
public static void alEffecti(int effect, int param, int value) {
|
||||||
|
nalEffecti(effect, param, value);
|
||||||
|
}
|
||||||
|
static native void nalEffecti(int effect, int param, int value);
|
||||||
|
|
||||||
|
public static void alEffect(int effect, int param, IntBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalEffectiv(effect, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalEffectiv(int effect, int param, long values);
|
||||||
|
|
||||||
|
public static void alEffectf(int effect, int param, float value) {
|
||||||
|
nalEffectf(effect, param, value);
|
||||||
|
}
|
||||||
|
static native void nalEffectf(int effect, int param, float value);
|
||||||
|
|
||||||
|
public static void alEffect(int effect, int param, FloatBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalEffectfv(effect, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalEffectfv(int effect, int param, long values);
|
||||||
|
|
||||||
|
public static int alGetEffecti(int effect, int param) {
|
||||||
|
int __result = nalGetEffecti(effect, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGetEffecti(int effect, int param);
|
||||||
|
|
||||||
|
public static void alGetEffect(int effect, int param, IntBuffer intdata) {
|
||||||
|
BufferChecks.checkBuffer(intdata, 1);
|
||||||
|
nalGetEffectiv(effect, param, MemoryUtil.getAddress(intdata));
|
||||||
|
}
|
||||||
|
static native void nalGetEffectiv(int effect, int param, long intdata);
|
||||||
|
|
||||||
|
public static float alGetEffectf(int effect, int param) {
|
||||||
|
float __result = nalGetEffectf(effect, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native float nalGetEffectf(int effect, int param);
|
||||||
|
|
||||||
|
public static void alGetEffect(int effect, int param, FloatBuffer floatdata) {
|
||||||
|
BufferChecks.checkBuffer(floatdata, 1);
|
||||||
|
nalGetEffectfv(effect, param, MemoryUtil.getAddress(floatdata));
|
||||||
|
}
|
||||||
|
static native void nalGetEffectfv(int effect, int param, long floatdata);
|
||||||
|
|
||||||
|
public static void alGenFilters(IntBuffer filters) {
|
||||||
|
BufferChecks.checkDirect(filters);
|
||||||
|
nalGenFilters(filters.remaining(), MemoryUtil.getAddress(filters));
|
||||||
|
}
|
||||||
|
static native void nalGenFilters(int filters_n, long filters);
|
||||||
|
|
||||||
|
/** Overloads alGenFilters. */
|
||||||
|
public static int alGenFilters() {
|
||||||
|
int __result = nalGenFilters2(1);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGenFilters2(int n);
|
||||||
|
|
||||||
|
public static void alDeleteFilters(IntBuffer filters) {
|
||||||
|
BufferChecks.checkDirect(filters);
|
||||||
|
nalDeleteFilters(filters.remaining(), MemoryUtil.getAddress(filters));
|
||||||
|
}
|
||||||
|
static native void nalDeleteFilters(int filters_n, long filters);
|
||||||
|
|
||||||
|
/** Overloads alDeleteFilters. */
|
||||||
|
public static void alDeleteFilters(int filter) {
|
||||||
|
nalDeleteFilters2(1, filter);
|
||||||
|
}
|
||||||
|
static native void nalDeleteFilters2(int n, int filter);
|
||||||
|
|
||||||
|
public static boolean alIsFilter(int filter) {
|
||||||
|
boolean __result = nalIsFilter(filter);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native boolean nalIsFilter(int filter);
|
||||||
|
|
||||||
|
public static void alFilteri(int filter, int param, int value) {
|
||||||
|
nalFilteri(filter, param, value);
|
||||||
|
}
|
||||||
|
static native void nalFilteri(int filter, int param, int value);
|
||||||
|
|
||||||
|
public static void alFilter(int filter, int param, IntBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalFilteriv(filter, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalFilteriv(int filter, int param, long values);
|
||||||
|
|
||||||
|
public static void alFilterf(int filter, int param, float value) {
|
||||||
|
nalFilterf(filter, param, value);
|
||||||
|
}
|
||||||
|
static native void nalFilterf(int filter, int param, float value);
|
||||||
|
|
||||||
|
public static void alFilter(int filter, int param, FloatBuffer values) {
|
||||||
|
BufferChecks.checkBuffer(values, 1);
|
||||||
|
nalFilterfv(filter, param, MemoryUtil.getAddress(values));
|
||||||
|
}
|
||||||
|
static native void nalFilterfv(int filter, int param, long values);
|
||||||
|
|
||||||
|
public static int alGetFilteri(int filter, int param) {
|
||||||
|
int __result = nalGetFilteri(filter, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nalGetFilteri(int filter, int param);
|
||||||
|
|
||||||
|
public static void alGetFilter(int filter, int param, IntBuffer intdata) {
|
||||||
|
BufferChecks.checkBuffer(intdata, 1);
|
||||||
|
nalGetFilteriv(filter, param, MemoryUtil.getAddress(intdata));
|
||||||
|
}
|
||||||
|
static native void nalGetFilteriv(int filter, int param, long intdata);
|
||||||
|
|
||||||
|
public static float alGetFilterf(int filter, int param) {
|
||||||
|
float __result = nalGetFilterf(filter, param);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native float nalGetFilterf(int filter, int param);
|
||||||
|
|
||||||
|
public static void alGetFilter(int filter, int param, FloatBuffer floatdata) {
|
||||||
|
BufferChecks.checkBuffer(floatdata, 1);
|
||||||
|
nalGetFilterfv(filter, param, MemoryUtil.getAddress(floatdata));
|
||||||
|
}
|
||||||
|
static native void nalGetFilterfv(int filter, int param, long floatdata);
|
||||||
|
}
|
|
@ -0,0 +1,228 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
import static org.lwjgl.openal.AL10.*;
|
||||||
|
import static org.lwjgl.openal.EFX10.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for the OpenAL extension ALC_EXT_EFX. Provides functions to check for the extension
|
||||||
|
* and support of various effects and filters.
|
||||||
|
* <p>
|
||||||
|
* Currently supports ALC_EXT_EFX version 1.0 effects and filters.
|
||||||
|
*
|
||||||
|
* @author Ciardhubh <ciardhubh[at]ciardhubh.de>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public final class EFXUtil {
|
||||||
|
|
||||||
|
/** Constant for testSupportGeneric to check an effect. */
|
||||||
|
private static final int EFFECT = 1111;
|
||||||
|
/** Constant for testSupportGeneric to check a filter. */
|
||||||
|
private static final int FILTER = 2222;
|
||||||
|
|
||||||
|
/** Utility class, hidden contructor. */
|
||||||
|
private EFXUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if OpenAL implementation is loaded and supports ALC_EXT_EFX.
|
||||||
|
*
|
||||||
|
* @return True if ALC_EXT_EFX is supported, false if not.
|
||||||
|
* @throws OpenALException If OpenAL has not been created yet.
|
||||||
|
*/
|
||||||
|
public static boolean isEfxSupported() {
|
||||||
|
if (!AL.isCreated()) {
|
||||||
|
throw new OpenALException("OpenAL has not been created.");
|
||||||
|
}
|
||||||
|
return ALC10.alcIsExtensionPresent(AL.getDevice(), ALC_EXT_EFX_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests OpenAL to see whether the given effect type is supported. This is done by creating an
|
||||||
|
* effect of the given type. If creation succeeds the effect is supported.
|
||||||
|
*
|
||||||
|
* @param effectType Type of effect whose support is to be tested, e.g. AL_EFFECT_REVERB.
|
||||||
|
* @return True if it is supported, false if not.
|
||||||
|
* @throws OpenALException If the request fails due to an AL_OUT_OF_MEMORY error or OpenAL has
|
||||||
|
* not been created yet.
|
||||||
|
* @throws IllegalArgumentException effectType is not a valid effect type.
|
||||||
|
*/
|
||||||
|
public static boolean isEffectSupported(final int effectType) {
|
||||||
|
// Make sure type is a real effect.
|
||||||
|
switch (effectType) {
|
||||||
|
case AL_EFFECT_NULL:
|
||||||
|
case AL_EFFECT_EAXREVERB:
|
||||||
|
case AL_EFFECT_REVERB:
|
||||||
|
case AL_EFFECT_CHORUS:
|
||||||
|
case AL_EFFECT_DISTORTION:
|
||||||
|
case AL_EFFECT_ECHO:
|
||||||
|
case AL_EFFECT_FLANGER:
|
||||||
|
case AL_EFFECT_FREQUENCY_SHIFTER:
|
||||||
|
case AL_EFFECT_VOCAL_MORPHER:
|
||||||
|
case AL_EFFECT_PITCH_SHIFTER:
|
||||||
|
case AL_EFFECT_RING_MODULATOR:
|
||||||
|
case AL_EFFECT_AUTOWAH:
|
||||||
|
case AL_EFFECT_COMPRESSOR:
|
||||||
|
case AL_EFFECT_EQUALIZER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown or invalid effect type: " + effectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return testSupportGeneric(EFFECT, effectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests OpenAL to see whether the given filter type is supported. This is done by creating a
|
||||||
|
* filter of the given type. If creation succeeds the filter is supported.
|
||||||
|
*
|
||||||
|
* @param filterType Type of filter whose support is to be tested, e.g. AL_FILTER_LOWPASS.
|
||||||
|
* @return True if it is supported, false if not.
|
||||||
|
* @throws OpenALException If the request fails due to an AL_OUT_OF_MEMORY error or OpenAL has
|
||||||
|
* not been created yet.
|
||||||
|
* @throws IllegalArgumentException filterType is not a valid filter type.
|
||||||
|
*/
|
||||||
|
public static boolean isFilterSupported(final int filterType) {
|
||||||
|
// Make sure type is a real filter.
|
||||||
|
switch (filterType) {
|
||||||
|
case AL_FILTER_NULL:
|
||||||
|
case AL_FILTER_LOWPASS:
|
||||||
|
case AL_FILTER_HIGHPASS:
|
||||||
|
case AL_FILTER_BANDPASS:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown or invalid filter type: " + filterType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return testSupportGeneric(FILTER, filterType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic test function to see if an EFX object supports a given kind of type. Works for
|
||||||
|
* effects and filters.
|
||||||
|
*
|
||||||
|
* @param objectType Type of object to test. Must be either EFXUtil.EFFECT or EFXUtil.FILTER.
|
||||||
|
* @param typeValue OpenAL type the object should be tested for support, e.g. AL_FILTER_LOWPASS
|
||||||
|
* or AL_EFFECT_REVERB.
|
||||||
|
* @return True if object supports typeValue, false else.
|
||||||
|
*/
|
||||||
|
private static boolean testSupportGeneric(final int objectType, final int typeValue) {
|
||||||
|
// Check for supported objectType.
|
||||||
|
switch (objectType) {
|
||||||
|
case EFFECT:
|
||||||
|
case FILTER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean supported = false;
|
||||||
|
if (isEfxSupported()) {
|
||||||
|
|
||||||
|
// Try to create object in order to check AL's response.
|
||||||
|
alGetError();
|
||||||
|
int genError;
|
||||||
|
int testObject = 0;
|
||||||
|
try {
|
||||||
|
switch (objectType) { // Create object based on type
|
||||||
|
case EFFECT:
|
||||||
|
testObject = alGenEffects();
|
||||||
|
break;
|
||||||
|
case FILTER:
|
||||||
|
testObject = alGenFilters();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||||
|
}
|
||||||
|
genError = alGetError();
|
||||||
|
} catch (final OpenALException debugBuildException) {
|
||||||
|
// Hack because OpenALException hides the original error code (short of parsing the
|
||||||
|
// error message String which would break if it gets changed).
|
||||||
|
if (debugBuildException.getMessage().contains("AL_OUT_OF_MEMORY")) {
|
||||||
|
genError = AL_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
genError = AL_INVALID_OPERATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (genError == AL_NO_ERROR) {
|
||||||
|
// Successfully created, now try to set type.
|
||||||
|
alGetError();
|
||||||
|
int setError;
|
||||||
|
try {
|
||||||
|
switch (objectType) { // Set based on object type
|
||||||
|
case EFFECT:
|
||||||
|
alEffecti(testObject, AL_EFFECT_TYPE, typeValue);
|
||||||
|
break;
|
||||||
|
case FILTER:
|
||||||
|
alFilteri(testObject, AL_FILTER_TYPE, typeValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||||
|
}
|
||||||
|
setError = alGetError();
|
||||||
|
} catch (final OpenALException debugBuildException) {
|
||||||
|
// Hack because OpenALException hides the original error code (short of parsing
|
||||||
|
// the error message String which would break when it gets changed).
|
||||||
|
setError = AL_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setError == AL_NO_ERROR) {
|
||||||
|
supported = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
try {
|
||||||
|
switch (objectType) { // Set based on object type
|
||||||
|
case EFFECT:
|
||||||
|
alDeleteEffects(testObject);
|
||||||
|
break;
|
||||||
|
case FILTER:
|
||||||
|
alDeleteFilters(testObject);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||||
|
}
|
||||||
|
} catch (final OpenALException debugBuildException) {
|
||||||
|
// Don't care about cleanup errors.
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (genError == AL_OUT_OF_MEMORY) {
|
||||||
|
throw new OpenALException(genError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <br>
|
||||||
|
* Thrown by the debug build library of the LWJGL if any OpenAL operation
|
||||||
|
* causes an error.
|
||||||
|
*
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
public class OpenALException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for OpenALException.
|
||||||
|
*/
|
||||||
|
public OpenALException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that takes an AL error number
|
||||||
|
*/
|
||||||
|
public OpenALException(int error_code) {
|
||||||
|
super("OpenAL error: " + AL10.alGetString(error_code) + " (" + error_code + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for OpenALException.
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public OpenALException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for OpenALException.
|
||||||
|
* @param message
|
||||||
|
* @param cause
|
||||||
|
*/
|
||||||
|
public OpenALException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for OpenALException.
|
||||||
|
* @param cause
|
||||||
|
*/
|
||||||
|
public OpenALException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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.openal;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple utility class for checking AL/ALC errors
|
||||||
|
*
|
||||||
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||||
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
|
||||||
|
public final class Util {
|
||||||
|
/** No c'tor */
|
||||||
|
private Util() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for any ALC errors and throws an unchecked exception on errors
|
||||||
|
* @param device Device for which to check ALC errors
|
||||||
|
*/
|
||||||
|
public static void checkALCError(ALCdevice device) {
|
||||||
|
int err = ALC10.alcGetError(device);
|
||||||
|
if (err != ALC10.ALC_NO_ERROR)
|
||||||
|
throw new OpenALException(ALC10.alcGetString(AL.getDevice(), err));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for any AL errors and throws an unchecked exception on errors
|
||||||
|
*/
|
||||||
|
public static void checkALError() {
|
||||||
|
int err = AL10.alGetError();
|
||||||
|
if (err != AL10.AL_NO_ERROR)
|
||||||
|
throw new OpenALException(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for a valid device
|
||||||
|
* @param device ALCdevice to check the validity of
|
||||||
|
*/
|
||||||
|
public static void checkALCValidDevice(ALCdevice device) {
|
||||||
|
if(!device.isValid()) {
|
||||||
|
throw new OpenALException("Invalid device: " + device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for a valid context
|
||||||
|
* @param context ALCcontext to check the validity of
|
||||||
|
*/
|
||||||
|
public static void checkALCValidContext(ALCcontext context) {
|
||||||
|
if(!context.isValid()) {
|
||||||
|
throw new OpenALException("Invalid context: " + context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class AMDDeviceAttributeQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as the <param_name> parameter of clGetDeviceInfo. Return the
|
||||||
|
* offset in nano-seconds between an event timestamp and Epoch.
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_PROFILING_TIMER_OFFSET_AMD = 0x4036;
|
||||||
|
|
||||||
|
private AMDDeviceAttributeQuery() {}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class AMDDeviceMemoryFlags {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alloc from GPU's CPU visible heap.
|
||||||
|
*/
|
||||||
|
public static final int CL_MEM_USE_PERSISTENT_MEM_AMD = 0x40;
|
||||||
|
|
||||||
|
private AMDDeviceMemoryFlags() {}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class AMDOfflineDevices {
|
||||||
|
|
||||||
|
public static final int CL_CONTEXT_OFFLINE_DEVICES_AMD = 0x403F;
|
||||||
|
|
||||||
|
private AMDOfflineDevices() {}
|
||||||
|
}
|
|
@ -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.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_device_attribute_query {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as the <param_name> parameter of clGetDeviceInfo. Return the
|
||||||
|
* offset in nano-seconds between an event timestamp and Epoch.
|
||||||
|
*/
|
||||||
|
int CL_DEVICE_PROFILING_TIMER_OFFSET_AMD = 0x4036;
|
||||||
|
|
||||||
|
}
|
|
@ -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.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_device_memory_flags {
|
||||||
|
|
||||||
|
/** Alloc from GPU's CPU visible heap. */
|
||||||
|
int CL_MEM_USE_PERSISTENT_MEM_AMD = (1 << 6);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_fp64 {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_media_ops {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_media_ops2 {
|
||||||
|
|
||||||
|
}
|
|
@ -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.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_offline_devices {
|
||||||
|
|
||||||
|
int CL_CONTEXT_OFFLINE_DEVICES_AMD = 0x403F;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_popcnt {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_printf {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface AMD_vec3 {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,550 @@
|
||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
import org.lwjgl.opencl.FastLongMap.Entry;
|
||||||
|
|
||||||
|
import java.nio.*;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import static org.lwjgl.opencl.APPLEGLSharing.*;
|
||||||
|
import static org.lwjgl.opencl.CL10.*;
|
||||||
|
import static org.lwjgl.opencl.EXTDeviceFission.*;
|
||||||
|
import static org.lwjgl.opencl.KHRGLSharing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for OpenCL API calls.
|
||||||
|
*
|
||||||
|
* @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<char[]> arrayTL = new ThreadLocal<char[]>() {
|
||||||
|
protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final ThreadLocal<ByteBuffer> bufferByteTL = new ThreadLocal<ByteBuffer>() {
|
||||||
|
protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final ThreadLocal<PointerBuffer> bufferPointerTL = new ThreadLocal<PointerBuffer>() {
|
||||||
|
protected PointerBuffer initialValue() { return BufferUtils.createPointerBuffer(INITIAL_BUFFER_SIZE); }
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final ThreadLocal<PointerBuffer> lengthsTL = new ThreadLocal<PointerBuffer>() {
|
||||||
|
protected PointerBuffer initialValue() { return BufferUtils.createPointerBuffer(INITIAL_LENGTHS_SIZE); }
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() {
|
||||||
|
protected Buffers initialValue() { return new Buffers(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple ASCII encoding.
|
||||||
|
*
|
||||||
|
* @param buffer The target buffer
|
||||||
|
* @param string The source string
|
||||||
|
*/
|
||||||
|
private static ByteBuffer encode(final ByteBuffer buffer, final CharSequence string) {
|
||||||
|
for ( int i = 0; i < string.length(); i++ ) {
|
||||||
|
final char c = string.charAt(i);
|
||||||
|
if ( LWJGLUtil.DEBUG && 0x80 <= c ) // Silently ignore and map to 0x1A.
|
||||||
|
buffer.put((byte)0x1A);
|
||||||
|
else
|
||||||
|
buffer.put((byte)c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 long getBuffer(final CharSequence string) {
|
||||||
|
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress0(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the specified string as bytes, starting at the specified offset.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
*
|
||||||
|
* @return the String as a ByteBuffer
|
||||||
|
*/
|
||||||
|
static long getBuffer(final CharSequence string, final int offset) {
|
||||||
|
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the specified string as bytes, including null-termination.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
*
|
||||||
|
* @return the String as a ByteBuffer
|
||||||
|
*/
|
||||||
|
static long getBufferNT(final CharSequence string) {
|
||||||
|
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
|
||||||
|
buffer.put((byte)0);
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress0(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTotalLength(final CharSequence[] strings) {
|
||||||
|
int length = 0;
|
||||||
|
for ( CharSequence string : strings )
|
||||||
|
length += string.length();
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the specified strings as bytes.
|
||||||
|
*
|
||||||
|
* @param strings
|
||||||
|
*
|
||||||
|
* @return the Strings as a ByteBuffer
|
||||||
|
*/
|
||||||
|
static long getBuffer(final CharSequence[] strings) {
|
||||||
|
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
|
||||||
|
|
||||||
|
for ( CharSequence string : strings )
|
||||||
|
encode(buffer, string);
|
||||||
|
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress0(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the specified strings as bytes, including null-termination.
|
||||||
|
*
|
||||||
|
* @param strings
|
||||||
|
*
|
||||||
|
* @return the Strings as a ByteBuffer
|
||||||
|
*/
|
||||||
|
static long getBufferNT(final CharSequence[] strings) {
|
||||||
|
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
|
||||||
|
|
||||||
|
for ( CharSequence string : strings ) {
|
||||||
|
encode(buffer, string);
|
||||||
|
buffer.put((byte)0);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress0(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the lengths of the specified strings.
|
||||||
|
*
|
||||||
|
* @param strings
|
||||||
|
*
|
||||||
|
* @return the String lengths in a PointerBuffer
|
||||||
|
*/
|
||||||
|
static long getLengths(final CharSequence[] strings) {
|
||||||
|
PointerBuffer buffer = getLengths(strings.length);
|
||||||
|
|
||||||
|
for ( CharSequence string : strings )
|
||||||
|
buffer.put(string.length());
|
||||||
|
|
||||||
|
buffer.flip();
|
||||||
|
return MemoryUtil.getAddress0(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a buffer containing the lengths of the specified buffers.
|
||||||
|
*
|
||||||
|
* @param buffers the buffer array
|
||||||
|
*
|
||||||
|
* @return the buffer lengths in a PointerBuffer
|
||||||
|
*/
|
||||||
|
static long getLengths(final ByteBuffer[] buffers) {
|
||||||
|
PointerBuffer lengths = getLengths(buffers.length);
|
||||||
|
|
||||||
|
for ( ByteBuffer buffer : buffers )
|
||||||
|
lengths.put(buffer.remaining());
|
||||||
|
|
||||||
|
lengths.flip();
|
||||||
|
return MemoryUtil.getAddress0(lengths);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 long getPointer(final PointerWrapper pointer) {
|
||||||
|
return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer));
|
||||||
|
}
|
||||||
|
|
||||||
|
static long getPointerSafe(final PointerWrapper pointer) {
|
||||||
|
return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer == null ? 0L : pointer.getPointer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
OPENCL API UTILITIES BELOW
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
static Set<String> getExtensions(final String extensionList) {
|
||||||
|
final Set<String> extensions = new HashSet<String>();
|
||||||
|
|
||||||
|
if ( extensionList != null ) {
|
||||||
|
final StringTokenizer tokenizer = new StringTokenizer(extensionList);
|
||||||
|
while ( tokenizer.hasMoreTokens() )
|
||||||
|
extensions.add(tokenizer.nextToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isDevicesParam(final int param_name) {
|
||||||
|
switch ( param_name ) {
|
||||||
|
case CL_CONTEXT_DEVICES:
|
||||||
|
case CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR:
|
||||||
|
case CL_DEVICES_FOR_GL_CONTEXT_KHR:
|
||||||
|
case CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE:
|
||||||
|
case CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CLPlatform getCLPlatform(final PointerBuffer properties) {
|
||||||
|
long platformID = 0;
|
||||||
|
|
||||||
|
final int keys = properties.remaining() / 2;
|
||||||
|
for ( int k = 0; k < keys; k++ ) {
|
||||||
|
final long key = properties.get(k << 1);
|
||||||
|
if ( key == 0 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( key == CL_CONTEXT_PLATFORM ) {
|
||||||
|
platformID = properties.get((k << 1) + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( platformID == 0 )
|
||||||
|
throw new IllegalArgumentException("Could not find CL_CONTEXT_PLATFORM in cl_context_properties.");
|
||||||
|
|
||||||
|
final CLPlatform platform = CLPlatform.getCLPlatform(platformID);
|
||||||
|
if ( platform == null )
|
||||||
|
throw new IllegalStateException("Could not find a valid CLPlatform. Make sure clGetPlatformIDs has been used before.");
|
||||||
|
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.isValid() || 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.isValid() || 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.isValid() || 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.isValid() || queue.getReferenceCount() > 1 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
releaseObjects(queue.getCLEventRegistry(), DESTRUCTOR_CLEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends CLObjectChild> void releaseObjects(final CLObjectRegistry<T> registry, final ObjectDestructor<T> destructor) {
|
||||||
|
if ( registry.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
for ( Entry<T> entry : registry.getAll() ) {
|
||||||
|
final T object = entry.value;
|
||||||
|
while ( object.isValid() )
|
||||||
|
destructor.release(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() {
|
||||||
|
public void release(final CLDevice object) { clReleaseDeviceEXT(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() {
|
||||||
|
public void release(final CLMem object) { clReleaseMemObject(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLCommandQueue> DESTRUCTOR_CLCommandQueue = new ObjectDestructor<CLCommandQueue>() {
|
||||||
|
public void release(final CLCommandQueue object) { clReleaseCommandQueue(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() {
|
||||||
|
public void release(final CLSampler object) { clReleaseSampler(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() {
|
||||||
|
public void release(final CLProgram object) { clReleaseProgram(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() {
|
||||||
|
public void release(final CLKernel object) { clReleaseKernel(object); }
|
||||||
|
};
|
||||||
|
private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() {
|
||||||
|
public void release(final CLEvent object) { clReleaseEvent(object); }
|
||||||
|
};
|
||||||
|
|
||||||
|
private interface ObjectDestructor<T extends CLObjectChild> {
|
||||||
|
|
||||||
|
void release(T object);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
final class APPLEContextLoggingFunctions {
|
||||||
|
|
||||||
|
private APPLEContextLoggingFunctions() {}
|
||||||
|
|
||||||
|
static void clLogMessagesToSystemLogAPPLE(ByteBuffer errstr, ByteBuffer private_info, ByteBuffer user_data) {
|
||||||
|
long function_pointer = CLCapabilities.clLogMessagesToSystemLogAPPLE;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(errstr);
|
||||||
|
BufferChecks.checkDirect(private_info);
|
||||||
|
BufferChecks.checkDirect(user_data);
|
||||||
|
nclLogMessagesToSystemLogAPPLE(MemoryUtil.getAddress(errstr), MemoryUtil.getAddress(private_info), private_info.remaining(), MemoryUtil.getAddress(user_data), function_pointer);
|
||||||
|
}
|
||||||
|
static native void nclLogMessagesToSystemLogAPPLE(long errstr, long private_info, long private_info_cb, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
static void clLogMessagesToStdoutAPPLE(ByteBuffer errstr, ByteBuffer private_info, ByteBuffer user_data) {
|
||||||
|
long function_pointer = CLCapabilities.clLogMessagesToStdoutAPPLE;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(errstr);
|
||||||
|
BufferChecks.checkDirect(private_info);
|
||||||
|
BufferChecks.checkDirect(user_data);
|
||||||
|
nclLogMessagesToStdoutAPPLE(MemoryUtil.getAddress(errstr), MemoryUtil.getAddress(private_info), private_info.remaining(), MemoryUtil.getAddress(user_data), function_pointer);
|
||||||
|
}
|
||||||
|
static native void nclLogMessagesToStdoutAPPLE(long errstr, long private_info, long private_info_cb, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
static void clLogMessagesToStderrAPPLE(ByteBuffer errstr, ByteBuffer private_info, ByteBuffer user_data) {
|
||||||
|
long function_pointer = CLCapabilities.clLogMessagesToStderrAPPLE;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(errstr);
|
||||||
|
BufferChecks.checkDirect(private_info);
|
||||||
|
BufferChecks.checkDirect(user_data);
|
||||||
|
nclLogMessagesToStderrAPPLE(MemoryUtil.getAddress(errstr), MemoryUtil.getAddress(private_info), private_info.remaining(), MemoryUtil.getAddress(user_data), function_pointer);
|
||||||
|
}
|
||||||
|
static native void nclLogMessagesToStderrAPPLE(long errstr, long private_info, long private_info_cb, long user_data, long function_pointer);
|
||||||
|
}
|
|
@ -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.
|
||||||
|
* <p/>
|
||||||
|
* 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.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() {}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class APPLEGLSharing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enumerated value can be specified as part of the <properties> argument passed to clCreateContext
|
||||||
|
* to allow OpenCL compliant devices in an existing CGL share group to be used as the devices in
|
||||||
|
* the newly created CL context. GL objects that were allocated in the given CGL share group can
|
||||||
|
* now be shared between CL and GL.
|
||||||
|
*/
|
||||||
|
public static final int CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE = 0x10000000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a cl_device_id for the CL device associated with the virtual screen for
|
||||||
|
* the given CGL context. Return type: cl_device_id
|
||||||
|
*/
|
||||||
|
public static final int CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE = 0x10000002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of cl_device_ids for the CL device(s) corresponding to
|
||||||
|
* the virtual screen(s) for the given CGL context. Return type: cl_device_id[]
|
||||||
|
*/
|
||||||
|
public static final int CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE = 0x10000003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error code returned by clGetGLContextInfoAPPLE if an invalid platform_gl_ctx is provided
|
||||||
|
*/
|
||||||
|
public static final int CL_INVALID_GL_CONTEXT_APPLE = 0xFFFFFC18;
|
||||||
|
|
||||||
|
private APPLEGLSharing() {}
|
||||||
|
|
||||||
|
public static int clGetGLContextInfoAPPLE(CLContext context, PointerBuffer platform_gl_ctx, int param_name, ByteBuffer param_value, PointerBuffer param_value_size_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clGetGLContextInfoAPPLE;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(platform_gl_ctx, 1);
|
||||||
|
if (param_value != null)
|
||||||
|
BufferChecks.checkDirect(param_value);
|
||||||
|
if (param_value_size_ret != null)
|
||||||
|
BufferChecks.checkBuffer(param_value_size_ret, 1);
|
||||||
|
if ( param_value_size_ret == null && APIUtil.isDevicesParam(param_name) ) param_value_size_ret = APIUtil.getBufferPointer();
|
||||||
|
int __result = nclGetGLContextInfoAPPLE(context.getPointer(), MemoryUtil.getAddress(platform_gl_ctx), param_name, (param_value == null ? 0 : param_value.remaining()), MemoryUtil.getAddressSafe(param_value), MemoryUtil.getAddressSafe(param_value_size_ret), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS && param_value != null && APIUtil.isDevicesParam(param_name) ) context.getParent().registerCLDevices(param_value, param_value_size_ret);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclGetGLContextInfoAPPLE(long context, long platform_gl_ctx, int param_name, long param_value_param_value_size, long param_value, long param_value_size_ret, long function_pointer);
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class APPLESetMemObjectDestructor {
|
||||||
|
|
||||||
|
private APPLESetMemObjectDestructor() {}
|
||||||
|
|
||||||
|
public static int clSetMemObjectDestructorAPPLE(CLMem memobj, CLMemObjectDestructorCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clSetMemObjectDestructorAPPLE;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclSetMemObjectDestructorAPPLE(memobj.getPointer(), pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclSetMemObjectDestructorAPPLE(long memobj, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
}
|
|
@ -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.util.generator.*;
|
||||||
|
import org.lwjgl.util.generator.opencl.*;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
@Private
|
||||||
|
@CLPlatformExtension
|
||||||
|
@CLDeviceExtension
|
||||||
|
@Extension(postfix = "APPLE", nativeName = "cl_APPLE_ContextLoggingFunctions")
|
||||||
|
public interface APPLE_ContextLoggingFunctions {
|
||||||
|
|
||||||
|
@Extern
|
||||||
|
void clLogMessagesToSystemLogAPPLE(@Check @Const @cl_char ByteBuffer errstr,
|
||||||
|
@Const @cl_void ByteBuffer private_info,
|
||||||
|
@AutoSize("private_info") @size_t long cb,
|
||||||
|
@Check @cl_void ByteBuffer user_data);
|
||||||
|
|
||||||
|
@Extern
|
||||||
|
void clLogMessagesToStdoutAPPLE(@Check @Const @cl_char ByteBuffer errstr,
|
||||||
|
@Const @cl_void ByteBuffer private_info,
|
||||||
|
@AutoSize("private_info") @size_t long cb,
|
||||||
|
@Check @cl_void ByteBuffer user_data);
|
||||||
|
|
||||||
|
@Extern
|
||||||
|
void clLogMessagesToStderrAPPLE(@Check @Const @cl_char ByteBuffer errstr,
|
||||||
|
@Const @cl_void ByteBuffer private_info,
|
||||||
|
@AutoSize("private_info") @size_t long cb,
|
||||||
|
@Check @cl_void ByteBuffer user_data);
|
||||||
|
|
||||||
|
}
|
|
@ -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.util.generator.Code;
|
||||||
|
import org.lwjgl.util.generator.Constant;
|
||||||
|
import org.lwjgl.util.generator.Extension;
|
||||||
|
import org.lwjgl.util.generator.PointerWrapper;
|
||||||
|
import org.lwjgl.util.generator.opencl.CLDeviceExtension;
|
||||||
|
import org.lwjgl.util.generator.opencl.CLPlatformExtension;
|
||||||
|
import org.lwjgl.util.generator.opencl.cl_int;
|
||||||
|
|
||||||
|
@CLPlatformExtension
|
||||||
|
@CLDeviceExtension
|
||||||
|
@Extension(postfix = "APPLE", nativeName = "cl_APPLE_SetMemObjectDestructor")
|
||||||
|
public interface APPLE_SetMemObjectDestructor {
|
||||||
|
|
||||||
|
@Code(
|
||||||
|
tryBlock = true,
|
||||||
|
// Create a GlobalRef to the callback object.
|
||||||
|
javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);",
|
||||||
|
// Check if we need to delete the GlobalRef.
|
||||||
|
javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);"
|
||||||
|
)
|
||||||
|
@cl_int
|
||||||
|
int clSetMemObjectDestructorAPPLE(@PointerWrapper("cl_mem") CLMem memobj,
|
||||||
|
@PointerWrapper("cl_mem_object_destructor_callback") CLMemObjectDestructorCallback pfn_notify,
|
||||||
|
@Constant("user_data") @PointerWrapper("void *") long user_data);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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.util.generator.*;
|
||||||
|
import org.lwjgl.util.generator.opencl.*;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
@CLPlatformExtension
|
||||||
|
@CLDeviceExtension
|
||||||
|
@Extension(postfix = "APPLE", className = "APPLEGLSharing", nativeName = "cl_APPLE_gl_sharing")
|
||||||
|
public interface APPLE_gl_sharing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enumerated value can be specified as part of the <properties> argument passed to clCreateContext
|
||||||
|
* to allow OpenCL compliant devices in an existing CGL share group to be used as the devices in
|
||||||
|
* the newly created CL context. GL objects that were allocated in the given CGL share group can
|
||||||
|
* now be shared between CL and GL.
|
||||||
|
*/
|
||||||
|
int CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE = 0x10000000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a cl_device_id for the CL device associated with the virtual screen for
|
||||||
|
* the given CGL context. Return type: cl_device_id
|
||||||
|
*/
|
||||||
|
int CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE = 0x10000002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of cl_device_ids for the CL device(s) corresponding to
|
||||||
|
* the virtual screen(s) for the given CGL context. Return type: cl_device_id[]
|
||||||
|
*/
|
||||||
|
int CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE = 0x10000003;
|
||||||
|
|
||||||
|
/** Error code returned by clGetGLContextInfoAPPLE if an invalid platform_gl_ctx is provided */
|
||||||
|
int CL_INVALID_GL_CONTEXT_APPLE = -1000;
|
||||||
|
|
||||||
|
@Code(
|
||||||
|
javaBeforeNative = "\t\tif ( param_value_size_ret == null && APIUtil.isDevicesParam(param_name) ) param_value_size_ret = APIUtil.getBufferPointer();",
|
||||||
|
javaAfterNative = "\t\tif ( __result == CL10.CL_SUCCESS && param_value != null && APIUtil.isDevicesParam(param_name) ) context.getParent().registerCLDevices(param_value, param_value_size_ret);"
|
||||||
|
)
|
||||||
|
@cl_int
|
||||||
|
int clGetGLContextInfoAPPLE(@PointerWrapper("cl_context") CLContext context,
|
||||||
|
@Check("1") @NativeType("cl_void") PointerBuffer platform_gl_ctx,
|
||||||
|
@NativeType("cl_gl_platform_info") int param_name,
|
||||||
|
@AutoSize(value = "param_value", canBeNull = true) @size_t long param_value_size,
|
||||||
|
@OutParameter @Check(canBeNull = true) @cl_void ByteBuffer param_value,
|
||||||
|
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,158 @@
|
||||||
|
/*
|
||||||
|
* 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.MemoryUtil;
|
||||||
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ( String oclPath : oclPaths ) {
|
||||||
|
try {
|
||||||
|
nCreate(oclPath);
|
||||||
|
created = true;
|
||||||
|
break;
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Failed to load " + oclPath + ": " + 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.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 ( String aliase : aliases ) {
|
||||||
|
long address = getFunctionAddress(aliase);
|
||||||
|
if ( address != 0 )
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper method to get a pointer to a named function in the OpenCL library. */
|
||||||
|
static long getFunctionAddress(String name) {
|
||||||
|
ByteBuffer buffer = MemoryUtil.encodeASCII(name);
|
||||||
|
return ngetFunctionAddress(MemoryUtil.getAddress(buffer));
|
||||||
|
}
|
||||||
|
private static native long ngetFunctionAddress(long name);
|
||||||
|
|
||||||
|
static native ByteBuffer getHostBuffer(final long address, final int size);
|
||||||
|
|
||||||
|
private static native void resetNativeStubs(Class clazz);
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,146 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core OpenCL 1.0 OpenGL interrop functionality.
|
||||||
|
*/
|
||||||
|
public final class CL10GL {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_gl_object_type
|
||||||
|
*/
|
||||||
|
public static final int CL_GL_OBJECT_BUFFER = 0x2000,
|
||||||
|
CL_GL_OBJECT_TEXTURE2D = 0x2001,
|
||||||
|
CL_GL_OBJECT_TEXTURE3D = 0x2002,
|
||||||
|
CL_GL_OBJECT_RENDERBUFFER = 0x2003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_gl_texture_info
|
||||||
|
*/
|
||||||
|
public static final int CL_GL_TEXTURE_TARGET = 0x2004,
|
||||||
|
CL_GL_MIPMAP_LEVEL = 0x2005;
|
||||||
|
|
||||||
|
private CL10GL() {}
|
||||||
|
|
||||||
|
public static CLMem clCreateFromGLBuffer(CLContext context, long flags, int bufobj, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateFromGLBuffer;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateFromGLBuffer(context.getPointer(), flags, bufobj, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateFromGLBuffer(long context, long flags, int bufobj, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static CLMem clCreateFromGLTexture2D(CLContext context, long flags, int target, int miplevel, int texture, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateFromGLTexture2D;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateFromGLTexture2D(context.getPointer(), flags, target, miplevel, texture, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateFromGLTexture2D(long context, long flags, int target, int miplevel, int texture, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static CLMem clCreateFromGLTexture3D(CLContext context, long flags, int target, int miplevel, int texture, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateFromGLTexture3D;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateFromGLTexture3D(context.getPointer(), flags, target, miplevel, texture, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateFromGLTexture3D(long context, long flags, int target, int miplevel, int texture, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static CLMem clCreateFromGLRenderbuffer(CLContext context, long flags, int renderbuffer, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateFromGLRenderbuffer;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateFromGLRenderbuffer(context.getPointer(), flags, renderbuffer, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateFromGLRenderbuffer(long context, long flags, int renderbuffer, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static int clGetGLObjectInfo(CLMem memobj, IntBuffer gl_object_type, IntBuffer gl_object_name) {
|
||||||
|
long function_pointer = CLCapabilities.clGetGLObjectInfo;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (gl_object_type != null)
|
||||||
|
BufferChecks.checkBuffer(gl_object_type, 1);
|
||||||
|
if (gl_object_name != null)
|
||||||
|
BufferChecks.checkBuffer(gl_object_name, 1);
|
||||||
|
int __result = nclGetGLObjectInfo(memobj.getPointer(), MemoryUtil.getAddressSafe(gl_object_type), MemoryUtil.getAddressSafe(gl_object_name), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclGetGLObjectInfo(long memobj, long gl_object_type, long gl_object_name, long function_pointer);
|
||||||
|
|
||||||
|
public static int clGetGLTextureInfo(CLMem memobj, int param_name, ByteBuffer param_value, PointerBuffer param_value_size_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clGetGLTextureInfo;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (param_value != null)
|
||||||
|
BufferChecks.checkDirect(param_value);
|
||||||
|
if (param_value_size_ret != null)
|
||||||
|
BufferChecks.checkBuffer(param_value_size_ret, 1);
|
||||||
|
int __result = nclGetGLTextureInfo(memobj.getPointer(), param_name, (param_value == null ? 0 : param_value.remaining()), MemoryUtil.getAddressSafe(param_value), MemoryUtil.getAddressSafe(param_value_size_ret), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclGetGLTextureInfo(long memobj, int param_name, long param_value_param_value_size, long param_value, long param_value_size_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueAcquireGLObjects(CLCommandQueue command_queue, PointerBuffer mem_objects, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueAcquireGLObjects;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(mem_objects, 1);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueAcquireGLObjects(command_queue.getPointer(), mem_objects.remaining(), MemoryUtil.getAddress(mem_objects), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueAcquireGLObjects(long command_queue, int mem_objects_num_objects, long mem_objects, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clEnqueueAcquireGLObjects. */
|
||||||
|
public static int clEnqueueAcquireGLObjects(CLCommandQueue command_queue, CLMem mem_object, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueAcquireGLObjects;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueAcquireGLObjects(command_queue.getPointer(), 1, APIUtil.getPointer(mem_object), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int clEnqueueReleaseGLObjects(CLCommandQueue command_queue, PointerBuffer mem_objects, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReleaseGLObjects;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(mem_objects, 1);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReleaseGLObjects(command_queue.getPointer(), mem_objects.remaining(), MemoryUtil.getAddress(mem_objects), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueReleaseGLObjects(long command_queue, int mem_objects_num_objects, long mem_objects, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clEnqueueReleaseGLObjects. */
|
||||||
|
public static int clEnqueueReleaseGLObjects(CLCommandQueue command_queue, CLMem mem_object, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReleaseGLObjects;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReleaseGLObjects(command_queue.getPointer(), 1, APIUtil.getPointer(mem_object), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core OpenCL 1.1 API
|
||||||
|
*/
|
||||||
|
public final class CL11 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Codes
|
||||||
|
*/
|
||||||
|
public static final int CL_MISALIGNED_SUB_BUFFER_OFFSET = 0xFFFFFFF3,
|
||||||
|
CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST = 0xFFFFFFF2,
|
||||||
|
CL_INVALID_PROPERTY = 0xFFFFFFC0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenCL Version
|
||||||
|
*/
|
||||||
|
public static final int CL_VERSION_1_1 = 0x1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_device_info
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF = 0x1034,
|
||||||
|
CL_DEVICE_HOST_UNIFIED_MEMORY = 0x1035,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR = 0x1036,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT = 0x1037,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_INT = 0x1038,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG = 0x1039,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT = 0x103A,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE = 0x103B,
|
||||||
|
CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF = 0x103C,
|
||||||
|
CL_DEVICE_OPENCL_C_VERSION = 0x103D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_device_fp_config - bitfield
|
||||||
|
*/
|
||||||
|
public static final int CL_FP_SOFT_FLOAT = 0x40;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_context_info
|
||||||
|
*/
|
||||||
|
public static final int CL_CONTEXT_NUM_DEVICES = 0x1083;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_channel_order
|
||||||
|
*/
|
||||||
|
public static final int CL_Rx = 0x10BA,
|
||||||
|
CL_RGx = 0x10BB,
|
||||||
|
CL_RGBx = 0x10BC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_mem_info
|
||||||
|
*/
|
||||||
|
public static final int CL_MEM_ASSOCIATED_MEMOBJECT = 0x1107,
|
||||||
|
CL_MEM_OFFSET = 0x1108;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_addressing_mode
|
||||||
|
*/
|
||||||
|
public static final int CL_ADDRESS_MIRRORED_REPEAT = 0x1134;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_kernel_work_group_info
|
||||||
|
*/
|
||||||
|
public static final int CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE = 0x11B3,
|
||||||
|
CL_KERNEL_PRIVATE_MEM_SIZE = 0x11B4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_event_info
|
||||||
|
*/
|
||||||
|
public static final int CL_EVENT_CONTEXT = 0x11D4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_command_type
|
||||||
|
*/
|
||||||
|
public static final int CL_COMMAND_READ_BUFFER_RECT = 0x1201,
|
||||||
|
CL_COMMAND_WRITE_BUFFER_RECT = 0x1202,
|
||||||
|
CL_COMMAND_COPY_BUFFER_RECT = 0x1203,
|
||||||
|
CL_COMMAND_USER = 0x1204;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_buffer_create_type
|
||||||
|
*/
|
||||||
|
public static final int CL_BUFFER_CREATE_TYPE_REGION = 0x1220;
|
||||||
|
|
||||||
|
private CL11() {}
|
||||||
|
|
||||||
|
public static CLMem clCreateSubBuffer(CLMem buffer, long flags, int buffer_create_type, ByteBuffer buffer_create_info, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateSubBuffer;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_create_info, 2 * PointerBuffer.getPointerSize());
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = CLMem.create(nclCreateSubBuffer(buffer.getPointer(), flags, buffer_create_type, MemoryUtil.getAddress(buffer_create_info), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), buffer.getParent());
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateSubBuffer(long buffer, long flags, int buffer_create_type, long buffer_create_info, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static int clSetMemObjectDestructorCallback(CLMem memobj, CLMemObjectDestructorCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clSetMemObjectDestructorCallback;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclSetMemObjectDestructorCallback(memobj.getPointer(), pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclSetMemObjectDestructorCallback(long memobj, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, ByteBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, DoubleBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, FloatBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, IntBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, LongBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueReadBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_read, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, ShortBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueReadBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueReadBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_read, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueReadBufferRect(long command_queue, long buffer, int blocking_read, long buffer_offset, long host_offset, long region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, long ptr, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, ByteBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, DoubleBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, FloatBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, IntBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, LongBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static int clEnqueueWriteBufferRect(CLCommandQueue command_queue, CLMem buffer, int blocking_write, PointerBuffer buffer_offset, PointerBuffer host_offset, PointerBuffer region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, ShortBuffer ptr, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueWriteBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(buffer_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(host_offset, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
BufferChecks.checkBuffer(ptr, CLChecks.calculateBufferRectSize(host_offset, region, host_row_pitch, host_slice_pitch));
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueWriteBufferRect(command_queue.getPointer(), buffer.getPointer(), blocking_write, MemoryUtil.getAddress(buffer_offset), MemoryUtil.getAddress(host_offset), MemoryUtil.getAddress(region), buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, MemoryUtil.getAddress(ptr), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueWriteBufferRect(long command_queue, long buffer, int blocking_write, long buffer_offset, long host_offset, long region, long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, long ptr, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueCopyBufferRect(CLCommandQueue command_queue, CLMem src_buffer, CLMem dst_buffer, PointerBuffer src_origin, PointerBuffer dst_origin, PointerBuffer region, long src_row_pitch, long src_slice_pitch, long dst_row_pitch, long dst_slice_pitch, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueCopyBufferRect;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(src_origin, 3);
|
||||||
|
BufferChecks.checkBuffer(dst_origin, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueCopyBufferRect(command_queue.getPointer(), src_buffer.getPointer(), dst_buffer.getPointer(), MemoryUtil.getAddress(src_origin), MemoryUtil.getAddress(dst_origin), MemoryUtil.getAddress(region), src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueCopyBufferRect(long command_queue, long src_buffer, long dst_buffer, long src_origin, long dst_origin, long region, long src_row_pitch, long src_slice_pitch, long dst_row_pitch, long dst_slice_pitch, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static CLEvent clCreateUserEvent(CLContext context, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateUserEvent;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLEvent __result = new CLEvent(nclCreateUserEvent(context.getPointer(), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateUserEvent(long context, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static int clSetUserEventStatus(CLEvent event, int execution_status) {
|
||||||
|
long function_pointer = CLCapabilities.clSetUserEventStatus;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
int __result = nclSetUserEventStatus(event.getPointer(), execution_status, function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclSetUserEventStatus(long event, int execution_status, long function_pointer);
|
||||||
|
|
||||||
|
public static int clSetEventCallback(CLEvent event, int command_exec_callback_type, CLEventCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clSetEventCallback;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
pfn_notify.setRegistry(event.getParentRegistry());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclSetEventCallback(event.getPointer(), command_exec_callback_type, pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclSetEventCallback(long event, int command_exec_callback_type, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
}
|
|
@ -0,0 +1,495 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core OpenCL 1.1 API
|
||||||
|
*/
|
||||||
|
public final class CL12 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Codes
|
||||||
|
*/
|
||||||
|
public static final int CL_COMPILE_PROGRAM_FAILURE = 0xFFFFFFF1,
|
||||||
|
CL_LINKER_NOT_AVAILABLE = 0xFFFFFFF0,
|
||||||
|
CL_LINK_PROGRAM_FAILURE = 0xFFFFFFEF,
|
||||||
|
CL_DEVICE_PARTITION_FAILED = 0xFFFFFFEE,
|
||||||
|
CL_KERNEL_ARG_INFO_NOT_AVAILABLE = 0xFFFFFFED,
|
||||||
|
CL_INVALID_IMAGE_DESCRIPTOR = 0xFFFFFFBF,
|
||||||
|
CL_INVALID_COMPILER_OPTIONS = 0xFFFFFFBE,
|
||||||
|
CL_INVALID_LINKER_OPTIONS = 0xFFFFFFBD,
|
||||||
|
CL_INVALID_DEVICE_PARTITION_COUNT = 0xFFFFFFBC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenCL Version
|
||||||
|
*/
|
||||||
|
public static final int CL_VERSION_1_2 = 0x1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_bool
|
||||||
|
*/
|
||||||
|
public static final int CL_BLOCKING = 0x1,
|
||||||
|
CL_NON_BLOCKING = 0x0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cl_device_type - bitfield
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_TYPE_CUSTOM = 0x10,
|
||||||
|
CL_DEVICE_DOUBLE_FP_CONFIG = 0x1032,
|
||||||
|
CL_DEVICE_LINKER_AVAILABLE = 0x103E,
|
||||||
|
CL_DEVICE_BUILT_IN_KERNELS = 0x103F,
|
||||||
|
CL_DEVICE_IMAGE_MAX_BUFFER_SIZE = 0x1040,
|
||||||
|
CL_DEVICE_IMAGE_MAX_ARRAY_SIZE = 0x1041,
|
||||||
|
CL_DEVICE_PARENT_DEVICE = 0x1042,
|
||||||
|
CL_DEVICE_PARTITION_MAX_SUB_DEVICES = 0x1043,
|
||||||
|
CL_DEVICE_PARTITION_PROPERTIES = 0x1044,
|
||||||
|
CL_DEVICE_PARTITION_AFFINITY_DOMAIN = 0x1045,
|
||||||
|
CL_DEVICE_PARTITION_TYPE = 0x1046,
|
||||||
|
CL_DEVICE_REFERENCE_COUNT = 0x1047,
|
||||||
|
CL_DEVICE_PREFERRED_INTEROP_USER_SYNC = 0x1048,
|
||||||
|
CL_DEVICE_PRINTF_BUFFER_SIZE = 0x1049,
|
||||||
|
CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT = 0x80,
|
||||||
|
CL_CONTEXT_INTEROP_USER_SYNC = 0x1085,
|
||||||
|
CL_DEVICE_PARTITION_EQUALLY = 0x1086,
|
||||||
|
CL_DEVICE_PARTITION_BY_COUNTS = 0x1087,
|
||||||
|
CL_DEVICE_PARTITION_BY_COUNTS_LIST_END = 0x0,
|
||||||
|
CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN = 0x1088,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_NUMA = 0x1,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE = 0x2,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE = 0x4,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE = 0x8,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE = 0x10,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE = 0x20,
|
||||||
|
CL_MEM_HOST_WRITE_ONLY = 0x80,
|
||||||
|
CL_MEM_HOST_READ_ONLY = 0x100,
|
||||||
|
CL_MEM_HOST_NO_ACCESS = 0x200,
|
||||||
|
CL_MIGRATE_MEM_OBJECT_HOST = 0x1,
|
||||||
|
CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED = 0x2,
|
||||||
|
CL_MEM_OBJECT_IMAGE2D_ARRAY = 0x10F3,
|
||||||
|
CL_MEM_OBJECT_IMAGE1D = 0x10F4,
|
||||||
|
CL_MEM_OBJECT_IMAGE1D_ARRAY = 0x10F5,
|
||||||
|
CL_MEM_OBJECT_IMAGE1D_BUFFER = 0x10F6,
|
||||||
|
CL_IMAGE_ARRAY_SIZE = 0x1117,
|
||||||
|
CL_IMAGE_BUFFER = 0x1118,
|
||||||
|
CL_IMAGE_NUM_MIP_LEVELS = 0x1119,
|
||||||
|
CL_IMAGE_NUM_SAMPLES = 0x111A,
|
||||||
|
CL_MAP_WRITE_INVALIDATE_REGION = 0x4,
|
||||||
|
CL_PROGRAM_NUM_KERNELS = 0x1167,
|
||||||
|
CL_PROGRAM_KERNEL_NAMES = 0x1168,
|
||||||
|
CL_PROGRAM_BINARY_TYPE = 0x1184,
|
||||||
|
CL_PROGRAM_BINARY_TYPE_NONE = 0x0,
|
||||||
|
CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT = 0x1,
|
||||||
|
CL_PROGRAM_BINARY_TYPE_LIBRARY = 0x2,
|
||||||
|
CL_PROGRAM_BINARY_TYPE_EXECUTABLE = 0x4,
|
||||||
|
CL_KERNEL_ATTRIBUTES = 0x1195,
|
||||||
|
CL_KERNEL_ARG_ADDRESS_QUALIFIER = 0x1196,
|
||||||
|
CL_KERNEL_ARG_ACCESS_QUALIFIER = 0x1197,
|
||||||
|
CL_KERNEL_ARG_TYPE_NAME = 0x1198,
|
||||||
|
CL_KERNEL_ARG_TYPE_QUALIFIER = 0x1199,
|
||||||
|
CL_KERNEL_ARG_NAME = 0x119A,
|
||||||
|
CL_KERNEL_ARG_ADDRESS_GLOBAL = 0x119A,
|
||||||
|
CL_KERNEL_ARG_ADDRESS_LOCAL = 0x119B,
|
||||||
|
CL_KERNEL_ARG_ADDRESS_CONSTANT = 0x119C,
|
||||||
|
CL_KERNEL_ARG_ADDRESS_PRIVATE = 0x119D,
|
||||||
|
CL_KERNEL_ARG_ACCESS_READ_ONLY = 0x11A0,
|
||||||
|
CL_KERNEL_ARG_ACCESS_WRITE_ONLY = 0x11A1,
|
||||||
|
CL_KERNEL_ARG_ACCESS_READ_WRITE = 0x11A2,
|
||||||
|
CL_KERNEL_ARG_ACCESS_NONE = 0x11A3,
|
||||||
|
CL_KERNEL_ARG_TYPE_NONE = 0x0,
|
||||||
|
CL_KERNEL_ARG_TYPE_CONST = 0x1,
|
||||||
|
CL_KERNEL_ARG_TYPE_RESTRICT = 0x2,
|
||||||
|
CL_KERNEL_ARG_TYPE_VOLATILE = 0x4,
|
||||||
|
CL_KERNEL_GLOBAL_WORK_SIZE = 0x11B5,
|
||||||
|
CL_COMMAND_BARRIER = 0x1205,
|
||||||
|
CL_COMMAND_MIGRATE_MEM_OBJECTS = 0x1206,
|
||||||
|
CL_COMMAND_FILL_BUFFER = 0x1207,
|
||||||
|
CL_COMMAND_FILL_IMAGE = 0x1208;
|
||||||
|
|
||||||
|
private CL12() {}
|
||||||
|
|
||||||
|
public static int clRetainDevice(CLDevice device) {
|
||||||
|
long function_pointer = CLCapabilities.clRetainDevice;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
int __result = nclRetainDevice(device.getPointer(), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) device.retain();
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclRetainDevice(long device, long function_pointer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: LWJGL will not automatically release any objects associated with sub-devices.
|
||||||
|
* The user is responsible for tracking and releasing everything prior to calling this method.
|
||||||
|
* <p>
|
||||||
|
* @param device the parent CLDevice
|
||||||
|
* <p>
|
||||||
|
* @return the error code
|
||||||
|
*/
|
||||||
|
public static int clReleaseDevice(CLDevice device) {
|
||||||
|
long function_pointer = CLCapabilities.clReleaseDevice;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
APIUtil.releaseObjects(device);
|
||||||
|
int __result = nclReleaseDevice(device.getPointer(), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) device.release();
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclReleaseDevice(long device, long function_pointer);
|
||||||
|
|
||||||
|
public static int clCreateSubDevices(CLDevice in_device, LongBuffer properties, PointerBuffer out_devices, IntBuffer num_devices_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateSubDevices;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(properties);
|
||||||
|
BufferChecks.checkNullTerminated(properties);
|
||||||
|
if (out_devices != null)
|
||||||
|
BufferChecks.checkDirect(out_devices);
|
||||||
|
if (num_devices_ret != null)
|
||||||
|
BufferChecks.checkBuffer(num_devices_ret, 1);
|
||||||
|
int __result = nclCreateSubDevices(in_device.getPointer(), MemoryUtil.getAddress(properties), (out_devices == null ? 0 : out_devices.remaining()), MemoryUtil.getAddressSafe(out_devices), MemoryUtil.getAddressSafe(num_devices_ret), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS && out_devices != null ) in_device.registerSubCLDevices(out_devices);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclCreateSubDevices(long in_device, long properties, int out_devices_num_devices, long out_devices, long num_devices_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static CLMem clCreateImage(CLContext context, long flags, ByteBuffer image_format, ByteBuffer image_desc, ByteBuffer host_ptr, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateImage;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(image_format, 2 * 4);
|
||||||
|
BufferChecks.checkBuffer(image_desc, 7 * PointerBuffer.getPointerSize() + 2 * 4 + PointerBuffer.getPointerSize());
|
||||||
|
if (host_ptr != null)
|
||||||
|
BufferChecks.checkDirect(host_ptr);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateImage(context.getPointer(), flags, MemoryUtil.getAddress(image_format), MemoryUtil.getAddress(image_desc), MemoryUtil.getAddressSafe(host_ptr), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static CLMem clCreateImage(CLContext context, long flags, ByteBuffer image_format, ByteBuffer image_desc, FloatBuffer host_ptr, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateImage;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(image_format, 2 * 4);
|
||||||
|
BufferChecks.checkBuffer(image_desc, 7 * PointerBuffer.getPointerSize() + 2 * 4 + PointerBuffer.getPointerSize());
|
||||||
|
if (host_ptr != null)
|
||||||
|
BufferChecks.checkDirect(host_ptr);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateImage(context.getPointer(), flags, MemoryUtil.getAddress(image_format), MemoryUtil.getAddress(image_desc), MemoryUtil.getAddressSafe(host_ptr), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static CLMem clCreateImage(CLContext context, long flags, ByteBuffer image_format, ByteBuffer image_desc, IntBuffer host_ptr, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateImage;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(image_format, 2 * 4);
|
||||||
|
BufferChecks.checkBuffer(image_desc, 7 * PointerBuffer.getPointerSize() + 2 * 4 + PointerBuffer.getPointerSize());
|
||||||
|
if (host_ptr != null)
|
||||||
|
BufferChecks.checkDirect(host_ptr);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateImage(context.getPointer(), flags, MemoryUtil.getAddress(image_format), MemoryUtil.getAddress(image_desc), MemoryUtil.getAddressSafe(host_ptr), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
public static CLMem clCreateImage(CLContext context, long flags, ByteBuffer image_format, ByteBuffer image_desc, ShortBuffer host_ptr, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateImage;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(image_format, 2 * 4);
|
||||||
|
BufferChecks.checkBuffer(image_desc, 7 * PointerBuffer.getPointerSize() + 2 * 4 + PointerBuffer.getPointerSize());
|
||||||
|
if (host_ptr != null)
|
||||||
|
BufferChecks.checkDirect(host_ptr);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateImage(context.getPointer(), flags, MemoryUtil.getAddress(image_format), MemoryUtil.getAddress(image_desc), MemoryUtil.getAddressSafe(host_ptr), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateImage(long context, long flags, long image_format, long image_desc, long host_ptr, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static CLProgram clCreateProgramWithBuiltInKernels(CLContext context, PointerBuffer device_list, ByteBuffer kernel_names, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateProgramWithBuiltInKernels;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(device_list, 1);
|
||||||
|
BufferChecks.checkDirect(kernel_names);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLProgram __result = new CLProgram(nclCreateProgramWithBuiltInKernels(context.getPointer(), device_list.remaining(), MemoryUtil.getAddress(device_list), MemoryUtil.getAddress(kernel_names), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateProgramWithBuiltInKernels(long context, int device_list_num_devices, long device_list, long kernel_names, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clCreateProgramWithBuiltInKernels. */
|
||||||
|
public static CLProgram clCreateProgramWithBuiltInKernels(CLContext context, PointerBuffer device_list, CharSequence kernel_names, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateProgramWithBuiltInKernels;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(device_list, 1);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLProgram __result = new CLProgram(nclCreateProgramWithBuiltInKernels(context.getPointer(), device_list.remaining(), MemoryUtil.getAddress(device_list), APIUtil.getBuffer(kernel_names), MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single null-terminated header include name.
|
||||||
|
*/
|
||||||
|
public static int clCompileProgram(CLProgram program, PointerBuffer device_list, ByteBuffer options, PointerBuffer input_header, ByteBuffer header_include_name, CLCompileProgramCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clCompileProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkDirect(options);
|
||||||
|
BufferChecks.checkNullTerminated(options);
|
||||||
|
BufferChecks.checkBuffer(input_header, 1);
|
||||||
|
BufferChecks.checkDirect(header_include_name);
|
||||||
|
BufferChecks.checkNullTerminated(header_include_name);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(program.getParent());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclCompileProgram(program.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), MemoryUtil.getAddress(options), 1, MemoryUtil.getAddress(input_header), MemoryUtil.getAddress(header_include_name), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclCompileProgram(long program, int device_list_num_devices, long device_list, long options, int num_input_headers, long input_header, long header_include_name, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overloads clCompileProgram.
|
||||||
|
* <p>
|
||||||
|
* Multiple null-terminated header include names, one after the other.
|
||||||
|
*/
|
||||||
|
public static int clCompileProgramMulti(CLProgram program, PointerBuffer device_list, ByteBuffer options, PointerBuffer input_headers, ByteBuffer header_include_names, CLCompileProgramCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clCompileProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkDirect(options);
|
||||||
|
BufferChecks.checkNullTerminated(options);
|
||||||
|
BufferChecks.checkBuffer(input_headers, 1);
|
||||||
|
BufferChecks.checkDirect(header_include_names);
|
||||||
|
BufferChecks.checkNullTerminated(header_include_names, input_headers.remaining());
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(program.getParent());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclCompileProgramMulti(program.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), MemoryUtil.getAddress(options), input_headers.remaining(), MemoryUtil.getAddress(input_headers), MemoryUtil.getAddress(header_include_names), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclCompileProgramMulti(long program, int device_list_num_devices, long device_list, long options, int input_headers_num_input_headers, long input_headers, long header_include_names, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clCompileProgram. */
|
||||||
|
public static int clCompileProgram(CLProgram program, PointerBuffer device_list, ByteBuffer options, PointerBuffer input_headers, ByteBuffer[] header_include_names, CLCompileProgramCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clCompileProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkDirect(options);
|
||||||
|
BufferChecks.checkNullTerminated(options);
|
||||||
|
BufferChecks.checkBuffer(input_headers, header_include_names.length);
|
||||||
|
BufferChecks.checkArray(header_include_names, 1);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(program.getParent());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclCompileProgram3(program.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), MemoryUtil.getAddress(options), header_include_names.length, MemoryUtil.getAddress(input_headers), header_include_names, pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclCompileProgram3(long program, int device_list_num_devices, long device_list, long options, int num_input_headers, long input_headers, ByteBuffer[] header_include_names, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clCompileProgram. */
|
||||||
|
public static int clCompileProgram(CLProgram program, PointerBuffer device_list, CharSequence options, PointerBuffer input_header, CharSequence header_include_name, CLCompileProgramCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clCompileProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkBuffer(input_header, 1);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(program.getParent());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclCompileProgram(program.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), APIUtil.getBufferNT(options), 1, MemoryUtil.getAddress(input_header), APIUtil.getBufferNT(header_include_name), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Overloads clCompileProgram. */
|
||||||
|
public static int clCompileProgram(CLProgram program, PointerBuffer device_list, CharSequence options, PointerBuffer input_header, CharSequence[] header_include_name, CLCompileProgramCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clCompileProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkBuffer(input_header, 1);
|
||||||
|
BufferChecks.checkArray(header_include_name);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(program.getParent());
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclCompileProgramMulti(program.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), APIUtil.getBufferNT(options), input_header.remaining(), MemoryUtil.getAddress(input_header), APIUtil.getBufferNT(header_include_name), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(__result, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CLProgram clLinkProgram(CLContext context, PointerBuffer device_list, ByteBuffer options, PointerBuffer input_programs, CLLinkProgramCallback pfn_notify, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clLinkProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkDirect(options);
|
||||||
|
BufferChecks.checkNullTerminated(options);
|
||||||
|
BufferChecks.checkDirect(input_programs);
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(context);
|
||||||
|
CLProgram __result = null;
|
||||||
|
try {
|
||||||
|
__result = new CLProgram(nclLinkProgram(context.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), MemoryUtil.getAddress(options), input_programs.remaining(), MemoryUtil.getAddress(input_programs), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, MemoryUtil.getAddress(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(errcode_ret.get(errcode_ret.position()), user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native long nclLinkProgram(long context, int device_list_num_devices, long device_list, long options, int input_programs_num_input_programs, long input_programs, long pfn_notify, long user_data, long errcode_ret, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clLinkProgram. */
|
||||||
|
public static CLProgram clLinkProgram(CLContext context, PointerBuffer device_list, CharSequence options, PointerBuffer input_programs, CLLinkProgramCallback pfn_notify, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clLinkProgram;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (device_list != null)
|
||||||
|
BufferChecks.checkDirect(device_list);
|
||||||
|
BufferChecks.checkDirect(input_programs);
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
if ( pfn_notify != null ) pfn_notify.setContext(context);
|
||||||
|
CLProgram __result = null;
|
||||||
|
try {
|
||||||
|
__result = new CLProgram(nclLinkProgram(context.getPointer(), (device_list == null ? 0 : device_list.remaining()), MemoryUtil.getAddressSafe(device_list), APIUtil.getBufferNT(options), input_programs.remaining(), MemoryUtil.getAddress(input_programs), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, MemoryUtil.getAddress(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
CallbackUtil.checkCallback(errcode_ret.get(errcode_ret.position()), user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int clUnloadPlatformCompiler(CLPlatform platform) {
|
||||||
|
long function_pointer = CLCapabilities.clUnloadPlatformCompiler;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
int __result = nclUnloadPlatformCompiler(platform.getPointer(), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclUnloadPlatformCompiler(long platform, long function_pointer);
|
||||||
|
|
||||||
|
public static int clGetKernelArgInfo(CLKernel kernel, int arg_indx, int param_name, ByteBuffer param_value, PointerBuffer param_value_size_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clGetKernelArgInfo;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (param_value != null)
|
||||||
|
BufferChecks.checkDirect(param_value);
|
||||||
|
if (param_value_size_ret != null)
|
||||||
|
BufferChecks.checkBuffer(param_value_size_ret, 1);
|
||||||
|
int __result = nclGetKernelArgInfo(kernel.getPointer(), arg_indx, param_name, (param_value == null ? 0 : param_value.remaining()), MemoryUtil.getAddressSafe(param_value), MemoryUtil.getAddressSafe(param_value_size_ret), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclGetKernelArgInfo(long kernel, int arg_indx, int param_name, long param_value_param_value_size, long param_value, long param_value_size_ret, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueFillBuffer(CLCommandQueue command_queue, CLMem buffer, ByteBuffer pattern, long offset, long size, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueFillBuffer;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(pattern);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueFillBuffer(command_queue.getPointer(), buffer.getPointer(), MemoryUtil.getAddress(pattern), pattern.remaining(), offset, size, (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueFillBuffer(long command_queue, long buffer, long pattern, long pattern_pattern_size, long offset, long size, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueFillImage(CLCommandQueue command_queue, CLMem image, ByteBuffer fill_color, PointerBuffer origin, PointerBuffer region, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueFillImage;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(fill_color, 4 * 4);
|
||||||
|
BufferChecks.checkBuffer(origin, 3);
|
||||||
|
BufferChecks.checkBuffer(region, 3);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueFillImage(command_queue.getPointer(), image.getPointer(), MemoryUtil.getAddress(fill_color), MemoryUtil.getAddress(origin), MemoryUtil.getAddress(region), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueFillImage(long command_queue, long image, long fill_color, long origin, long region, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueMigrateMemObjects(CLCommandQueue command_queue, PointerBuffer mem_objects, long flags, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueMigrateMemObjects;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(mem_objects);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueMigrateMemObjects(command_queue.getPointer(), mem_objects.remaining(), MemoryUtil.getAddress(mem_objects), flags, (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueMigrateMemObjects(long command_queue, int mem_objects_num_mem_objects, long mem_objects, long flags, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueMarkerWithWaitList(CLCommandQueue command_queue, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueMarkerWithWaitList;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueMarkerWithWaitList(command_queue.getPointer(), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueMarkerWithWaitList(long command_queue, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clEnqueueBarrierWithWaitList(CLCommandQueue command_queue, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueBarrierWithWaitList;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueBarrierWithWaitList(command_queue.getPointer(), (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueBarrierWithWaitList(long command_queue, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
public static int clSetPrintfCallback(CLContext context, CLPrintfCallback pfn_notify) {
|
||||||
|
long function_pointer = CLCapabilities.clSetPrintfCallback;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
long user_data = CallbackUtil.createGlobalRef(pfn_notify);
|
||||||
|
int __result = 0;
|
||||||
|
try {
|
||||||
|
__result = nclSetPrintfCallback(context.getPointer(), pfn_notify.getPointer(), user_data, function_pointer);
|
||||||
|
return __result;
|
||||||
|
} finally {
|
||||||
|
context.setPrintfCallback(user_data, __result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static native int nclSetPrintfCallback(long context, long pfn_notify, long user_data, long function_pointer);
|
||||||
|
|
||||||
|
static CLFunctionAddress clGetExtensionFunctionAddressForPlatform(CLPlatform platform, ByteBuffer func_name) {
|
||||||
|
long function_pointer = CLCapabilities.clGetExtensionFunctionAddressForPlatform;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(func_name);
|
||||||
|
BufferChecks.checkNullTerminated(func_name);
|
||||||
|
CLFunctionAddress __result = new CLFunctionAddress(nclGetExtensionFunctionAddressForPlatform(platform.getPointer(), MemoryUtil.getAddress(func_name), function_pointer));
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclGetExtensionFunctionAddressForPlatform(long platform, long func_name, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clGetExtensionFunctionAddressForPlatform. */
|
||||||
|
static CLFunctionAddress clGetExtensionFunctionAddressForPlatform(CLPlatform platform, CharSequence func_name) {
|
||||||
|
long function_pointer = CLCapabilities.clGetExtensionFunctionAddressForPlatform;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
CLFunctionAddress __result = new CLFunctionAddress(nclGetExtensionFunctionAddressForPlatform(platform.getPointer(), APIUtil.getBufferNT(func_name), function_pointer));
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core OpenCL 1.2 OpenGL interrop functionality.
|
||||||
|
*/
|
||||||
|
public final class CL12GL {
|
||||||
|
|
||||||
|
public static final int CL_GL_OBJECT_TEXTURE2D_ARRAY = 0x200E,
|
||||||
|
CL_GL_OBJECT_TEXTURE1D = 0x200F,
|
||||||
|
CL_GL_OBJECT_TEXTURE1D_ARRAY = 0x2010,
|
||||||
|
CL_GL_OBJECT_TEXTURE_BUFFER = 0x2011;
|
||||||
|
|
||||||
|
private CL12GL() {}
|
||||||
|
|
||||||
|
public static CLMem clCreateFromGLTexture(CLContext context, long flags, int target, int miplevel, int texture, IntBuffer errcode_ret) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateFromGLTexture;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (errcode_ret != null)
|
||||||
|
BufferChecks.checkBuffer(errcode_ret, 1);
|
||||||
|
CLMem __result = new CLMem(nclCreateFromGLTexture(context.getPointer(), flags, target, miplevel, texture, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native long nclCreateFromGLTexture(long context, long flags, int target, int miplevel, int texture, long errcode_ret, long function_pointer);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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 program build notifications.
|
||||||
|
* A single CLBuildProgramCallback instance should only be used with programs created
|
||||||
|
* in the same CLContext.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLBuildProgramCallback extends CLProgramCallback {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,362 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
public final class CLCapabilities {
|
||||||
|
|
||||||
|
static final boolean CL_APPLE_ContextLoggingFunctions;
|
||||||
|
static final long clLogMessagesToSystemLogAPPLE = CL.getFunctionAddress("clLogMessagesToSystemLogAPPLE");
|
||||||
|
static final long clLogMessagesToStdoutAPPLE = CL.getFunctionAddress("clLogMessagesToStdoutAPPLE");
|
||||||
|
static final long clLogMessagesToStderrAPPLE = CL.getFunctionAddress("clLogMessagesToStderrAPPLE");
|
||||||
|
|
||||||
|
static final boolean CL_APPLE_SetMemObjectDestructor;
|
||||||
|
static final long clSetMemObjectDestructorAPPLE = CL.getFunctionAddress("clSetMemObjectDestructorAPPLE");
|
||||||
|
|
||||||
|
static final boolean CL_APPLE_gl_sharing;
|
||||||
|
static final long clGetGLContextInfoAPPLE = CL.getFunctionAddress("clGetGLContextInfoAPPLE");
|
||||||
|
|
||||||
|
static final boolean OpenCL10;
|
||||||
|
static final long clGetPlatformIDs = CL.getFunctionAddress("clGetPlatformIDs");
|
||||||
|
static final long clGetPlatformInfo = CL.getFunctionAddress("clGetPlatformInfo");
|
||||||
|
static final long clGetDeviceIDs = CL.getFunctionAddress("clGetDeviceIDs");
|
||||||
|
static final long clGetDeviceInfo = CL.getFunctionAddress("clGetDeviceInfo");
|
||||||
|
static final long clCreateContext = CL.getFunctionAddress("clCreateContext");
|
||||||
|
static final long clCreateContextFromType = CL.getFunctionAddress("clCreateContextFromType");
|
||||||
|
static final long clRetainContext = CL.getFunctionAddress("clRetainContext");
|
||||||
|
static final long clReleaseContext = CL.getFunctionAddress("clReleaseContext");
|
||||||
|
static final long clGetContextInfo = CL.getFunctionAddress("clGetContextInfo");
|
||||||
|
static final long clCreateCommandQueue = CL.getFunctionAddress("clCreateCommandQueue");
|
||||||
|
static final long clRetainCommandQueue = CL.getFunctionAddress("clRetainCommandQueue");
|
||||||
|
static final long clReleaseCommandQueue = CL.getFunctionAddress("clReleaseCommandQueue");
|
||||||
|
static final long clGetCommandQueueInfo = CL.getFunctionAddress("clGetCommandQueueInfo");
|
||||||
|
static final long clCreateBuffer = CL.getFunctionAddress("clCreateBuffer");
|
||||||
|
static final long clEnqueueReadBuffer = CL.getFunctionAddress("clEnqueueReadBuffer");
|
||||||
|
static final long clEnqueueWriteBuffer = CL.getFunctionAddress("clEnqueueWriteBuffer");
|
||||||
|
static final long clEnqueueCopyBuffer = CL.getFunctionAddress("clEnqueueCopyBuffer");
|
||||||
|
static final long clEnqueueMapBuffer = CL.getFunctionAddress("clEnqueueMapBuffer");
|
||||||
|
static final long clCreateImage2D = CL.getFunctionAddress("clCreateImage2D");
|
||||||
|
static final long clCreateImage3D = CL.getFunctionAddress("clCreateImage3D");
|
||||||
|
static final long clGetSupportedImageFormats = CL.getFunctionAddress("clGetSupportedImageFormats");
|
||||||
|
static final long clEnqueueReadImage = CL.getFunctionAddress("clEnqueueReadImage");
|
||||||
|
static final long clEnqueueWriteImage = CL.getFunctionAddress("clEnqueueWriteImage");
|
||||||
|
static final long clEnqueueCopyImage = CL.getFunctionAddress("clEnqueueCopyImage");
|
||||||
|
static final long clEnqueueCopyImageToBuffer = CL.getFunctionAddress("clEnqueueCopyImageToBuffer");
|
||||||
|
static final long clEnqueueCopyBufferToImage = CL.getFunctionAddress("clEnqueueCopyBufferToImage");
|
||||||
|
static final long clEnqueueMapImage = CL.getFunctionAddress("clEnqueueMapImage");
|
||||||
|
static final long clGetImageInfo = CL.getFunctionAddress("clGetImageInfo");
|
||||||
|
static final long clRetainMemObject = CL.getFunctionAddress("clRetainMemObject");
|
||||||
|
static final long clReleaseMemObject = CL.getFunctionAddress("clReleaseMemObject");
|
||||||
|
static final long clEnqueueUnmapMemObject = CL.getFunctionAddress("clEnqueueUnmapMemObject");
|
||||||
|
static final long clGetMemObjectInfo = CL.getFunctionAddress("clGetMemObjectInfo");
|
||||||
|
static final long clCreateSampler = CL.getFunctionAddress("clCreateSampler");
|
||||||
|
static final long clRetainSampler = CL.getFunctionAddress("clRetainSampler");
|
||||||
|
static final long clReleaseSampler = CL.getFunctionAddress("clReleaseSampler");
|
||||||
|
static final long clGetSamplerInfo = CL.getFunctionAddress("clGetSamplerInfo");
|
||||||
|
static final long clCreateProgramWithSource = CL.getFunctionAddress("clCreateProgramWithSource");
|
||||||
|
static final long clCreateProgramWithBinary = CL.getFunctionAddress("clCreateProgramWithBinary");
|
||||||
|
static final long clRetainProgram = CL.getFunctionAddress("clRetainProgram");
|
||||||
|
static final long clReleaseProgram = CL.getFunctionAddress("clReleaseProgram");
|
||||||
|
static final long clBuildProgram = CL.getFunctionAddress("clBuildProgram");
|
||||||
|
static final long clUnloadCompiler = CL.getFunctionAddress("clUnloadCompiler");
|
||||||
|
static final long clGetProgramInfo = CL.getFunctionAddress("clGetProgramInfo");
|
||||||
|
static final long clGetProgramBuildInfo = CL.getFunctionAddress("clGetProgramBuildInfo");
|
||||||
|
static final long clCreateKernel = CL.getFunctionAddress("clCreateKernel");
|
||||||
|
static final long clCreateKernelsInProgram = CL.getFunctionAddress("clCreateKernelsInProgram");
|
||||||
|
static final long clRetainKernel = CL.getFunctionAddress("clRetainKernel");
|
||||||
|
static final long clReleaseKernel = CL.getFunctionAddress("clReleaseKernel");
|
||||||
|
static final long clSetKernelArg = CL.getFunctionAddress("clSetKernelArg");
|
||||||
|
static final long clGetKernelInfo = CL.getFunctionAddress("clGetKernelInfo");
|
||||||
|
static final long clGetKernelWorkGroupInfo = CL.getFunctionAddress("clGetKernelWorkGroupInfo");
|
||||||
|
static final long clEnqueueNDRangeKernel = CL.getFunctionAddress("clEnqueueNDRangeKernel");
|
||||||
|
static final long clEnqueueTask = CL.getFunctionAddress("clEnqueueTask");
|
||||||
|
static final long clEnqueueNativeKernel = CL.getFunctionAddress("clEnqueueNativeKernel");
|
||||||
|
static final long clWaitForEvents = CL.getFunctionAddress("clWaitForEvents");
|
||||||
|
static final long clGetEventInfo = CL.getFunctionAddress("clGetEventInfo");
|
||||||
|
static final long clRetainEvent = CL.getFunctionAddress("clRetainEvent");
|
||||||
|
static final long clReleaseEvent = CL.getFunctionAddress("clReleaseEvent");
|
||||||
|
static final long clEnqueueMarker = CL.getFunctionAddress("clEnqueueMarker");
|
||||||
|
static final long clEnqueueBarrier = CL.getFunctionAddress("clEnqueueBarrier");
|
||||||
|
static final long clEnqueueWaitForEvents = CL.getFunctionAddress("clEnqueueWaitForEvents");
|
||||||
|
static final long clGetEventProfilingInfo = CL.getFunctionAddress("clGetEventProfilingInfo");
|
||||||
|
static final long clFlush = CL.getFunctionAddress("clFlush");
|
||||||
|
static final long clFinish = CL.getFunctionAddress("clFinish");
|
||||||
|
static final long clGetExtensionFunctionAddress = CL.getFunctionAddress("clGetExtensionFunctionAddress");
|
||||||
|
|
||||||
|
static final boolean OpenCL10GL;
|
||||||
|
static final long clCreateFromGLBuffer = CL.getFunctionAddress("clCreateFromGLBuffer");
|
||||||
|
static final long clCreateFromGLTexture2D = CL.getFunctionAddress("clCreateFromGLTexture2D");
|
||||||
|
static final long clCreateFromGLTexture3D = CL.getFunctionAddress("clCreateFromGLTexture3D");
|
||||||
|
static final long clCreateFromGLRenderbuffer = CL.getFunctionAddress("clCreateFromGLRenderbuffer");
|
||||||
|
static final long clGetGLObjectInfo = CL.getFunctionAddress("clGetGLObjectInfo");
|
||||||
|
static final long clGetGLTextureInfo = CL.getFunctionAddress("clGetGLTextureInfo");
|
||||||
|
static final long clEnqueueAcquireGLObjects = CL.getFunctionAddress("clEnqueueAcquireGLObjects");
|
||||||
|
static final long clEnqueueReleaseGLObjects = CL.getFunctionAddress("clEnqueueReleaseGLObjects");
|
||||||
|
|
||||||
|
static final boolean OpenCL11;
|
||||||
|
static final long clCreateSubBuffer = CL.getFunctionAddress("clCreateSubBuffer");
|
||||||
|
static final long clSetMemObjectDestructorCallback = CL.getFunctionAddress("clSetMemObjectDestructorCallback");
|
||||||
|
static final long clEnqueueReadBufferRect = CL.getFunctionAddress("clEnqueueReadBufferRect");
|
||||||
|
static final long clEnqueueWriteBufferRect = CL.getFunctionAddress("clEnqueueWriteBufferRect");
|
||||||
|
static final long clEnqueueCopyBufferRect = CL.getFunctionAddress("clEnqueueCopyBufferRect");
|
||||||
|
static final long clCreateUserEvent = CL.getFunctionAddress("clCreateUserEvent");
|
||||||
|
static final long clSetUserEventStatus = CL.getFunctionAddress("clSetUserEventStatus");
|
||||||
|
static final long clSetEventCallback = CL.getFunctionAddress("clSetEventCallback");
|
||||||
|
|
||||||
|
static final boolean OpenCL12;
|
||||||
|
static final long clRetainDevice = CL.getFunctionAddress("clRetainDevice");
|
||||||
|
static final long clReleaseDevice = CL.getFunctionAddress("clReleaseDevice");
|
||||||
|
static final long clCreateSubDevices = CL.getFunctionAddress("clCreateSubDevices");
|
||||||
|
static final long clCreateImage = CL.getFunctionAddress("clCreateImage");
|
||||||
|
static final long clCreateProgramWithBuiltInKernels = CL.getFunctionAddress("clCreateProgramWithBuiltInKernels");
|
||||||
|
static final long clCompileProgram = CL.getFunctionAddress("clCompileProgram");
|
||||||
|
static final long clLinkProgram = CL.getFunctionAddress("clLinkProgram");
|
||||||
|
static final long clUnloadPlatformCompiler = CL.getFunctionAddress("clUnloadPlatformCompiler");
|
||||||
|
static final long clGetKernelArgInfo = CL.getFunctionAddress("clGetKernelArgInfo");
|
||||||
|
static final long clEnqueueFillBuffer = CL.getFunctionAddress("clEnqueueFillBuffer");
|
||||||
|
static final long clEnqueueFillImage = CL.getFunctionAddress("clEnqueueFillImage");
|
||||||
|
static final long clEnqueueMigrateMemObjects = CL.getFunctionAddress("clEnqueueMigrateMemObjects");
|
||||||
|
static final long clEnqueueMarkerWithWaitList = CL.getFunctionAddress("clEnqueueMarkerWithWaitList");
|
||||||
|
static final long clEnqueueBarrierWithWaitList = CL.getFunctionAddress("clEnqueueBarrierWithWaitList");
|
||||||
|
static final long clSetPrintfCallback = CL.getFunctionAddress("clSetPrintfCallback");
|
||||||
|
static final long clGetExtensionFunctionAddressForPlatform = CL.getFunctionAddress("clGetExtensionFunctionAddressForPlatform");
|
||||||
|
|
||||||
|
static final boolean OpenCL12GL;
|
||||||
|
static final long clCreateFromGLTexture = CL.getFunctionAddress("clCreateFromGLTexture");
|
||||||
|
|
||||||
|
static final boolean CL_EXT_device_fission;
|
||||||
|
static final long clRetainDeviceEXT = CL.getFunctionAddress("clRetainDeviceEXT");
|
||||||
|
static final long clReleaseDeviceEXT = CL.getFunctionAddress("clReleaseDeviceEXT");
|
||||||
|
static final long clCreateSubDevicesEXT = CL.getFunctionAddress("clCreateSubDevicesEXT");
|
||||||
|
|
||||||
|
static final boolean CL_EXT_migrate_memobject;
|
||||||
|
static final long clEnqueueMigrateMemObjectEXT = CL.getFunctionAddress("clEnqueueMigrateMemObjectEXT");
|
||||||
|
|
||||||
|
static final boolean CL_KHR_gl_event;
|
||||||
|
static final long clCreateEventFromGLsyncKHR = CL.getFunctionAddress("clCreateEventFromGLsyncKHR");
|
||||||
|
|
||||||
|
static final boolean CL_KHR_gl_sharing;
|
||||||
|
static final long clGetGLContextInfoKHR = CL.getFunctionAddress("clGetGLContextInfoKHR");
|
||||||
|
|
||||||
|
static final boolean CL_KHR_icd;
|
||||||
|
static final long clIcdGetPlatformIDsKHR = CL.getFunctionAddress("clIcdGetPlatformIDsKHR");
|
||||||
|
|
||||||
|
static final boolean CL_KHR_subgroups;
|
||||||
|
static final long clGetKernelSubGroupInfoKHR = CL.getFunctionAddress("clGetKernelSubGroupInfoKHR");
|
||||||
|
|
||||||
|
static final boolean CL_KHR_terminate_context;
|
||||||
|
static final long clTerminateContextKHR = CL.getFunctionAddress("clTerminateContextKHR");
|
||||||
|
|
||||||
|
|
||||||
|
private CLCapabilities() {}
|
||||||
|
|
||||||
|
static {
|
||||||
|
CL_APPLE_ContextLoggingFunctions = isAPPLE_ContextLoggingFunctionsSupported();
|
||||||
|
CL_APPLE_SetMemObjectDestructor = isAPPLE_SetMemObjectDestructorSupported();
|
||||||
|
CL_APPLE_gl_sharing = isAPPLE_gl_sharingSupported();
|
||||||
|
OpenCL10 = isCL10Supported();
|
||||||
|
OpenCL10GL = isCL10GLSupported();
|
||||||
|
OpenCL11 = isCL11Supported();
|
||||||
|
OpenCL12 = isCL12Supported();
|
||||||
|
OpenCL12GL = isCL12GLSupported();
|
||||||
|
CL_EXT_device_fission = isEXT_device_fissionSupported();
|
||||||
|
CL_EXT_migrate_memobject = isEXT_migrate_memobjectSupported();
|
||||||
|
CL_KHR_gl_event = isKHR_gl_eventSupported();
|
||||||
|
CL_KHR_gl_sharing = isKHR_gl_sharingSupported();
|
||||||
|
CL_KHR_icd = isKHR_icdSupported();
|
||||||
|
CL_KHR_subgroups = isKHR_subgroupsSupported();
|
||||||
|
CL_KHR_terminate_context = isKHR_terminate_contextSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {
|
||||||
|
platform.checkValid();
|
||||||
|
|
||||||
|
CLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();
|
||||||
|
if ( caps == null )
|
||||||
|
platform.setCapabilities(caps = new CLPlatformCapabilities(platform));
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {
|
||||||
|
device.checkValid();
|
||||||
|
|
||||||
|
CLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();
|
||||||
|
if ( caps == null )
|
||||||
|
device.setCapabilities(caps = new CLDeviceCapabilities(device));
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAPPLE_ContextLoggingFunctionsSupported() {
|
||||||
|
return
|
||||||
|
clLogMessagesToSystemLogAPPLE != 0 &
|
||||||
|
clLogMessagesToStdoutAPPLE != 0 &
|
||||||
|
clLogMessagesToStderrAPPLE != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAPPLE_SetMemObjectDestructorSupported() {
|
||||||
|
return
|
||||||
|
clSetMemObjectDestructorAPPLE != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAPPLE_gl_sharingSupported() {
|
||||||
|
return
|
||||||
|
clGetGLContextInfoAPPLE != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCL10Supported() {
|
||||||
|
return
|
||||||
|
clGetPlatformIDs != 0 &
|
||||||
|
clGetPlatformInfo != 0 &
|
||||||
|
clGetDeviceIDs != 0 &
|
||||||
|
clGetDeviceInfo != 0 &
|
||||||
|
clCreateContext != 0 &
|
||||||
|
clCreateContextFromType != 0 &
|
||||||
|
clRetainContext != 0 &
|
||||||
|
clReleaseContext != 0 &
|
||||||
|
clGetContextInfo != 0 &
|
||||||
|
clCreateCommandQueue != 0 &
|
||||||
|
clRetainCommandQueue != 0 &
|
||||||
|
clReleaseCommandQueue != 0 &
|
||||||
|
clGetCommandQueueInfo != 0 &
|
||||||
|
clCreateBuffer != 0 &
|
||||||
|
clEnqueueReadBuffer != 0 &
|
||||||
|
clEnqueueWriteBuffer != 0 &
|
||||||
|
clEnqueueCopyBuffer != 0 &
|
||||||
|
clEnqueueMapBuffer != 0 &
|
||||||
|
clCreateImage2D != 0 &
|
||||||
|
clCreateImage3D != 0 &
|
||||||
|
clGetSupportedImageFormats != 0 &
|
||||||
|
clEnqueueReadImage != 0 &
|
||||||
|
clEnqueueWriteImage != 0 &
|
||||||
|
clEnqueueCopyImage != 0 &
|
||||||
|
clEnqueueCopyImageToBuffer != 0 &
|
||||||
|
clEnqueueCopyBufferToImage != 0 &
|
||||||
|
clEnqueueMapImage != 0 &
|
||||||
|
clGetImageInfo != 0 &
|
||||||
|
clRetainMemObject != 0 &
|
||||||
|
clReleaseMemObject != 0 &
|
||||||
|
clEnqueueUnmapMemObject != 0 &
|
||||||
|
clGetMemObjectInfo != 0 &
|
||||||
|
clCreateSampler != 0 &
|
||||||
|
clRetainSampler != 0 &
|
||||||
|
clReleaseSampler != 0 &
|
||||||
|
clGetSamplerInfo != 0 &
|
||||||
|
clCreateProgramWithSource != 0 &
|
||||||
|
clCreateProgramWithBinary != 0 &
|
||||||
|
clRetainProgram != 0 &
|
||||||
|
clReleaseProgram != 0 &
|
||||||
|
clBuildProgram != 0 &
|
||||||
|
clUnloadCompiler != 0 &
|
||||||
|
clGetProgramInfo != 0 &
|
||||||
|
clGetProgramBuildInfo != 0 &
|
||||||
|
clCreateKernel != 0 &
|
||||||
|
clCreateKernelsInProgram != 0 &
|
||||||
|
clRetainKernel != 0 &
|
||||||
|
clReleaseKernel != 0 &
|
||||||
|
clSetKernelArg != 0 &
|
||||||
|
clGetKernelInfo != 0 &
|
||||||
|
clGetKernelWorkGroupInfo != 0 &
|
||||||
|
clEnqueueNDRangeKernel != 0 &
|
||||||
|
clEnqueueTask != 0 &
|
||||||
|
clEnqueueNativeKernel != 0 &
|
||||||
|
clWaitForEvents != 0 &
|
||||||
|
clGetEventInfo != 0 &
|
||||||
|
clRetainEvent != 0 &
|
||||||
|
clReleaseEvent != 0 &
|
||||||
|
clEnqueueMarker != 0 &
|
||||||
|
clEnqueueBarrier != 0 &
|
||||||
|
clEnqueueWaitForEvents != 0 &
|
||||||
|
clGetEventProfilingInfo != 0 &
|
||||||
|
clFlush != 0 &
|
||||||
|
clFinish != 0 &
|
||||||
|
clGetExtensionFunctionAddress != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCL10GLSupported() {
|
||||||
|
return
|
||||||
|
clCreateFromGLBuffer != 0 &
|
||||||
|
clCreateFromGLTexture2D != 0 &
|
||||||
|
clCreateFromGLTexture3D != 0 &
|
||||||
|
clCreateFromGLRenderbuffer != 0 &
|
||||||
|
clGetGLObjectInfo != 0 &
|
||||||
|
clGetGLTextureInfo != 0 &
|
||||||
|
clEnqueueAcquireGLObjects != 0 &
|
||||||
|
clEnqueueReleaseGLObjects != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCL11Supported() {
|
||||||
|
return
|
||||||
|
clCreateSubBuffer != 0 &
|
||||||
|
clSetMemObjectDestructorCallback != 0 &
|
||||||
|
clEnqueueReadBufferRect != 0 &
|
||||||
|
clEnqueueWriteBufferRect != 0 &
|
||||||
|
clEnqueueCopyBufferRect != 0 &
|
||||||
|
clCreateUserEvent != 0 &
|
||||||
|
clSetUserEventStatus != 0 &
|
||||||
|
clSetEventCallback != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCL12Supported() {
|
||||||
|
return
|
||||||
|
clRetainDevice != 0 &
|
||||||
|
clReleaseDevice != 0 &
|
||||||
|
clCreateSubDevices != 0 &
|
||||||
|
clCreateImage != 0 &
|
||||||
|
clCreateProgramWithBuiltInKernels != 0 &
|
||||||
|
clCompileProgram != 0 &
|
||||||
|
clLinkProgram != 0 &
|
||||||
|
clUnloadPlatformCompiler != 0 &
|
||||||
|
clGetKernelArgInfo != 0 &
|
||||||
|
clEnqueueFillBuffer != 0 &
|
||||||
|
clEnqueueFillImage != 0 &
|
||||||
|
clEnqueueMigrateMemObjects != 0 &
|
||||||
|
clEnqueueMarkerWithWaitList != 0 &
|
||||||
|
clEnqueueBarrierWithWaitList != 0 &
|
||||||
|
(clSetPrintfCallback != 0 || true) &
|
||||||
|
clGetExtensionFunctionAddressForPlatform != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCL12GLSupported() {
|
||||||
|
return
|
||||||
|
clCreateFromGLTexture != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isEXT_device_fissionSupported() {
|
||||||
|
return
|
||||||
|
clRetainDeviceEXT != 0 &
|
||||||
|
clReleaseDeviceEXT != 0 &
|
||||||
|
clCreateSubDevicesEXT != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isEXT_migrate_memobjectSupported() {
|
||||||
|
return
|
||||||
|
clEnqueueMigrateMemObjectEXT != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKHR_gl_eventSupported() {
|
||||||
|
return
|
||||||
|
clCreateEventFromGLsyncKHR != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKHR_gl_sharingSupported() {
|
||||||
|
return
|
||||||
|
clGetGLContextInfoKHR != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKHR_icdSupported() {
|
||||||
|
return
|
||||||
|
(clIcdGetPlatformIDsKHR != 0 || true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKHR_subgroupsSupported() {
|
||||||
|
return
|
||||||
|
clGetKernelSubGroupInfoKHR != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKHR_terminate_contextSupported() {
|
||||||
|
return
|
||||||
|
clTerminateContextKHR != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,268 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import static org.lwjgl.opencl.CL10.*;
|
||||||
|
import static org.lwjgl.opencl.CL11.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 offset the host offset
|
||||||
|
* @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 offset, final PointerBuffer region, long row_pitch, long slice_pitch) {
|
||||||
|
if ( !LWJGLUtil.CHECKS )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
final long x = offset.get(0);
|
||||||
|
final long y = offset.get(1);
|
||||||
|
final long z = offset.get(2);
|
||||||
|
|
||||||
|
if ( LWJGLUtil.DEBUG && (x < 0 || y < 0 || z < 0) )
|
||||||
|
throw new IllegalArgumentException("Invalid cl_mem host offset: " + x + ", " + y + ", " + z);
|
||||||
|
|
||||||
|
final long w = region.get(0);
|
||||||
|
final long h = region.get(1);
|
||||||
|
final long d = region.get(2);
|
||||||
|
|
||||||
|
if ( LWJGLUtil.DEBUG && (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 ( LWJGLUtil.DEBUG && row_pitch < w )
|
||||||
|
throw new IllegalArgumentException("Invalid host row pitch specified: " + row_pitch);
|
||||||
|
|
||||||
|
if ( slice_pitch == 0 )
|
||||||
|
slice_pitch = row_pitch * h;
|
||||||
|
else if ( LWJGLUtil.DEBUG && 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 ( LWJGLUtil.DEBUG && (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 ( LWJGLUtil.DEBUG && row_pitch < w )
|
||||||
|
throw new IllegalArgumentException("Invalid row pitch specified: " + row_pitch);
|
||||||
|
|
||||||
|
if ( slice_pitch == 0 )
|
||||||
|
slice_pitch = row_pitch * h;
|
||||||
|
else if ( LWJGLUtil.DEBUG && 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 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( LWJGLUtil.DEBUG && (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.DEBUG && ((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 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( LWJGLUtil.DEBUG && (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.DEBUG && ((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.DEBUG && ((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 CL_R:
|
||||||
|
case CL_A:
|
||||||
|
case CL_INTENSITY:
|
||||||
|
case CL_LUMINANCE:
|
||||||
|
case CL_Rx:
|
||||||
|
return 1;
|
||||||
|
case CL_RG:
|
||||||
|
case CL_RA:
|
||||||
|
case CL_RGx:
|
||||||
|
return 2;
|
||||||
|
case CL_RGB:
|
||||||
|
case CL_RGBx:
|
||||||
|
return 3;
|
||||||
|
case CL_RGBA:
|
||||||
|
case CL_BGRA:
|
||||||
|
case CL_ARGB:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid cl_channel_order specified: " + LWJGLUtil.toHexString(channelOrder));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 CL_SNORM_INT8:
|
||||||
|
case CL_UNORM_INT8:
|
||||||
|
case CL_SIGNED_INT8:
|
||||||
|
case CL_UNSIGNED_INT8:
|
||||||
|
return 1;
|
||||||
|
case CL_SNORM_INT16:
|
||||||
|
case CL_UNORM_INT16:
|
||||||
|
case CL_UNORM_SHORT_565:
|
||||||
|
case CL_UNORM_SHORT_555:
|
||||||
|
case CL_SIGNED_INT16:
|
||||||
|
case CL_UNSIGNED_INT16:
|
||||||
|
case CL_HALF_FLOAT:
|
||||||
|
return 2;
|
||||||
|
case CL_UNORM_INT_101010:
|
||||||
|
case CL_SIGNED_INT32:
|
||||||
|
case CL_UNSIGNED_INT32:
|
||||||
|
case CL_FLOAT:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid cl_channel_type specified: " + LWJGLUtil.toHexString(channelType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* 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<CLContext> {
|
||||||
|
|
||||||
|
private static final InfoUtil<CLCommandQueue> util = CLPlatform.getInfoUtilInstance(CLCommandQueue.class, "CL_COMMAND_QUEUE_UTIL");
|
||||||
|
|
||||||
|
private final CLDevice device;
|
||||||
|
|
||||||
|
private final CLObjectRegistry<CLEvent> clEvents;
|
||||||
|
|
||||||
|
CLCommandQueue(final long pointer, final CLContext context, final CLDevice device) {
|
||||||
|
super(pointer, context);
|
||||||
|
if ( isValid() ) {
|
||||||
|
this.device = device;
|
||||||
|
this.clEvents = new CLObjectRegistry<CLEvent>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
CLObjectRegistry<CLEvent> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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 program compilation notifications.
|
||||||
|
* A single CLCompileProgramCallback instance should only be used with programs created
|
||||||
|
* in the same CLContext.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLCompileProgramCallback extends CLProgramCallback {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,322 @@
|
||||||
|
/*
|
||||||
|
* 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.opencl.api.CLImageFormat;
|
||||||
|
import org.lwjgl.opencl.api.Filter;
|
||||||
|
import org.lwjgl.opengl.Drawable;
|
||||||
|
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper around a cl_context pointer.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class CLContext extends CLObjectChild<CLPlatform> {
|
||||||
|
|
||||||
|
private static final CLContextUtil util = (CLContextUtil)CLPlatform.getInfoUtilInstance(CLContext.class, "CL_CONTEXT_UTIL");
|
||||||
|
|
||||||
|
private final CLObjectRegistry<CLCommandQueue> clCommandQueues;
|
||||||
|
private final CLObjectRegistry<CLMem> clMems;
|
||||||
|
private final CLObjectRegistry<CLSampler> clSamplers;
|
||||||
|
private final CLObjectRegistry<CLProgram> clPrograms;
|
||||||
|
private final CLObjectRegistry<CLEvent> clEvents;
|
||||||
|
|
||||||
|
private long
|
||||||
|
contextCallback,
|
||||||
|
printfCallback;
|
||||||
|
|
||||||
|
CLContext(final long pointer, final CLPlatform platform) {
|
||||||
|
super(pointer, platform);
|
||||||
|
|
||||||
|
// We do not need to register the context with the platform,
|
||||||
|
// there is no API that returns cl_context, except clCreateContext.
|
||||||
|
|
||||||
|
if ( isValid() ) {
|
||||||
|
clCommandQueues = new CLObjectRegistry<CLCommandQueue>();
|
||||||
|
clMems = new CLObjectRegistry<CLMem>();
|
||||||
|
clSamplers = new CLObjectRegistry<CLSampler>();
|
||||||
|
clPrograms = new CLObjectRegistry<CLProgram>();
|
||||||
|
clEvents = new CLObjectRegistry<CLEvent>();
|
||||||
|
} 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); }
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param devices the devices to use
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return create(platform, devices, null, null, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param devices the devices to use
|
||||||
|
* @param pfn_notify the context callback function
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return create(platform, devices, pfn_notify, null, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param devices the devices to use
|
||||||
|
* @param share_drawable the OpenGL drawable to share objects with
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return util.create(platform, devices, pfn_notify, share_drawable, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param device_type the device type to use
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext createFromType(final CLPlatform platform, final long device_type, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return util.createFromType(platform, device_type, null, null, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param device_type the device type to use
|
||||||
|
* @param pfn_notify the context callback function
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext createFromType(final CLPlatform platform, final long device_type, final CLContextCallback pfn_notify, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return util.createFromType(platform, device_type, pfn_notify, null, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new CLContext.
|
||||||
|
*
|
||||||
|
* @param platform the platform to use
|
||||||
|
* @param device_type the device type to use
|
||||||
|
* @param share_drawable the OpenGL drawable to share objects with
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLContext
|
||||||
|
*
|
||||||
|
* @throws LWJGLException if an exception occurs while creating the context
|
||||||
|
*/
|
||||||
|
public static CLContext createFromType(final CLPlatform platform, final long device_type, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException {
|
||||||
|
return util.createFromType(platform, device_type, pfn_notify, share_drawable, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of devices in context.
|
||||||
|
*
|
||||||
|
* @return the list of devices
|
||||||
|
*/
|
||||||
|
public List<CLDevice> getInfoDevices() {
|
||||||
|
return util.getInfoDevices(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CLImageFormat> getSupportedImageFormats(final long flags, final int image_type) {
|
||||||
|
return getSupportedImageFormats(flags, image_type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CLImageFormat> getSupportedImageFormats(final long flags, final int image_type, final Filter<CLImageFormat> filter) {
|
||||||
|
return util.getSupportedImageFormats(this, flags, image_type, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLContext utility methods interface. */
|
||||||
|
interface CLContextUtil extends InfoUtil<CLContext> {
|
||||||
|
|
||||||
|
List<CLDevice> getInfoDevices(CLContext context);
|
||||||
|
|
||||||
|
CLContext create(CLPlatform platform, List<CLDevice> devices, CLContextCallback pfn_notify, Drawable share_drawable, IntBuffer errcode_ret) throws LWJGLException;
|
||||||
|
|
||||||
|
CLContext createFromType(CLPlatform platform, long device_type, CLContextCallback pfn_notify, Drawable share_drawable, IntBuffer errcode_ret) throws LWJGLException;
|
||||||
|
|
||||||
|
List<CLImageFormat> getSupportedImageFormats(CLContext context, final long flags, final int image_type, Filter<CLImageFormat> filter);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
CLObjectRegistry<CLCommandQueue> getCLCommandQueueRegistry() { return clCommandQueues; }
|
||||||
|
|
||||||
|
CLObjectRegistry<CLMem> getCLMemRegistry() { return clMems; }
|
||||||
|
|
||||||
|
CLObjectRegistry<CLSampler> getCLSamplerRegistry() { return clSamplers; }
|
||||||
|
|
||||||
|
CLObjectRegistry<CLProgram> getCLProgramRegistry() { return clPrograms; }
|
||||||
|
|
||||||
|
CLObjectRegistry<CLEvent> getCLEventRegistry() { return clEvents; }
|
||||||
|
|
||||||
|
private boolean checkCallback(final long callback, final int result) {
|
||||||
|
if ( result == 0 && (callback == 0 || isValid()) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( callback != 0 )
|
||||||
|
CallbackUtil.deleteGlobalRef(callback);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associates this context with the specified context callback reference. If the context
|
||||||
|
* is invalid, the callback reference is deleted. NO-OP if user_data is 0.
|
||||||
|
*
|
||||||
|
* @param callback the context callback pointer
|
||||||
|
*/
|
||||||
|
void setContextCallback(final long callback) {
|
||||||
|
if ( checkCallback(callback, 0) )
|
||||||
|
this.contextCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associates this context with the specified printf callback reference. If the context
|
||||||
|
* is invalid, the callback reference is deleted. NO-OP if user_data is 0.
|
||||||
|
*
|
||||||
|
* @param callback the printf callback pointer
|
||||||
|
*/
|
||||||
|
void setPrintfCallback(final long callback, final int result) {
|
||||||
|
if ( checkCallback(callback, result) )
|
||||||
|
this.printfCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the context's reference count. If the reference
|
||||||
|
* count hits zero, it also deletes
|
||||||
|
* any callback objects associated with it.
|
||||||
|
*/
|
||||||
|
void releaseImpl() {
|
||||||
|
if ( release() > 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( contextCallback != 0 )
|
||||||
|
CallbackUtil.deleteGlobalRef(contextCallback);
|
||||||
|
if ( printfCallback != 0 )
|
||||||
|
CallbackUtil.deleteGlobalRef(printfCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,206 @@
|
||||||
|
/*
|
||||||
|
* 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<CLDevice> {
|
||||||
|
|
||||||
|
private static final InfoUtil<CLDevice> util = CLPlatform.getInfoUtilInstance(CLDevice.class, "CL_DEVICE_UTIL");
|
||||||
|
|
||||||
|
private final CLPlatform platform;
|
||||||
|
private final CLObjectRegistry<CLDevice> subCLDevices;
|
||||||
|
|
||||||
|
private Object caps;
|
||||||
|
|
||||||
|
CLDevice(final long pointer, final CLPlatform platform) {
|
||||||
|
this(pointer, null, platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EXT_device_fission constructor.
|
||||||
|
*
|
||||||
|
* @param pointer the sub-device pointer
|
||||||
|
* @param parent the parent CLDevice
|
||||||
|
*/
|
||||||
|
CLDevice(final long pointer, final CLDevice parent) {
|
||||||
|
this(pointer, parent, parent.getPlatform());
|
||||||
|
}
|
||||||
|
|
||||||
|
CLDevice(final long pointer, final CLDevice parent, final CLPlatform platform) {
|
||||||
|
super(pointer, parent);
|
||||||
|
|
||||||
|
if ( isValid() ) {
|
||||||
|
this.platform = platform;
|
||||||
|
platform.getCLDeviceRegistry().registerObject(this);
|
||||||
|
|
||||||
|
this.subCLDevices = new CLObjectRegistry<CLDevice>();
|
||||||
|
if ( parent != null )
|
||||||
|
parent.subCLDevices.registerObject(this);
|
||||||
|
} else {
|
||||||
|
this.platform = null;
|
||||||
|
this.subCLDevices = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CLPlatform getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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); }
|
||||||
|
|
||||||
|
// ---------------[ UTILITY 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 util.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 util.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 util.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 util.getInfoSize(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of size_t values of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter values
|
||||||
|
*/
|
||||||
|
public long[] getInfoSizeArray(int param_name) {
|
||||||
|
return util.getInfoSizeArray(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 util.getInfoLong(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
void setCapabilities(final Object caps) {
|
||||||
|
this.caps = caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object getCapabilities() {
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<CLDevice> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,193 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CLDeviceCapabilities {
|
||||||
|
|
||||||
|
public final int majorVersion;
|
||||||
|
public final int minorVersion;
|
||||||
|
|
||||||
|
public final boolean OpenCL11;
|
||||||
|
public final boolean OpenCL12;
|
||||||
|
|
||||||
|
public final boolean CL_AMD_device_attribute_query;
|
||||||
|
public final boolean CL_AMD_device_memory_flags;
|
||||||
|
public final boolean CL_AMD_fp64;
|
||||||
|
public final boolean CL_AMD_media_ops;
|
||||||
|
public final boolean CL_AMD_media_ops2;
|
||||||
|
public final boolean CL_AMD_offline_devices;
|
||||||
|
public final boolean CL_AMD_popcnt;
|
||||||
|
public final boolean CL_AMD_printf;
|
||||||
|
public final boolean CL_AMD_vec3;
|
||||||
|
final boolean CL_APPLE_ContextLoggingFunctions;
|
||||||
|
public final boolean CL_APPLE_SetMemObjectDestructor;
|
||||||
|
public final boolean CL_APPLE_gl_sharing;
|
||||||
|
public final boolean CL_EXT_atomic_counters_32;
|
||||||
|
public final boolean CL_EXT_atomic_counters_64;
|
||||||
|
public final boolean CL_EXT_device_fission;
|
||||||
|
public final boolean CL_EXT_migrate_memobject;
|
||||||
|
public final boolean CL_INTEL_immediate_execution;
|
||||||
|
public final boolean CL_INTEL_printf;
|
||||||
|
public final boolean CL_INTEL_thread_local_exec;
|
||||||
|
public final boolean CL_KHR_3d_image_writes;
|
||||||
|
public final boolean CL_KHR_byte_addressable_store;
|
||||||
|
public final boolean CL_KHR_depth_images;
|
||||||
|
public final boolean CL_KHR_fp16;
|
||||||
|
public final boolean CL_KHR_fp64;
|
||||||
|
public final boolean CL_KHR_gl_depth_images;
|
||||||
|
public final boolean CL_KHR_gl_event;
|
||||||
|
public final boolean CL_KHR_gl_msaa_sharing;
|
||||||
|
public final boolean CL_KHR_gl_sharing;
|
||||||
|
public final boolean CL_KHR_global_int32_base_atomics;
|
||||||
|
public final boolean CL_KHR_global_int32_extended_atomics;
|
||||||
|
public final boolean CL_KHR_image2d_from_buffer;
|
||||||
|
public final boolean CL_KHR_initialize_memory;
|
||||||
|
public final boolean CL_KHR_int64_base_atomics;
|
||||||
|
public final boolean CL_KHR_int64_extended_atomics;
|
||||||
|
public final boolean CL_KHR_local_int32_base_atomics;
|
||||||
|
public final boolean CL_KHR_local_int32_extended_atomics;
|
||||||
|
public final boolean CL_KHR_mipmap_image;
|
||||||
|
public final boolean CL_KHR_mipmap_image_writes;
|
||||||
|
public final boolean CL_KHR_select_fprounding_mode;
|
||||||
|
public final boolean CL_KHR_spir;
|
||||||
|
public final boolean CL_KHR_srgb_image_writes;
|
||||||
|
public final boolean CL_KHR_subgroups;
|
||||||
|
public final boolean CL_KHR_terminate_context;
|
||||||
|
public final boolean CL_NV_compiler_options;
|
||||||
|
public final boolean CL_NV_device_attribute_query;
|
||||||
|
public final boolean CL_NV_pragma_unroll;
|
||||||
|
|
||||||
|
public CLDeviceCapabilities(final CLDevice device) {
|
||||||
|
final String extensionList = device.getInfoString(CL10.CL_DEVICE_EXTENSIONS);
|
||||||
|
final String version = device.getInfoString(CL10.CL_DEVICE_VERSION);
|
||||||
|
if ( !version.startsWith("OpenCL ") )
|
||||||
|
throw new RuntimeException("Invalid OpenCL version string: " + version);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final StringTokenizer tokenizer = new StringTokenizer(version.substring(7), ". ");
|
||||||
|
|
||||||
|
majorVersion = Integer.parseInt(tokenizer.nextToken());
|
||||||
|
minorVersion = Integer.parseInt(tokenizer.nextToken());
|
||||||
|
|
||||||
|
OpenCL11 = 1 < majorVersion || (1 == majorVersion && 1 <= minorVersion);
|
||||||
|
OpenCL12 = 1 < majorVersion || (1 == majorVersion && 2 <= minorVersion);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new RuntimeException("The major and/or minor OpenCL version \"" + version + "\" is malformed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<String> extensions = APIUtil.getExtensions(extensionList);
|
||||||
|
CL_AMD_device_attribute_query = extensions.contains("cl_amd_device_attribute_query");
|
||||||
|
CL_AMD_device_memory_flags = extensions.contains("cl_amd_device_memory_flags");
|
||||||
|
CL_AMD_fp64 = extensions.contains("cl_amd_fp64");
|
||||||
|
CL_AMD_media_ops = extensions.contains("cl_amd_media_ops");
|
||||||
|
CL_AMD_media_ops2 = extensions.contains("cl_amd_media_ops2");
|
||||||
|
CL_AMD_offline_devices = extensions.contains("cl_amd_offline_devices");
|
||||||
|
CL_AMD_popcnt = extensions.contains("cl_amd_popcnt");
|
||||||
|
CL_AMD_printf = extensions.contains("cl_amd_printf");
|
||||||
|
CL_AMD_vec3 = extensions.contains("cl_amd_vec3");
|
||||||
|
CL_APPLE_ContextLoggingFunctions = extensions.contains("cl_APPLE_ContextLoggingFunctions") && CLCapabilities.CL_APPLE_ContextLoggingFunctions;
|
||||||
|
CL_APPLE_SetMemObjectDestructor = extensions.contains("cl_APPLE_SetMemObjectDestructor") && CLCapabilities.CL_APPLE_SetMemObjectDestructor;
|
||||||
|
CL_APPLE_gl_sharing = extensions.contains("cl_APPLE_gl_sharing") && CLCapabilities.CL_APPLE_gl_sharing;
|
||||||
|
CL_EXT_atomic_counters_32 = extensions.contains("cl_ext_atomic_counters_32");
|
||||||
|
CL_EXT_atomic_counters_64 = extensions.contains("cl_ext_atomic_counters_64");
|
||||||
|
CL_EXT_device_fission = extensions.contains("cl_ext_device_fission") && CLCapabilities.CL_EXT_device_fission;
|
||||||
|
CL_EXT_migrate_memobject = extensions.contains("cl_ext_migrate_memobject") && CLCapabilities.CL_EXT_migrate_memobject;
|
||||||
|
CL_INTEL_immediate_execution = extensions.contains("cl_intel_immediate_execution");
|
||||||
|
CL_INTEL_printf = extensions.contains("cl_intel_printf");
|
||||||
|
CL_INTEL_thread_local_exec = extensions.contains("cl_intel_thread_local_exec");
|
||||||
|
CL_KHR_3d_image_writes = extensions.contains("cl_khr_3d_image_writes");
|
||||||
|
CL_KHR_byte_addressable_store = extensions.contains("cl_khr_byte_addressable_store");
|
||||||
|
CL_KHR_depth_images = extensions.contains("cl_khr_depth_images");
|
||||||
|
CL_KHR_fp16 = extensions.contains("cl_khr_fp16");
|
||||||
|
CL_KHR_fp64 = extensions.contains("cl_khr_fp64");
|
||||||
|
CL_KHR_gl_depth_images = extensions.contains("cl_khr_gl_depth_images");
|
||||||
|
CL_KHR_gl_event = extensions.contains("cl_khr_gl_event") && CLCapabilities.CL_KHR_gl_event;
|
||||||
|
CL_KHR_gl_msaa_sharing = extensions.contains("cl_khr_gl_msaa_sharing");
|
||||||
|
CL_KHR_gl_sharing = extensions.contains("cl_khr_gl_sharing") && CLCapabilities.CL_KHR_gl_sharing;
|
||||||
|
CL_KHR_global_int32_base_atomics = extensions.contains("cl_khr_global_int32_base_atomics");
|
||||||
|
CL_KHR_global_int32_extended_atomics = extensions.contains("cl_khr_global_int32_extended_atomics");
|
||||||
|
CL_KHR_image2d_from_buffer = extensions.contains("cl_khr_image2d_from_buffer");
|
||||||
|
CL_KHR_initialize_memory = extensions.contains("cl_khr_initialize_memory");
|
||||||
|
CL_KHR_int64_base_atomics = extensions.contains("cl_khr_int64_base_atomics");
|
||||||
|
CL_KHR_int64_extended_atomics = extensions.contains("cl_khr_int64_extended_atomics");
|
||||||
|
CL_KHR_local_int32_base_atomics = extensions.contains("cl_khr_local_int32_base_atomics");
|
||||||
|
CL_KHR_local_int32_extended_atomics = extensions.contains("cl_khr_local_int32_extended_atomics");
|
||||||
|
CL_KHR_mipmap_image = extensions.contains("cl_khr_mipmap_image");
|
||||||
|
CL_KHR_mipmap_image_writes = extensions.contains("cl_khr_mipmap_image_writes");
|
||||||
|
CL_KHR_select_fprounding_mode = extensions.contains("cl_khr_select_fprounding_mode");
|
||||||
|
CL_KHR_spir = extensions.contains("cl_khr_spir");
|
||||||
|
CL_KHR_srgb_image_writes = extensions.contains("cl_khr_srgb_image_writes");
|
||||||
|
CL_KHR_subgroups = extensions.contains("cl_khr_subgroups") && CLCapabilities.CL_KHR_subgroups;
|
||||||
|
CL_KHR_terminate_context = extensions.contains("cl_khr_terminate_context") && CLCapabilities.CL_KHR_terminate_context;
|
||||||
|
CL_NV_compiler_options = extensions.contains("cl_nv_compiler_options");
|
||||||
|
CL_NV_device_attribute_query = extensions.contains("cl_nv_device_attribute_query");
|
||||||
|
CL_NV_pragma_unroll = extensions.contains("cl_nv_pragma_unroll");
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMajorVersion() {
|
||||||
|
return majorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinorVersion() {
|
||||||
|
return minorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
|
buf.append("OpenCL ").append(majorVersion).append('.').append(minorVersion);
|
||||||
|
|
||||||
|
buf.append(" - Extensions: ");
|
||||||
|
if ( CL_AMD_device_attribute_query ) buf.append("cl_amd_device_attribute_query ");
|
||||||
|
if ( CL_AMD_device_memory_flags ) buf.append("cl_amd_device_memory_flags ");
|
||||||
|
if ( CL_AMD_fp64 ) buf.append("cl_amd_fp64 ");
|
||||||
|
if ( CL_AMD_media_ops ) buf.append("cl_amd_media_ops ");
|
||||||
|
if ( CL_AMD_media_ops2 ) buf.append("cl_amd_media_ops2 ");
|
||||||
|
if ( CL_AMD_offline_devices ) buf.append("cl_amd_offline_devices ");
|
||||||
|
if ( CL_AMD_popcnt ) buf.append("cl_amd_popcnt ");
|
||||||
|
if ( CL_AMD_printf ) buf.append("cl_amd_printf ");
|
||||||
|
if ( CL_AMD_vec3 ) buf.append("cl_amd_vec3 ");
|
||||||
|
if ( CL_APPLE_ContextLoggingFunctions ) buf.append("cl_apple_contextloggingfunctions ");
|
||||||
|
if ( CL_APPLE_SetMemObjectDestructor ) buf.append("cl_apple_setmemobjectdestructor ");
|
||||||
|
if ( CL_APPLE_gl_sharing ) buf.append("cl_apple_gl_sharing ");
|
||||||
|
if ( CL_EXT_atomic_counters_32 ) buf.append("cl_ext_atomic_counters_32 ");
|
||||||
|
if ( CL_EXT_atomic_counters_64 ) buf.append("cl_ext_atomic_counters_64 ");
|
||||||
|
if ( CL_EXT_device_fission ) buf.append("cl_ext_device_fission ");
|
||||||
|
if ( CL_EXT_migrate_memobject ) buf.append("cl_ext_migrate_memobject ");
|
||||||
|
if ( CL_INTEL_immediate_execution ) buf.append("cl_intel_immediate_execution ");
|
||||||
|
if ( CL_INTEL_printf ) buf.append("cl_intel_printf ");
|
||||||
|
if ( CL_INTEL_thread_local_exec ) buf.append("cl_intel_thread_local_exec ");
|
||||||
|
if ( CL_KHR_3d_image_writes ) buf.append("cl_khr_3d_image_writes ");
|
||||||
|
if ( CL_KHR_byte_addressable_store ) buf.append("cl_khr_byte_addressable_store ");
|
||||||
|
if ( CL_KHR_depth_images ) buf.append("cl_khr_depth_images ");
|
||||||
|
if ( CL_KHR_fp16 ) buf.append("cl_khr_fp16 ");
|
||||||
|
if ( CL_KHR_fp64 ) buf.append("cl_khr_fp64 ");
|
||||||
|
if ( CL_KHR_gl_depth_images ) buf.append("cl_khr_gl_depth_images ");
|
||||||
|
if ( CL_KHR_gl_event ) buf.append("cl_khr_gl_event ");
|
||||||
|
if ( CL_KHR_gl_msaa_sharing ) buf.append("cl_khr_gl_msaa_sharing ");
|
||||||
|
if ( CL_KHR_gl_sharing ) buf.append("cl_khr_gl_sharing ");
|
||||||
|
if ( CL_KHR_global_int32_base_atomics ) buf.append("cl_khr_global_int32_base_atomics ");
|
||||||
|
if ( CL_KHR_global_int32_extended_atomics ) buf.append("cl_khr_global_int32_extended_atomics ");
|
||||||
|
if ( CL_KHR_image2d_from_buffer ) buf.append("cl_khr_image2d_from_buffer ");
|
||||||
|
if ( CL_KHR_initialize_memory ) buf.append("cl_khr_initialize_memory ");
|
||||||
|
if ( CL_KHR_int64_base_atomics ) buf.append("cl_khr_int64_base_atomics ");
|
||||||
|
if ( CL_KHR_int64_extended_atomics ) buf.append("cl_khr_int64_extended_atomics ");
|
||||||
|
if ( CL_KHR_local_int32_base_atomics ) buf.append("cl_khr_local_int32_base_atomics ");
|
||||||
|
if ( CL_KHR_local_int32_extended_atomics ) buf.append("cl_khr_local_int32_extended_atomics ");
|
||||||
|
if ( CL_KHR_mipmap_image ) buf.append("cl_khr_mipmap_image ");
|
||||||
|
if ( CL_KHR_mipmap_image_writes ) buf.append("cl_khr_mipmap_image_writes ");
|
||||||
|
if ( CL_KHR_select_fprounding_mode ) buf.append("cl_khr_select_fprounding_mode ");
|
||||||
|
if ( CL_KHR_spir ) buf.append("cl_khr_spir ");
|
||||||
|
if ( CL_KHR_srgb_image_writes ) buf.append("cl_khr_srgb_image_writes ");
|
||||||
|
if ( CL_KHR_subgroups ) buf.append("cl_khr_subgroups ");
|
||||||
|
if ( CL_KHR_terminate_context ) buf.append("cl_khr_terminate_context ");
|
||||||
|
if ( CL_NV_compiler_options ) buf.append("cl_nv_compiler_options ");
|
||||||
|
if ( CL_NV_device_attribute_query ) buf.append("cl_nv_device_attribute_query ");
|
||||||
|
if ( CL_NV_pragma_unroll ) buf.append("cl_nv_pragma_unroll ");
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* 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<CLContext> {
|
||||||
|
|
||||||
|
private static final CLEventUtil util = (CLEventUtil)CLPlatform.getInfoUtilInstance(CLEvent.class, "CL_EVENT_UTIL");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(final int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetEventProfilingInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 getProfilingInfoLong(int param_name) {
|
||||||
|
return util.getProfilingInfoLong(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLEvent utility methods interface. */
|
||||||
|
interface CLEventUtil extends InfoUtil<CLEvent> {
|
||||||
|
|
||||||
|
long getProfilingInfoLong(CLEvent event, int param_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
CLObjectRegistry<CLEvent> getParentRegistry() {
|
||||||
|
if ( queue == null )
|
||||||
|
return getParent().getCLEventRegistry();
|
||||||
|
else
|
||||||
|
return queue.getCLEventRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
int release() {
|
||||||
|
try {
|
||||||
|
return super.release();
|
||||||
|
} finally {
|
||||||
|
if ( !isValid() ) {
|
||||||
|
if ( queue == null )
|
||||||
|
getParent().getCLEventRegistry().unregisterObject(this);
|
||||||
|
else
|
||||||
|
queue.getCLEventRegistry().unregisterObject(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.PointerWrapperAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instances of this class can be used to handle OpenCL event callbacks. A single
|
||||||
|
* CLEventCallback instance should only be used on events generated from the same
|
||||||
|
* CLCommandQueue or on user events associated with the same CLContext.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLEventCallback extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
private CLObjectRegistry<CLEvent> eventRegistry;
|
||||||
|
|
||||||
|
protected CLEventCallback() {
|
||||||
|
super(CallbackUtil.getEventCallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the eventRegistry that contains the CLEvents to which we're registered.
|
||||||
|
*
|
||||||
|
* @param eventRegistry the CLEvent object registry
|
||||||
|
*/
|
||||||
|
void setRegistry(final CLObjectRegistry<CLEvent> eventRegistry) {
|
||||||
|
this.eventRegistry = eventRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from native code.
|
||||||
|
*
|
||||||
|
* @param event_address the CLEvent object pointer
|
||||||
|
*/
|
||||||
|
private void handleMessage(long event_address, int event_command_exec_status) {
|
||||||
|
handleMessage(eventRegistry.getObject(event_address), event_command_exec_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback method.
|
||||||
|
*
|
||||||
|
* @param event the CLEvent object
|
||||||
|
* @param event_command_exec_status the execution status
|
||||||
|
*/
|
||||||
|
protected abstract void handleMessage(CLEvent event, int event_command_exec_status);
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,262 @@
|
||||||
|
/*
|
||||||
|
* 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_kernel pointer.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class CLKernel extends CLObjectChild<CLProgram> {
|
||||||
|
|
||||||
|
private static final CLKernelUtil util = (CLKernelUtil)CLPlatform.getInfoUtilInstance(CLKernel.class, "CL_KERNEL_UTIL");
|
||||||
|
|
||||||
|
CLKernel(final long pointer, final CLProgram program) {
|
||||||
|
super(pointer, program);
|
||||||
|
if ( isValid() )
|
||||||
|
program.getCLKernelRegistry().registerObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
// clSetKernelArg methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* byte value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final byte value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* byte value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final short value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* int value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final int value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* long value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final long value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* float value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final float value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* double value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final double value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a kernel argument at the specified index to the specified
|
||||||
|
* pointer value.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param value the argument value
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArg(final int index, final CLObject value) {
|
||||||
|
util.setArg(this, index, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of a __local kernel argument at the specified index.
|
||||||
|
*
|
||||||
|
* @param index the argument index
|
||||||
|
* @param size the argument size
|
||||||
|
*
|
||||||
|
* @return this CLKernel object
|
||||||
|
*/
|
||||||
|
public CLKernel setArgSize(final int index, final long size) {
|
||||||
|
util.setArgSize(this, index, size);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetKernelInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public String getInfoString(final int param_name) {
|
||||||
|
return util.getInfoString(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(final int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetKernelWorkGroupInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size_t value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public long getWorkGroupInfoSize(final CLDevice device, int param_name) {
|
||||||
|
return util.getWorkGroupInfoSize(this, device, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of size_t values of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter values
|
||||||
|
*/
|
||||||
|
public long[] getWorkGroupInfoSizeArray(final CLDevice device, int param_name) {
|
||||||
|
return util.getWorkGroupInfoSizeArray(this, device, 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 getWorkGroupInfoLong(final CLDevice device, int param_name) {
|
||||||
|
return util.getWorkGroupInfoLong(this, device, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLKernel utility methods interface. */
|
||||||
|
interface CLKernelUtil extends InfoUtil<CLKernel> {
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, byte value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, short value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, int value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, long value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, float value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, double value);
|
||||||
|
|
||||||
|
void setArg(CLKernel kernel, int index, CLObject pointer);
|
||||||
|
|
||||||
|
void setArgSize(CLKernel kernel, int index, long size);
|
||||||
|
|
||||||
|
long getWorkGroupInfoSize(CLKernel kernel, CLDevice device, int param_name);
|
||||||
|
|
||||||
|
long[] getWorkGroupInfoSizeArray(CLKernel kernel, CLDevice device, int param_name);
|
||||||
|
|
||||||
|
long getWorkGroupInfoLong(CLKernel kernel, CLDevice device, int param_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
int release() {
|
||||||
|
try {
|
||||||
|
return super.release();
|
||||||
|
} finally {
|
||||||
|
if ( !isValid() )
|
||||||
|
getParent().getCLKernelRegistry().unregisterObject(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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 program linkage notifications.
|
||||||
|
* A single CLLinkProgramCallback instance should only be used with programs created
|
||||||
|
* in the same CLContext.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLLinkProgramCallback extends CLProgramCallback {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,279 @@
|
||||||
|
/*
|
||||||
|
* 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.opencl.api.CLBufferRegion;
|
||||||
|
import org.lwjgl.opencl.api.CLImageFormat;
|
||||||
|
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper around a cl_mem pointer.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class CLMem extends CLObjectChild<CLContext> {
|
||||||
|
|
||||||
|
private static final CLMemUtil util = (CLMemUtil)CLPlatform.getInfoUtilInstance(CLMem.class, "CL_MEM_UTIL");
|
||||||
|
|
||||||
|
CLMem(final long pointer, final CLContext context) {
|
||||||
|
super(pointer, context);
|
||||||
|
if ( isValid() )
|
||||||
|
context.getCLMemRegistry().registerObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new 2D image object.
|
||||||
|
*
|
||||||
|
* @param context the context on which to create the image object
|
||||||
|
* @param flags the memory object flags
|
||||||
|
* @param image_format the image format
|
||||||
|
* @param image_width the image width
|
||||||
|
* @param image_height the image height
|
||||||
|
* @param image_row_pitch the image row pitch
|
||||||
|
* @param host_ptr the host buffer from which to read image data (optional)
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLMem object
|
||||||
|
*/
|
||||||
|
public static CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format,
|
||||||
|
final long image_width, final long image_height, final long image_row_pitch,
|
||||||
|
final Buffer host_ptr, final IntBuffer errcode_ret) {
|
||||||
|
return util.createImage2D(context, flags, image_format, image_width, image_height, image_row_pitch, host_ptr, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new 3D image object.
|
||||||
|
*
|
||||||
|
* @param context the context on which to create the image object
|
||||||
|
* @param flags the memory object flags
|
||||||
|
* @param image_format the image format
|
||||||
|
* @param image_width the image width
|
||||||
|
* @param image_height the image height
|
||||||
|
* @param image_depth the image depth
|
||||||
|
* @param image_row_pitch the image row pitch
|
||||||
|
* @param image_slice_pitch the image slice pitch
|
||||||
|
* @param host_ptr the host buffer from which to read image data (optional)
|
||||||
|
* @param errcode_ret the error code result
|
||||||
|
*
|
||||||
|
* @return the new CLMem object
|
||||||
|
*/
|
||||||
|
public static CLMem createImage3D(final CLContext context, final long flags, final CLImageFormat image_format,
|
||||||
|
final long image_width, final long image_height, final long image_depth, final long image_row_pitch, final long image_slice_pitch,
|
||||||
|
final Buffer host_ptr, final IntBuffer errcode_ret) {
|
||||||
|
return util.createImage3D(context, flags, image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CLMem createSubBuffer(final long flags, final int buffer_create_type, final CLBufferRegion buffer_create_info, final IntBuffer errcode_ret) {
|
||||||
|
return util.createSubBuffer(this, flags, buffer_create_type, buffer_create_info, errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 util.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 util.getInfoLong(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a direct ByteBuffer instance that points to the host
|
||||||
|
* memory that backs this CLMem object. Applicable only to CLMem
|
||||||
|
* objects that were created with the CL_MEM_USE_HOST_PTR flag.
|
||||||
|
*
|
||||||
|
* @return the host memory ByteBuffer
|
||||||
|
*/
|
||||||
|
public ByteBuffer getInfoHostBuffer() {
|
||||||
|
return util.getInfoHostBuffer(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetImageInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size_t value of the specified parameter. Applicable to image objects only.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public long getImageInfoSize(int param_name) {
|
||||||
|
return util.getImageInfoSize(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the image format. Applicable to image objects only.
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public CLImageFormat getImageFormat() {
|
||||||
|
return util.getImageInfoFormat(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the image channel order. Applicable to image objects only.
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getImageChannelOrder() {
|
||||||
|
return util.getImageInfoFormat(this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the image channel type. Applicable to image objects only.
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getImageChannelType() {
|
||||||
|
return util.getImageInfoFormat(this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetGLObjectInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GL object type. Applicable to CLMem objects
|
||||||
|
* that have been created GL objects only.
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getGLObjectType() {
|
||||||
|
return util.getGLObjectType(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GL object name. Applicable to CLMem objects
|
||||||
|
* that have been created GL objects only.
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getGLObjectName() {
|
||||||
|
return util.getGLObjectName(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetGLTextureInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the int value of the specified parameter. Applicable to CLMem objects
|
||||||
|
* that have been created by GL textures only.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getGLTextureInfoInt(int param_name) {
|
||||||
|
return util.getGLTextureInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLMem utility methods interface. */
|
||||||
|
interface CLMemUtil extends InfoUtil<CLMem> {
|
||||||
|
|
||||||
|
CLMem createImage2D(CLContext context, long flags, CLImageFormat image_format, long image_width, long image_height, long image_row_pitch, Buffer host_ptr, IntBuffer errcode_ret);
|
||||||
|
|
||||||
|
CLMem createImage3D(CLContext context, long flags, CLImageFormat image_format, long image_width, long image_height, long image_depth, long image_row_pitch, long image_slice_pitch, Buffer host_ptr, IntBuffer errcode_ret);
|
||||||
|
|
||||||
|
CLMem createSubBuffer(CLMem mem, long flags, int buffer_create_type, CLBufferRegion buffer_create_info, IntBuffer errcode_ret);
|
||||||
|
|
||||||
|
ByteBuffer getInfoHostBuffer(CLMem mem);
|
||||||
|
|
||||||
|
long getImageInfoSize(CLMem mem, int param_name);
|
||||||
|
|
||||||
|
CLImageFormat getImageInfoFormat(CLMem mem);
|
||||||
|
|
||||||
|
int getImageInfoFormat(CLMem mem, int index);
|
||||||
|
|
||||||
|
int getGLObjectType(CLMem mem);
|
||||||
|
|
||||||
|
int getGLObjectName(CLMem mem);
|
||||||
|
|
||||||
|
int getGLTextureInfoInt(CLMem mem, int param_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sub-buffer factory. clCreateSubBuffer may return an existing CLMem.
|
||||||
|
*
|
||||||
|
* @param pointer the sub-buffer id
|
||||||
|
* @param context the context in which the sub-buffer was created
|
||||||
|
*
|
||||||
|
* @return the CLMem that represents the sub-buffer
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
import org.lwjgl.PointerWrapperAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instances of this class can be used to receive OpenCL memory object destruction notifications.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLMemObjectDestructorCallback extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
protected CLMemObjectDestructorCallback() {
|
||||||
|
super(CallbackUtil.getMemObjectDestructorCallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback method.
|
||||||
|
*
|
||||||
|
* @param memobj id of the CLMem object that was destroyed
|
||||||
|
*/
|
||||||
|
protected abstract void handleMessage(long memobj);
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
import org.lwjgl.PointerWrapperAbstract;
|
||||||
|
|
||||||
|
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 <code>execute</code> 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(ByteBuffer[])
|
||||||
|
*/
|
||||||
|
public abstract class CLNativeKernel extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
import org.lwjgl.PointerWrapperAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all OpenCL objects.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
abstract class CLObject extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
protected CLObject(final long pointer) {
|
||||||
|
super(pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
final long getPointerUnsafe() {
|
||||||
|
return pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<P extends CLObject> extends CLObjectRetainable {
|
||||||
|
|
||||||
|
private final P parent;
|
||||||
|
|
||||||
|
protected 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CLObjectChild container.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
class CLObjectRegistry<T extends CLObjectChild> {
|
||||||
|
|
||||||
|
private FastLongMap<T> 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 Iterable<FastLongMap.Entry<T>> getAll() {
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerObject(final T object) {
|
||||||
|
final FastLongMap<T> map = getMap();
|
||||||
|
final Long key = object.getPointer();
|
||||||
|
|
||||||
|
if ( LWJGLUtil.DEBUG && map.containsKey(key) )
|
||||||
|
throw new IllegalStateException("Duplicate object found: " + object.getClass() + " - " + key);
|
||||||
|
|
||||||
|
getMap().put(object.getPointer(), object);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregisterObject(final T object) {
|
||||||
|
getMap().remove(object.getPointerUnsafe());
|
||||||
|
}
|
||||||
|
|
||||||
|
private FastLongMap<T> getMap() {
|
||||||
|
if ( registry == null )
|
||||||
|
registry = new FastLongMap<T>();
|
||||||
|
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all retainable OpenCL objects.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
abstract class CLObjectRetainable extends CLObject {
|
||||||
|
|
||||||
|
private int refCount;
|
||||||
|
|
||||||
|
protected CLObjectRetainable(final long pointer) {
|
||||||
|
super(pointer);
|
||||||
|
|
||||||
|
if ( super.isValid() )
|
||||||
|
this.refCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getReferenceCount() {
|
||||||
|
return refCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isValid() {
|
||||||
|
return refCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,226 @@
|
||||||
|
/*
|
||||||
|
* 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.List;
|
||||||
|
|
||||||
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper around a cl_platform_id pointer.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class CLPlatform extends CLObject {
|
||||||
|
|
||||||
|
private static final CLPlatformUtil util = (CLPlatformUtil)getInfoUtilInstance(CLPlatform.class, "CL_PLATFORM_UTIL");
|
||||||
|
|
||||||
|
private static final FastLongMap<CLPlatform> clPlatforms = new FastLongMap<CLPlatform>();
|
||||||
|
|
||||||
|
private final CLObjectRegistry<CLDevice> clDevices;
|
||||||
|
|
||||||
|
private Object caps;
|
||||||
|
|
||||||
|
CLPlatform(final long pointer) {
|
||||||
|
super(pointer);
|
||||||
|
|
||||||
|
if ( isValid() ) {
|
||||||
|
clPlatforms.put(pointer, this);
|
||||||
|
clDevices = new CLObjectRegistry<CLDevice>();
|
||||||
|
} else
|
||||||
|
clDevices = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a CLPlatform with the specified id.
|
||||||
|
*
|
||||||
|
* @param id the platform object id
|
||||||
|
*
|
||||||
|
* @return the CLPlatform object
|
||||||
|
*/
|
||||||
|
public static CLPlatform getCLPlatform(final long id) { return clPlatforms.get(id); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a CLDevice that is available on this platform.
|
||||||
|
*
|
||||||
|
* @param id the device object id
|
||||||
|
*
|
||||||
|
* @return the CLDevice object
|
||||||
|
*/
|
||||||
|
public CLDevice getCLDevice(final long id) { return clDevices.getObject(id); }
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
static <T extends CLObject> InfoUtil<T> getInfoUtilInstance(final Class<T> clazz, final String fieldName) {
|
||||||
|
InfoUtil<T> instance = null;
|
||||||
|
try {
|
||||||
|
final Class<?> infoUtil = Class.forName("org.lwjgl.opencl.InfoUtilFactory");
|
||||||
|
instance = (InfoUtil<T>)infoUtil.getDeclaredField(fieldName).get(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all the available platforms.
|
||||||
|
*
|
||||||
|
* @return the available platforms
|
||||||
|
*/
|
||||||
|
public static List<CLPlatform> getPlatforms() {
|
||||||
|
return getPlatforms(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of the available platforms, filtered by the specified filter.
|
||||||
|
*
|
||||||
|
* @param filter the platform filter
|
||||||
|
*
|
||||||
|
* @return the available platforms
|
||||||
|
*/
|
||||||
|
public static List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
|
||||||
|
return util.getPlatforms(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public String getInfoString(int param_name) {
|
||||||
|
return util.getInfoString(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of the available devices on this platform that
|
||||||
|
* match the specified type.
|
||||||
|
*
|
||||||
|
* @param device_type the device type
|
||||||
|
*
|
||||||
|
* @return the available devices
|
||||||
|
*/
|
||||||
|
public List<CLDevice> getDevices(final int device_type) {
|
||||||
|
return getDevices(device_type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of the available devices on this platform that
|
||||||
|
* match the specified type, filtered by the specified filter.
|
||||||
|
*
|
||||||
|
* @param device_type the device type
|
||||||
|
* @param filter the device filter
|
||||||
|
*
|
||||||
|
* @return the available devices
|
||||||
|
*/
|
||||||
|
public List<CLDevice> getDevices(final int device_type, final Filter<CLDevice> filter) {
|
||||||
|
return util.getDevices(this, device_type, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLPlatform utility methods interface. */
|
||||||
|
interface CLPlatformUtil extends InfoUtil<CLPlatform> {
|
||||||
|
|
||||||
|
List<CLPlatform> getPlatforms(Filter<CLPlatform> filter);
|
||||||
|
|
||||||
|
List<CLDevice> getDevices(CLPlatform platform, int device_type, final Filter<CLDevice> filter);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
void setCapabilities(final Object caps) {
|
||||||
|
this.caps = caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object getCapabilities() {
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from clGetPlatformIDs to register new platforms.
|
||||||
|
*
|
||||||
|
* @param platforms a buffer containing CLPlatform pointers.
|
||||||
|
*/
|
||||||
|
static void registerCLPlatforms(final PointerBuffer platforms, final IntBuffer num_platforms) {
|
||||||
|
if ( platforms == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
final int pos = platforms.position();
|
||||||
|
final int count = min(num_platforms.get(0), platforms.remaining()); // We can't depend on .remaining()
|
||||||
|
for ( int i = 0; i < count; i++ ) {
|
||||||
|
final long id = platforms.get(pos + i);
|
||||||
|
if ( !clPlatforms.containsKey(id) )
|
||||||
|
new CLPlatform(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CLObjectRegistry<CLDevice> getCLDeviceRegistry() { return clDevices; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from <code>clGetDeviceIDs</code> to register new devices.
|
||||||
|
*
|
||||||
|
* @param devices a buffer containing CLDevice pointers.
|
||||||
|
*/
|
||||||
|
void registerCLDevices(final PointerBuffer devices, final IntBuffer num_devices) {
|
||||||
|
final int pos = devices.position();
|
||||||
|
final int count = min(num_devices.get(num_devices.position()), devices.remaining()); // We can't depend on .remaining()
|
||||||
|
for ( int i = 0; i < count; i++ ) {
|
||||||
|
final long id = devices.get(pos + i);
|
||||||
|
if ( !clDevices.hasObject(id) )
|
||||||
|
new CLDevice(id, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from <code>clGetContextInfo</code> to register new devices.
|
||||||
|
*
|
||||||
|
* @param devices a buffer containing CLDevice pointers.
|
||||||
|
*/
|
||||||
|
void registerCLDevices(final ByteBuffer devices, final PointerBuffer num_devices) {
|
||||||
|
final int pos = devices.position();
|
||||||
|
final int count = min((int)num_devices.get(num_devices.position()), devices.remaining()) / PointerBuffer.getPointerSize(); // We can't depend on .remaining()
|
||||||
|
for ( int i = 0; i < count; i++ ) {
|
||||||
|
final int offset = pos + (i * PointerBuffer.getPointerSize());
|
||||||
|
final long id = PointerBuffer.is64Bit() ? devices.getLong(offset) : devices.getInt(offset);
|
||||||
|
if ( !clDevices.hasObject(id) )
|
||||||
|
new CLDevice(id, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CLPlatformCapabilities {
|
||||||
|
|
||||||
|
public final int majorVersion;
|
||||||
|
public final int minorVersion;
|
||||||
|
|
||||||
|
public final boolean OpenCL11;
|
||||||
|
public final boolean OpenCL12;
|
||||||
|
|
||||||
|
final boolean CL_APPLE_ContextLoggingFunctions;
|
||||||
|
public final boolean CL_APPLE_SetMemObjectDestructor;
|
||||||
|
public final boolean CL_APPLE_gl_sharing;
|
||||||
|
public final boolean CL_KHR_d3d10_sharing;
|
||||||
|
public final boolean CL_KHR_gl_event;
|
||||||
|
public final boolean CL_KHR_gl_sharing;
|
||||||
|
public final boolean CL_KHR_icd;
|
||||||
|
|
||||||
|
public CLPlatformCapabilities(final CLPlatform platform) {
|
||||||
|
final String extensionList = platform.getInfoString(CL10.CL_PLATFORM_EXTENSIONS);
|
||||||
|
final String version = platform.getInfoString(CL10.CL_PLATFORM_VERSION);
|
||||||
|
if ( !version.startsWith("OpenCL ") )
|
||||||
|
throw new RuntimeException("Invalid OpenCL version string: " + version);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final StringTokenizer tokenizer = new StringTokenizer(version.substring(7), ". ");
|
||||||
|
|
||||||
|
majorVersion = Integer.parseInt(tokenizer.nextToken());
|
||||||
|
minorVersion = Integer.parseInt(tokenizer.nextToken());
|
||||||
|
|
||||||
|
OpenCL11 = 1 < majorVersion || (1 == majorVersion && 1 <= minorVersion);
|
||||||
|
OpenCL12 = 1 < majorVersion || (1 == majorVersion && 2 <= minorVersion);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new RuntimeException("The major and/or minor OpenCL version \"" + version + "\" is malformed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<String> extensions = APIUtil.getExtensions(extensionList);
|
||||||
|
CL_APPLE_ContextLoggingFunctions = extensions.contains("cl_APPLE_ContextLoggingFunctions") && CLCapabilities.CL_APPLE_ContextLoggingFunctions;
|
||||||
|
CL_APPLE_SetMemObjectDestructor = extensions.contains("cl_APPLE_SetMemObjectDestructor") && CLCapabilities.CL_APPLE_SetMemObjectDestructor;
|
||||||
|
CL_APPLE_gl_sharing = extensions.contains("cl_APPLE_gl_sharing") && CLCapabilities.CL_APPLE_gl_sharing;
|
||||||
|
CL_KHR_d3d10_sharing = extensions.contains("cl_khr_d3d10_sharing");
|
||||||
|
CL_KHR_gl_event = extensions.contains("cl_khr_gl_event") && CLCapabilities.CL_KHR_gl_event;
|
||||||
|
CL_KHR_gl_sharing = extensions.contains("cl_khr_gl_sharing") && CLCapabilities.CL_KHR_gl_sharing;
|
||||||
|
CL_KHR_icd = extensions.contains("cl_khr_icd") && CLCapabilities.CL_KHR_icd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMajorVersion() {
|
||||||
|
return majorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinorVersion() {
|
||||||
|
return minorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
|
buf.append("OpenCL ").append(majorVersion).append('.').append(minorVersion);
|
||||||
|
|
||||||
|
buf.append(" - Extensions: ");
|
||||||
|
if ( CL_APPLE_ContextLoggingFunctions ) buf.append("cl_apple_contextloggingfunctions ");
|
||||||
|
if ( CL_APPLE_SetMemObjectDestructor ) buf.append("cl_apple_setmemobjectdestructor ");
|
||||||
|
if ( CL_APPLE_gl_sharing ) buf.append("cl_apple_gl_sharing ");
|
||||||
|
if ( CL_KHR_d3d10_sharing ) buf.append("cl_khr_d3d10_sharing ");
|
||||||
|
if ( CL_KHR_gl_event ) buf.append("cl_khr_gl_event ");
|
||||||
|
if ( CL_KHR_gl_sharing ) buf.append("cl_khr_gl_sharing ");
|
||||||
|
if ( CL_KHR_icd ) buf.append("cl_khr_icd ");
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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 printf messages.
|
||||||
|
* Different CLContexts should use different CLPrintfCallback instances.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public abstract class CLPrintfCallback extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
protected CLPrintfCallback() {
|
||||||
|
super(CallbackUtil.getPrintfCallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The callback method. */
|
||||||
|
protected abstract void handleMessage(String data);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,220 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper around a cl_program pointer.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
public final class CLProgram extends CLObjectChild<CLContext> {
|
||||||
|
|
||||||
|
private static final CLProgramUtil util = (CLProgramUtil)CLPlatform.getInfoUtilInstance(CLProgram.class, "CL_PROGRAM_UTIL");
|
||||||
|
|
||||||
|
private final CLObjectRegistry<CLKernel> clKernels;
|
||||||
|
|
||||||
|
CLProgram(final long pointer, final CLContext context) {
|
||||||
|
super(pointer, context);
|
||||||
|
|
||||||
|
if ( isValid() ) {
|
||||||
|
context.getCLProgramRegistry().registerObject(this);
|
||||||
|
clKernels = new CLObjectRegistry<CLKernel>();
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates kernel objects for all kernels functions in this program.
|
||||||
|
*
|
||||||
|
* @return a CLKernel array
|
||||||
|
*/
|
||||||
|
public CLKernel[] createKernelsInProgram() {
|
||||||
|
return util.createKernelsInProgram(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public String getInfoString(final int param_name) {
|
||||||
|
return util.getInfoString(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(final int param_name) {
|
||||||
|
return util.getInfoInt(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of size_t values of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter values
|
||||||
|
*/
|
||||||
|
public long[] getInfoSizeArray(final int param_name) {
|
||||||
|
return util.getInfoSizeArray(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of CLDevices associated with this program.
|
||||||
|
*
|
||||||
|
* @return the array of devices
|
||||||
|
*/
|
||||||
|
public CLDevice[] getInfoDevices() {
|
||||||
|
return util.getInfoDevices(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the program binaries for all devices associated with program,
|
||||||
|
* written sequentially in the target ByteBuffer. If the <code>target</code>
|
||||||
|
* parameter is null, a new ByteBuffer will be allocated. If not, the
|
||||||
|
* target ByteBuffer must be big enough to hold the program binaries, as
|
||||||
|
* returned by CL_PROGRAM_BINARY_SIZES.
|
||||||
|
*
|
||||||
|
* @param target the target ByteBuffer array.
|
||||||
|
*
|
||||||
|
* @return the array of devices
|
||||||
|
*/
|
||||||
|
public ByteBuffer getInfoBinaries(final ByteBuffer target) {
|
||||||
|
return util.getInfoBinaries(this, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the program binaries for all devices associated with program,
|
||||||
|
* as a ByteBuffer array. If the <code>target</code> parameter is null,
|
||||||
|
* a new ByteBuffer array will be allocated. If not, the target ByteBuffers
|
||||||
|
* must be big enough to hold the program binaries, as returned by
|
||||||
|
* CL_PROGRAM_BINARY_SIZES.
|
||||||
|
*
|
||||||
|
* @param target the target ByteBuffer array.
|
||||||
|
*
|
||||||
|
* @return the array of devices
|
||||||
|
*/
|
||||||
|
public ByteBuffer[] getInfoBinaries(final ByteBuffer[] target) {
|
||||||
|
return util.getInfoBinaries(this, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clGetProgramBuildInfo methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the String value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public String getBuildInfoString(final CLDevice device, final int param_name) {
|
||||||
|
return util.getBuildInfoString(this, device, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getBuildInfoInt(final CLDevice device, final int param_name) {
|
||||||
|
return util.getBuildInfoInt(this, device, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CLProgram utility methods interface. */
|
||||||
|
interface CLProgramUtil extends InfoUtil<CLProgram> {
|
||||||
|
|
||||||
|
CLKernel[] createKernelsInProgram(CLProgram program);
|
||||||
|
|
||||||
|
CLDevice[] getInfoDevices(CLProgram program);
|
||||||
|
|
||||||
|
ByteBuffer getInfoBinaries(CLProgram program, ByteBuffer target);
|
||||||
|
|
||||||
|
ByteBuffer[] getInfoBinaries(CLProgram program, ByteBuffer[] target);
|
||||||
|
|
||||||
|
String getBuildInfoString(CLProgram program, final CLDevice device, int param_name);
|
||||||
|
|
||||||
|
int getBuildInfoInt(CLProgram program, final CLDevice device, int param_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
CLObjectRegistry<CLKernel> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002-2011 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 program action notifications.
|
||||||
|
*
|
||||||
|
* @author Spasi
|
||||||
|
*/
|
||||||
|
abstract class CLProgramCallback extends PointerWrapperAbstract {
|
||||||
|
|
||||||
|
private CLContext context;
|
||||||
|
|
||||||
|
protected CLProgramCallback() {
|
||||||
|
super(CallbackUtil.getProgramCallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the context that contains the CLPrograms to which we're registered.
|
||||||
|
*
|
||||||
|
* @param context the CLContext object
|
||||||
|
*/
|
||||||
|
final void setContext(final CLContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from native code.
|
||||||
|
*
|
||||||
|
* @param program_address the CLProgram object pointer
|
||||||
|
*/
|
||||||
|
private void handleMessage(long program_address) {
|
||||||
|
handleMessage(context.getCLProgram(program_address));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback method.
|
||||||
|
*
|
||||||
|
* @param program the CLProgram object affected
|
||||||
|
*/
|
||||||
|
protected abstract void handleMessage(CLProgram program);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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<CLContext> {
|
||||||
|
|
||||||
|
private static final InfoUtil<CLSampler> util = CLPlatform.getInfoUtilInstance(CLSampler.class, "CL_SAMPLER_UTIL");
|
||||||
|
|
||||||
|
CLSampler(final long pointer, final CLContext context) {
|
||||||
|
super(pointer, context);
|
||||||
|
if ( isValid() )
|
||||||
|
context.getCLSamplerRegistry().registerObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------[ UTILITY METHODS ]---------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified parameter.
|
||||||
|
*
|
||||||
|
* @param param_name the parameter
|
||||||
|
*
|
||||||
|
* @return the parameter value
|
||||||
|
*/
|
||||||
|
public int getInfoInt(int param_name) {
|
||||||
|
return util.getInfoInt(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 util.getInfoLong(this, param_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||||
|
|
||||||
|
int release() {
|
||||||
|
try {
|
||||||
|
return super.release();
|
||||||
|
} finally {
|
||||||
|
if ( !isValid() )
|
||||||
|
getParent().getCLSamplerRegistry().unregisterObject(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
* 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<CLContext, Long> contextUserData = new HashMap<CLContext, Long>();
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
|
||||||
|
/* [ 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 getProgramCallback();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 clSetPrintfCallback.
|
||||||
|
*
|
||||||
|
* @return the callback function address
|
||||||
|
*/
|
||||||
|
static native long getPrintfCallback();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the memory address of the native function we pass to clCreateContext(FromType),
|
||||||
|
* when <code>APPLEContextLoggingUtil.SYSTEM_LOG_CALLBACK</code> 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 <code>APPLEContextLoggingUtil.STD_OUT_CALLBACK</code> 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 <code>APPLEContextLoggingUtil.STD_ERR_CALLBACK</code> is used.
|
||||||
|
*
|
||||||
|
* @return the callback function address
|
||||||
|
*
|
||||||
|
* @see APPLEContextLoggingUtil#STD_ERR_CALLBACK
|
||||||
|
*/
|
||||||
|
static native long getLogMessageToStderrAPPLE();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class EXTAtomicCounters32 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CLDevice query: Max number of atomic counters that can be used by a kernel.
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032;
|
||||||
|
|
||||||
|
private EXTAtomicCounters32() {}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class EXTAtomicCounters64 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CLDevice query: Max number of atomic counters that can be used by a kernel.
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032;
|
||||||
|
|
||||||
|
private EXTAtomicCounters64() {}
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class EXTDeviceFission {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as a property name in the <properties> parameter of
|
||||||
|
* clCreateSubDeviceEXT:
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_PARTITION_EQUALLY_EXT = 0x4050,
|
||||||
|
CL_DEVICE_PARTITION_BY_COUNTS_EXT = 0x4051,
|
||||||
|
CL_DEVICE_PARTITION_BY_NAMES_EXT = 0x4052,
|
||||||
|
CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT = 0x4053;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as a property name, when accompanying the
|
||||||
|
* CL_DEVICE_PARITION_BY_AFFINITY_DOMAIN_EXT property, in the <properties>
|
||||||
|
* parameter of clCreateSubDeviceEXT:
|
||||||
|
*/
|
||||||
|
public static final int CL_AFFINITY_DOMAIN_L1_CACHE_EXT = 0x1,
|
||||||
|
CL_AFFINITY_DOMAIN_L2_CACHE_EXT = 0x2,
|
||||||
|
CL_AFFINITY_DOMAIN_L3_CACHE_EXT = 0x3,
|
||||||
|
CL_AFFINITY_DOMAIN_L4_CACHE_EXT = 0x4,
|
||||||
|
CL_AFFINITY_DOMAIN_NUMA_EXT = 0x10,
|
||||||
|
CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT = 0x100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as a property being queried in the <param_name> argument of
|
||||||
|
* clGetDeviceInfo:
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_PARENT_DEVICE_EXT = 0x4054,
|
||||||
|
CL_DEVICE_PARITION_TYPES_EXT = 0x4055,
|
||||||
|
CL_DEVICE_AFFINITY_DOMAINS_EXT = 0x4056,
|
||||||
|
CL_DEVICE_REFERENCE_COUNT_EXT = 0x4057,
|
||||||
|
CL_DEVICE_PARTITION_STYLE_EXT = 0x4058;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as the property list terminator in the <properties> parameter of
|
||||||
|
* clCreateSubDeviceEXT:
|
||||||
|
*/
|
||||||
|
public static final int CL_PROPERTIES_LIST_END_EXT = 0x0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as the partition counts list terminator in the <properties>
|
||||||
|
* parameter of clCreateSubDeviceEXT:
|
||||||
|
*/
|
||||||
|
public static final int CL_PARTITION_BY_COUNTS_LIST_END_EXT = 0x0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepted as the partition names list terminator in the <properties>
|
||||||
|
* parameter of clCreateSubDeviceEXT:
|
||||||
|
*/
|
||||||
|
public static final int CL_PARTITION_BY_NAMES_LIST_END_EXT = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returned by clCreateSubDevicesEXT when the indicated partition scheme is
|
||||||
|
* supported by the implementation, but the implementation can not further
|
||||||
|
* partition the device in this way.
|
||||||
|
*/
|
||||||
|
public static final int CL_DEVICE_PARTITION_FAILED_EXT = 0xFFFFFBDF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returned by clCreateSubDevicesEXT when the total number of compute units
|
||||||
|
* requested exceeds CL_DEVICE_MAX_COMPUTE_UNITS, or the number of compute
|
||||||
|
* units for any one sub-device is less than 1.
|
||||||
|
*/
|
||||||
|
public static final int CL_INVALID_PARTITION_COUNT_EXT = 0xFFFFFBDE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returned by clCreateSubDevicesEXT when a compute unit name appearing in a
|
||||||
|
* name list following CL_DEVICE_PARTITION_BY_NAMES_EXT is not in range.
|
||||||
|
*/
|
||||||
|
public static final int CL_INVALID_PARTITION_NAME_EXT = 0xFFFFFBDD;
|
||||||
|
|
||||||
|
private EXTDeviceFission() {}
|
||||||
|
|
||||||
|
public static int clRetainDeviceEXT(CLDevice device) {
|
||||||
|
long function_pointer = CLCapabilities.clRetainDeviceEXT;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
int __result = nclRetainDeviceEXT(device.getPointer(), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) device.retain();
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclRetainDeviceEXT(long device, long function_pointer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: LWJGL will not automatically release any objects associated with sub-devices.
|
||||||
|
* The user is responsible for tracking and releasing everything prior to calling this method.
|
||||||
|
* <p>
|
||||||
|
* @param device the parent CLDevice
|
||||||
|
* <p>
|
||||||
|
* @return the error code
|
||||||
|
*/
|
||||||
|
public static int clReleaseDeviceEXT(CLDevice device) {
|
||||||
|
long function_pointer = CLCapabilities.clReleaseDeviceEXT;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
APIUtil.releaseObjects(device);
|
||||||
|
int __result = nclReleaseDeviceEXT(device.getPointer(), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) device.release();
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclReleaseDeviceEXT(long device, long function_pointer);
|
||||||
|
|
||||||
|
public static int clCreateSubDevicesEXT(CLDevice in_device, LongBuffer properties, PointerBuffer out_devices, IntBuffer num_devices) {
|
||||||
|
long function_pointer = CLCapabilities.clCreateSubDevicesEXT;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkDirect(properties);
|
||||||
|
BufferChecks.checkNullTerminated(properties);
|
||||||
|
if (out_devices != null)
|
||||||
|
BufferChecks.checkDirect(out_devices);
|
||||||
|
if (num_devices != null)
|
||||||
|
BufferChecks.checkBuffer(num_devices, 1);
|
||||||
|
int __result = nclCreateSubDevicesEXT(in_device.getPointer(), MemoryUtil.getAddress(properties), (out_devices == null ? 0 : out_devices.remaining()), MemoryUtil.getAddressSafe(out_devices), MemoryUtil.getAddressSafe(num_devices), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS && out_devices != null ) in_device.registerSubCLDevices(out_devices);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclCreateSubDevicesEXT(long in_device, long properties, int out_devices_num_entries, long out_devices, long num_devices, long function_pointer);
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* MACHINE GENERATED FILE, DO NOT EDIT */
|
||||||
|
|
||||||
|
package org.lwjgl.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.*;
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public final class EXTMigrateMemobject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Besides a value of zero, the following cl_mem_migration_flags_ext values are
|
||||||
|
* allowed:
|
||||||
|
*/
|
||||||
|
public static final int CL_MIGRATE_MEM_OBJECT_HOST_EXT = 0x1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returned in the <param_value> parameter of the clGetEventInfo when
|
||||||
|
* <param_name> is CL_EVENT_COMMAND_TYPE:
|
||||||
|
*/
|
||||||
|
public static final int CL_COMMAND_MIGRATE_MEM_OBJECT_EXT = 0x4040;
|
||||||
|
|
||||||
|
private EXTMigrateMemobject() {}
|
||||||
|
|
||||||
|
public static int clEnqueueMigrateMemObjectEXT(CLCommandQueue command_queue, PointerBuffer mem_objects, long flags, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueMigrateMemObjectEXT;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
BufferChecks.checkBuffer(mem_objects, 1);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueMigrateMemObjectEXT(command_queue.getPointer(), mem_objects.remaining(), MemoryUtil.getAddress(mem_objects), flags, (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
static native int nclEnqueueMigrateMemObjectEXT(long command_queue, int mem_objects_num_mem_objects, long mem_objects, long flags, int event_wait_list_num_events_in_wait_list, long event_wait_list, long event, long function_pointer);
|
||||||
|
|
||||||
|
/** Overloads clEnqueueMigrateMemObjectEXT. */
|
||||||
|
public static int clEnqueueMigrateMemObjectEXT(CLCommandQueue command_queue, CLMem mem_object, long flags, PointerBuffer event_wait_list, PointerBuffer event) {
|
||||||
|
long function_pointer = CLCapabilities.clEnqueueMigrateMemObjectEXT;
|
||||||
|
BufferChecks.checkFunctionAddress(function_pointer);
|
||||||
|
if (event_wait_list != null)
|
||||||
|
BufferChecks.checkDirect(event_wait_list);
|
||||||
|
if (event != null)
|
||||||
|
BufferChecks.checkBuffer(event, 1);
|
||||||
|
int __result = nclEnqueueMigrateMemObjectEXT(command_queue.getPointer(), 1, APIUtil.getPointer(mem_object), flags, (event_wait_list == null ? 0 : event_wait_list.remaining()), MemoryUtil.getAddressSafe(event_wait_list), MemoryUtil.getAddressSafe(event), function_pointer);
|
||||||
|
if ( __result == CL10.CL_SUCCESS ) command_queue.registerCLEvent(event);
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.opencl;
|
||||||
|
|
||||||
|
import org.lwjgl.util.generator.opencl.CLDeviceExtension;
|
||||||
|
|
||||||
|
@CLDeviceExtension
|
||||||
|
public interface EXT_atomic_counters_32 {
|
||||||
|
|
||||||
|
/** CLDevice query: Max number of atomic counters that can be used by a kernel. */
|
||||||
|
int CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032;
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue