00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SIMPLEMESH_INCLUDED
00024 #define SIMPLEMESH_INCLUDED
00025
00026 #include "../grinliz/gldebug.h"
00027 #include "../grinliz/glvector.h"
00028 #include "../grinliz/glcontainer.h"
00029
00030 #include "lilith3dgl.h"
00031
00032 #include <vector>
00033
00034 namespace lilith3d {
00035
00036 class Texture;
00037 class Tri;
00038
00039 class SimpleMesh
00040 {
00041 public:
00042
00043 SimpleMesh( const Texture* tex, bool smooth ) :
00044 texture( tex ),
00045 smoothing( smooth ),
00046 nIndex( 0 ),
00047 nTri( 0 ),
00048 nVertex( 0 ),
00049 vbo( 0 ),
00050 flatVertexSet( 0 ), smoothVertexSet( 0 ), triAtVertex( 0 ),
00051 index( 0 ), tri( 0 ), vertex( 0 )
00052 {}
00053
00054 ~SimpleMesh();
00055
00056 const Texture* GetTexture() const { return texture; }
00057
00058 const U16* PIndex() const { return index; }
00059 const Tri* PTri() const { return tri; }
00060 const Vertex* PVertex() const { return vertex; }
00061
00062 const Vertex& GetVertex( unsigned i ) const { GLASSERT( i>=0 && i<nVertex );
00063 return vertex[i]; }
00064 const Tri& GetTri( unsigned i ) const;
00065
00066
00067 U32 NIndex() const { GLASSERT( nIndex % 3 == 0 );
00068 GLASSERT( nIndex / 3 == nTri );
00069 return nIndex; }
00070 U32 NTri() const { GLASSERT( nIndex % 3 == 0 );
00071 GLASSERT( nIndex / 3 == nTri );
00072 return nTri; }
00073 U32 NVertex() const { return nVertex; }
00074
00075 const std::vector< int >& TriAtVertex( int vIndex ) const
00076 {
00077 GLASSERT( vIndex >= 0 && vIndex < (int)nVertex );
00078 GLASSERT( triAtVertex );
00079 GLASSERT( triAtVertex->size() == nVertex );
00080 return (*triAtVertex)[vIndex];
00081 }
00082
00083 void Validate() const;
00084
00085
00086 void AddVertex( const Vertex& vertex );
00087 void InitImport();
00088 void EndImport();
00089 void ConnectTri();
00090 void FreeImport();
00091
00092 void GenerateVBO();
00093 bool HasVBO() const;
00094 void BindVBO() const;
00095
00096 private:
00097 void AllocateMax();
00098 void Trim();
00099 void NormalizeVertices();
00100 void FreeMem();
00101
00102 SimpleMesh( const SimpleMesh& rhs );
00103 void operator=( const SimpleMesh& rhs );
00104
00105 const Texture* texture;
00106 bool smoothing;
00107
00108 U32 nIndex;
00109 U32 nTri;
00110 U32 nVertex;
00111 U32 vbo;
00112
00113
00114 grinliz::PtrHashTable< Vertex, VertexEqual > *flatVertexSet;
00115 grinliz::PtrHashTable< Vertex, VertexEqualWONormal > *smoothVertexSet;
00116 std::vector< std::vector<int> > *triAtVertex;
00117
00118 U16* index;
00119 Tri* tri;
00120 Vertex* vertex;
00121
00122 };
00123 };
00124
00125 #endif