simplemesh.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2007
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
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         // Add a vertex (if new) or return the existing
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;    // every 3 indices is a tri.
00109         U32      nTri;          // always nIndex/3
00110         U32  nVertex;   // tris are made of vertices
00111         U32      vbo;
00112 
00113         // Used when the MeshObject is set up, and then deleted.
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

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1