glc_mesh.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_MESH_H_
00026 #define GLC_MESH_H_
00027 
00028 #include <QHash>
00029 #include <QList>
00030 #include "../maths/glc_vector2df.h"
00031 #include "../maths/glc_vector3df.h"
00032 #include "../glc_global.h"
00033 #include "../shading/glc_material.h"
00034 #include "glc_meshdata.h"
00035 #include "glc_geometry.h"
00036 #include "glc_primitivegroup.h"
00037 #include "../glc_state.h"
00038 #include "../shading/glc_selectionmaterial.h"
00039 
00040 #include "../glc_config.h"
00041 
00044 
00048 
00049 class GLC_LIB_EXPORT GLC_Mesh : public GLC_Geometry
00050 {
00051         friend QDataStream &operator<<(QDataStream &, const GLC_Mesh &);
00052         friend QDataStream &operator>>(QDataStream &, GLC_Mesh &);
00053 
00054 public:
00055         typedef QHash<GLC_uint, GLC_PrimitiveGroup*> LodPrimitiveGroups;
00056         typedef QHash<const int, LodPrimitiveGroups*> PrimitiveGroupsHash;
00057 
00059 
00061 
00062 public:
00064         GLC_Mesh();
00065 
00067         GLC_Mesh(const GLC_Mesh&);
00068 
00070         GLC_Mesh& operator=(const GLC_Mesh&);
00071 
00073         virtual ~GLC_Mesh();
00075 
00076 
00078 
00079 public:
00081         static quint32 chunckID();
00082 
00084         virtual unsigned int faceCount(int lod) const;
00085 
00087         virtual unsigned int VertexCount() const;
00088 
00090         inline unsigned int numberOfNormals() const
00091         { return m_NumberOfNormals;}
00092 
00094         virtual const GLC_BoundingBox& boundingBox(void);
00095 
00097         virtual GLC_Geometry* clone() const;
00098 
00100         inline bool ColorPearVertexIsAcivated() const
00101         {return m_ColorPearVertex;}
00102 
00104         inline int lodCount() const
00105         {return m_MeshData.lodCount();}
00106 
00108         inline GLfloatVector positionVector() const
00109         {return m_MeshData.positionVector();}
00110 
00112         inline GLfloatVector normalVector() const
00113         {return m_MeshData.normalVector();}
00114 
00116         inline GLfloatVector texelVector() const
00117         {return m_MeshData.texelVector();}
00118 
00120         bool containsTriangles(int lod, GLC_uint materialId) const;
00121 
00123 
00124         QVector<GLuint> getTrianglesIndex(int lod, GLC_uint materialId) const;
00125 
00127         int numberOfTriangles(int lod, GLC_uint materialId) const;
00128 
00130         bool containsStrips(int lod, GLC_uint materialId) const;
00131 
00133 
00134         QList<QVector<GLuint> > getStripsIndex(int lod, GLC_uint materialId) const;
00135 
00137         int numberOfStrips(int lod, GLC_uint materialId) const;
00138 
00140         bool containsFans(int lod, GLC_uint materialId) const;
00141 
00143 
00144         QList<QVector<GLuint> > getFansIndex(int lod, GLC_uint materialId) const;
00145 
00147         int numberOfFans(int lod, GLC_uint materialId) const;
00148 
00150         inline bool containsLod(int lod) const
00151         {return (NULL != m_MeshData.getLod(lod));}
00152 
00154         inline bool lodContainsMaterial(int lod, GLC_uint materialId) const
00155         {
00156                 if (!m_PrimitiveGroups.contains(lod))return false;
00157                 else return m_PrimitiveGroups.value(lod)->contains(materialId);
00158         }
00159 
00161 
00162         inline double getLodAccuracy(int lod) const
00163         {
00164                 Q_ASSERT(containsLod(lod));
00165                 return m_MeshData.getLod(lod)->accuracy();
00166         }
00167 
00169         inline GLC_uint nextPrimitiveLocalId() const
00170         {return m_NextPrimitiveLocalId;}
00171 
00173         inline bool isEmpty() const
00174         {return m_MeshData.isEmpty();}
00175 
00177         inline QColor wireColor() const
00178         {return m_WireColor;}
00179 
00181         GLC_Mesh* createMeshOfGivenLod(int lodIndex);
00182 
00184         GLC_Mesh* createMeshFromGivenLod(int lodIndex);
00185 
00187         GLC_Mesh& transformVertice(const GLC_Matrix4x4& matrix);
00188 
00190         virtual double volume();
00191 
00193 
00194 
00196 
00197 public:
00198 
00200         virtual void clear();
00201 
00203         void clearMeshWireAndBoundingBox();
00204 
00206         inline void addVertice(const GLfloatVector& vertices)
00207         {
00208                 *(m_MeshData.positionVectorHandle())+= vertices;
00209                 m_NumberOfVertice+= vertices.size() / 3;
00210         }
00211 
00213         inline void addNormals(const GLfloatVector& normals)
00214         {
00215                 *(m_MeshData.normalVectorHandle())+= normals;
00216                 m_NumberOfNormals+= normals.size() / 3;
00217         }
00218 
00220         inline void addTexels(const GLfloatVector& texels)
00221         {*(m_MeshData.texelVectorHandle())+= texels;}
00222 
00224         inline void addColors(const GLfloatVector& colors)
00225         {*(m_MeshData.colorVectorHandle())+= colors;}
00226 
00228         GLC_uint addTriangles(GLC_Material*, const IndexList&, const int lod= 0, double accuracy= 0.0);
00229 
00231         GLC_uint addTrianglesStrip(GLC_Material*, const IndexList&, const int lod= 0, double accuracy= 0.0);
00232 
00234         GLC_uint addTrianglesFan(GLC_Material*, const IndexList&, const int lod= 0, double accuracy= 0.0);
00235 
00237         void reverseNormals();
00238 
00240         inline void setColorPearVertex(bool flag)
00241         {m_ColorPearVertex= flag;}
00242 
00244         void finish();
00245 
00247         virtual void setCurrentLod(const int);
00248 
00250         virtual void replaceMasterMaterial(GLC_Material*);
00251 
00253         void replaceMaterial(const GLC_uint, GLC_Material*);
00254 
00256         inline void setNextPrimitiveLocalId(GLC_uint id)
00257         {m_NextPrimitiveLocalId= id;}
00258 
00260         inline void setWireColor(const QColor& color)
00261         {m_WireColor= color;}
00262 
00264         virtual void copyVboToClientSide();
00265 
00267         virtual void releaseVboClientSide(bool update);
00268 
00270         virtual void setVboUsage(bool usage);
00271 
00273 
00275 
00277 
00278 public:
00280 
00284         void loadFromDataStream(QDataStream&, const MaterialHash&, const QHash<GLC_uint, GLC_uint>&);
00285 
00287         void saveToDataStream(QDataStream&) const;
00288 
00290 
00291 
00293 
00294 protected:
00295 
00297 
00298         virtual void glDraw(const GLC_RenderProperties&);
00299 
00301 
00303 
00305 
00306 private:
00308         GLC_uint setCurrentMaterial(GLC_Material*, const int, double);
00309 
00311         void fillVbosAndIbos();
00312 
00314         void finishSerialized();
00315 
00317         //void finishVbo();
00318 
00320         void moveIndexToMeshDataLod();
00321 
00323         inline void vboDrawPrimitivesOf(GLC_PrimitiveGroup*);
00324 
00326         inline void vertexArrayDrawPrimitivesOf(GLC_PrimitiveGroup*);
00327 
00329         inline void vboDrawInSelectionModePrimitivesOf(GLC_PrimitiveGroup*);
00330 
00332         inline void vertexArrayDrawInSelectionModePrimitivesOf(GLC_PrimitiveGroup*);
00333 
00335         inline void vboDrawPrimitivesGroupOf(GLC_PrimitiveGroup*, GLC_Material*, bool, bool, QHash<GLC_uint, GLC_Material*>*);
00336 
00338         inline void vertexArrayDrawPrimitivesGroupOf(GLC_PrimitiveGroup*, GLC_Material*, bool, bool, QHash<GLC_uint, GLC_Material*>*);
00339 
00341         inline void vboDrawSelectedPrimitivesGroupOf(GLC_PrimitiveGroup*, GLC_Material*, bool, bool, const GLC_RenderProperties&);
00342 
00344         inline void vertexArrayDrawSelectedPrimitivesGroupOf(GLC_PrimitiveGroup*, GLC_Material*, bool, bool, const GLC_RenderProperties&);
00345 
00347         inline void activateVboAndIbo();
00348 
00350         inline void activateVertexArray();
00351 
00353         void normalRenderLoop(const GLC_RenderProperties&, bool);
00354 
00356         void OverwriteMaterialRenderLoop(const GLC_RenderProperties&, bool);
00357 
00359         void OverwriteTransparencyRenderLoop(const GLC_RenderProperties&, bool);
00360 
00362         void OverwriteTransparencyAndMaterialRenderLoop(const GLC_RenderProperties&, bool);
00363 
00365         void bodySelectionRenderLoop(bool);
00366 
00368         void primitiveSelectionRenderLoop(bool);
00369 
00371         void primitiveRenderLoop(const GLC_RenderProperties&, bool);
00372 
00374         void primitiveSelectedRenderLoop(const GLC_RenderProperties&, bool);
00375 
00377         void copyIndex(int lod, GLC_Mesh* pLodMesh, QHash<GLuint, GLuint>& sourceToTargetIndexMap, QHash<GLuint, GLuint>& tagetToSourceIndexMap, int& maxIndex, int targetLod);
00378 
00380         void copyBulkData(GLC_Mesh* pLodMesh, const QHash<GLuint, GLuint>& tagetToSourceIndexMap, int maxIndex);
00381 
00383         IndexList equivalentTrianglesIndexOfstripsIndex(int lodIndex, GLC_uint materialId);
00384 
00386         IndexList equivalentTrianglesIndexOfFansIndex(int lodIndex, GLC_uint materialId);
00387 
00388 
00390 
00391 
00393 // Private members
00395 private:
00397         GLC_uint m_NextPrimitiveLocalId;
00398 
00400         PrimitiveGroupsHash m_PrimitiveGroups;
00401 
00403         GLC_uint m_DefaultMaterialId;
00404 
00406         unsigned int m_NumberOfVertice;
00407 
00409         unsigned int m_NumberOfNormals;
00410 
00412         bool m_ColorPearVertex;
00413 
00415         GLC_MeshData m_MeshData;
00416 
00418         int m_CurrentLod;
00419 
00421         static quint32 m_ChunkId;
00422 
00423 };
00424 
00425 // Inline functions
00426 
00427 // Use VBO to Draw triangles from the specified GLC_PrimitiveGroup
00428 void GLC_Mesh::vboDrawPrimitivesOf(GLC_PrimitiveGroup* pCurrentGroup)
00429 {
00430         // Draw triangles
00431         if (pCurrentGroup->containsTriangles())
00432         {
00433                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSize(), GL_UNSIGNED_INT, pCurrentGroup->trianglesIndexOffset());
00434         }
00435 
00436         // Draw Triangles strip
00437         if (pCurrentGroup->containsStrip())
00438         {
00439                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffset().size());
00440                 for (GLint i= 0; i < stripsCount; ++i)
00441                 {
00442                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00443                 }
00444         }
00445 
00446         // Draw Triangles fan
00447         if (pCurrentGroup->containsFan())
00448         {
00449                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffset().size());
00450                 for (GLint i= 0; i < fansCount; ++i)
00451                 {
00452                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00453                 }
00454         }
00455 }
00456 // Use Vertex Array to Draw triangles from the specified GLC_PrimitiveGroup
00457 void GLC_Mesh::vertexArrayDrawPrimitivesOf(GLC_PrimitiveGroup* pCurrentGroup)
00458 {
00459         // Draw triangles
00460         if (pCurrentGroup->containsTriangles())
00461         {
00462                 GLvoid* pOffset= &(m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesIndexOffseti()]);
00463                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSize(), GL_UNSIGNED_INT, pOffset);
00464         }
00465 
00466         // Draw Triangles strip
00467         if (pCurrentGroup->containsStrip())
00468         {
00469                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffseti().size());
00470                 for (GLint i= 0; i < stripsCount; ++i)
00471                 {
00472                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
00473                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
00474                 }
00475         }
00476 
00477         // Draw Triangles fan
00478         if (pCurrentGroup->containsFan())
00479         {
00480                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffseti().size());
00481                 for (GLint i= 0; i < fansCount; ++i)
00482                 {
00483                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
00484                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
00485                 }
00486         }
00487 }
00488 
00489 // Use VBO to Draw primitives in selection mode from the specified GLC_PrimitiveGroup
00490 void GLC_Mesh::vboDrawInSelectionModePrimitivesOf(GLC_PrimitiveGroup* pCurrentGroup)
00491 {
00492         GLubyte colorId[4];
00493         // Draw triangles
00494         if (pCurrentGroup->containsTrianglesGroupId())
00495         {
00496                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffset().size());
00497                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00498                 {
00499                         glc::encodeRgbId(pCurrentGroup->triangleGroupId(i), colorId);
00500                         glColor3ubv(colorId);
00501                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->trianglesGroupOffset().at(i));
00502                 }
00503         }
00504 
00505         // Draw Triangles strip
00506         if (pCurrentGroup->containsStripGroupId())
00507         {
00508                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffset().size());
00509                 for (GLint i= 0; i < stripsCount; ++i)
00510                 {
00511                         glc::encodeRgbId(pCurrentGroup->stripGroupId(i), colorId);
00512                         glColor3ubv(colorId);
00513                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00514                 }
00515         }
00516 
00517         // Draw Triangles fan
00518         if (pCurrentGroup->containsFanGroupId())
00519         {
00520                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffset().size());
00521                 for (GLint i= 0; i < fansCount; ++i)
00522                 {
00523                         glc::encodeRgbId(pCurrentGroup->fanGroupId(i), colorId);
00524                         glColor3ubv(colorId);
00525 
00526                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00527                 }
00528         }
00529 
00530 }
00531 
00532 // Use Vertex Array to Draw primitives in selection mode from the specified GLC_PrimitiveGroup
00533 void GLC_Mesh::vertexArrayDrawInSelectionModePrimitivesOf(GLC_PrimitiveGroup* pCurrentGroup)
00534 {
00535         GLubyte colorId[4];
00536         // Draw triangles
00537         if (pCurrentGroup->containsTrianglesGroupId())
00538         {
00539                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffseti().size());
00540                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00541                 {
00542                         glc::encodeRgbId(pCurrentGroup->triangleGroupId(i), colorId);
00543                         glColor3ubv(colorId);
00544 
00545                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesGroupOffseti().at(i)];
00546                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pOffset);
00547                 }
00548 
00549                 GLvoid* pOffset= &(m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesIndexOffseti()]);
00550                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSize(), GL_UNSIGNED_INT, pOffset);
00551         }
00552 
00553         // Draw Triangles strip
00554         if (pCurrentGroup->containsStripGroupId())
00555         {
00556                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffseti().size());
00557                 for (GLint i= 0; i < stripsCount; ++i)
00558                 {
00559                         glc::encodeRgbId(pCurrentGroup->stripGroupId(i), colorId);
00560                         glColor3ubv(colorId);
00561 
00562                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
00563                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
00564                 }
00565         }
00566 
00567         // Draw Triangles fan
00568         if (pCurrentGroup->containsFanGroupId())
00569         {
00570                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffseti().size());
00571                 for (GLint i= 0; i < fansCount; ++i)
00572                 {
00573                         glc::encodeRgbId(pCurrentGroup->fanGroupId(i), colorId);
00574                         glColor3ubv(colorId);
00575 
00576                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
00577                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
00578                 }
00579         }
00580 }
00581 
00582 // Use VBO to Draw primitives with specific materials from the specified GLC_PrimitiveGroup
00583 void GLC_Mesh::vboDrawPrimitivesGroupOf(GLC_PrimitiveGroup* pCurrentGroup, GLC_Material* pCurrentMaterial, bool materialIsRenderable
00584                 , bool isTransparent,  QHash<GLC_uint, GLC_Material*>* pMaterialHash)
00585 {
00586         GLC_Material* pCurrentLocalMaterial= pCurrentMaterial;
00587         // Draw triangles
00588         if (pCurrentGroup->containsTriangles())
00589         {
00590                 Q_ASSERT(pCurrentGroup->containsTrianglesGroupId());
00591                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffset().size());
00592                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00593                 {
00594                         GLC_uint currentPrimitiveId= pCurrentGroup->triangleGroupId(i);
00595                         if (pMaterialHash->contains(currentPrimitiveId))
00596                         {
00597                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00598                                 {
00599                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00600                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00601                                 }
00602                         }
00603                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00604                         {
00605                                 pCurrentLocalMaterial= pCurrentMaterial;
00606                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00607                         }
00608                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00609                         {
00610                                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->trianglesGroupOffset().at(i));
00611                         }
00612                 }
00613         }
00614 
00615         // Draw Triangles strip
00616         if (pCurrentGroup->containsStrip())
00617         {
00618                 Q_ASSERT(pCurrentGroup->containsStripGroupId());
00619                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffset().size());
00620                 for (GLint i= 0; i < stripsCount; ++i)
00621                 {
00622                         GLC_uint currentPrimitiveId= pCurrentGroup->stripGroupId(i);
00623                         if (pMaterialHash->contains(currentPrimitiveId))
00624                         {
00625                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00626                                 {
00627                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00628                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00629                                 }
00630                         }
00631                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00632                         {
00633                                 pCurrentLocalMaterial= pCurrentMaterial;
00634                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00635                         }
00636                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00637                         {
00638                                 glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00639                         }
00640                 }
00641         }
00642 
00643         // Draw Triangles fan
00644         if (pCurrentGroup->containsFan())
00645         {
00646                 Q_ASSERT(pCurrentGroup->containsFanGroupId());
00647                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffset().size());
00648                 for (GLint i= 0; i < fansCount; ++i)
00649                 {
00650                         GLC_uint currentPrimitiveId= pCurrentGroup->fanGroupId(i);
00651                         if (pMaterialHash->contains(currentPrimitiveId))
00652                         {
00653                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00654                                 {
00655                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00656                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00657                                 }
00658                         }
00659                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00660                         {
00661                                 pCurrentLocalMaterial= pCurrentMaterial;
00662                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00663                         }
00664                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00665                         {
00666                                 glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00667                         }
00668                 }
00669         }
00670 
00671 }
00672 
00673 // Use Vertex Array to Draw primitives with specific materials from the specified GLC_PrimitiveGroup
00674 void GLC_Mesh::vertexArrayDrawPrimitivesGroupOf(GLC_PrimitiveGroup* pCurrentGroup, GLC_Material* pCurrentMaterial, bool materialIsRenderable
00675                 , bool isTransparent, QHash<GLC_uint, GLC_Material*>* pMaterialHash)
00676 {
00677         GLC_Material* pCurrentLocalMaterial= pCurrentMaterial;
00678         // Draw triangles
00679         if (pCurrentGroup->containsTriangles())
00680         {
00681                 Q_ASSERT(pCurrentGroup->containsTrianglesGroupId());
00682                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffseti().size());
00683                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00684                 {
00685                         GLC_uint currentPrimitiveId= pCurrentGroup->triangleGroupId(i);
00686                         if (pMaterialHash->contains(currentPrimitiveId))
00687                         {
00688                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00689                                 {
00690                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00691                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00692                                 }
00693                         }
00694                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00695                         {
00696                                 pCurrentLocalMaterial= pCurrentMaterial;
00697                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00698                         }
00699                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00700                         {
00701                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesGroupOffseti().at(i)];
00702                                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pOffset);
00703                         }
00704                 }
00705         }
00706 
00707         // Draw Triangles strip
00708         if (pCurrentGroup->containsStrip())
00709         {
00710                 Q_ASSERT(pCurrentGroup->containsStripGroupId());
00711                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffseti().size());
00712                 for (GLint i= 0; i < stripsCount; ++i)
00713                 {
00714                         GLC_uint currentPrimitiveId= pCurrentGroup->stripGroupId(i);
00715                         if (pMaterialHash->contains(currentPrimitiveId))
00716                         {
00717                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00718                                 {
00719                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00720                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00721                                 }
00722                         }
00723                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00724                         {
00725                                 pCurrentLocalMaterial= pCurrentMaterial;
00726                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00727                         }
00728                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00729                         {
00730                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
00731                                 glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
00732                         }
00733                 }
00734         }
00735 
00736         // Draw Triangles fan
00737         if (pCurrentGroup->containsFan())
00738         {
00739                 Q_ASSERT(pCurrentGroup->containsFanGroupId());
00740                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffseti().size());
00741                 for (GLint i= 0; i < fansCount; ++i)
00742                 {
00743                         GLC_uint currentPrimitiveId= pCurrentGroup->fanGroupId(i);
00744                         if (pMaterialHash->contains(currentPrimitiveId))
00745                         {
00746                                 if (pCurrentLocalMaterial != pMaterialHash->value(currentPrimitiveId))
00747                                 {
00748                                         pCurrentLocalMaterial= pMaterialHash->value(currentPrimitiveId);
00749                                         if (pCurrentLocalMaterial->isTransparent() == isTransparent) pCurrentLocalMaterial->glExecute();
00750                                 }
00751                         }
00752                         else if (pCurrentLocalMaterial != pCurrentMaterial)
00753                         {
00754                                 pCurrentLocalMaterial= pCurrentMaterial;
00755                                 if (materialIsRenderable) pCurrentLocalMaterial->glExecute();
00756                         }
00757                         if (pCurrentLocalMaterial->isTransparent() == isTransparent)
00758                         {
00759                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
00760                                 glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
00761                         }
00762                 }
00763         }
00764 
00765 }
00766 
00767 // Use VBO to Draw primitives with specific materials from the specified GLC_PrimitiveGroup
00768 void GLC_Mesh::vboDrawSelectedPrimitivesGroupOf(GLC_PrimitiveGroup* pCurrentGroup, GLC_Material* pCurrentMaterial, bool materialIsRenderable
00769                 , bool isTransparent, const GLC_RenderProperties& renderProperties)
00770 {
00771         QSet<GLC_uint>* pSelectedPrimitive= renderProperties.setOfSelectedPrimitivesId();
00772         Q_ASSERT(NULL != pSelectedPrimitive);
00773 
00774         QHash<GLC_uint, GLC_Material*>* pMaterialHash= NULL;
00775         if (!renderProperties.hashOfOverwritePrimitiveMaterialsIsEmpty())
00776         {
00777                 pMaterialHash= renderProperties.hashOfOverwritePrimitiveMaterials();
00778         }
00779 
00780         GLC_Material* pCurrentLocalMaterial= pCurrentMaterial;
00781         // Draw triangles
00782         if (pCurrentGroup->containsTriangles())
00783         {
00784                 Q_ASSERT(pCurrentGroup->containsTrianglesGroupId());
00785                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffset().size());
00786                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00787                 {
00788                         GLC_uint currentPrimitiveId= pCurrentGroup->triangleGroupId(i);
00789                         if (pSelectedPrimitive->contains(currentPrimitiveId))
00790                         {
00791                                 if (!isTransparent)
00792                                 {
00793                                         GLC_SelectionMaterial::glExecute();
00794                                         pCurrentLocalMaterial= NULL;
00795                                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->trianglesGroupOffset().at(i));
00796                                 }
00797                         }
00798                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
00799                         {
00800                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
00801                                 {
00802                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
00803                                         if (pMat != pCurrentLocalMaterial)
00804                                         {
00805                                                 pCurrentLocalMaterial= pMat;
00806                                                 pCurrentLocalMaterial->glExecute();
00807                                         }
00808                                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->trianglesGroupOffset().at(i));
00809                                 }
00810 
00811                         }
00812                         else if (materialIsRenderable)
00813                         {
00814                                 if (pCurrentLocalMaterial != pCurrentMaterial)
00815                                 {
00816                                         pCurrentLocalMaterial= pCurrentMaterial;
00817                                         pCurrentLocalMaterial->glExecute();
00818                                 }
00819                                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->trianglesGroupOffset().at(i));
00820                         }
00821                 }
00822         }
00823 
00824         // Draw Triangles strip
00825         if (pCurrentGroup->containsStrip())
00826         {
00827                 Q_ASSERT(pCurrentGroup->containsStripGroupId());
00828                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffset().size());
00829                 for (GLint i= 0; i < stripsCount; ++i)
00830                 {
00831                         GLC_uint currentPrimitiveId= pCurrentGroup->stripGroupId(i);
00832                         if (pSelectedPrimitive->contains(currentPrimitiveId))
00833                         {
00834                                 if (!isTransparent)
00835                                 {
00836                                         GLC_SelectionMaterial::glExecute();
00837                                         pCurrentLocalMaterial= NULL;
00838                                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00839                                 }
00840                         }
00841                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
00842                         {
00843                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
00844                                 {
00845                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
00846                                         if (pMat != pCurrentLocalMaterial)
00847                                         {
00848                                                 pCurrentLocalMaterial= pMat;
00849                                                 pCurrentLocalMaterial->glExecute();
00850                                         }
00851                                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00852                                 }
00853 
00854                         }
00855                         else if (materialIsRenderable)
00856                         {
00857                                 if (pCurrentLocalMaterial != pCurrentMaterial)
00858                                 {
00859                                         pCurrentLocalMaterial= pCurrentMaterial;
00860                                         pCurrentLocalMaterial->glExecute();
00861                                 }
00862                                 glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->stripsOffset().at(i));
00863                         }
00864                 }
00865         }
00866 
00867         // Draw Triangles fan
00868         if (pCurrentGroup->containsFan())
00869         {
00870                 Q_ASSERT(pCurrentGroup->containsFanGroupId());
00871                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffset().size());
00872                 for (GLint i= 0; i < fansCount; ++i)
00873                 {
00874                         GLC_uint currentPrimitiveId= pCurrentGroup->fanGroupId(i);
00875                         if (pSelectedPrimitive->contains(currentPrimitiveId))
00876                         {
00877                                 if (!isTransparent)
00878                                 {
00879                                         GLC_SelectionMaterial::glExecute();
00880                                         pCurrentLocalMaterial= NULL;
00881                                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00882                                 }
00883                         }
00884                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
00885                         {
00886                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
00887                                 {
00888                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
00889                                         if (pMat != pCurrentLocalMaterial)
00890                                         {
00891                                                 pCurrentLocalMaterial= pMat;
00892                                                 pCurrentLocalMaterial->glExecute();
00893                                         }
00894                                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00895                                 }
00896 
00897                         }
00898                         else if (materialIsRenderable)
00899                         {
00900                                 if (pCurrentLocalMaterial != pCurrentMaterial)
00901                                 {
00902                                         pCurrentLocalMaterial= pCurrentMaterial;
00903                                         pCurrentLocalMaterial->glExecute();
00904                                 }
00905                                 glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pCurrentGroup->fansOffset().at(i));
00906                         }
00907                 }
00908         }
00909 
00910 }
00911 
00912 // Use Vertex Array to Draw primitives with specific materials from the specified GLC_PrimitiveGroup
00913 void GLC_Mesh::vertexArrayDrawSelectedPrimitivesGroupOf(GLC_PrimitiveGroup* pCurrentGroup, GLC_Material* pCurrentMaterial, bool materialIsRenderable
00914                 , bool isTransparent, const GLC_RenderProperties& renderProperties)
00915 {
00916         QSet<GLC_uint>* pSelectedPrimitive= renderProperties.setOfSelectedPrimitivesId();
00917         Q_ASSERT(NULL != pSelectedPrimitive);
00918 
00919         QHash<GLC_uint, GLC_Material*>* pMaterialHash= NULL;
00920         if (!renderProperties.hashOfOverwritePrimitiveMaterialsIsEmpty())
00921         {
00922                 pMaterialHash= renderProperties.hashOfOverwritePrimitiveMaterials();
00923         }
00924 
00925         GLC_Material* pCurrentLocalMaterial= pCurrentMaterial;
00926         // Draw triangles
00927         if (pCurrentGroup->containsTriangles())
00928         {
00929                 Q_ASSERT(pCurrentGroup->containsTrianglesGroupId());
00930                 const GLsizei trianglesGroupCount= static_cast<GLsizei>(pCurrentGroup->trianglesGroupOffseti().size());
00931                 for (GLint i= 0; i < trianglesGroupCount; ++i)
00932                 {
00933                         GLC_uint currentPrimitiveId= pCurrentGroup->triangleGroupId(i);
00934                         if (pSelectedPrimitive->contains(currentPrimitiveId))
00935                         {
00936                                 if (!isTransparent)
00937                                 {
00938                                         GLC_SelectionMaterial::glExecute();
00939                                         pCurrentLocalMaterial= NULL;
00940                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesGroupOffseti().at(i)];
00941                                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pOffset);
00942                                 }
00943                         }
00944                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
00945                         {
00946                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
00947                                 {
00948                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
00949                                         if (pMat != pCurrentLocalMaterial)
00950                                         {
00951                                                 pCurrentLocalMaterial= pMat;
00952                                                 pCurrentLocalMaterial->glExecute();
00953                                         }
00954                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesGroupOffseti().at(i)];
00955                                         glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pOffset);
00956                                 }
00957 
00958                         }
00959                         else if (materialIsRenderable)
00960                         {
00961                                 if (pCurrentLocalMaterial != pCurrentMaterial)
00962                                 {
00963                                         pCurrentLocalMaterial= pCurrentMaterial;
00964                                         pCurrentLocalMaterial->glExecute();
00965                                 }
00966                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->trianglesGroupOffseti().at(i)];
00967                                 glDrawElements(GL_TRIANGLES, pCurrentGroup->trianglesIndexSizes().at(i), GL_UNSIGNED_INT, pOffset);
00968                         }
00969                 }
00970         }
00971 
00972         // Draw Triangles strip
00973         if (pCurrentGroup->containsStrip())
00974         {
00975                 Q_ASSERT(pCurrentGroup->containsStripGroupId());
00976                 const GLsizei stripsCount= static_cast<GLsizei>(pCurrentGroup->stripsOffseti().size());
00977                 for (GLint i= 0; i < stripsCount; ++i)
00978                 {
00979                         GLC_uint currentPrimitiveId= pCurrentGroup->stripGroupId(i);
00980                         if (pSelectedPrimitive->contains(currentPrimitiveId))
00981                         {
00982                                 if (!isTransparent)
00983                                 {
00984                                         GLC_SelectionMaterial::glExecute();
00985                                         pCurrentLocalMaterial= NULL;
00986                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
00987                                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
00988                                 }
00989                         }
00990                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
00991                         {
00992                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
00993                                 {
00994                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
00995                                         if (pMat != pCurrentLocalMaterial)
00996                                         {
00997                                                 pCurrentLocalMaterial= pMat;
00998                                                 pCurrentLocalMaterial->glExecute();
00999                                         }
01000                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
01001                                         glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
01002                                 }
01003 
01004                         }
01005                         else if (materialIsRenderable)
01006                         {
01007                                 if (pCurrentLocalMaterial != pCurrentMaterial)
01008                                 {
01009                                         pCurrentLocalMaterial= pCurrentMaterial;
01010                                         pCurrentLocalMaterial->glExecute();
01011                                 }
01012                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->stripsOffseti().at(i)];
01013                                 glDrawElements(GL_TRIANGLE_STRIP, pCurrentGroup->stripsSizes().at(i), GL_UNSIGNED_INT, pOffset);
01014                         }
01015                 }
01016         }
01017 
01018         // Draw Triangles fan
01019         if (pCurrentGroup->containsFan())
01020         {
01021                 Q_ASSERT(pCurrentGroup->containsFanGroupId());
01022                 const GLsizei fansCount= static_cast<GLsizei>(pCurrentGroup->fansOffseti().size());
01023                 for (GLint i= 0; i < fansCount; ++i)
01024                 {
01025                         GLC_uint currentPrimitiveId= pCurrentGroup->fanGroupId(i);
01026                         if (pSelectedPrimitive->contains(currentPrimitiveId))
01027                         {
01028                                 if (!isTransparent)
01029                                 {
01030                                         GLC_SelectionMaterial::glExecute();
01031                                         pCurrentLocalMaterial= NULL;
01032                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
01033                                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
01034                                 }
01035                         }
01036                         else if ((NULL != pMaterialHash) && pMaterialHash->contains(currentPrimitiveId))
01037                         {
01038                                 if (pMaterialHash->value(currentPrimitiveId)->isTransparent() == isTransparent)
01039                                 {
01040                                         GLC_Material* pMat= pMaterialHash->value(currentPrimitiveId);
01041                                         if (pMat != pCurrentLocalMaterial)
01042                                         {
01043                                                 pCurrentLocalMaterial= pMat;
01044                                                 pCurrentLocalMaterial->glExecute();
01045                                         }
01046                                         GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
01047                                         glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
01048                                 }
01049 
01050                         }
01051                         else if (materialIsRenderable)
01052                         {
01053                                 if (pCurrentLocalMaterial != pCurrentMaterial)
01054                                 {
01055                                         pCurrentLocalMaterial= pCurrentMaterial;
01056                                         pCurrentLocalMaterial->glExecute();
01057                                 }
01058                                 GLvoid* pOffset= &m_MeshData.indexVectorHandle(m_CurrentLod)->data()[pCurrentGroup->fansOffseti().at(i)];
01059                                 glDrawElements(GL_TRIANGLE_FAN, pCurrentGroup->fansSizes().at(i), GL_UNSIGNED_INT, pOffset);
01060                         }
01061                 }
01062         }
01063 
01064 }
01065 
01066 // Activate mesh VBOs and IBO of the current LOD
01067 void GLC_Mesh::activateVboAndIbo()
01068 {
01069         // Activate Vertices VBO
01070         m_MeshData.useVBO(true, GLC_MeshData::GLC_Vertex);
01071         glVertexPointer(3, GL_FLOAT, 0, 0);
01072         glEnableClientState(GL_VERTEX_ARRAY);
01073 
01074         // Activate Normals VBO
01075         m_MeshData.useVBO(true, GLC_MeshData::GLC_Normal);
01076         glNormalPointer(GL_FLOAT, 0, 0);
01077         glEnableClientState(GL_NORMAL_ARRAY);
01078 
01079         // Activate texel VBO if needed
01080         if (m_MeshData.useVBO(true, GLC_MeshData::GLC_Texel))
01081         {
01082                 glTexCoordPointer(2, GL_FLOAT, 0, 0);
01083                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
01084         }
01085 
01086         // Activate Color VBO if needed
01087         if ((m_ColorPearVertex && !m_IsSelected && !GLC_State::isInSelectionMode()) && m_MeshData.useVBO(true, GLC_MeshData::GLC_Color))
01088         {
01089                 glEnable(GL_COLOR_MATERIAL);
01090                 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
01091                 glColorPointer(4, GL_FLOAT, 0, 0);
01092                 glEnableClientState(GL_COLOR_ARRAY);
01093         }
01094 
01095         m_MeshData.useIBO(true, m_CurrentLod);
01096 }
01097 
01098 // Activate vertex Array
01099 void GLC_Mesh::activateVertexArray()
01100 {
01101         // Use Vertex Array
01102         glVertexPointer(3, GL_FLOAT, 0, m_MeshData.positionVectorHandle()->data());
01103         glEnableClientState(GL_VERTEX_ARRAY);
01104 
01105         glNormalPointer(GL_FLOAT, 0, m_MeshData.normalVectorHandle()->data());
01106         glEnableClientState(GL_NORMAL_ARRAY);
01107 
01108         // Activate texel if needed
01109         if (!m_MeshData.texelVectorHandle()->isEmpty())
01110         {
01111                 glTexCoordPointer(2, GL_FLOAT, 0, m_MeshData.texelVectorHandle()->data());
01112                 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
01113         }
01114 
01115         // Activate Color array if needed
01116         if ((m_ColorPearVertex && !m_IsSelected && !GLC_State::isInSelectionMode()) && !m_MeshData.colorVectorHandle()->isEmpty())
01117         {
01118                 glEnable(GL_COLOR_MATERIAL);
01119                 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
01120                 glColorPointer(4, GL_FLOAT, 0, m_MeshData.colorVectorHandle()->data());
01121                 glEnableClientState(GL_COLOR_ARRAY);
01122         }
01123 }
01124 
01125 
01126 
01127 #endif /* GLC_MESH_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon