diff --git a/src/modules/graphics/opengl/wrap_Font.cpp b/src/modules/graphics/opengl/wrap_Font.cpp index ce1566a40..a3761690e 100644 --- a/src/modules/graphics/opengl/wrap_Font.cpp +++ b/src/modules/graphics/opengl/wrap_Font.cpp @@ -93,8 +93,7 @@ int w_Font_getLineHeight(lua_State *L) int w_Font_setFilter(lua_State *L) { Font *t = luax_checkfont(L, 1); - - Image::Filter f; + Image::Filter f = t->getFilter(); const char *minstr = luaL_checkstring(L, 2); const char *magstr = luaL_optstring(L, 3, minstr); @@ -104,15 +103,6 @@ int w_Font_setFilter(lua_State *L) if (!Image::getConstant(magstr, f.mag)) return luaL_error(L, "Invalid filter mode: %s", magstr); - if (lua_isnoneornil(L, 4)) - f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given - else - { - const char *mipmapstr = luaL_checkstring(L, 4); - if (!Image::getConstant(mipmapstr, f.mipmap)) - return luaL_error(L, "Invalid filter mode: %s", mipmapstr); - } - try { t->setFilter(f); @@ -135,14 +125,47 @@ int w_Font_getFilter(lua_State *L) Image::getConstant(f.mag, magstr); lua_pushstring(L, minstr); lua_pushstring(L, magstr); + 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)) - lua_pushstring(L, mipmapstr); - else - lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled + if (!Image::getConstant(f.mipmap, mipmapstr)) + return 0; // only return a mipmap filter if mipmapping is enabled - return 3; + lua_pushstring(L, mipmapstr); + + return 1; } int w_Font_setMipmapSharpness(lua_State *L) @@ -192,6 +215,8 @@ 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 }, diff --git a/src/modules/graphics/opengl/wrap_Font.h b/src/modules/graphics/opengl/wrap_Font.h index 28dca46de..26d1932ea 100644 --- a/src/modules/graphics/opengl/wrap_Font.h +++ b/src/modules/graphics/opengl/wrap_Font.h @@ -40,6 +40,8 @@ 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); diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index e92c22952..c70d23e0d 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -50,8 +50,7 @@ int w_Image_getHeight(lua_State *L) int w_Image_setFilter(lua_State *L) { Image *t = luax_checkimage(L, 1); - - Image::Filter f; + Image::Filter f = t->getFilter(); const char *minstr = luaL_checkstring(L, 2); const char *magstr = luaL_optstring(L, 3, minstr); @@ -61,15 +60,6 @@ int w_Image_setFilter(lua_State *L) if (!Image::getConstant(magstr, f.mag)) return luaL_error(L, "Invalid filter mode: %s", magstr); - if (lua_isnoneornil(L, 4)) - f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given - else - { - const char *mipmapstr = luaL_checkstring(L, 4); - if (!Image::getConstant(mipmapstr, f.mipmap)) - return luaL_error(L, "Invalid filter mode: %s", mipmapstr); - } - try { t->setFilter(f); @@ -92,14 +82,47 @@ int w_Image_getFilter(lua_State *L) Image::getConstant(f.mag, magstr); lua_pushstring(L, minstr); lua_pushstring(L, magstr); + return 2; +} + +int w_Image_setMipmapFilter(lua_State *L) +{ + Image *t = luax_checkimage(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_Image_getMipmapFilter(lua_State *L) +{ + Image *t = luax_checkimage(L, 1); + const Image::Filter f = t->getFilter(); const char *mipmapstr; - if (Image::getConstant(f.mipmap, mipmapstr)) - lua_pushstring(L, mipmapstr); - else - lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled + if (!Image::getConstant(f.mipmap, mipmapstr)) + return 0; // only return a mipmap filter if mipmapping is enabled - return 3; + lua_pushstring(L, mipmapstr); + + return 1; } int w_Image_setWrap(lua_State *L) @@ -159,6 +182,8 @@ static const luaL_Reg functions[] = { "getFilter", w_Image_getFilter }, { "setWrap", w_Image_setWrap }, { "getWrap", w_Image_getWrap }, + { "setMipmapFilter", w_Image_setMipmapFilter }, + { "getMipmapFilter", w_Image_getMipmapFilter }, { "setMipmapSharpness", w_Image_setMipmapSharpness }, { "getMipmapSharpness", w_Image_getMipmapSharpness }, { 0, 0 } diff --git a/src/modules/graphics/opengl/wrap_Image.h b/src/modules/graphics/opengl/wrap_Image.h index a6c8d5d6a..67882174c 100644 --- a/src/modules/graphics/opengl/wrap_Image.h +++ b/src/modules/graphics/opengl/wrap_Image.h @@ -37,6 +37,8 @@ int w_Image_getWidth(lua_State *L); int w_Image_getHeight(lua_State *L); int w_Image_setFilter(lua_State *L); int w_image_getFilter(lua_State *L); +int w_Image_setMipmapFilter(lua_State *L); +int w_Image_getMipmapFilter(lua_State *L); int w_Image_setWrap(lua_State *L); int w_Image_getWrap(lua_State *L); int w_Image_setMipmapSharpness(lua_State *L);