glc_meshdata.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_MESHDATA_H_
00026 #define GLC_MESHDATA_H_
00027 
00028 #include <QVector>
00029 
00030 #include "glc_lod.h"
00031 #include "../glc_global.h"
00032 
00033 #include "../glc_config.h"
00034 
00035 
00038 
00040 
00041 class GLC_LIB_EXPORT GLC_MeshData
00042 {
00043         friend GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
00044         friend GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
00045 
00046 public:
00047 
00049         enum VboType
00050         {
00051                 GLC_Vertex= 30,
00052                 GLC_Normal,
00053                 GLC_Texel,
00054                 GLC_Color
00055         };
00056 
00058 
00060 
00061 public:
00063         GLC_MeshData();
00064 
00066         GLC_MeshData(const GLC_MeshData&);
00067 
00069         GLC_MeshData& operator=(const GLC_MeshData&);
00070 
00072         virtual ~GLC_MeshData();
00074 
00076 
00078 
00079 public:
00081         static quint32 chunckID();
00082 
00084         inline int lodCount() const
00085         {return m_LodList.size();}
00086 
00088         GLfloatVector positionVector() const;
00089 
00091         GLfloatVector normalVector() const;
00092 
00094         GLfloatVector texelVector() const;
00095 
00097         GLfloatVector colorVector() const;
00098 
00100         inline GLfloatVector* positionVectorHandle()
00101         { return &m_Positions;}
00102 
00104         inline GLfloatVector* normalVectorHandle()
00105         { return &m_Normals;}
00106 
00108         inline GLfloatVector* texelVectorHandle()
00109         { return &m_Texels;}
00110 
00112         inline GLfloatVector* colorVectorHandle()
00113         { return &m_Colors;}
00114 
00116         inline GLuintVector indexVector(const int i= 0) const
00117         {
00118                 Q_ASSERT(i < m_LodList.size());
00119                 return m_LodList.at(i)->indexVector();
00120         }
00121 
00123         inline GLuintVector* indexVectorHandle(const int i= 0) const
00124         {
00125                 Q_ASSERT(i < m_LodList.size());
00126                 return m_LodList.at(i)->indexVectorHandle();
00127         }
00128 
00130         inline int indexVectorSize(const int i= 0) const
00131         {
00132                 Q_ASSERT(i < m_LodList.size());
00133                 return m_LodList.at(i)->indexVectorSize();
00134         }
00136         inline GLC_Lod* getLod(int index) const
00137         {
00138                 return m_LodList.value(index);
00139         }
00140 
00142         inline bool isEmpty() const
00143         {return (0 == m_PositionSize) && (0 == m_Positions.size());}
00144 
00146         inline unsigned int trianglesCount(int lod) const
00147         {
00148                 Q_ASSERT(lod < m_LodList.size());
00149                 return m_LodList.at(lod)->trianglesCount();
00150         }
00151 
00153 
00155 
00157 
00158 public:
00160         inline void appendLod(double accuracy= 0.0)
00161         {m_LodList.append(new GLC_Lod(accuracy));}
00162 
00164         void finishVbo();
00165 
00167         void finishLod();
00168 
00170         void clear();
00171 
00173         void copyVboToClientSide();
00174 
00176         void releaseVboClientSide(bool update= false);
00177 
00179         inline void trianglesAdded(int lod, int number)
00180         {
00181                 if (lod != 0) lod-= 1;
00182                 else lod= m_LodList.size() - 1;
00183                 m_LodList.at(lod)->trianglesAdded(number);
00184         }
00185 
00187 
00189 
00191 
00192 public:
00194         void createVBOs();
00195 
00197         bool useVBO(bool, GLC_MeshData::VboType) const;
00198 
00200         inline void useIBO(bool use, const int currentLod= 0)
00201         {
00202                 if (use) m_LodList.at(currentLod)->useIBO();
00203                 else glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
00204         }
00205 
00207         void fillVbo(GLC_MeshData::VboType vboType);
00208 
00210 
00212 // Private members
00214 private:
00215 
00217         GLuint m_VboId;
00218 
00220         GLfloatVector m_Positions;
00221 
00223         GLfloatVector m_Normals;
00224 
00226         GLfloatVector m_Texels;
00227 
00229         GLfloatVector m_Colors;
00230 
00232         GLuint m_NormalVboId;
00233 
00235         GLuint m_TexelVboId;
00236 
00238         GLuint m_ColorVboId;
00239 
00241         QList<GLC_Lod*> m_LodList;
00242 
00244         int m_PositionSize;
00245 
00247         int m_TexelsSize;
00248 
00250         int m_ColorSize;
00251 
00253         static quint32 m_ChunkId;
00254 };
00255 
00257 GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
00258 GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
00259 
00260 #endif /* GLC_MESHDATA_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon