summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-06-25 00:18:16 +0200
committerMichael Bien <[email protected]>2010-06-25 00:18:16 +0200
commitb6d6f75129cac5f4719d1cbfb3c0b63159086137 (patch)
treecc1780cba01108e6044e39a85832cf0df63de9d7 /src/com/jogamp/opencl
parent735c9cbbec16457358eee7424a0533fcc1b8c64c (diff)
added CLContext.getSupportedImageFormats() methods and unit test.
Diffstat (limited to 'src/com/jogamp/opencl')
-rw-r--r--src/com/jogamp/opencl/CLContext.java48
-rw-r--r--src/com/jogamp/opencl/CLImageFormat.java15
2 files changed, 60 insertions, 3 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index 72694d61..5deaf4cf 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -1,10 +1,10 @@
package com.jogamp.opencl;
import com.jogamp.opencl.CLDevice.Type;
-import com.jogamp.opencl.CLMemory.Mem;
import com.jogamp.opencl.CLSampler.AddressingMode;
import com.jogamp.opencl.CLSampler.FilteringMode;
import com.jogamp.common.nio.PointerBuffer;
+import com.jogamp.opencl.impl.CLImageFormatImpl;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -27,6 +27,8 @@ import static java.lang.System.*;
import static com.jogamp.opencl.CLException.*;
import static com.jogamp.common.nio.Buffers.*;
import static com.jogamp.common.os.Platform.*;
+import static com.jogamp.opencl.CL.*;
+import static com.jogamp.opencl.CLBuffer.*;
/**
* CLContext is responsible for managing objects such as command-queues, memory,
@@ -414,6 +416,50 @@ public class CLContext extends CLObject implements CLResource {
device.setContext(this);
}
+ private CLImageFormat[] getSupportedImageFormats(int flags, int type) {
+
+ int[] entries = new int[1];
+ int ret = cl.clGetSupportedImageFormats(ID, flags, type, 0, null, entries, 0);
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "error calling clGetSupportedImageFormats");
+ }
+
+ int count = entries[0];
+ if(count == 0) {
+ return new CLImageFormat[0];
+ }
+
+ CLImageFormat[] formats = new CLImageFormat[count];
+ CLImageFormatImpl impl = CLImageFormatImpl.create(newDirectByteBuffer(count * CLImageFormatImpl.size()));
+ ret = cl.clGetSupportedImageFormats(ID, flags, type, count, impl, null, 0);
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "error calling clGetSupportedImageFormats");
+ }
+
+ ByteBuffer buffer = impl.getBuffer();
+ for (int i = 0; i < formats.length; i++) {
+ formats[i] = new CLImageFormat(CLImageFormatImpl.create(buffer.slice()));
+ buffer.position(i*CLImageFormatImpl.size());
+ }
+
+ return formats;
+
+ }
+
+ /**
+ * Returns all supported 2d image formats with the (optional) memory allocation flags.
+ */
+ public CLImageFormat[] getSupportedImage2dFormats(Mem... flags) {
+ return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL_MEM_OBJECT_IMAGE2D);
+ }
+
+ /**
+ * Returns all supported 3d image formats with the (optional) memory allocation flags.
+ */
+ public CLImageFormat[] getSupportedImage3dFormats(Mem... flags) {
+ return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL_MEM_OBJECT_IMAGE3D);
+ }
+
/**
* Returns the CLPlatform this context is running on.
*/
diff --git a/src/com/jogamp/opencl/CLImageFormat.java b/src/com/jogamp/opencl/CLImageFormat.java
index 20f2c4b1..e3eb3667 100644
--- a/src/com/jogamp/opencl/CLImageFormat.java
+++ b/src/com/jogamp/opencl/CLImageFormat.java
@@ -5,17 +5,23 @@ import com.jogamp.opencl.impl.CLImageFormatImpl;
import static com.jogamp.opencl.CL.*;
/**
- *
+ * Represents the OpenCL image format with its channeltype and order.
* @author Michael Bien
*/
public final class CLImageFormat {
- private final CLImageFormatImpl format = CLImageFormatImpl.create();
+ private final CLImageFormatImpl format;
CLImageFormat() {
+ format = CLImageFormatImpl.create();
+ }
+
+ CLImageFormat(CLImageFormatImpl format) {
+ this.format = format;
}
public CLImageFormat(ChannelOrder order, ChannelType type) {
+ format = CLImageFormatImpl.create();
setImageChannelOrder(order);
setImageChannelDataType(type);
}
@@ -45,6 +51,11 @@ public final class CLImageFormat {
return format;
}
+ @Override
+ public String toString() {
+ return "CLImageFormat["+getImageChannelOrder()+" "+getImageChannelDataType()+"]";
+ }
+
/**
* Specifies the number of channels and the channel layout i.e. the memory
* layout in which channels are stored in the image.