mirror of
https://github.com/glest/glest-source.git
synced 2025-08-23 16:32:53 +02:00
only update the font vertex buffer if text or color changed
This commit is contained in:
@@ -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;
|
||||||
|
@@ -89,39 +89,44 @@ 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());
|
||||||
|
|
||||||
Pen pen ;
|
if(lastTextRendered != str || lastTextColorRendered != currentColor) {
|
||||||
pen.x = 0; pen.y = 0;
|
Pen pen ;
|
||||||
|
pen.x = 0; pen.y = 0;
|
||||||
|
|
||||||
vertex_buffer_clear( this->buffer );
|
Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 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 };
|
||||||
|
|
||||||
float currentColor[4] = { 0,0,0,1 };
|
// Add glyph one by one to the vertex buffer
|
||||||
glGetFloatv(GL_CURRENT_COLOR,currentColor);
|
// Expand totalBox by each glyph in string
|
||||||
|
|
||||||
Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0,
|
vertex_buffer_clear( this->buffer );
|
||||||
{currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {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 };
|
|
||||||
|
|
||||||
// Add glyph one by one to the vertex buffer
|
// for multibyte - we can't rely on sizeof(T) == character
|
||||||
// Expand totalBox by each glyph in string
|
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
|
||||||
|
|
||||||
// for multibyte - we can't rely on sizeof(T) == character
|
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
|
||||||
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
|
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
||||||
|
unsigned int thisChar = *ustr++;
|
||||||
|
unsigned int nextChar = *ustr;
|
||||||
|
|
||||||
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
|
// Get glyph (build it if needed
|
||||||
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
|
||||||
unsigned int thisChar = *ustr++;
|
|
||||||
unsigned int nextChar = *ustr;
|
|
||||||
|
|
||||||
// Get glyph (build it if needed
|
// Take kerning into account if necessary
|
||||||
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
|
float kx = texture_glyph_get_kerning( glyph, prevChar );
|
||||||
|
|
||||||
// Take kerning into account if necessary
|
// Add glyph to the vertex buffer
|
||||||
float kx = texture_glyph_get_kerning( glyph, prevChar );
|
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx );
|
||||||
|
}
|
||||||
|
|
||||||
// Add glyph to the vertex buffer
|
lastTextRendered = str;
|
||||||
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx );
|
lastTextColorRendered = currentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
|
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
|
||||||
|
Reference in New Issue
Block a user