Commit cb8ae5d9027df4abb061c2f152cd10d66cd15acc

sammy 2008-04-22T16:18:07

* Fix displaylist usage in FTOutlineGlyph and FTPolyGlyph. FTExtrdGlyph still needs to be fixed, but that will be after pending Render() changes. Partially addresses SourceForge ticket #1945392.

diff --git a/include/FTOutlineGlyph.h b/include/FTOutlineGlyph.h
index e5cd61e..028f72e 100644
--- a/include/FTOutlineGlyph.h
+++ b/include/FTOutlineGlyph.h
@@ -10,10 +10,10 @@
  * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -47,7 +47,7 @@ class FTVectoriser;
 
 /**
  * FTOutlineGlyph is a specialisation of FTGlyph for creating outlines.
- * 
+ *
  * @see FTGlyphContainer
  * @see FTVectoriser
  *
@@ -77,15 +77,24 @@ class FTGL_EXPORT FTOutlineGlyph : public FTGlyph
          * @param pen	The current pen position.
          * @return		The advance distance for this glyph.
          */
-        virtual const FTPoint& Render( const FTPoint& pen);
-        
+        virtual const FTPoint& Render(const FTPoint& pen);
+
     private:		
         /**
+         * Private rendering method.
+         */
+        void DoRender();
+
+        /**
+         * Private rendering variables.
+         */
+        FTVectoriser *vectoriser;
+
+        /**
          * OpenGL display list
          */
         GLuint glList;
 };
 
-
 #endif	//	__FTOutlineGlyph__
 
diff --git a/include/FTPolyGlyph.h b/include/FTPolyGlyph.h
index a6cdcb5..15dd747 100644
--- a/include/FTPolyGlyph.h
+++ b/include/FTPolyGlyph.h
@@ -10,10 +10,10 @@
  * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -48,7 +48,7 @@ class FTVectoriser;
 /**
  * FTPolyGlyph is a specialisation of FTGlyph for creating tessellated
  * polygon glyphs.
- * 
+ *
  * @see FTGlyphContainer
  * @see FTVectoriser
  *
@@ -78,10 +78,21 @@ class FTGL_EXPORT FTPolyGlyph : public FTGlyph
          * @param pen   The current pen position.
          * @return      The advance distance for this glyph.
          */
-        virtual const FTPoint& Render( const FTPoint& pen);
-        
+        virtual const FTPoint& Render(const FTPoint& pen);
+
     private:
         /**
+         * Private rendering method.
+         */
+        void DoRender();
+
+        /**
+         * Private rendering variables.
+         */
+        unsigned int hscale, vscale;
+        FTVectoriser *vectoriser;
+
+        /**
          * OpenGL display list
          */
         GLuint glList;
diff --git a/src/FTOutlineGlyph.cpp b/src/FTOutlineGlyph.cpp
index 477e3be..f6f80a7 100644
--- a/src/FTOutlineGlyph.cpp
+++ b/src/FTOutlineGlyph.cpp
@@ -11,10 +11,10 @@
  * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -40,72 +40,90 @@
 
 
 FTOutlineGlyph::FTOutlineGlyph(FT_GlyphSlot glyph, float outset, bool useDisplayList)
-:   FTGlyph( glyph),
+:   FTGlyph(glyph),
     glList(0)
 {
-    if( ft_glyph_format_outline != glyph->format)
+    if(ft_glyph_format_outline != glyph->format)
     {
         err = 0x14; // Invalid_Outline
         return;
     }
 
-    FTVectoriser vectoriser(glyph, outset * 64.0f);
+    vectoriser = new FTVectoriser(glyph, outset * 64.0f);
 
-    size_t numContours = vectoriser.ContourCount();
-    if ( ( numContours < 1) || ( vectoriser.PointCount() < 3))
+    if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
     {
+        delete vectoriser;
+        vectoriser = NULL;
         return;
     }
 
     if(useDisplayList)
     {
         glList = glGenLists(1);
-        glNewList( glList, GL_COMPILE);
-    }
-    
-    for( unsigned int c = 0; c < numContours; ++c)
-    {
-        const FTContour* contour = vectoriser.Contour(c);
-        
-        glBegin( GL_LINE_LOOP);
-            for(unsigned int i = 0; i < contour->PointCount(); ++i)
-            {
-                FTPoint point = contour->Point(i);
-                glVertex2f( point.X() / 64.0f, point.Y() / 64.0f);
-            }
-        glEnd();
-        /* Outset contour */
-        glBegin(GL_LINE_LOOP);
-            for(unsigned int i = 0; i < contour->FrontPointCount(); ++i)
-            {
-                FTPoint point = contour->FrontPoint(i);
-                glVertex2f(point.X() / 64.0f, point.Y() / 64.0f);
-            }
-        glEnd();
-    }
+        glNewList(glList, GL_COMPILE);
+
+        DoRender();
 
-    if(useDisplayList)
-    {
         glEndList();
+
+        delete vectoriser;
+        vectoriser = NULL;
     }
 }
 
 
 FTOutlineGlyph::~FTOutlineGlyph()
 {
-    glDeleteLists( glList, 1);
+    if(glList)
+    {
+        glDeleteLists(glList, 1);
+    }
+    else if(vectoriser)
+    {
+        delete vectoriser;
+    }
 }
 
 
 const FTPoint& FTOutlineGlyph::Render(const FTPoint& pen)
 {
+    glTranslatef(pen.X(), pen.Y(), 0.0f);
     if(glList)
     {
-        glTranslatef(pen.X(), pen.Y(), 0.0f);
         glCallList(glList);
-        glTranslatef(-pen.X(), -pen.Y(), 0.0f);
     }
-    
+    else if(vectoriser)
+    {
+        DoRender();
+    }
+    glTranslatef(-pen.X(), -pen.Y(), 0.0f);
+
     return advance;
 }
 
+
+void FTOutlineGlyph::DoRender()
+{
+    for(unsigned int c = 0; c < vectoriser->ContourCount(); ++c)
+    {
+        const FTContour* contour = vectoriser->Contour(c);
+
+        glBegin(GL_LINE_LOOP);
+            for(unsigned int i = 0; i < contour->PointCount(); ++i)
+            {
+                FTPoint point = contour->Point(i);
+                glVertex2f(point.X() / 64.0f, point.Y() / 64.0f);
+            }
+        glEnd();
+        /* Outset contour */
+        glBegin(GL_LINE_LOOP);
+            for(unsigned int i = 0; i < contour->FrontPointCount(); ++i)
+            {
+                FTPoint point = contour->FrontPoint(i);
+                glVertex2f(point.X() / 64.0f, point.Y() / 64.0f);
+            }
+        glEnd();
+    }
+}
+
diff --git a/src/FTPolyGlyph.cpp b/src/FTPolyGlyph.cpp
index a3f742f..4713ed3 100644
--- a/src/FTPolyGlyph.cpp
+++ b/src/FTPolyGlyph.cpp
@@ -11,10 +11,10 @@
  * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -40,76 +40,91 @@
 
 
 FTPolyGlyph::FTPolyGlyph(FT_GlyphSlot glyph, float outset, bool useDisplayList)
-:   FTGlyph( glyph),
+:   FTGlyph(glyph),
     glList(0)
 {
-    if( ft_glyph_format_outline != glyph->format)
+    if(ft_glyph_format_outline != glyph->format)
     {
         err = 0x14; // Invalid_Outline
         return;
     }
 
-    FTVectoriser vectoriser(glyph, outset * 64.0f);
+    vectoriser = new FTVectoriser(glyph, outset * 64.0f);
 
-    if(( vectoriser.ContourCount() < 1) || ( vectoriser.PointCount() < 3))
+    if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
     {
+        delete vectoriser;
+        vectoriser = NULL;
         return;
     }
-    
-    unsigned int horizontalTextureScale = glyph->face->size->metrics.x_ppem * 64;
-    unsigned int verticalTextureScale = glyph->face->size->metrics.y_ppem * 64;        
-        
-    vectoriser.MakeMesh(1.0, 1);
-    
-    if( useDisplayList)
-    {
-        glList = glGenLists( 1);
-        glNewList( glList, GL_COMPILE);
-    }
 
-    const FTMesh* mesh = vectoriser.GetMesh();
-    for( unsigned int index = 0; index < mesh->TesselationCount(); ++index)
-    {
-        const FTTesselation* subMesh = mesh->Tesselation( index);
-        unsigned int polygonType = subMesh->PolygonType();
+    vectoriser->MakeMesh(1.0, 1);
 
-        glBegin( polygonType);
-            for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
-            {
-                FTPoint point = subMesh->Point(pointIndex);
-                
-                glTexCoord2f( point.X() / horizontalTextureScale,
-                              point.Y() / verticalTextureScale);
-                
-                glVertex3f( point.X() / 64.0f,
-                            point.Y() / 64.0f,
-                            0.0f);
-            }
-        glEnd();
-    }
+    hscale = glyph->face->size->metrics.x_ppem * 64;
+    vscale = glyph->face->size->metrics.y_ppem * 64;
 
     if(useDisplayList)
     {
+        glList = glGenLists(1);
+        glNewList(glList, GL_COMPILE);
+
+        DoRender();
+
         glEndList();
+
+        delete vectoriser;
+        vectoriser = NULL;
     }
 }
 
 
 FTPolyGlyph::~FTPolyGlyph()
 {
-    glDeleteLists( glList, 1);
+    if(useDisplayList)
+    {
+        glDeleteLists(glList, 1);
+    }
+    else if(vectoriser)
+    {
+        delete vectoriser;
+    }
 }
 
 
 const FTPoint& FTPolyGlyph::Render(const FTPoint& pen)
 {
+    glTranslatef(pen.X(), pen.Y(), 0.0f);
     if(glList)
     {
-        glTranslatef(pen.X(), pen.Y(), 0.0f);
         glCallList(glList);
-        glTranslatef(-pen.X(), -pen.Y(), 0.0f);
     }
-    
+    else if(vectoriser)
+    {
+        DoRender();
+    }
+    glTranslatef(-pen.X(), -pen.Y(), 0.0f);
+
     return advance;
 }
 
+
+void FTPolyGlyph::DoRender()
+{
+    const FTMesh *mesh = vectoriser->GetMesh();
+
+    for(unsigned int t = 0; t < mesh->TesselationCount(); ++t)
+    {
+        const FTTesselation* subMesh = mesh->Tesselation(t);
+        unsigned int polygonType = subMesh->PolygonType();
+
+        glBegin(polygonType);
+            for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+            {
+                FTPoint point = subMesh->Point(i);
+                glTexCoord2f(point.X() / hscale, point.Y() / vscale);
+                glVertex3f(point.X() / 64.0f, point.Y() / 64.0f, 0.0f);
+            }
+        glEnd();
+    }
+}
+