Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfVertexBuffer.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2008, 2009 (see file CONTACT 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 __glfVertexBuffer_hh__
26 #define __glfVertexBuffer_hh__
27 
28 #include "glfVertexFormat.hh"
29 
30 namespace BIAS {
31 
32  /**
33  * \brief A vertex buffer contains an array of vertices that can be used for
34  * rendering. If possible, the buffer is stored in the video memory.
35  * \ingroup g_openglframework
36  * \author jkollmann
37  */
38  class BIASOpenGLFramework_EXPORT glfVertexBuffer {
39  public:
41  ~glfVertexBuffer();
42 
43  /**
44  * Creates the vertex buffer for the given number of vertices and vertex format.
45  * If the given data is non-<code>NULL</code>, it will be uploaded to the
46  * vertex buffer. It must contain <code>numVertices</code> vertices of the
47  * given <code>format</code>. The size of the given data buffer must be
48  * <code>numVertices * format.GetVertexSize()</code> bytes.
49  */
50  void Create(int numVertices, const glfVertexFormat& format,
51  const void* data = NULL, bool useBufferIfPossible = true);
52 
53  /**
54  * Secure convenience wrapper for other glfVertexBuffer::Create method.
55  * T is the vertex structure in C++ that is described by <code>format</code>.
56  */
57  template<class T>
58  inline void Create(const std::vector<T>& vertices, const glfVertexFormat& format) {
59  BIASASSERT(sizeof(T) == format.GetVertexSize());
60  Create((int)vertices.size(), format, &vertices[0]);
61  }
62 
63  /**
64  * Maps the vertex buffer to system memory, so it can be modified after creation.
65  * \attention Access is write-only!
66  */
67  void* Map();
68 
69  /**
70  * Unmaps the vertex buffer. Must be called after glfVertexBuffer::Map and before
71  * the vertex buffer is used for rendering again.
72  */
73  void Unmap();
74 
75  /**
76  * Returns the number of vertices in the vertex buffer.
77  */
78  int GetNumVertices() const;
79 
80  /**
81  * Binds the vertex buffer in OpenGL.
82  */
83  void Bind() const;
84 
85  int GetBufferID() const { return bufferID_; }
86 
87  glfVertexFormat GetFormat() const { return format_; }
88 
89  private:
90  glfVertexFormat format_;
91  int numVertices_;
92  bool useBuffer_;
93  GLuint bufferID_;
94  bool mapped_;
95  // std::vector<GLubyte> array_;
96  GLubyte* array_;
97 
98  /** An intuitive assignment operator should generate a copy, as long as nobody is willing to implement
99  * the generation of a copy in gl controlled memory this operator cannot be used.
100  */
101  glfVertexBuffer& operator=(const glfVertexBuffer& b);
102 
103  /** An intuitive copy constructor should generate a copy, as long as nobody is willing to implement
104  * the generation of a copy in gl controlled memory this constructor cannot be used.
105  */
106  glfVertexBuffer(const glfVertexBuffer& b);
107 
108  };
109 
110 } // namespace BIAS
111 
112 #endif // __glfVertexBuffer_hh__
A vertex buffer contains an array of vertices that can be used for rendering.
int GetVertexSize() const
Returns the size in bytes of a single vertex.
A vertex format describes the attributes of a vertex.
void Create(const std::vector< T > &vertices, const glfVertexFormat &format)
Secure convenience wrapper for other glfVertexBuffer::Create method.
glfVertexFormat GetFormat() const