Removed mipmap support from Font graphics objects

This commit is contained in:
Alex Szpakowski
2013-02-19 14:21:01 -04:00
parent 5bf78f891d
commit d9736ab3ab
4 changed files with 2 additions and 138 deletions
+2 -62
View File
@@ -48,7 +48,6 @@ Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
, lineHeight(1)
, mSpacing(1)
, filter(filter)
, mipmapsharpness(0.0f)
{
// try to find the best texture size match for the font size
// default to the largest texture size if no rough match is found
@@ -125,8 +124,8 @@ void Font::createTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
@@ -167,7 +166,6 @@ void Font::createTexture()
&emptyData[0]);
setFilter(filter);
setMipmapSharpness(mipmapsharpness);
}
Font::Glyph *Font::addGlyph(unsigned int glyph)
@@ -498,39 +496,6 @@ float Font::getSpacing() const
return mSpacing;
}
void Font::checkMipmapsCreated() const
{
if (filter.mipmap != Image::FILTER_NEAREST && filter.mipmap != Image::FILTER_LINEAR)
return;
if (!Image::hasMipmapSupport())
throw love::Exception("Mipmap filtering is not supported on this system!");
GLint mipmapscreated;
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &mipmapscreated);
// generate mipmaps for this image if we haven't already
if (!mipmapscreated)
{
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
glGenerateMipmap(GL_TEXTURE_2D);
else
{
// modify single texel to trigger mipmap chain generation
std::vector<GLubyte> emptydata(type == FONT_TRUETYPE ? 2 : 4);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0, 0,
1, 1,
type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA,
GL_UNSIGNED_BYTE,
&emptydata[0]);
}
}
}
void Font::setFilter(const Image::Filter &f)
{
filter = f;
@@ -539,7 +504,6 @@ void Font::setFilter(const Image::Filter &f)
for (it = textures.begin(); it != textures.end(); ++it)
{
bindTexture(*it);
checkMipmapsCreated();
setTextureFilter(f);
}
}
@@ -549,32 +513,8 @@ const Image::Filter &Font::getFilter()
return filter;
}
void Font::setMipmapSharpness(float sharpness)
{
if (!Image::hasMipmapSharpnessSupport())
return;
// LOD bias has the range (-maxbias, maxbias)
mipmapsharpness = std::min(std::max(sharpness, -maxmipmapsharpness + 0.01f), maxmipmapsharpness - 0.01f);
std::vector<GLuint>::const_iterator it;
for (it = textures.begin(); it != textures.end(); ++it)
{
bindTexture(*it);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -mipmapsharpness); // negative bias is sharper
}
}
float Font::getMipmapSharpness() const
{
return mipmapsharpness;
}
bool Font::loadVolatile()
{
if (Image::hasMipmapSharpnessSupport())
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &maxmipmapsharpness);
createTexture();
return true;
}
-11
View File
@@ -129,9 +129,6 @@ public:
void setFilter(const Image::Filter &f);
const Image::Filter &getFilter();
void setMipmapSharpness(float sharpness);
float getMipmapSharpness() const;
// Implements Volatile.
bool loadVolatile();
void unloadVolatile();
@@ -204,14 +201,6 @@ private:
int texture_x, texture_y;
int rowHeight;
// Mipmap texture LOD bias value
float mipmapsharpness;
// Implementation-dependent maximum/minimum mipmap sharpness values
float maxmipmapsharpness;
void checkMipmapsCreated() const;
bool initializeTexture(GLint format);
void createTexture();
Glyph *addGlyph(unsigned int glyph);
-61
View File
@@ -128,63 +128,6 @@ int w_Font_getFilter(lua_State *L)
return 2;
}
int w_Font_setMipmapFilter(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
Image::Filter f = t->getFilter();
if (lua_isnoneornil(L, 2))
f.mipmap = Image::FILTER_NONE; // mipmapping is disabled if no argument is given
else
{
const char *mipmapstr = luaL_checkstring(L, 2);
if (!Image::getConstant(mipmapstr, f.mipmap))
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
}
try
{
t->setFilter(f);
}
catch(love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 0;
}
int w_Font_getMipmapFilter(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
const Image::Filter f = t->getFilter();
const char *mipmapstr;
if (!Image::getConstant(f.mipmap, mipmapstr))
return 0; // only return a mipmap filter if mipmapping is enabled
lua_pushstring(L, mipmapstr);
return 1;
}
int w_Font_setMipmapSharpness(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
float sharpness = (float) luaL_checknumber(L, 2);
t->setMipmapSharpness(sharpness);
return 0;
}
int w_Font_getMipmapSharpness(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getMipmapSharpness());
return 1;
}
int w_Font_getAscent(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
@@ -215,10 +158,6 @@ static const luaL_Reg functions[] =
{ "getLineHeight", w_Font_getLineHeight },
{ "setFilter", w_Font_setFilter },
{ "getFilter", w_Font_getFilter },
{ "setMipmapFilter", w_Font_setMipmapFilter },
{ "getMipmapFilter", w_Font_getMipmapFilter },
{ "setMipmapSharpness", w_Font_setMipmapSharpness },
{ "getMipmapSharpness", w_Font_getMipmapSharpness },
{ "getAscent", w_Font_getAscent },
{ "getDescent", w_Font_getDescent },
{ "getBaseline", w_Font_getBaseline },
-4
View File
@@ -40,10 +40,6 @@ int w_Font_setLineHeight(lua_State *L);
int w_Font_getLineHeight(lua_State *L);
int w_Font_setFilter(lua_State *L);
int w_Font_getFilter(lua_State *L);
int w_Font_setMipmapFilter(lua_State *L);
int w_Font_getMipmapFilter(lua_State *L);
int w_Font_setMipmapSharpness(lua_State *L);
int w_Font_getMipmapSharpness(lua_State *L);
int w_Font_getAscent(lua_State *L);
int w_Font_getDescent(lua_State *L);
int w_Font_getBaseline(lua_State *L);