diff options
author | Michael Bien <[email protected]> | 2010-04-12 22:18:39 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-04-12 22:18:39 +0200 |
commit | bf07b44ed6a8958dd321cc4c08fd2bdd08299611 (patch) | |
tree | e24b7c4e4197a80e0ecaad75b9b3667299fd8323 /src/com/jogamp/opencl/CLBuffer.java | |
parent | 7680472b21ec1e2deacb49addae65c820a2e2a4d (diff) |
renamed package com.mbien.* in com.jogamp.* JOCL is now officially a JogAmp team player ;).
Diffstat (limited to 'src/com/jogamp/opencl/CLBuffer.java')
-rw-r--r-- | src/com/jogamp/opencl/CLBuffer.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/CLBuffer.java b/src/com/jogamp/opencl/CLBuffer.java new file mode 100644 index 00000000..5a2a37e7 --- /dev/null +++ b/src/com/jogamp/opencl/CLBuffer.java @@ -0,0 +1,60 @@ +package com.jogamp.opencl; + +import java.nio.Buffer; + +import static com.jogamp.opencl.CLException.*; + +/** + * + * @author Michael Bien + */ +public class CLBuffer<B extends Buffer> extends CLMemory<B> { + + protected CLBuffer(CLContext context, long id, int flags) { + super(context, id, flags); + } + + protected CLBuffer(CLContext context, B directBuffer, long id, int flags) { + super(context, directBuffer, id, flags); + } + + @SuppressWarnings("unchecked") + static CLBuffer<?> create(CLContext context, int size, int flags) { + + CL cl = context.cl; + int[] result = new int[1]; + + if(isHostPointerFlag(flags)) { + throw new IllegalArgumentException("no host pointer defined"); + } + + long id = cl.clCreateBuffer(context.ID, flags, size, null, result, 0); + checkForError(result[0], "can not create cl buffer"); + + return new CLBuffer(context, id, flags); + } + + static <B extends Buffer> CLBuffer<B> create(CLContext context, B directBuffer, int flags) { + + if(!directBuffer.isDirect()) + throw new IllegalArgumentException("buffer is not direct"); + + B host_ptr = null; + CL cl = context.cl; + int[] result = new int[1]; + + if(isHostPointerFlag(flags)) { + host_ptr = directBuffer; + } + long id = cl.clCreateBuffer(context.ID, flags, sizeOfBufferElem(directBuffer)*directBuffer.capacity(), host_ptr, result, 0); + checkForError(result[0], "can not create cl buffer"); + + return new CLBuffer<B>(context, directBuffer, id, flags); + } + + @Override + public <T extends Buffer> CLBuffer<T> cloneWith(T directBuffer) { + return new CLBuffer<T>(context, directBuffer, ID, FLAGS); + } + +} |