From 4df2a1b266a25c1d37126acdb82cf578ac61f9a8 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 27 Oct 2009 18:51:36 +0100 Subject: generified CLBuffer, added createFromGLBuffer(...). --- src/com/mbien/opencl/CLContext.java | 38 +++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/com/mbien/opencl/CLContext.java') diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 68ff131c..66716e41 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -7,6 +7,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; @@ -32,7 +33,7 @@ public final class CLContext { private CLDevice[] devices; private final List programs; - private final List buffers; + private final List> buffers; private final Map> queuesMap; @@ -40,7 +41,7 @@ public final class CLContext { this.cl = CLPlatform.getLowLevelBinding(); this.ID = contextID; this.programs = new ArrayList(); - this.buffers = new ArrayList(); + this.buffers = new ArrayList>(); this.queuesMap = new HashMap>(); } @@ -194,22 +195,39 @@ public final class CLContext { /** * Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer. */ - public CLBuffer createBuffer(ByteBuffer directBuffer, Mem... flags) { + public CLBuffer createBuffer(B directBuffer, Mem... flags) { return createBuffer(directBuffer, Mem.flagsToInt(flags)); } + /** - * Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer. + * Creates a CLBuffer with the specified flags and buffer size in bytes. No flags creates a MEM.READ_WRITE buffer. */ - public CLBuffer createBuffer(int size, Mem... flags) { + public CLBuffer createBuffer(int size, Mem... flags) { return createBuffer(size, Mem.flagsToInt(flags)); } - public CLBuffer createBuffer(int size, int flags) { + /** + * Creates a CLBuffer with the specified flags and buffer size in bytes. + */ + public CLBuffer createBuffer(int size, int flags) { return createBuffer(BufferFactory.newDirectByteBuffer(size), flags); } - public CLBuffer createBuffer(ByteBuffer directBuffer, int flags) { - CLBuffer buffer = new CLBuffer(this, directBuffer, flags); + /** + * Creates a CLBuffer with the specified flags. + */ + public CLBuffer createBuffer(B directBuffer, int flags) { + CLBuffer buffer = new CLBuffer(this, directBuffer, flags); + buffers.add(buffer); + return buffer; + } + + public CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, Mem... flags) { + return createFromGLBuffer(directBuffer, glBuffer, Mem.flagsToInt(flags)); + } + + public CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, int flags) { + CLBuffer buffer = new CLBuffer(this, directBuffer, glBuffer, flags); buffers.add(buffer); return buffer; } @@ -232,7 +250,7 @@ public final class CLContext { programs.remove(program); } - void onBufferReleased(CLBuffer buffer) { + void onBufferReleased(CLBuffer buffer) { buffers.remove(buffer); } @@ -270,7 +288,7 @@ public final class CLContext { /** * Returns a read only view of all buffers associated with this context. */ - public List getCLBuffers() { + public List> getCLBuffers() { return Collections.unmodifiableList(buffers); } -- cgit v1.2.3