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 #include <QGLBuffer>
00030 
00031 #include "glc_lod.h"
00032 #include "../glc_global.h"
00033 
00034 #include "../glc_config.h"
00035 
00036 
00039 
00041 
00042 class GLC_LIB_EXPORT GLC_MeshData
00043 {
00044         friend GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
00045         friend GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
00046 
00047 public:
00048 
00050         enum VboType
00051         {
00052                 GLC_Vertex= 30,
00053                 GLC_Normal,
00054                 GLC_Texel,
00055                 GLC_Color
00056         };
00057 
00059 
00061 
00062 public:
00064         GLC_MeshData();
00065 
00067         GLC_MeshData(const GLC_MeshData&);
00068 
00070         GLC_MeshData& operator=(const GLC_MeshData&);
00071 
00073         virtual ~GLC_MeshData();
00075 
00077 
00079 
00080 public:
00082         static quint32 chunckID();
00083 
00085         inline int lodCount() const
00086         {return m_LodList.size();}
00087 
00089         GLfloatVector positionVector() const;
00090 
00092         GLfloatVector normalVector() const;
00093 
00095         GLfloatVector texelVector() const;
00096 
00098         GLfloatVector colorVector() const;
00099 
00101         inline GLfloatVector* positionVectorHandle()
00102         { return &m_Positions;}
00103 
00105         inline GLfloatVector* normalVectorHandle()
00106         { return &m_Normals;}
00107 
00109         inline GLfloatVector* texelVectorHandle()
00110         { return &m_Texels;}
00111 
00113         inline GLfloatVector* colorVectorHandle()
00114         { return &m_Colors;}
00115 
00117         inline GLuintVector indexVector(const int i= 0) const
00118         {
00119                 Q_ASSERT(i < m_LodList.size());
00120                 return m_LodList.at(i)->indexVector();
00121         }
00122 
00124         inline GLuintVector* indexVectorHandle(const int i= 0) const
00125         {
00126                 Q_ASSERT(i < m_LodList.size());
00127                 return m_LodList.at(i)->indexVectorHandle();
00128         }
00129 
00131         inline int indexVectorSize(const int i= 0) const
00132         {
00133                 Q_ASSERT(i < m_LodList.size());
00134                 return m_LodList.at(i)->indexVectorSize();
00135         }
00137         inline GLC_Lod* getLod(int index) const
00138         {
00139                 return m_LodList.value(index);
00140         }
00141 
00143         inline bool isEmpty() const
00144         {return (1 > m_PositionSize) && (0 == m_Positions.size());}
00145 
00147         inline unsigned int trianglesCount(int lod) const
00148         {
00149                 Q_ASSERT(lod < m_LodList.size());
00150                 return m_LodList.at(lod)->trianglesCount();
00151         }
00152 
00154         inline bool positionSizeIsSet() const
00155         {return m_PositionSize != -1;}
00156 
00158 
00160 
00162 
00163 public:
00165         inline void appendLod(double accuracy= 0.0)
00166         {m_LodList.append(new GLC_Lod(accuracy));}
00167 
00169         void finishLod();
00170 
00172         void clear();
00173 
00175         void copyVboToClientSide();
00176 
00178         void releaseVboClientSide(bool update= false);
00179 
00181         inline void trianglesAdded(int lod, int number)
00182         {
00183                 if (lod != 0) lod-= 1;
00184                 else lod= m_LodList.size() - 1;
00185                 m_LodList.at(lod)->trianglesAdded(number);
00186         }
00187 
00189         void setVboUsage(bool usage);
00190 
00192         inline void initPositionSize()
00193         {m_PositionSize= m_Positions.size();}
00194 
00196 
00198 
00200 
00201 public:
00203         void createVBOs();
00204 
00206         bool useVBO(bool, GLC_MeshData::VboType);
00207 
00209         inline void useIBO(bool use, const int currentLod= 0)
00210         {
00211                 if (use) m_LodList.at(currentLod)->useIBO();
00212                 else QGLBuffer::release(QGLBuffer::IndexBuffer);
00213         }
00214 
00216         void fillLodIbo();
00217 
00219         void fillVbo(GLC_MeshData::VboType vboType);
00220 
00222 
00224 // Private members
00226 private:
00227 
00229         QGLBuffer m_VertexBuffer;
00230 
00232         GLfloatVector m_Positions;
00233 
00235         GLfloatVector m_Normals;
00236 
00238         GLfloatVector m_Texels;
00239 
00241         GLfloatVector m_Colors;
00242 
00244         QGLBuffer m_NormalBuffer;
00245 
00247         QGLBuffer m_TexelBuffer;
00248 
00250         QGLBuffer m_ColorBuffer;
00251 
00253         QList<GLC_Lod*> m_LodList;
00254 
00256         int m_PositionSize;
00257 
00259         int m_TexelsSize;
00260 
00262         int m_ColorSize;
00263 
00265         bool m_UseVbo;
00266 
00268         static quint32 m_ChunkId;
00269 };
00270 
00272 GLC_LIB_EXPORT QDataStream &operator<<(QDataStream &, const GLC_MeshData &);
00273 GLC_LIB_EXPORT QDataStream &operator>>(QDataStream &, GLC_MeshData &);
00274 
00275 #endif /* GLC_MESHDATA_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon