From 4760089650228703bab990565fa9a3bdba2edb43 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sun, 4 Jul 2010 22:10:17 +0200 Subject: initial import of CLSubBuffer to HLB. --- src/com/jogamp/opencl/CLBuffer.java | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/com/jogamp/opencl/CLBuffer.java') diff --git a/src/com/jogamp/opencl/CLBuffer.java b/src/com/jogamp/opencl/CLBuffer.java index 5a2a37e7..e2c74c7d 100644 --- a/src/com/jogamp/opencl/CLBuffer.java +++ b/src/com/jogamp/opencl/CLBuffer.java @@ -1,15 +1,22 @@ package com.jogamp.opencl; +import com.jogamp.common.nio.Buffers; +import java.util.List; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.opencl.CLMemory.Mem; import java.nio.Buffer; +import java.util.ArrayList; import static com.jogamp.opencl.CLException.*; /** - * + * OpenCL buffer object. * @author Michael Bien */ public class CLBuffer extends CLMemory { + private List> childs; + protected CLBuffer(CLContext context, long id, int flags) { super(context, id, flags); } @@ -51,6 +58,52 @@ public class CLBuffer extends CLMemory { return new CLBuffer(context, directBuffer, id, flags); } + + /** + * Creates a sub buffer with the specified region from this buffer. + */ + public CLBuffer createSubBuffer(int origin, int size, Mem... flags) { + PointerBuffer info = PointerBuffer.allocateDirect(2); + info.put(origin).put(size).rewind(); + int bitset = Mem.flagsToInt(flags); + + int[] err = new int[1]; + long subID = cl.clCreateSubBuffer(ID, bitset, CL.CL_BUFFER_CREATE_TYPE_REGION, info.getBuffer(), err, 0); + checkForError(err[0], "can not create sub buffer"); + + B slice = null; + if(buffer != null) { + slice = (B)Buffers.slice(buffer, origin, size); + } + + CLSubBuffer clSubBuffer = new CLSubBuffer(this, origin, slice, subID, bitset); + if(childs == null) { + childs = new ArrayList>(); + } + childs.add(clSubBuffer); + return clSubBuffer; + } + + @Override + public void release() { + if(childs != null) { + for (CLBuffer child : childs) { + child.release(); + } + } + super.release(); + } + + void onReleaseSubBuffer(CLSubBuffer sub) { + childs.remove(sub); + } + + /** + * Returns true if this is a sub buffer. + */ + public boolean isSubBuffer() { + return false; + } @Override public CLBuffer cloneWith(T directBuffer) { -- cgit v1.2.3