Commit fa5631df790433f75a07f005364406a6032e4b7b

sammy 2008-05-21T15:43:52

* Add proper glPushAttrib() and glPushClientAttrib() calls to the rendering methods that need them.

diff --git a/src/FTFont/FTBitmapFont.cpp b/src/FTFont/FTBitmapFont.cpp
index 08df30c..1e77379 100644
--- a/src/FTFont/FTBitmapFont.cpp
+++ b/src/FTFont/FTBitmapFont.cpp
@@ -67,8 +67,11 @@ inline FTPoint FTBitmapFontImpl::RenderI(const T* string, const int len,
                                          FTPoint position, FTPoint spacing,
                                          int renderMode)
 {
+    // Protect GL_BLEND
+    glPushAttrib(GL_COLOR_BUFFER_BIT);
+
+    // Protect glPixelStorei() calls (also in FTBitmapGlyphImpl::RenderImpl)
     glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
-    glPushAttrib(GL_ENABLE_BIT);
 
     glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -78,8 +81,8 @@ inline FTPoint FTBitmapFontImpl::RenderI(const T* string, const int len,
     FTPoint tmp = FTFontImpl::Render(string, len,
                                      position, spacing, renderMode);
 
-    glPopAttrib();
     glPopClientAttrib();
+    glPopAttrib();
 
     return tmp;
 }
diff --git a/src/FTFont/FTBufferFont.cpp b/src/FTFont/FTBufferFont.cpp
index a78abc2..0b25126 100644
--- a/src/FTFont/FTBufferFont.cpp
+++ b/src/FTFont/FTBufferFont.cpp
@@ -160,10 +160,12 @@ inline FTPoint FTBufferFontImpl::RenderI(const T* string, const int len,
     FTPoint tmp = FTFontImpl::Render(string, len, position,
                                      spacing, renderMode);
 
+    // Protect blending functions, GL_BLEND and GL_TEXTURE_2D
     glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
+
+    // Protect glPixelStorei() calls
     glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
 
-    /* FIXME: can we push/pop these instead? */
     glEnable(GL_BLEND);
     glEnable(GL_TEXTURE_2D);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
diff --git a/src/FTFont/FTOutlineFont.cpp b/src/FTFont/FTOutlineFont.cpp
index 8a7f270..1fbc928 100644
--- a/src/FTFont/FTOutlineFont.cpp
+++ b/src/FTFont/FTOutlineFont.cpp
@@ -74,11 +74,11 @@ inline FTPoint FTOutlineFontImpl::RenderI(const T* string, const int len,
                                           FTPoint position, FTPoint spacing,
                                           int renderMode)
 {
+    // Protect GL_TEXTURE_2D, glHint(), GL_LINE_SMOOTH and blending functions
     glPushAttrib(GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT
                   | GL_COLOR_BUFFER_BIT);
 
     glDisable(GL_TEXTURE_2D);
-
     glEnable(GL_LINE_SMOOTH);
     glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
     glEnable(GL_BLEND);
diff --git a/src/FTFont/FTPixmapFont.cpp b/src/FTFont/FTPixmapFont.cpp
index f298fe5..2113e61 100644
--- a/src/FTFont/FTPixmapFont.cpp
+++ b/src/FTFont/FTPixmapFont.cpp
@@ -67,7 +67,11 @@ inline FTPoint FTPixmapFontImpl::RenderI(const T* string, const int len,
                                          FTPoint position, FTPoint spacing,
                                          int renderMode)
 {
+    // Protect GL_TEXTURE_2D and GL_BLEND, glPixelTransferf(), and blending
+    // functions.
     glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
+
+    // Protect glPixelStorei() calls (made by FTPixmapGlyphImpl::RenderImpl).
     glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
 
     glEnable(GL_BLEND);
diff --git a/src/FTFont/FTTextureFont.cpp b/src/FTFont/FTTextureFont.cpp
index 9773ddd..d782397 100644
--- a/src/FTFont/FTTextureFont.cpp
+++ b/src/FTFont/FTTextureFont.cpp
@@ -228,14 +228,22 @@ inline FTPoint FTTextureFontImpl::RenderI(const T* string, const int len,
                                           FTPoint position, FTPoint spacing,
                                           int renderMode)
 {
-    /* FIXME: can we push/pop these instead? */
+    // Protect GL_TEXTURE_2D, GL_BLEND and blending functions
+    glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
+
     glEnable(GL_BLEND);
-    glEnable(GL_TEXTURE_2D);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
 
+    glEnable(GL_TEXTURE_2D);
+
     FTTextureGlyphImpl::ResetActiveTexture();
 
-    return FTFontImpl::Render(string, len, position, spacing, renderMode);
+    FTPoint tmp = FTFontImpl::Render(string, len,
+                                     position, spacing, renderMode);
+
+    glPopAttrib();
+
+    return tmp;
 }