25 #include <Base/Common/BIASpragma.hh>
26 #include <OpenCLFramework/clfBuffer.hh>
27 #include <OpenCLFramework/clfException.hh>
28 #include <Base/Debug/Error.hh>
45 void clfBuffer::Allocate(
unsigned int bufsize,
bool readonly,
bool writeonly,
void *hostptr,
bool copy) {
54 }
catch(cl::Error &err) {
55 THROW_CL_EXCEPTION(err);
61 void clfBuffer::Allocate(
unsigned int rows,
unsigned int cols,
unsigned int channels,
unsigned int itemsize,
bool readonly,
bool writeonly,
void *hostptr,
bool copy) {
65 cl_mem_flags = CL_READ_ONLY_CACHE;
67 cl_mem_flags = CL_READ_WRITE_CACHE;
72 size_ = rows*cols*itemsize;
77 stride_=cols*itemsize;
80 size_ = rows*cols*itemsize*channels;
84 stride_=cols*itemsize;
89 }
catch(cl::Error &err) {
90 THROW_CL_EXCEPTION(err);
100 }
catch(cl::Error &err) {
101 THROW_CL_EXCEPTION(err);
122 queue_->enqueueWriteBuffer(
buffer(), CL_TRUE, offset, size, data);
123 }
catch (cl::Error &error) {
124 THROW_CL_EXCEPTION(error);
133 queue_->enqueueReadBuffer(
buffer(), CL_TRUE, offset, size, data);
134 }
catch (cl::Error &error) {
135 THROW_CL_EXCEPTION(error);
145 queue_->enqueueCopyBuffer(
buffer(), outputbuffer.
buffer(), srcoffset, dstoffset, size, NULL, &event);
147 }
catch (cl::Error &error) {
148 THROW_CL_EXCEPTION(error);
154 cl_map_flags mapflags = 0;
156 mapflags = CL_MAP_WRITE;
158 mapflags = CL_MAP_READ;
163 return queue_->enqueueMapBuffer(
buffer(), CL_TRUE, mapflags, offset, size);
164 }
catch (cl::Error &error) {
165 THROW_CL_EXCEPTION(error);
unsigned int GetItemSize() const
int GetNumVertices() const
Returns the number of vertices in the vertex buffer.
void SetCached(bool cache)
void * MapBuffer(bool write=false, unsigned int offset=0, unsigned int size=0)
void AllocateFromVertexBuffer(BIAS::glfVertexBuffer &vbo, bool readonly=false, bool writeonly=false)
Allocation of a memory buffer from a GL vertexBuffer (works only on shared context!) ...
unsigned int GetCols() const
A vertex buffer contains an array of vertices that can be used for rendering.
unsigned int GetChannels() const
unsigned int GetStride() const
int DetermineMemFlags_(bool readonly, bool writeonly, const void *hostptr=NULL, bool copy=false)
cl::CommandQueue * queue_
void ReadFromBuffer(void *data, unsigned int offset=0, unsigned int size=0)
read from buffer object to host memory
void Allocate(unsigned int bufsize, bool readonly=false, bool writeonly=false, void *hostptr=NULL, bool copy=false)
Allocation of a memory buffer A memory buffer can be created on device or host, it can be initialized...
unsigned int GetRows() const
clfBuffer(cl::Context *context, cl::CommandQueue *queue_)
void CopyBuffer(clfBuffer &outputbuffer, unsigned int srcoffset=0, unsigned int dstoffset=0, unsigned int size=0)
copy from one buffer to another
void WriteToBuffer(const void *data, unsigned int offset=0, unsigned int size=0)
write from host memory to buffer object
glfVertexFormat GetFormat() const