Commit 74b5881268df0a2f82f36066a4d09ee5268c65fa

henry 2002-12-20T22:21:21

Added Mesh::Combine and changed tempPointList to FTList

diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index dc751bc..4223d1c 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -3,6 +3,7 @@
 
 
 #include "FTContour.h"
+#include "FTList.h"
 #include "FTPoint.h"
 #include "FTVector.h"
 #include "FTGL.h"
@@ -22,7 +23,8 @@ class FTGL_EXPORT FTTesselation
         /**
          * Default constructor
          */
-        FTTesselation()
+        FTTesselation( GLenum m)
+        :	meshType(m)
         {
             pointList.reserve( 128);
         }
@@ -35,19 +37,27 @@ class FTGL_EXPORT FTTesselation
             pointList.clear();
         }
 
-        
+        /**
+         * Add a point to the mesh.
+         */
         void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
         {   
             pointList.push_back( FTPoint( x, y, z));
         }
 
-
+        /**
+         * The number of points in this mesh
+         */
         size_t PointCount() const { return pointList.size();}
         
+        /**
+         *
+         */
         const FTPoint& Point( unsigned int index) const { return pointList[index];}
-
-        void PolygonType( GLenum m) { meshType = m;}
         
+        /**
+         * Return the OpenGL polygon type.
+         */
         GLenum PolygonType() const { return meshType;}
         
     private:
@@ -69,6 +79,9 @@ class FTGL_EXPORT FTTesselation
  */
 class FTGL_EXPORT FTMesh
 {
+	typedef FTVector<FTTesselation*> TesselationVector;
+	typedef FTList<FTPoint> PointList;
+
     public:
         /**
          * Default constructor
@@ -80,28 +93,51 @@ class FTGL_EXPORT FTMesh
          */
         ~FTMesh();
         
+        /**
+         *
+         */
         void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
-        void Begin( GLenum m);
+        
+        /**
+         *
+         */
+        FTGL_DOUBLE* Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
+        
+        /**
+         *
+         */
+        void Begin( GLenum meshType);
+        
+        /**
+         *
+         */
         void End();
+        
+        /**
+         *
+         */
         void Error( GLenum e) { err = e;}
         
+        /**
+         *
+         */
         unsigned int TesselationCount() const { return tesselationList.size();}
 
+        /**
+         *
+         */
         const FTTesselation* const Tesselation( unsigned int index) const;
+        
+        /**
+         *
+         */
+        const PointList& TempPointList() const { return tempPointList;}
 
         /**
          * Get the GL ERROR returned by the glu tesselator
          */
         GLenum Error() const { return err;}
 
-        /**
-         * Holds extra points created by gluTesselator. See ftglCombine.
-         */
-        typedef FTVector<FTPoint> PointVector;
-        PointVector tempPointList;
-        
-    protected:
-    
     private:
         /**
          * The current sub mesh that we are constructing.
@@ -111,10 +147,14 @@ class FTGL_EXPORT FTMesh
         /**
          * Holds each sub mesh that comprises this glyph.
          */
-        typedef FTVector<FTTesselation*> TesselationVector;
         TesselationVector tesselationList;
         
         /**
+         * Holds extra points created by gluTesselator. See ftglCombine.
+         */
+        PointList tempPointList;
+        
+        /**
          * GL ERROR returned by the glu tesselator
          */
         GLenum err;
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 982cd9e..02c6a08 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -22,13 +22,21 @@ void CALLBACK ftglError( GLenum errCode, FTMesh* mesh)
     mesh->Error( errCode);
 }
 
+
 void CALLBACK ftglVertex( void* data, FTMesh* mesh)
 {
-    FTGL_DOUBLE* vertex = (FTGL_DOUBLE*)data;
+    FTGL_DOUBLE* vertex = static_cast<FTGL_DOUBLE*>(data);
     mesh->AddPoint( vertex[0], vertex[1], vertex[2]);
 }
 
 
+void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, FTMesh* mesh)
+{
+    FTGL_DOUBLE* vertex = static_cast<FTGL_DOUBLE*>(coords);
+    *outData = mesh->Combine( vertex[0], vertex[1], vertex[2]);
+}
+        
+
 void CALLBACK ftglBegin( GLenum type, FTMesh* mesh)
 {
     mesh->Begin( type);
@@ -41,22 +49,11 @@ void CALLBACK ftglEnd( FTMesh* mesh)
 }
 
 
-void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, FTMesh* mesh)
-{
-    FTGL_DOUBLE* vertex = (FTGL_DOUBLE*)coords;
-    mesh->tempPointList.push_back( FTPoint( vertex[0], vertex[1], vertex[2]));
-    
-    // FIXME if tempPointList reallocs we'll loose these. replace it with a list.
-    *outData = &mesh->tempPointList[ mesh->tempPointList.size() - 1].x;
-}
-        
-
 FTMesh::FTMesh()
 :	currentTesselation(0),
     err(0)
 {
     tesselationList.reserve( 16);
-    tempPointList.reserve( 128);
 }
 
 
@@ -67,8 +64,6 @@ FTMesh::~FTMesh()
         delete tesselationList[t];
     }
     tesselationList.clear();
-
-    tempPointList.clear();
 }
 
 
@@ -77,10 +72,17 @@ void FTMesh::AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUB
     currentTesselation->AddPoint( x, y, z);
 }
 
-void FTMesh::Begin( GLenum m)
+
+FTGL_DOUBLE* FTMesh::Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
 {
-    currentTesselation = new FTTesselation;
-    currentTesselation->PolygonType( m);
+    tempPointList.push_back( FTPoint( x, y,z));
+    return &tempPointList.back().x;
+}
+
+
+void FTMesh::Begin( GLenum meshType)
+{
+    currentTesselation = new FTTesselation( meshType);
 }
 
 
@@ -95,6 +97,7 @@ const FTTesselation* const FTMesh::Tesselation( unsigned int index) const
     return ( index < tesselationList.size()) ? tesselationList[index] : NULL;
 }
 
+
 FTVectoriser::FTVectoriser( const FT_Glyph glyph)
 :   contourList(0),
     mesh(0),
diff --git a/test/FTTesselation-Test.cpp b/test/FTTesselation-Test.cpp
index 1c665cf..a7fc85d 100755
--- a/test/FTTesselation-Test.cpp
+++ b/test/FTTesselation-Test.cpp
@@ -22,7 +22,7 @@ class FTTesselationTest : public CppUnit::TestCase
 
         void testAddPoint()
         {
-            FTTesselation tesselation;
+            FTTesselation tesselation( 1);
             
             CPPUNIT_ASSERT( tesselation.PointCount() == 0);
             
@@ -44,7 +44,7 @@ class FTTesselationTest : public CppUnit::TestCase
         
         void testGetPoint()
         {
-            FTTesselation tesselation;
+            FTTesselation tesselation(1);
             
             CPPUNIT_ASSERT( tesselation.PointCount() == 0);