{
+
+ ByteBuffer getInfoHostBuffer(CLMem mem);
+
+ long getImageInfoSize(CLMem mem, int param_name);
+
+ 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 )
diff --git a/src/java/org/lwjgl/opencl/CLObject.java b/src/java/org/lwjgl/opencl/CLObject.java
index 3377456c..72fc9c32 100644
--- a/src/java/org/lwjgl/opencl/CLObject.java
+++ b/src/java/org/lwjgl/opencl/CLObject.java
@@ -31,58 +31,21 @@
*/
package org.lwjgl.opencl;
-import org.lwjgl.LWJGLUtil;
import org.lwjgl.PointerWrapperAbstract;
/**
- * Base class for all retainable OpenCL objects.
+ * Base class for all OpenCL objects.
*
* @author Spasi
*/
abstract class CLObject extends PointerWrapperAbstract {
- private int refCount;
-
- CLObject(final long pointer) {
+ protected CLObject(final long pointer) {
super(pointer);
-
- if ( pointer != 0 )
- this.refCount = 1;
- }
-
- public final int getReferenceCount() {
- return refCount;
- }
-
- public final boolean isValid() {
- return refCount > 0;
- }
-
- public final long getPointer() {
- checkValid();
- return super.getPointer();
}
final long getPointerUnsafe() {
- return super.getPointer();
- }
-
- int retain() {
- checkValid();
- //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount + 1));
- return ++refCount;
- }
-
- int release() {
- checkValid();
- //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount - 1));
- return --refCount;
- }
-
- final void checkValid() {
- checkNull();
- if ( LWJGLUtil.DEBUG && refCount == 0 )
- throw new IllegalStateException("This CL object is invalid.");
+ return pointer;
}
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLObjectChild.java b/src/java/org/lwjgl/opencl/CLObjectChild.java
index c3b8b219..bebefd16 100644
--- a/src/java/org/lwjgl/opencl/CLObjectChild.java
+++ b/src/java/org/lwjgl/opencl/CLObjectChild.java
@@ -38,11 +38,11 @@ import org.lwjgl.LWJGLUtil;
*
* @author Spasi
*/
-abstract class CLObjectChild extends CLObject {
+abstract class CLObjectChild
extends CLObjectRetainable {
private final P parent;
- CLObjectChild(final long pointer, final P parent) {
+ protected CLObjectChild(final long pointer, final P parent) {
super(pointer);
if ( LWJGLUtil.DEBUG && parent != null && !parent.isValid() )
diff --git a/src/java/org/lwjgl/opencl/CLObjectRegistry.java b/src/java/org/lwjgl/opencl/CLObjectRegistry.java
index 0641983e..4c35419d 100644
--- a/src/java/org/lwjgl/opencl/CLObjectRegistry.java
+++ b/src/java/org/lwjgl/opencl/CLObjectRegistry.java
@@ -1,12 +1,14 @@
package org.lwjgl.opencl;
+import org.lwjgl.LWJGLUtil;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
- * A CLContextObject container.
+ * A CLObjectChild container.
*
* @author Spasi
*/
@@ -37,8 +39,10 @@ class CLObjectRegistry {
final Map map = getMap();
final Long key = object.getPointer();
- if ( !map.containsKey(key) )
- getMap().put(object.getPointer(), object);
+ 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) {
diff --git a/src/java/org/lwjgl/opencl/CLKernelImpl.java b/src/java/org/lwjgl/opencl/CLObjectRetainable.java
similarity index 53%
rename from src/java/org/lwjgl/opencl/CLKernelImpl.java
rename to src/java/org/lwjgl/opencl/CLObjectRetainable.java
index fc2f3695..7c6b4a9b 100644
--- a/src/java/org/lwjgl/opencl/CLKernelImpl.java
+++ b/src/java/org/lwjgl/opencl/CLObjectRetainable.java
@@ -31,47 +31,40 @@
*/
package org.lwjgl.opencl;
-import org.lwjgl.PointerBuffer;
-import org.lwjgl.PointerWrapper;
-
-import static org.lwjgl.opencl.CL10.*;
-
/**
- * Implementation of CLKernel helper methods.
+ * Base class for all retainable OpenCL objects.
*
* @author Spasi
*/
-final class CLKernelImpl implements CLKernel.CLKernelImpl {
+abstract class CLObjectRetainable extends CLObject {
- CLKernelImpl() {
+ private int refCount;
+
+ protected CLObjectRetainable(final long pointer) {
+ super(pointer);
+
+ if ( super.isValid() )
+ this.refCount = 1;
}
- public void setArg(final CLKernel clKernel, final int index, final byte value) {
- clSetKernelArg(clKernel, index, 1, APIUtil.getBufferByte(1).put(0, value));
+ public final int getReferenceCount() {
+ return refCount;
}
- public void setArg(final CLKernel clKernel, final int index, final short value) {
- clSetKernelArg(clKernel, index, 2, APIUtil.getBufferShort().put(0, value));
+ public final boolean isValid() {
+ return refCount > 0;
}
- public void setArg(final CLKernel clKernel, final int index, final int value) {
- clSetKernelArg(clKernel, index, 4, APIUtil.getBufferInt().put(0, value));
+ int retain() {
+ checkValid();
+ //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount + 1));
+ return ++refCount;
}
- public void setArg(final CLKernel clKernel, final int index, final long value) {
- clSetKernelArg(clKernel, index, 8, APIUtil.getBufferLong().put(0, value));
- }
-
- public void setArg(final CLKernel clKernel, final int index, final float value) {
- clSetKernelArg(clKernel, index, 4, APIUtil.getBufferFloat().put(0, value));
- }
-
- public void setArg(final CLKernel clKernel, final int index, final double value) {
- clSetKernelArg(clKernel, index, 8, APIUtil.getBufferDouble().put(0, value));
- }
-
- public void setArg(final CLKernel clKernel, final int index, final PointerWrapper pointer) {
- clSetKernelArg(clKernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer());
+ int release() {
+ checkValid();
+ //System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount - 1));
+ return --refCount;
}
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLPlatform.java b/src/java/org/lwjgl/opencl/CLPlatform.java
index 65880a15..35f70e5a 100644
--- a/src/java/org/lwjgl/opencl/CLPlatform.java
+++ b/src/java/org/lwjgl/opencl/CLPlatform.java
@@ -31,26 +31,144 @@
*/
package org.lwjgl.opencl;
-import org.lwjgl.PointerWrapperAbstract;
+import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.api.Filter;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+
+import static java.lang.Math.*;
/**
* This class is a wrapper around a cl_platform_id pointer.
*
* @author Spasi
*/
-public final class CLPlatform extends PointerWrapperAbstract {
+public final class CLPlatform extends CLObject {
- private static final CLPlatformImpl impl = (CLPlatformImpl)getClassInstance("org.lwjgl.opencl.CLPlatformImpl");
+ private static final CLPlatformUtil util = (CLPlatformUtil)getInfoUtilInstance(CLPlatform.class, "CL_PLATFORM_UTIL");
+
+ private static final Map clPlatforms = new HashMap();
+
+ private final CLObjectRegistry clDevices;
+
+ /** Global registry for build callbacks. */
+ static final Map clDevicesGlobal = new HashMap();
private Object caps;
- public CLPlatform(final long pointer) {
+ CLPlatform(final long pointer) {
super(pointer);
+
+ if ( isValid() ) {
+ clPlatforms.put(pointer, this);
+ clDevices = new CLObjectRegistryGlobal(clDevicesGlobal);
+ } 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 InfoUtil getInfoUtilInstance(final Class clazz, final String fieldName) {
+ InfoUtil instance = null;
+ try {
+ final Class> infoUtil = Class.forName("org.lwjgl.opencl.InfoUtilFactory");
+ instance = (InfoUtil)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 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 getPlatforms(final Filter 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 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 getDevices(final int device_type, final Filter filter) {
+ return util.getDevices(this, device_type, filter);
+ }
+
+ /** CLPlatform utility methods interface. */
+ interface CLPlatformUtil extends InfoUtil {
+
+ List getPlatforms(Filter filter);
+
+ List getDevices(CLPlatform platform, int device_type, final Filter filter);
+
+ }
+
+ // -------[ IMPLEMENTATION STUFF BELOW ]-------
+
void setCapabilities(final Object caps) {
this.caps = caps;
}
@@ -59,46 +177,57 @@ public final class CLPlatform extends PointerWrapperAbstract {
return caps;
}
- // ---------------[ HELPER METHODS ]---------------
+ /**
+ * 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;
- static Object getClassInstance(final String className) {
- Object instance = null;
- try {
- instance = Class.forName(className).newInstance();
- } finally {
- return instance;
+ 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);
}
}
- public static List getPlatforms() {
- return getPlatforms(null);
+ CLObjectRegistry getCLDeviceRegistry() { return clDevices; }
+
+ static CLDevice getCLDeviceGlobal(final long id) { return clDevicesGlobal.get(id); }
+
+ /**
+ * Called from clGetDeviceIDs
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(devices.get(pos + i), this);
+ }
}
- public static List getPlatforms(final Filter filter) {
- return impl.getPlatforms(filter);
- }
-
- public String getInfoString(int param_name) {
- return impl.getInfoString(this, param_name);
- }
-
- public List getDevices(final int device_type) {
- return getDevices(device_type, null);
- }
-
- public List getDevices(final int device_type, final Filter filter) {
- return impl.getDevices(this, device_type, filter);
- }
-
- /** CLPlatform helper methods implementation interface. */
- interface CLPlatformImpl {
-
- List getPlatforms(Filter filter);
-
- String getInfoString(CLPlatform platform, int param_name);
-
- List getDevices(CLPlatform platform, int device_type, final Filter filter);
-
+ /**
+ * Called from clGetContextInfo
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(devices.get(pos + i), this);
+ }
}
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLPlatformImpl.java b/src/java/org/lwjgl/opencl/CLPlatformImpl.java
deleted file mode 100644
index 967a0b4e..00000000
--- a/src/java/org/lwjgl/opencl/CLPlatformImpl.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2002-2010 LWJGL Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'LWJGL' nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.lwjgl.opencl;
-
-import org.lwjgl.PointerBuffer;
-import org.lwjgl.opencl.api.Filter;
-
-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.lwjgl.opencl.CL10.*;
-
-/**
- * Implementation of CLPlatform helper methods.
- *
- * @author Spasi
- */
-final class CLPlatformImpl implements CLPlatform.CLPlatformImpl {
-
- CLPlatformImpl() {
- }
-
- static CLPlatformCapabilities getCapabilities(final CLPlatform platform) {
- platform.checkNull();
-
- CLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();
- if ( caps == null )
- platform.setCapabilities(caps = new CLPlatformCapabilities(platform));
-
- return caps;
- }
-
- public List getPlatforms(final Filter filter) {
- final IntBuffer numBuffer = APIUtil.getBufferInt();
- clGetPlatformIDs(null, numBuffer);
-
- final int num_platforms = numBuffer.get(0);
- if ( num_platforms == 0 )
- return null;
-
- final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
- clGetPlatformIDs(platformIDs, null);
-
- final List platforms = new ArrayList(num_platforms);
- for ( int i = 0; i < num_platforms; i++ ) {
- final CLPlatform platform = new CLPlatform(platformIDs.get(i));
- if ( filter == null || filter.accept(platform) )
- platforms.add(platform);
- }
-
- return platforms.size() == 0 ? null : platforms;
- }
-
- public String getInfoString(final CLPlatform platform, final int param_name) {
- platform.checkNull();
-
- final PointerBuffer bytes = APIUtil.getBufferPointer();
- clGetPlatformInfo(platform, param_name, null, bytes);
-
- final ByteBuffer versionBuffer = APIUtil.getBufferByte((int)bytes.get(0));
- clGetPlatformInfo(platform, param_name, versionBuffer, null);
-
- versionBuffer.limit((int)bytes.get(0) - 1); // Exclude null-termination
- return APIUtil.getString(versionBuffer);
- }
-
- public List getDevices(final CLPlatform platform, final int device_type, final Filter filter) {
- platform.checkNull();
-
- final IntBuffer numBuffer = APIUtil.getBufferInt();
- clGetDeviceIDs(platform, device_type, null, numBuffer);
-
- final int num_devices = numBuffer.get(0);
- if ( num_devices == 0 )
- return null;
-
- final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
- clGetDeviceIDs(platform, device_type, deviceIDs, null);
-
- final List devices = new ArrayList(num_devices);
- for ( int i = 0; i < num_devices; i++ ) {
- final CLDevice device = new CLDevice(deviceIDs.get(i));
- if ( filter == null || filter.accept(device) )
- devices.add(device);
- }
-
- return devices.size() == 0 ? null : devices;
- }
-
-}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/CLProgram.java b/src/java/org/lwjgl/opencl/CLProgram.java
index f50d4e56..57bf853f 100644
--- a/src/java/org/lwjgl/opencl/CLProgram.java
+++ b/src/java/org/lwjgl/opencl/CLProgram.java
@@ -33,7 +33,7 @@ package org.lwjgl.opencl;
import org.lwjgl.PointerBuffer;
-import java.io.Serializable;
+import java.nio.ByteBuffer;
/**
* This class is a wrapper around a cl_program pointer.
@@ -42,6 +42,8 @@ import java.io.Serializable;
*/
public final class CLProgram extends CLObjectChild {
+ private static final CLProgramUtil util = (CLProgramUtil)CLPlatform.getInfoUtilInstance(CLProgram.class, "CL_PROGRAM_UTIL");
+
private final CLObjectRegistry clKernels;
CLProgram(final long pointer, final CLContext context) {
@@ -65,6 +67,119 @@ public final class CLProgram extends CLObjectChild {
return clKernels.getObject(id);
}
+ // ---------------[ UTILITY 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);
+ }
+
+ /**
+ * 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 target
+ * 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 target
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 {
+
+ 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 getCLKernelRegistry() { return clKernels; }
diff --git a/src/java/org/lwjgl/opencl/CLSampler.java b/src/java/org/lwjgl/opencl/CLSampler.java
index 2b25d674..6408b669 100644
--- a/src/java/org/lwjgl/opencl/CLSampler.java
+++ b/src/java/org/lwjgl/opencl/CLSampler.java
@@ -38,12 +38,41 @@ package org.lwjgl.opencl;
*/
public final class CLSampler extends CLObjectChild {
+ private static final InfoUtil 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();
diff --git a/src/java/org/lwjgl/opencl/InfoUtil.java b/src/java/org/lwjgl/opencl/InfoUtil.java
new file mode 100644
index 00000000..c7cc060e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/InfoUtil.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+/**
+ * Base interface for information utility classes.
+ *
+ * @author Spasi
+ */
+interface InfoUtil {
+
+ int getInfoInt(final T object, final int param_name);
+
+ long getInfoSize(final T object, final int param_name);
+
+ long[] getInfoSizeArray(final T object, final int param_name);
+
+ long getInfoLong(final T object, final int param_name);
+
+ String getInfoString(final T object, final int param_name);
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/InfoUtilAbstract.java b/src/java/org/lwjgl/opencl/InfoUtilAbstract.java
new file mode 100644
index 00000000..b28d457e
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/InfoUtilAbstract.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opencl;
+
+import org.lwjgl.PointerBuffer;
+
+import java.nio.ByteBuffer;
+
+import static org.lwjgl.opencl.CL10.*;
+
+/**
+ * Base implementation of information utility classes.
+ *
+ * @author Spasi
+ */
+abstract class InfoUtilAbstract implements InfoUtil {
+
+ protected InfoUtilAbstract() {
+ }
+
+ protected abstract int getInfo(T object, int param_name, ByteBuffer param_value, PointerBuffer param_value_size_ret);
+
+ // Optional
+
+ protected int getInfoSizeArraySize(final T object, final int param_name) {
+ throw new UnsupportedOperationException();
+ }
+
+ protected PointerBuffer getSizesBuffer(final T object, final int param_name) {
+ final int size = getInfoSizeArraySize(object, param_name);
+
+ final PointerBuffer buffer = APIUtil.getBufferPointer(size);
+ buffer.limit(size);
+
+ getInfo(object, param_name, buffer.getBuffer(), null);
+
+ return buffer;
+ }
+
+ public int getInfoInt(final T object, final int param_name) {
+ object.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(4);
+ getInfo(object, param_name, buffer, null);
+
+ return buffer.getInt(0);
+ }
+
+ public long getInfoSize(final T object, final int param_name) {
+ object.checkValid();
+
+ final PointerBuffer buffer = APIUtil.getBufferPointer();
+ getInfo(object, param_name, buffer.getBuffer(), null);
+
+ return buffer.get(0);
+ }
+
+ public long[] getInfoSizeArray(final T object, final int param_name) {
+ object.checkValid();
+
+ final int size = getInfoSizeArraySize(object, param_name);
+ final PointerBuffer buffer = APIUtil.getBufferPointer(size);
+
+ getInfo(object, param_name, buffer.getBuffer(), null);
+
+ final long[] array = new long[size];
+ for ( int i = 0; i < size; i++ )
+ array[i] = buffer.get(i);
+
+ return array;
+ }
+
+ public long getInfoLong(final T object, final int param_name) {
+ object.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(8);
+ getInfo(object, param_name, buffer, null);
+
+ return buffer.getLong(0);
+ }
+
+ public String getInfoString(final T object, final int param_name) {
+ object.checkValid();
+
+ final int bytes = getSizeRet(object, param_name);
+ if ( bytes == 0 )
+ return "";
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(bytes);
+ getInfo(object, param_name, buffer, null);
+
+ buffer.limit(bytes - 1); // Exclude null-termination
+ return APIUtil.getString(buffer);
+ }
+
+ protected final int getSizeRet(final T object, final int param_name) {
+ final PointerBuffer bytes = APIUtil.getBufferPointer();
+ final int errcode = getInfo(object, param_name, null, bytes);
+ if ( errcode != CL_SUCCESS )
+ throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name));
+
+ return (int)bytes.get(0);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/InfoUtilFactory.java b/src/java/org/lwjgl/opencl/InfoUtilFactory.java
new file mode 100644
index 00000000..d73726ca
--- /dev/null
+++ b/src/java/org/lwjgl/opencl/InfoUtilFactory.java
@@ -0,0 +1,450 @@
+/*
+ * 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.api.Filter;
+
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.lwjgl.opencl.CL10.*;
+import static org.lwjgl.opencl.CL10GL.*;
+import static org.lwjgl.opencl.CL11.*;
+
+/**
+ * This class contains concrete InfoUtil implementations for our CLObject
+ * class. The public CLObject classes are grabbing these via reflection,
+ * so that they can be compiled for the generator.
+ *
+ * @author Spasi
+ * @since 28 Óåð 2010
+ */
+final class InfoUtilFactory {
+
+ private InfoUtilFactory() {}
+
+ static final InfoUtil CL_COMMAND_QUEUE_UTIL = new InfoUtilAbstract() {
+ protected int getInfo(final CLCommandQueue object, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetCommandQueueInfo(object, param_name, param_value, null);
+ }
+ };
+
+ static final CLContext.CLContextUtil CL_CONTEXT_UTIL = new CLContextUtil();
+ private static final class CLContextUtil extends InfoUtilAbstract implements CLContext.CLContextUtil {
+
+ protected int getInfo(final CLContext context, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetContextInfo(context, param_name, param_value, param_value_size_ret);
+ }
+
+ public List getInfoDevices(final CLContext context) {
+ context.checkValid();
+
+ final int num_devices;
+
+ if ( CLCapabilities.getPlatformCapabilities(context.getParent()).OpenCL11 )
+ num_devices = getInfoInt(context, CL_CONTEXT_NUM_DEVICES);
+ else {
+ final PointerBuffer size_ret = APIUtil.getBufferPointer();
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, null, size_ret);
+ num_devices = (int)(size_ret.get(0) / PointerBuffer.getPointerSize());
+ }
+
+ final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, deviceIDs.getBuffer(), null);
+
+ final List devices = new ArrayList(num_devices);
+ for ( int i = 0; i < num_devices; i++ )
+ devices.add(context.getParent().getCLDevice(deviceIDs.get(i)));
+
+ return devices.size() == 0 ? null : devices;
+
+ }
+
+ }
+
+ static final InfoUtil CL_DEVICE_UTIL = new CLDeviceUtil();
+ private static final class CLDeviceUtil extends InfoUtilAbstract {
+
+ protected int getInfo(final CLDevice device, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetDeviceInfo(device, param_name, param_value, param_value_size_ret);
+ }
+
+ protected int getInfoSizeArraySize(final CLDevice device, final int param_name) {
+ switch ( param_name ) {
+ case CL_DEVICE_MAX_WORK_ITEM_SIZES:
+ return getInfoInt(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
+ default:
+ throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
+ }
+ }
+
+ }
+
+ static final CLEvent.CLEventUtil CL_EVENT_UTIL = new CLEventUtil();
+ private static final class CLEventUtil extends InfoUtilAbstract implements CLEvent.CLEventUtil {
+
+ protected int getInfo(final CLEvent event, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetEventInfo(event, param_name, param_value, param_value_size_ret);
+ }
+
+ public long getProfilingInfoLong(final CLEvent event, final int param_name) {
+ event.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(8);
+ clGetEventProfilingInfo(event, param_name, buffer, null);
+
+ return buffer.getLong(0);
+ }
+
+ }
+
+ static final CLKernel.CLKernelUtil CL_KERNEL_UTIL = new CLKernelUtil();
+ private static final class CLKernelUtil extends InfoUtilAbstract implements CLKernel.CLKernelUtil {
+
+ public void setArg(final CLKernel kernel, final int index, final byte value) {
+ clSetKernelArg(kernel, index, 1, APIUtil.getBufferByte(1).put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final short value) {
+ clSetKernelArg(kernel, index, 2, APIUtil.getBufferShort().put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final int value) {
+ clSetKernelArg(kernel, index, 4, APIUtil.getBufferInt().put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final long value) {
+ clSetKernelArg(kernel, index, 8, APIUtil.getBufferLong().put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final float value) {
+ clSetKernelArg(kernel, index, 4, APIUtil.getBufferFloat().put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final double value) {
+ clSetKernelArg(kernel, index, 8, APIUtil.getBufferDouble().put(0, value));
+ }
+
+ public void setArg(final CLKernel kernel, final int index, final PointerWrapper pointer) {
+ clSetKernelArg(kernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer());
+ }
+
+ protected int getInfo(final CLKernel kernel, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetKernelInfo(kernel, param_name, param_value, param_value_size_ret);
+ }
+
+ public long getWorkGroupInfoSize(final CLKernel kernel, final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final PointerBuffer buffer = APIUtil.getBufferPointer();
+ clGetKernelWorkGroupInfo(kernel, device, param_name, buffer.getBuffer(), null);
+
+ return buffer.get(0);
+ }
+
+ public long[] getWorkGroupInfoSizeArray(final CLKernel kernel, final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final int size;
+ switch ( param_name ) {
+ case CL_KERNEL_WORK_GROUP_SIZE:
+ size = 3;
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
+ }
+
+ final PointerBuffer buffer = APIUtil.getBufferPointer(size);
+
+ clGetKernelWorkGroupInfo(kernel, device, param_name, buffer.getBuffer(), null);
+
+ final long[] array = new long[size];
+ for ( int i = 0; i < size; i++ )
+ array[i] = buffer.get(i);
+
+ return array;
+ }
+
+ public long getWorkGroupInfoLong(final CLKernel kernel, final CLDevice device, final int param_name) {
+ device.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(8);
+ clGetKernelWorkGroupInfo(kernel, device, param_name, buffer, null);
+
+ return buffer.getLong(0);
+ }
+
+ }
+
+ static final CLMem.CLMemUtil CL_MEM_UTIL = new CLMemUtil();
+ private static final class CLMemUtil extends InfoUtilAbstract implements CLMem.CLMemUtil {
+
+ protected int getInfo(final CLMem mem, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetMemObjectInfo(mem, param_name, param_value, param_value_size_ret);
+ }
+
+ public ByteBuffer getInfoHostBuffer(final CLMem mem) {
+ mem.checkValid();
+
+ if ( LWJGLUtil.DEBUG ) {
+ final long mem_flags = getInfoLong(mem, CL_MEM_FLAGS);
+ if ( (mem_flags & CL_MEM_USE_HOST_PTR) != CL_MEM_USE_HOST_PTR )
+ throw new IllegalArgumentException("The specified CLMem object does not use host memory.");
+ }
+
+ final long size = getInfoSize(mem, CL_MEM_SIZE);
+ if ( size == 0 )
+ return null;
+
+ final long address = getInfoSize(mem, CL_MEM_HOST_PTR);
+
+ return CL.getHostBuffer(address, (int)size);
+ }
+
+ public long getImageInfoSize(final CLMem mem, final int param_name) {
+ mem.checkValid();
+
+ final PointerBuffer buffer = APIUtil.getBufferPointer();
+ clGetImageInfo(mem, param_name, buffer.getBuffer(), null);
+
+ return buffer.get(0);
+ }
+
+ public int getImageInfoFormat(final CLMem mem, final int index) {
+ mem.checkValid();
+
+ final ByteBuffer format = APIUtil.getBufferByte(2 * 4);
+
+ clGetImageInfo(mem, CL_IMAGE_FORMAT, format, null);
+
+ return format.getInt(index << 2);
+ }
+
+ public int getGLObjectType(final CLMem mem) {
+ mem.checkValid();
+
+ final IntBuffer buffer = APIUtil.getBufferInt();
+ clGetGLObjectInfo(mem, buffer, null);
+
+ return buffer.get(0);
+ }
+
+ public int getGLObjectName(final CLMem mem) {
+ mem.checkValid();
+
+ final IntBuffer buffer = APIUtil.getBufferInt();
+ clGetGLObjectInfo(mem, null, buffer);
+
+ return buffer.get(0);
+ }
+
+ public int getGLTextureInfoInt(final CLMem mem, final int param_name) {
+ mem.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(4);
+ clGetGLTextureInfo(mem, param_name, buffer, null);
+
+ return buffer.getInt(0);
+ }
+
+ }
+
+ static final CLPlatform.CLPlatformUtil CL_PLATFORM_UTIL = new CLPlatformUtil();
+ private static final class CLPlatformUtil extends InfoUtilAbstract implements CLPlatform.CLPlatformUtil {
+
+ protected int getInfo(final CLPlatform platform, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetPlatformInfo(platform, param_name, param_value, param_value_size_ret);
+ }
+
+ public List getPlatforms(final Filter filter) {
+ final IntBuffer numBuffer = APIUtil.getBufferInt();
+ clGetPlatformIDs(null, numBuffer);
+
+ final int num_platforms = numBuffer.get(0);
+ if ( num_platforms == 0 )
+ return null;
+
+ final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
+ clGetPlatformIDs(platformIDs, null);
+
+ final List platforms = new ArrayList(num_platforms);
+ for ( int i = 0; i < num_platforms; i++ ) {
+ final CLPlatform platform = CLPlatform.getCLPlatform(platformIDs.get(i));
+ if ( filter == null || filter.accept(platform) )
+ platforms.add(platform);
+ }
+
+ return platforms.size() == 0 ? null : platforms;
+ }
+
+ public List getDevices(final CLPlatform platform, final int device_type, final Filter filter) {
+ platform.checkValid();
+
+ final IntBuffer numBuffer = APIUtil.getBufferInt();
+ clGetDeviceIDs(platform, device_type, null, numBuffer);
+
+ final int num_devices = numBuffer.get(0);
+ if ( num_devices == 0 )
+ return null;
+
+ final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
+ clGetDeviceIDs(platform, device_type, deviceIDs, null);
+
+ final List devices = new ArrayList(num_devices);
+ for ( int i = 0; i < num_devices; i++ ) {
+ final CLDevice device = platform.getCLDevice(deviceIDs.get(i));
+ if ( filter == null || filter.accept(device) )
+ devices.add(device);
+ }
+
+ return devices.size() == 0 ? null : devices;
+ }
+
+ }
+
+ static final CLProgram.CLProgramUtil CL_PROGRAM_UTIL = new CLProgramUtil();
+ private static final class CLProgramUtil extends InfoUtilAbstract implements CLProgram.CLProgramUtil {
+
+ protected int getInfo(final CLProgram program, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetProgramInfo(program, param_name, param_value, param_value_size_ret);
+ }
+
+ protected int getInfoSizeArraySize(final CLProgram program, final int param_name) {
+ switch ( param_name ) {
+ case CL_PROGRAM_BINARY_SIZES:
+ return getInfoInt(program, CL_PROGRAM_NUM_DEVICES);
+ default:
+ throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
+ }
+ }
+
+ public CLDevice[] getInfoDevices(final CLProgram program) {
+ program.checkValid();
+
+ final int size = getInfoInt(program, CL_PROGRAM_NUM_DEVICES);
+ final PointerBuffer buffer = APIUtil.getBufferPointer(size);
+
+ clGetProgramInfo(program, CL_PROGRAM_DEVICES, buffer.getBuffer(), null);
+
+ final CLPlatform platform = program.getParent().getParent();
+ final CLDevice[] array = new CLDevice[size];
+ for ( int i = 0; i < size; i++ )
+ array[i] = platform.getCLDevice(buffer.get(i));
+
+ return array;
+ }
+
+ public ByteBuffer getInfoBinaries(final CLProgram program, ByteBuffer target) {
+ program.checkValid();
+
+ final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
+
+ int totalSize = 0;
+ for ( int i = 0; i < sizes.limit(); i++ )
+ totalSize += sizes.get(i);
+
+ if ( target == null )
+ target = BufferUtils.createByteBuffer(totalSize);
+ else if ( LWJGLUtil.DEBUG )
+ BufferChecks.checkBuffer(target, totalSize);
+
+ clGetProgramInfo(program, sizes, target, null);
+
+ return target;
+ }
+
+ public ByteBuffer[] getInfoBinaries(final CLProgram program, ByteBuffer[] target) {
+ program.checkValid();
+
+ if ( target == null ) {
+ final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
+
+ target = new ByteBuffer[sizes.remaining()];
+ for ( int i = 0; i < sizes.remaining(); i++ )
+ target[i] = BufferUtils.createByteBuffer((int)sizes.get(0));
+ } else if ( LWJGLUtil.DEBUG ) {
+ final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
+
+ if ( target.length < sizes.remaining() )
+ throw new IllegalArgumentException("The target array is not big enough: " + sizes.remaining() + " buffers are required.");
+
+ for ( int i = 0; i < target.length; i++ )
+ BufferChecks.checkBuffer(target[i], (int)sizes.get(i));
+ }
+
+ clGetProgramInfo(program, target, null);
+
+ return target;
+ }
+
+ public String getBuildInfoString(final CLProgram program, final CLDevice device, final int param_name) {
+ program.checkValid();
+
+ final int bytes = getBuildSizeRet(program, device, param_name);
+ if ( bytes == 0 )
+ throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name));
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(bytes);
+ clGetProgramBuildInfo(program, device, param_name, buffer, null);
+
+ buffer.limit(bytes - 1); // Exclude null-termination
+ return APIUtil.getString(buffer);
+ }
+
+ public int getBuildInfoInt(final CLProgram program, final CLDevice device, final int param_name) {
+ program.checkValid();
+
+ final ByteBuffer buffer = APIUtil.getBufferByte(4);
+ clGetProgramBuildInfo(program, device, param_name, buffer, null);
+
+ return buffer.getInt(0);
+ }
+
+ private static int getBuildSizeRet(final CLProgram program, final CLDevice device, final int param_name) {
+ final PointerBuffer bytes = APIUtil.getBufferPointer();
+ final int errcode = clGetProgramBuildInfo(program, device, param_name, null, bytes);
+
+ return errcode == CL_SUCCESS ? (int)bytes.get(0) : 0;
+ }
+
+ }
+
+ static final InfoUtil CL_SAMPLER_UTIL = new InfoUtilAbstract() {
+ protected int getInfo(final CLSampler sampler, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
+ return clGetSamplerInfo(sampler, param_name, param_value, param_value_size_ret);
+ }
+ };
+
+}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opencl/Util.java b/src/java/org/lwjgl/opencl/Util.java
index 848b5357..dd300823 100644
--- a/src/java/org/lwjgl/opencl/Util.java
+++ b/src/java/org/lwjgl/opencl/Util.java
@@ -70,7 +70,7 @@ public final class Util {
String errname = CL_ERROR_TOKENS.get(errcode);
if ( errname == null )
errname = "UNKNOWN";
- throw new OpenCLException("Error Code: " + errname + " (0x" + Integer.toHexString(errcode).toUpperCase() + ")");
+ throw new OpenCLException("Error Code: " + errname + " (" + APIUtil.toHexString(errcode) + ")");
}
}
\ No newline at end of file
diff --git a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
index 1146839c..4fcaa653 100644
--- a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
+++ b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java
@@ -58,6 +58,19 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
GL_DEBUG_CATEGORY_APPLICATION_AMD = 0x914F,
GL_DEBUG_CATEGORY_OTHER_AMD = 0x9150;
+ private static final long CALLBACK_POINTER;
+
+ static {
+ long pointer = 0;
+ try {
+ // Call reflectively so that we can compile this class for the Generator.
+ pointer = (Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackAMD").invoke(null);
+ } catch (Exception e) {
+ // ignore
+ }
+ CALLBACK_POINTER = pointer;
+ }
+
private final Handler handler;
/**
@@ -129,7 +142,7 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
* @param handler the callback handler
*/
public AMDDebugOutputCallback(final Handler handler) {
- super(getFunctionPointer());
+ super(CALLBACK_POINTER);
this.handler = handler;
}
@@ -138,15 +151,6 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
return handler;
}
- private static long getFunctionPointer() {
- try {
- // Call reflectively so that we can compile this class for the Generator.
- return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackAMD", null).invoke(null, null)).longValue();
- } catch (Exception e) {
- throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
- }
- }
-
/** Implementations of this interface can be used to receive AMD_debug_output notifications. */
public interface Handler {
diff --git a/src/java/org/lwjgl/opengl/APIUtil.java b/src/java/org/lwjgl/opengl/APIUtil.java
index d3584317..526cbd5e 100644
--- a/src/java/org/lwjgl/opengl/APIUtil.java
+++ b/src/java/org/lwjgl/opengl/APIUtil.java
@@ -45,24 +45,24 @@ final class APIUtil {
private static final int BUFFERS_SIZE = 32;
- private static final ThreadLocal arrayTL = new ThreadLocal() {
- protected Object initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
+ private static final ThreadLocal arrayTL = new ThreadLocal() {
+ protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
};
- private static final ThreadLocal bufferTL = new ThreadLocal() {
- protected Object initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
+ private static final ThreadLocal bufferTL = new ThreadLocal() {
+ protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
};
- private static final ThreadLocal lengthsTL = new ThreadLocal() {
- protected Object initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
+ private static final ThreadLocal lengthsTL = new ThreadLocal() {
+ protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
};
- private static final ThreadLocal infiniteSeqTL = new ThreadLocal() {
- protected Object initialValue() { return new InfiniteCharSequence(); }
+ private static final ThreadLocal infiniteSeqTL = new ThreadLocal() {
+ protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); }
};
- private static final ThreadLocal buffersTL = new ThreadLocal() {
- protected Object initialValue() { return new Buffers(); }
+ private static final ThreadLocal buffersTL = new ThreadLocal() {
+ protected Buffers initialValue() { return new Buffers(); }
};
private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
@@ -71,7 +71,7 @@ final class APIUtil {
}
private static char[] getArray(final int size) {
- char[] array = (char[])arrayTL.get();
+ char[] array = arrayTL.get();
if ( array.length < size ) {
int sizeNew = array.length << 1;
@@ -86,7 +86,7 @@ final class APIUtil {
}
static ByteBuffer getBufferByte(final int size) {
- ByteBuffer buffer = (ByteBuffer)bufferTL.get();
+ ByteBuffer buffer = bufferTL.get();
if ( buffer.capacity() < size ) {
int sizeNew = buffer.capacity() << 1;
@@ -102,7 +102,7 @@ final class APIUtil {
}
private static ByteBuffer getBufferByteOffset(final int size) {
- ByteBuffer buffer = (ByteBuffer)bufferTL.get();
+ ByteBuffer buffer = bufferTL.get();
if ( buffer.capacity() < size ) {
int sizeNew = buffer.capacity() << 1;
@@ -120,22 +120,22 @@ final class APIUtil {
return buffer;
}
- static ShortBuffer getBufferShort() { return ((Buffers)buffersTL.get()).shorts; }
+ static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
- static IntBuffer getBufferInt() { return ((Buffers)buffersTL.get()).ints; }
+ static IntBuffer getBufferInt() { return buffersTL.get().ints; }
- static LongBuffer getBufferLong() { return ((Buffers)buffersTL.get()).longs; }
+ static LongBuffer getBufferLong() { return buffersTL.get().longs; }
- static FloatBuffer getBufferFloat() { return ((Buffers)buffersTL.get()).floats; }
+ static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
- static DoubleBuffer getBufferDouble() { return ((Buffers)buffersTL.get()).doubles; }
+ static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; }
static IntBuffer getLengths() {
return getLengths(1);
}
static IntBuffer getLengths(final int size) {
- IntBuffer lengths = (IntBuffer)lengthsTL.get();
+ IntBuffer lengths = lengthsTL.get();
if ( lengths.capacity() < size ) {
int sizeNew = lengths.capacity();
@@ -151,7 +151,7 @@ final class APIUtil {
}
private static InfiniteCharSequence getInfiniteSeq() {
- return (InfiniteCharSequence)infiniteSeqTL.get();
+ return infiniteSeqTL.get();
}
private static void encode(final ByteBuffer buffer, final CharSequence string) {
@@ -229,8 +229,8 @@ final class APIUtil {
static int getTotalLength(final CharSequence[] strings) {
int length = 0;
- for ( int i = 0; i < strings.length; i++ )
- length += strings[i].length();
+ for ( CharSequence string : strings )
+ length += string.length();
return length;
}
@@ -246,8 +246,8 @@ final class APIUtil {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
- for ( int i = 0; i < strings.length; i++ ) {
- infiniteSeq.setString(strings[i]);
+ for ( CharSequence string : strings ) {
+ infiniteSeq.setString(string);
encoder.encode(infiniteSeq.buffer, buffer, true);
}
infiniteSeq.clear();
@@ -267,8 +267,8 @@ final class APIUtil {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
- for ( int i = 0; i < strings.length; i++ ) {
- infiniteSeq.setString(strings[i]);
+ for ( CharSequence string : strings ) {
+ infiniteSeq.setString(string);
encoder.encode(infiniteSeq.buffer, buffer, true);
buffer.put((byte)0);
}
@@ -288,8 +288,8 @@ final class APIUtil {
static IntBuffer getLengths(final CharSequence[] strings) {
IntBuffer buffer = getLengths(strings.length);
- for ( int i = 0; i < strings.length; i++ )
- buffer.put(strings[i].length());
+ for ( CharSequence string : strings )
+ buffer.put(string.length());
buffer.flip();
return buffer;
diff --git a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
index 2602d5b2..e1b02dd5 100644
--- a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
+++ b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java
@@ -67,6 +67,19 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
GL_DEBUG_TYPE_PERFORMANCE_ARB = 0x8250,
GL_DEBUG_TYPE_OTHER_ARB = 0x8251;
+ private static final long CALLBACK_POINTER;
+
+ static {
+ long pointer = 0;
+ try {
+ // Call reflectively so that we can compile this class for the Generator.
+ pointer = (Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackARB").invoke(null);
+ } catch (Exception e) {
+ // ignore
+ }
+ CALLBACK_POINTER = pointer;
+ }
+
private final Handler handler;
/**
@@ -156,7 +169,7 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
* @param handler the callback handler
*/
public ARBDebugOutputCallback(final Handler handler) {
- super(getFunctionPointer());
+ super(CALLBACK_POINTER);
this.handler = handler;
}
@@ -165,15 +178,6 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
return handler;
}
- private static long getFunctionPointer() {
- try {
- // Call reflectively so that we can compile this class for the Generator.
- return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackARB", null).invoke(null, null)).longValue();
- } catch (Exception e) {
- throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
- }
- }
-
/** Implementations of this interface can be used to receive ARB_debug_output notifications. */
public interface Handler {
diff --git a/src/java/org/lwjgl/opengl/AWTGLCanvas.java b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
index d5e433d8..2a694881 100644
--- a/src/java/org/lwjgl/opengl/AWTGLCanvas.java
+++ b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
@@ -55,7 +55,7 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
private static final long serialVersionUID = 1L;
- private final static AWTCanvasImplementation implementation;
+ private static final AWTCanvasImplementation implementation;
private boolean update_context;
private Object SYNC_LOCK = new Object();
diff --git a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
index 8d5927ee..d2450ce9 100644
--- a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
+++ b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java
@@ -48,11 +48,11 @@ import org.lwjgl.LWJGLUtil;
*/
final class AWTSurfaceLock {
- private final static int WAIT_DELAY_MILLIS = 100;
+ private static final int WAIT_DELAY_MILLIS = 100;
private final ByteBuffer lock_buffer;
- private boolean firstLockSucceeded = false;
+ private boolean firstLockSucceeded;
AWTSurfaceLock() {
lock_buffer = createHandle();
@@ -83,13 +83,11 @@ final class AWTSurfaceLock {
return lockAndInitHandle(lock_buffer, component);
else
try {
- final Object result = AccessController.doPrivileged(new PrivilegedExceptionAction() {
-
- public Object run() throws LWJGLException {
- return Boolean.valueOf(lockAndInitHandle(lock_buffer, component));
+ firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Boolean run() throws LWJGLException {
+ return lockAndInitHandle(lock_buffer, component);
}
});
- firstLockSucceeded = ((Boolean) result).booleanValue();
return firstLockSucceeded;
} catch (PrivilegedActionException e) {
throw (LWJGLException) e.getException();
diff --git a/src/java/org/lwjgl/opengl/AWTUtil.java b/src/java/org/lwjgl/opengl/AWTUtil.java
index 11855231..2e81cea2 100644
--- a/src/java/org/lwjgl/opengl/AWTUtil.java
+++ b/src/java/org/lwjgl/opengl/AWTUtil.java
@@ -87,12 +87,11 @@ final class AWTUtil {
public static Robot createRobot(final Component component) {
try {
- Robot robot = (Robot)AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws Exception {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Robot run() throws Exception {
return new Robot(component.getGraphicsConfiguration().getDevice());
}
});
- return robot;
} catch (PrivilegedActionException e) {
LWJGLUtil.log("Got exception while creating robot: " + e.getCause());
return null;
@@ -112,8 +111,8 @@ final class AWTUtil {
try {
final GraphicsConfiguration config = component.getGraphicsConfiguration();
if (config != null) {
- PointerInfo pointer_info = (PointerInfo)AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws Exception {
+ PointerInfo pointer_info = AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public PointerInfo run() throws Exception {
return MouseInfo.getPointerInfo();
}
});
diff --git a/src/java/org/lwjgl/opengl/BaseReferences.java b/src/java/org/lwjgl/opengl/BaseReferences.java
index 7058cce6..e2fa56d5 100644
--- a/src/java/org/lwjgl/opengl/BaseReferences.java
+++ b/src/java/org/lwjgl/opengl/BaseReferences.java
@@ -34,12 +34,16 @@ package org.lwjgl.opengl;
import java.nio.Buffer;
import java.util.Arrays;
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL13.*;
+import static org.lwjgl.opengl.GL20.*;
+
class BaseReferences {
int elementArrayBuffer;
int arrayBuffer;
- Buffer[] glVertexAttribPointer_buffer;
- Buffer[] glTexCoordPointer_buffer;
+ final Buffer[] glVertexAttribPointer_buffer;
+ final Buffer[] glTexCoordPointer_buffer;
int glClientActiveTexture;
int pixelPackBuffer;
@@ -50,16 +54,16 @@ class BaseReferences {
BaseReferences(ContextCapabilities caps) {
int max_vertex_attribs;
if (caps.OpenGL20 || caps.GL_ARB_vertex_shader)
- max_vertex_attribs = GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB);
+ max_vertex_attribs = glGetInteger(GL_MAX_VERTEX_ATTRIBS);
else
max_vertex_attribs = 0;
glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs];
int max_texture_units;
if (caps.OpenGL20)
- max_texture_units = GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS);
+ max_texture_units = glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS);
else if (caps.OpenGL13 || caps.GL_ARB_multitexture)
- max_texture_units = GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS);
+ max_texture_units = glGetInteger(GL_MAX_TEXTURE_UNITS);
else
max_texture_units = 1;
glTexCoordPointer_buffer = new Buffer[max_texture_units];
@@ -79,7 +83,7 @@ class BaseReferences {
}
void copy(BaseReferences references, int mask) {
- if ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {
+ if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {
this.elementArrayBuffer = references.elementArrayBuffer;
this.arrayBuffer = references.arrayBuffer;
this.glClientActiveTexture = references.glClientActiveTexture;
@@ -89,7 +93,7 @@ class BaseReferences {
this.indirectBuffer = references.indirectBuffer;
}
- if ( (mask & GL11.GL_CLIENT_PIXEL_STORE_BIT) != 0 ) {
+ if ( (mask & GL_CLIENT_PIXEL_STORE_BIT) != 0 ) {
this.pixelPackBuffer = references.pixelPackBuffer;
this.pixelUnpackBuffer = references.pixelUnpackBuffer;
}
diff --git a/src/java/org/lwjgl/opengl/CallbackUtil.java b/src/java/org/lwjgl/opengl/CallbackUtil.java
index 728ece3e..0c938e75 100644
--- a/src/java/org/lwjgl/opengl/CallbackUtil.java
+++ b/src/java/org/lwjgl/opengl/CallbackUtil.java
@@ -42,9 +42,9 @@ import java.util.Map;
final class CallbackUtil {
/** Context -> Long */
- private static final Map contextUserParamsARB = new HashMap();
+ private static final Map contextUserParamsARB = new HashMap();
/** Context -> Long */
- private static final Map contextUserParamsAMD = new HashMap();
+ private static final Map contextUserParamsAMD = new HashMap();
private CallbackUtil() {}
@@ -84,19 +84,19 @@ final class CallbackUtil {
*
* @param userParam the global reference pointer
*/
- private static void registerContextCallback(final long userParam, final Map contextUserData) {
+ private static void registerContextCallback(final long userParam, final Map contextUserData) {
Context context = Context.getCurrentContext();
if ( context == null ) {
deleteGlobalRef(userParam);
throw new IllegalStateException("No context is current.");
}
- final Long userParam_old = (Long)contextUserData.remove(context);
+ final Long userParam_old = contextUserData.remove(context);
if ( userParam_old != null )
- deleteGlobalRef(userParam_old.longValue());
+ deleteGlobalRef(userParam_old);
if ( userParam != 0 )
- contextUserData.put(context, new Long(userParam));
+ contextUserData.put(context, userParam);
}
/**
@@ -105,13 +105,13 @@ final class CallbackUtil {
* @param context the Context to unregister
*/
static void unregisterCallbacks(final Context context) {
- Long userParam = (Long)contextUserParamsARB.remove(context);
+ Long userParam = contextUserParamsARB.remove(context);
if ( userParam != null )
- deleteGlobalRef(userParam.longValue());
+ deleteGlobalRef(userParam);
- userParam = (Long)contextUserParamsAMD.remove(context);
+ userParam = contextUserParamsAMD.remove(context);
if ( userParam != null )
- deleteGlobalRef(userParam.longValue());
+ deleteGlobalRef(userParam);
}
// --------- [ ARB_debug_output ] ---------
diff --git a/src/java/org/lwjgl/opengl/Context.java b/src/java/org/lwjgl/opengl/Context.java
index fa9d0074..d0147cae 100644
--- a/src/java/org/lwjgl/opengl/Context.java
+++ b/src/java/org/lwjgl/opengl/Context.java
@@ -40,6 +40,8 @@ import org.lwjgl.opencl.KHRGLSharing;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
+import static org.lwjgl.opengl.GL11.*;
+
/**
*
* Context encapsulates an OpenGL context.
@@ -57,7 +59,7 @@ final class Context {
private static final ContextImplementation implementation;
/** The current Context */
- private static final ThreadLocal current_context_local = new ThreadLocal();
+ private static final ThreadLocal current_context_local = new ThreadLocal();
/** Handle to the native GL rendering context */
private final ByteBuffer handle;
@@ -101,7 +103,7 @@ final class Context {
}
static Context getCurrentContext() {
- return (Context)current_context_local.get();
+ return current_context_local.get();
}
/** Create a context with the specified peer info and shared context */
@@ -248,14 +250,14 @@ final class Context {
return;
destroy_requested = true;
boolean was_current = isCurrent();
- int error = GL11.GL_NO_ERROR;
+ int error = GL_NO_ERROR;
if ( was_current ) {
if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
- error = GL11.glGetError();
+ error = glGetError();
releaseCurrentContext();
}
checkDestroy();
- if ( was_current && error != GL11.GL_NO_ERROR )
+ if ( was_current && error != GL_NO_ERROR )
throw new OpenGLException(error);
}
diff --git a/src/java/org/lwjgl/opengl/ContextAttribs.java b/src/java/org/lwjgl/opengl/ContextAttribs.java
index c87e39ff..552a1bbb 100644
--- a/src/java/org/lwjgl/opengl/ContextAttribs.java
+++ b/src/java/org/lwjgl/opengl/ContextAttribs.java
@@ -304,7 +304,7 @@ public final class ContextAttribs {
}
public String toString() {
- StringBuffer sb = new StringBuffer(32);
+ StringBuilder sb = new StringBuilder(32);
sb.append("ContextAttribs:");
sb.append(" Version=").append(majorVersion).append('.').append(minorVersion);
diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java
index e90db80c..d3f7042c 100644
--- a/src/java/org/lwjgl/opengl/Display.java
+++ b/src/java/org/lwjgl/opengl/Display.java
@@ -62,6 +62,8 @@ import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashSet;
+import static org.lwjgl.opengl.GL11.*;
+
public final class Display {
private static final Thread shutdown_hook = new Thread() {
@@ -114,9 +116,9 @@ public final class Display {
private static boolean parent_resized;
/** Initial Background Color of Display */
- private static float r = 0, g = 0, b = 0;
+ private static float r, g, b;
- private static ComponentListener component_listener = new ComponentAdapter() {
+ private static final ComponentListener component_listener = new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
synchronized ( GlobalLock.lock ) {
parent_resized = true;
@@ -201,7 +203,7 @@ public final class Display {
}
// We'll use a HashSet to filter out the duplicated modes
- HashSet modes = new HashSet(unfilteredModes.length);
+ HashSet modes = new HashSet(unfilteredModes.length);
modes.addAll(Arrays.asList(unfilteredModes));
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
@@ -638,7 +640,7 @@ public final class Display {
* Swap the display buffers. This method is called from update(), and should normally not be called by
* the application.
*
- * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
+ * @throws OpenGLException if an OpenGL error has occured since the last call to glGetError()
*/
public static void swapBuffers() throws LWJGLException {
synchronized ( GlobalLock.lock ) {
@@ -731,7 +733,7 @@ public final class Display {
}
private static void removeShutdownHook() {
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction