GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_meshdata.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_MESHDATA_H_
26 #define GLC_MESHDATA_H_
27 
28 #include <QVector>
29 #include <QGLBuffer>
30 
31 #include "glc_lod.h"
32 #include "../glc_global.h"
33 
34 #include "../glc_config.h"
35 
36 
39 
41 
43 {
44  friend GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
45  friend GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
46 
47 public:
48 
50  enum VboType
51  {
52  GLC_Vertex= 30,
55  GLC_Color
56  };
57 
59 
61 
62 public:
64  GLC_MeshData();
65 
67  GLC_MeshData(const GLC_MeshData&);
68 
70  GLC_MeshData& operator=(const GLC_MeshData&);
71 
73  virtual ~GLC_MeshData();
75 
77 
79 
80 public:
82  static quint32 chunckID();
83 
85  inline int lodCount() const
86  {return m_LodList.size();}
87 
89  GLfloatVector positionVector() const;
90 
92  GLfloatVector normalVector() const;
93 
95  GLfloatVector texelVector() const;
96 
98  GLfloatVector colorVector() const;
99 
101  inline GLfloatVector* positionVectorHandle()
102  { return &m_Positions;}
103 
105  inline GLfloatVector* normalVectorHandle()
106  { return &m_Normals;}
107 
109  inline GLfloatVector* texelVectorHandle()
110  { return &m_Texels;}
111 
113  inline GLfloatVector* colorVectorHandle()
114  { return &m_Colors;}
115 
117  inline GLuintVector indexVector(const int i= 0) const
118  {
119  Q_ASSERT(i < m_LodList.size());
120  return m_LodList.at(i)->indexVector();
121  }
122 
124  inline GLuintVector* indexVectorHandle(const int i= 0) const
125  {
126  Q_ASSERT(i < m_LodList.size());
127  return m_LodList.at(i)->indexVectorHandle();
128  }
129 
131  inline int indexVectorSize(const int i= 0) const
132  {
133  Q_ASSERT(i < m_LodList.size());
134  return m_LodList.at(i)->indexVectorSize();
135  }
137  inline GLC_Lod* getLod(int index) const
138  {
139  return m_LodList.value(index);
140  }
141 
143  inline bool isEmpty() const
144  {return (1 > m_PositionSize) && (0 == m_Positions.size());}
145 
147  inline unsigned int trianglesCount(int lod) const
148  {
149  unsigned int subject= 0;
150  if (!m_LodList.isEmpty())
151  {
152  Q_ASSERT(lod < m_LodList.size());
153  subject= m_LodList.at(lod)->trianglesCount();
154  }
155  return subject;
156  }
157 
159  inline bool positionSizeIsSet() const
160  {return m_PositionSize != -1;}
161 
163 
165 
167 
168 public:
170  inline void appendLod(double accuracy= 0.0)
171  {m_LodList.append(new GLC_Lod(accuracy));}
172 
174  void finishLod();
175 
177  void clear();
178 
180  void copyVboToClientSide();
181 
183  void releaseVboClientSide(bool update= false);
184 
186  inline void trianglesAdded(int lod, int number)
187  {
188  if (lod != 0) lod-= 1;
189  else lod= m_LodList.size() - 1;
190  m_LodList.at(lod)->trianglesAdded(number);
191  }
192 
194  void setVboUsage(bool usage);
195 
197  inline void initPositionSize()
198  {m_PositionSize= m_Positions.size();}
199 
201 
203 
205 
206 public:
208  void createVBOs();
209 
211  bool useVBO(bool, GLC_MeshData::VboType);
212 
214  inline void useIBO(bool use, const int currentLod= 0)
215  {
216  if (use) m_LodList.at(currentLod)->useIBO();
217  else QGLBuffer::release(QGLBuffer::IndexBuffer);
218  }
219 
221  void fillLodIbo();
222 
224  void fillVbo(GLC_MeshData::VboType vboType);
225 
227 
229 // Private members
231 private:
232 
234  QGLBuffer m_VertexBuffer;
235 
238 
241 
244 
247 
249  QGLBuffer m_NormalBuffer;
250 
252  QGLBuffer m_TexelBuffer;
253 
255  QGLBuffer m_ColorBuffer;
256 
258  QList<GLC_Lod*> m_LodList;
259 
262 
265 
268 
270  bool m_UseVbo;
271 
273  static quint32 m_ChunkId;
274 };
275 
277 GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
278 GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
279 
280 #endif /* GLC_MESHDATA_H_ */

©2005-2013 Laurent Ribon