Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfElementBuffer.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-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 __glfElementBuffer_hh__
26 #define __glfElementBuffer_hh__
27 
28 #include "glfCommon.hh"
29 #include <vector>
30 
31 namespace BIAS {
32 
33  /**
34  * \brief An element buffer contains vertex indices that form primitives.
35  * With element buffers, a single vertex can be used by multiple
36  * primitives, although it is only stored once in the vertex buffer.
37  * \ingroup g_openglframework
38  * \author jkollmann
39  */
40  class BIASOpenGLFramework_EXPORT glfElementBuffer {
41  public:
44 
45  /**
46  * Creates the element buffer for the given number of indices.
47  * \param numIndices Number of indices to fit into the buffer.
48  * \param type Data type of indices. May be GL_UNSIGNED_BYTE,
49  * GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.
50  * \param mode Primitive type. May be GL_POINTS, GL_LINE_STRIP,
51  GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN,
52  GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, or GL_POLYGON.
53  * \param indices Pointer to vertex indices.
54  */
55  void Create(int numIndices, GLenum type, GLenum mode, const void* indices);
56 
57  /**
58  * Secure convenience wrapper for glfElementBuffer::Create method with
59  * type = GL_UNSIGNED_BYTE.
60  */
61  void Create(const std::vector<unsigned char>& indices, GLenum mode) {
62  Create((int)indices.size(), GL_UNSIGNED_BYTE, mode, &indices[0]);
63  }
64 
65  /**
66  * Secure convenience wrapper for glfElementBuffer::Create method with
67  * type = GL_UNSIGNED_SHORT.
68  */
69  void Create(const std::vector<unsigned short>& indices, GLenum mode) {
70  Create((int)indices.size(), GL_UNSIGNED_SHORT, mode, &indices[0]);
71  }
72 
73  /**
74  * Secure convenience wrapper for glfElementBuffer::Create method with
75  * type = GL_UNSIGNED_INT;
76  */
77  void Create(const std::vector<unsigned int>& indices, GLenum mode) {
78  Create((int)indices.size(), GL_UNSIGNED_INT, mode, &indices[0]);
79  }
80 
81  /**
82  * Maps the element buffer to system memory, so it can be modified after creation.
83  * \attention Access is write-only!
84  */
85  void* Map();
86 
87  /**
88  * Unmaps the element buffer. Must be called after glfElementBuffer::Map and before
89  * the element buffer is used for rendering again.
90  */
91  void Unmap();
92 
93  /**
94  * Draw elements from the buffer.
95  */
96  void Draw(int first = 0, int count = -1) const;
97 
98  private:
99  GLenum mode_;
100  GLenum type_;
101  int typeSize_;
102  int numIndices_;
103  bool useBuffer_;
104  GLuint bufferID_;
105  bool mapped_;
106  std::vector<GLubyte> array_;
107 
108  /** An intuitive assignment operator should generate a copy, as long as nobody is willing to implement
109  * the generation of a copy in gl controlled memory this operator cannot be used.
110  */
111  glfElementBuffer& operator=(const glfElementBuffer& b);
112 
113  /** An intuitive copy constructor should generate a copy, as long as nobody is willing to implement
114  * the generation of a copy in gl controlled memory this constructor cannot be used.
115  */
117 
118 
119  };
120 
121 } // namespace BIAS
122 
123 #endif // __glfElementBuffer_hh__
An element buffer contains vertex indices that form primitives.
void Create(const std::vector< unsigned short > &indices, GLenum mode)
Secure convenience wrapper for glfElementBuffer::Create method with type = GL_UNSIGNED_SHORT.
void Create(const std::vector< unsigned int > &indices, GLenum mode)
Secure convenience wrapper for glfElementBuffer::Create method with type = GL_UNSIGNED_INT;.
void Create(const std::vector< unsigned char > &indices, GLenum mode)
Secure convenience wrapper for glfElementBuffer::Create method with type = GL_UNSIGNED_BYTE.