Browse Source

Alexander's patch for improved mipmap API.

rude 12 years ago
parent
commit
4e2c424cd1

+ 41 - 16
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)
 int w_Font_setFilter(lua_State *L)
 {
 {
 	Font *t = luax_checkfont(L, 1);
 	Font *t = luax_checkfont(L, 1);
-
-	Image::Filter f;
+	Image::Filter f = t->getFilter();
 
 
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	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))
 	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 		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
 	try
 	{
 	{
 		t->setFilter(f);
 		t->setFilter(f);
@@ -135,14 +125,47 @@ int w_Font_getFilter(lua_State *L)
 	Image::getConstant(f.mag, magstr);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
 	lua_pushstring(L, magstr);
+	return 2;
+}
 
 
-	const char *mipmapstr;
-	if (Image::getConstant(f.mipmap, mipmapstr))
-		lua_pushstring(L, mipmapstr);
+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
 	else
-		lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
+	{
+		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();
 
 
-	return 3;
+	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)
 int w_Font_setMipmapSharpness(lua_State *L)
@@ -192,6 +215,8 @@ static const luaL_Reg functions[] =
 	{ "getLineHeight", w_Font_getLineHeight },
 	{ "getLineHeight", w_Font_getLineHeight },
 	{ "setFilter", w_Font_setFilter },
 	{ "setFilter", w_Font_setFilter },
 	{ "getFilter", w_Font_getFilter },
 	{ "getFilter", w_Font_getFilter },
+	{ "setMipmapFilter", w_Font_setMipmapFilter },
+	{ "getMipmapFilter", w_Font_getMipmapFilter },
 	{ "setMipmapSharpness", w_Font_setMipmapSharpness },
 	{ "setMipmapSharpness", w_Font_setMipmapSharpness },
 	{ "getMipmapSharpness", w_Font_getMipmapSharpness },
 	{ "getMipmapSharpness", w_Font_getMipmapSharpness },
 	{ "getAscent", w_Font_getAscent },
 	{ "getAscent", w_Font_getAscent },

+ 2 - 0
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_getLineHeight(lua_State *L);
 int w_Font_setFilter(lua_State *L);
 int w_Font_setFilter(lua_State *L);
 int w_Font_getFilter(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_setMipmapSharpness(lua_State *L);
 int w_Font_getMipmapSharpness(lua_State *L);
 int w_Font_getMipmapSharpness(lua_State *L);
 int w_Font_getAscent(lua_State *L);
 int w_Font_getAscent(lua_State *L);

+ 41 - 16
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)
 int w_Image_setFilter(lua_State *L)
 {
 {
 	Image *t = luax_checkimage(L, 1);
 	Image *t = luax_checkimage(L, 1);
-
-	Image::Filter f;
+	Image::Filter f = t->getFilter();
 
 
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	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))
 	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 		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
 	try
 	{
 	{
 		t->setFilter(f);
 		t->setFilter(f);
@@ -92,14 +82,47 @@ int w_Image_getFilter(lua_State *L)
 	Image::getConstant(f.mag, magstr);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
 	lua_pushstring(L, magstr);
+	return 2;
+}
 
 
-	const char *mipmapstr;
-	if (Image::getConstant(f.mipmap, mipmapstr))
-		lua_pushstring(L, mipmapstr);
+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
 	else
-		lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
+	{
+		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();
 
 
-	return 3;
+	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_Image_setWrap(lua_State *L)
 int w_Image_setWrap(lua_State *L)
@@ -159,6 +182,8 @@ static const luaL_Reg functions[] =
 	{ "getFilter", w_Image_getFilter },
 	{ "getFilter", w_Image_getFilter },
 	{ "setWrap", w_Image_setWrap },
 	{ "setWrap", w_Image_setWrap },
 	{ "getWrap", w_Image_getWrap },
 	{ "getWrap", w_Image_getWrap },
+	{ "setMipmapFilter", w_Image_setMipmapFilter },
+	{ "getMipmapFilter", w_Image_getMipmapFilter },
 	{ "setMipmapSharpness", w_Image_setMipmapSharpness },
 	{ "setMipmapSharpness", w_Image_setMipmapSharpness },
 	{ "getMipmapSharpness", w_Image_getMipmapSharpness },
 	{ "getMipmapSharpness", w_Image_getMipmapSharpness },
 	{ 0, 0 }
 	{ 0, 0 }

+ 2 - 0
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_getHeight(lua_State *L);
 int w_Image_setFilter(lua_State *L);
 int w_Image_setFilter(lua_State *L);
 int w_image_getFilter(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_setWrap(lua_State *L);
 int w_Image_getWrap(lua_State *L);
 int w_Image_getWrap(lua_State *L);
 int w_Image_setMipmapSharpness(lua_State *L);
 int w_Image_setMipmapSharpness(lua_State *L);