Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clfBuffer.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef CLFBUFFER_HH_
26 #define CLFBUFFER_HH_
27 
28 #include <OpenCLFramework/clfOpenCL.hh>
29 #include <OpenCLFramework/clfMemory.hh>
30 #include <OpenGLFramework/Base/glfVertexBuffer.hh>
31 
32 namespace BIAS {
33 
34  /**
35  *
36  * @brief OpenCL Buffer wrapper
37  *
38  * An clfBuffer is used for Buffers both host and GL objects.
39  * All buffers are created from a valid clfContext, hence the constructor is protected.
40  *
41  * @author fkellner 06/11
42  */
43  class BIASOpenCLFramework_EXPORT clfBuffer : public clfMemory {
44  public:
45 
46  virtual ~clfBuffer();
47 
48  /**
49  * @brief Allocation of a memory buffer
50  * A memory buffer can be created on device or host, it can be initialized from a host ptr. if the buffer is not readonly and not writeonly
51  * it is declared read/write.
52  * @param bufsize size of buffer in byte
53  * @param readonly if this buffer is read only
54  * @param writeonly if this buffer is write only
55  * @param hostptr ptr to host memory which is used for initialization (if NULL, do not initialize)
56  * @param copy copy host ptr data to device or use host memory
57  */
58  void Allocate(unsigned int bufsize, bool readonly=false, bool writeonly=false, void *hostptr = NULL, bool copy = false);
59  void Allocate(unsigned int rows, unsigned int cols, unsigned int channels, unsigned int itemsize, bool readonly=false, bool writeonly=false, void *hostptr = NULL, bool copy = false);
60  void SetCached(bool cache);
61  /**
62  * @brief Allocation of a memory buffer from a GL vertexBuffer (works only on shared context!)
63  */
64  void AllocateFromVertexBuffer(BIAS::glfVertexBuffer &vbo, bool readonly=false, bool writeonly=false);
65 
66  /**
67  * @brief write from host memory to buffer object
68  * @param data host memory pointer
69  * @param offset offset in bytes
70  * @param size number of bytes to write
71  */
72  void WriteToBuffer(const void *data, unsigned int offset = 0, unsigned int size = 0);
73 
74  /**
75  * @brief read from buffer object to host memory
76  * @param data host memory pointer
77  * @param offset offset in bytes
78  * @param size number of bytes to read
79  */
80  void ReadFromBuffer(void *data, unsigned int offset = 0, unsigned int size = 0);
81 
82  /**
83  * @brief copy from one buffer to another
84  * @param outputbuffer buffer object (to)
85  * @param size number of bytes to copy
86  */
87  void CopyBuffer(clfBuffer &outputbuffer, unsigned int srcoffset = 0, unsigned int dstoffset = 0, unsigned int size = 0);
88 
89  void* MapBuffer(bool write = false, unsigned int offset = 0, unsigned int size = 0);
90 
91  unsigned int GetRows() const;
92  unsigned int GetCols() const;
93  unsigned int GetChannels() const;
94  unsigned int GetItemSize() const;
95  unsigned int GetStride() const;
96 
97  protected:
98  clfBuffer(cl::Context *context, cl::CommandQueue *queue_);
99  cl::Buffer& buffer();
100 
101  private:
102  friend class clfContext;
103  friend class clfProgram;
104 
105  unsigned int rows_, cols_, channels_, itemsize_, stride_;
106  bool cache_;
107  };
108 }
109 
110 #endif /* CLFBUFFER_HH_ */
OpenCL Program wrapper.
Definition: clfProgram.hh:53
OpenCL Buffer wrapper.
Definition: clfBuffer.hh:43
A vertex buffer contains an array of vertices that can be used for rendering.
OpenCL Context wrapper.
Definition: clfContext.hh:49