Fix issue #406: Empty glyphs cause some ATI cards to crash in Font::addGlyph().

This commit is contained in:
vrld
2012-04-03 13:55:12 +02:00
parent 7925b1b059
commit d4c59d3508
+24 -9
View File
@@ -95,17 +95,10 @@ namespace opengl
Font::Glyph * Font::addGlyph(int glyph)
{
Glyph * g = new Glyph;
g->list = glGenLists(1);
if (g->list == 0)
{ // opengl failed to generate the list
delete g;
return NULL;
}
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
g->spacing = gd->getAdvance();
int w = gd->getWidth();
int h = gd->getHeight();
if (texture_x + w + TEXTURE_PADDING > TEXTURE_WIDTH)
{ // out of space - new row!
texture_x = TEXTURE_PADDING;
@@ -116,6 +109,21 @@ namespace opengl
{ // totally out of space - new texture!
createTexture();
}
Glyph * g = new Glyph;
g->list = g->texture = 0;
g->spacing = gd->getAdvance();
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
if (w > 0 && h > 0)
{
g->list = glGenLists(1);
if (0 == g->list)
{
delete g;
return NULL;
}
GLuint t = textures.back();
bindTexture(t);
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
@@ -146,11 +154,14 @@ namespace opengl
glDisableClientState(GL_VERTEX_ARRAY);
delete q;
delete gd;
}
if (w > 0)
texture_x += (w + TEXTURE_PADDING);
if (h > 0)
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
delete gd;
glyphs[glyph] = g;
return g;
}
@@ -205,12 +216,16 @@ namespace opengl
{
Glyph * glyph = glyphs[character];
if (!glyph) glyph = addGlyph(character);
if (0 != glyph->texture)
{
glPushMatrix();
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
bindTexture(glyph->texture);
glCallList(glyph->list);
glPopMatrix();
}
}
int Font::getWidth(const std::string & line)
{