summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLMemory.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-03-16 18:05:06 +0100
committerMichael Bien <[email protected]>2010-03-16 18:05:06 +0100
commit919d8e9f992c07ab18ddd6d192d6747e8d7aa40b (patch)
tree8a92dc8adb52758e1f09f2e87632e6f3f6ac695f /src/com/mbien/opencl/CLMemory.java
parent81b94f83cb76128c481d21134c3d462590db23d0 (diff)
even more utility methods and general awesomeness.
Diffstat (limited to 'src/com/mbien/opencl/CLMemory.java')
-rw-r--r--src/com/mbien/opencl/CLMemory.java51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/com/mbien/opencl/CLMemory.java b/src/com/mbien/opencl/CLMemory.java
index 072fbaf5..444acba2 100644
--- a/src/com/mbien/opencl/CLMemory.java
+++ b/src/com/mbien/opencl/CLMemory.java
@@ -9,6 +9,9 @@ import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
import static com.mbien.opencl.CLException.*;
import static com.mbien.opencl.gl.CLGLI.*;
@@ -20,14 +23,17 @@ import static com.mbien.opencl.gl.CLGLI.*;
public abstract class CLMemory <B extends Buffer> extends CLObject implements CLResource {
B buffer;
+ protected final int FLAGS;
- protected <Buffer> CLMemory(CLContext context, long id) {
+ protected <Buffer> CLMemory(CLContext context, long id, int flags) {
super(context, id);
+ this.FLAGS = flags;
}
- protected CLMemory(CLContext context, B directBuffer, long id) {
+ protected CLMemory(CLContext context, B directBuffer, long id, int flags) {
super(context, id);
this.buffer = directBuffer;
+ this.FLAGS = flags;
}
/**
@@ -110,6 +116,34 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL
return pb.get();
}
+ /**
+ * Returns the configuration of this memory object.
+ */
+ public EnumSet<Mem> getConfig() {
+ return Mem.valuesOf(FLAGS);
+ }
+
+ /**
+ * Returns true if this memory object was created with the {@link Mem#READ_ONLY} flag.
+ */
+ public boolean isReadOnly() {
+ return (Mem.READ_ONLY.CONFIG & FLAGS) != 0;
+ }
+
+ /**
+ * Returns true if this memory object was created with the {@link Mem#WRITE_ONLY} flag.
+ */
+ public boolean isWriteOnly() {
+ return (Mem.WRITE_ONLY.CONFIG & FLAGS) != 0;
+ }
+
+ /**
+ * Returns true if this memory object was created with the {@link Mem#READ_WRITE} flag.
+ */
+ public boolean isReadWrite() {
+ return (Mem.READ_WRITE.CONFIG & FLAGS) != 0;
+ }
+
public void release() {
int ret = cl.clReleaseMemObject(ID);
context.onMemoryReleased(this);
@@ -255,6 +289,19 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL
return null;
}
+ public static EnumSet<Mem> valuesOf(int bitfield) {
+ List<Mem> matching = new ArrayList<Mem>();
+ Mem[] values = Mem.values();
+ for (Mem value : values) {
+ if((value.CONFIG & bitfield) != 0)
+ matching.add(value);
+ }
+ if(matching.isEmpty())
+ return EnumSet.noneOf(Mem.class);
+ else
+ return EnumSet.copyOf(matching);
+ }
+
public static int flagsToInt(Mem[] flags) {
int clFlags = 0;
if (flags != null) {