Got rid fo the GL_TEXTURE_2D_BINDING_EXT call in FTTextureGlyph and replaced it with a static member.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/include/FTTextureGlyph.h b/include/FTTextureGlyph.h
index 389e6f7..bff82c9 100755
--- a/include/FTTextureGlyph.h
+++ b/include/FTTextureGlyph.h
@@ -48,6 +48,12 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
*/
virtual float Render( const FTPoint& pen);
+ /**
+ * Reset the currently active texture to zero to get into a known state before
+ * drawing a string. This is to get round possible threading issues.
+ */
+ static void FTTextureGlyph::ResetActiveTexture(){ activeTextureID = 0;}
+
private:
/**
* The width of the glyph 'image'
@@ -77,11 +83,10 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
/**
* The texture index of the currently active texture
*
- * We call glGetIntegerv( GL_TEXTURE_2D_BINDING, activeTextureID);
- * to get the currently active texture to try to reduce the number
- * of texture bind operations
+ * We keep track of the currently active texture to try to reduce the number
+ * of texture bind operations.
*/
- GLint activeTextureID;
+ static GLint activeTextureID;
};
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index aa6b645..03fa272 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -157,6 +157,8 @@ void FTGLTextureFont::Render( const char* string)
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+
+ FTTextureGlyph::ResetActiveTexture();
FTFont::Render( string);
@@ -171,6 +173,8 @@ void FTGLTextureFont::Render( const wchar_t* string)
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+ FTTextureGlyph::ResetActiveTexture();
+
FTFont::Render( string);
glPopAttrib();
diff --git a/src/FTTextureGlyph.cpp b/src/FTTextureGlyph.cpp
index 5529a89..2739378 100755
--- a/src/FTTextureGlyph.cpp
+++ b/src/FTTextureGlyph.cpp
@@ -1,12 +1,13 @@
#include "FTTextureGlyph.h"
-
+GLint FTTextureGlyph::activeTextureID = 0;
+
FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height)
: FTGlyph( glyph),
destWidth(0),
destHeight(0),
- glTextureID(id),
- activeTextureID(0)
+ glTextureID(id)//,
+// activeTextureID(0)
{
err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
if( err || glyph->format != ft_glyph_format_bitmap)
@@ -57,10 +58,10 @@ FTTextureGlyph::~FTTextureGlyph()
float FTTextureGlyph::Render( const FTPoint& pen)
{
- glGetIntegerv( GL_TEXTURE_2D_BINDING_EXT, &activeTextureID);
if( activeTextureID != glTextureID)
{
glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID);
+ activeTextureID = glTextureID;
}
glTranslatef( pen.x, pen.y, 0);