diff options
author | Michael Bien <[email protected]> | 2009-10-19 19:26:15 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-10-19 19:26:15 +0200 |
commit | cb7fa23952a10795215eda50848530828b92895e (patch) | |
tree | e9e34a7cf55505fe3a381e474ddeb9d224caf545 /src/com/mbien/opencl/CLBuffer.java | |
parent | 9abfd00399e4ca5c351df9cdf25cd85c960b3d44 (diff) |
initial import of CLBuffer and CLKernel.
added hashCode(), equals() and toString() methods.
updated JUnit test to test new classes.
Diffstat (limited to 'src/com/mbien/opencl/CLBuffer.java')
-rw-r--r-- | src/com/mbien/opencl/CLBuffer.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLBuffer.java b/src/com/mbien/opencl/CLBuffer.java new file mode 100644 index 00000000..0f6e34a4 --- /dev/null +++ b/src/com/mbien/opencl/CLBuffer.java @@ -0,0 +1,70 @@ +package com.mbien.opencl; + +import java.nio.ByteBuffer; +import static com.mbien.opencl.CLException.*; + +/** + * + * @author Michael Bien + */ +public class CLBuffer { + + public final ByteBuffer buffer; + public final long bufferID; + + private final CLContext context; + private final CL cl; + + CLBuffer(CLContext context, int flags, ByteBuffer directBuffer) { + + if(!directBuffer.isDirect()) + throw new IllegalArgumentException("buffer is not a direct buffer"); + + this.buffer = directBuffer; + this.context = context; + this.cl = context.cl; + + int[] intArray = new int[1]; + + this.bufferID = cl.clCreateBuffer(context.contextID, flags, directBuffer.capacity(), null, intArray, 0); + + checkForError(intArray[0], "can not create cl buffer"); + + } + + public CLBuffer release() { + cl.clReleaseMemObject(bufferID); + context.bufferReleased(this); + return this; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CLBuffer other = (CLBuffer) obj; + if (this.buffer != other.buffer && (this.buffer == null || !this.buffer.equals(other.buffer))) { + return false; + } + if (this.context.contextID != other.context.contextID) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 29 * hash + (this.buffer != null ? this.buffer.hashCode() : 0); + hash = 29 * hash + (int) (this.context.contextID ^ (this.context.contextID >>> 32)); + return hash; + } + + + + +} |