only update the font vertex buffer if text or color changed

This commit is contained in:
Mark Vejvoda
2011-11-19 18:25:16 +00:00
parent 53e1610234
commit 646ec7707a
2 changed files with 32 additions and 23 deletions

View File

@@ -24,6 +24,7 @@
#include "font-manager.h" #include "font-manager.h"
#include "font_text.h" #include "font_text.h"
#include "vec.h"
namespace Shared { namespace Graphics { namespace Gl { namespace Shared { namespace Graphics { namespace Gl {
@@ -55,6 +56,9 @@ public:
private: private:
string lastTextRendered;
Vec4f lastTextColorRendered;
VertexBuffer *buffer; VertexBuffer *buffer;
TextureAtlas *atlas; TextureAtlas *atlas;
TextureFont *font; TextureFont *font;

View File

@@ -89,23 +89,24 @@ void TextFreetypeGL::Render(const char* str, const int len) {
} }
//printf("Render TextFreetypeGL\n"); //printf("Render TextFreetypeGL\n");
//float currentColor[4] = { 0,0,0,1 };
Vec4f currentColor;
glGetFloatv(GL_CURRENT_COLOR,currentColor.ptr());
if(lastTextRendered != str || lastTextColorRendered != currentColor) {
Pen pen ; Pen pen ;
pen.x = 0; pen.y = 0; pen.x = 0; pen.y = 0;
vertex_buffer_clear( this->buffer );
float currentColor[4] = { 0,0,0,1 };
glGetFloatv(GL_CURRENT_COLOR,currentColor);
Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0, Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0,
{currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {0,0,0,0}, {currentColor.x,currentColor.y,currentColor.z,currentColor.w}, {0,0,0,0},
0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1},
0, {0,0,0,1}, 0, {0,0,0,1}, 0 }; 0, {0,0,0,1}, 0, {0,0,0,1}, 0 };
// Add glyph one by one to the vertex buffer // Add glyph one by one to the vertex buffer
// Expand totalBox by each glyph in string // Expand totalBox by each glyph in string
vertex_buffer_clear( this->buffer );
// for multibyte - we can't rely on sizeof(T) == character // for multibyte - we can't rely on sizeof(T) == character
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str); FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
@@ -124,6 +125,10 @@ void TextFreetypeGL::Render(const char* str, const int len) {
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx ); texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx );
} }
lastTextRendered = str;
lastTextColorRendered = currentColor;
}
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid ); //glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
glBindTexture( GL_TEXTURE_2D, this->atlas->texid ); glBindTexture( GL_TEXTURE_2D, this->atlas->texid );