Commits

Alex Szpakowski committed 6d08ca9

Changed image mipmap api: Image:setFilter now takes an optional third argument (mipmap filter mode), Image:get/setMipmapFilter is removed.

  • Participants
  • Parent commits f7ee7ec

Comments (0)

Files changed (4)

src/modules/graphics/opengl/Image.cpp

 	if (f.mipmap == FILTER_NEAREST || f.mipmap == FILTER_LINEAR)
 	{
 		if (!hasMipmapSupport())
-			throw love::Exception("Mipmaps are not supported on this system!");
+			throw love::Exception("Mipmap filtering is not supported on this system!");
 		
 		if (width != next_p2(width) || height != next_p2(height))
 			throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
 		
-		GLboolean aremipmapscreated;
-		glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&aremipmapscreated);
+		GLboolean mipmapscreated;
+		glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
 		
 		// generate mipmaps for this image if we haven't already
-		if (!aremipmapscreated)
+		if (!mipmapscreated)
 		{
 			glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
 			
 			else if (GLEE_EXT_framebuffer_object)
 				glGenerateMipmapEXT(GL_TEXTURE_2D);
 			else
-				// modify single pixel in texture to trigger mip chain generation
+				// modify single pixel in texture to trigger mipmap chain generation
 				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei)width, (GLsizei)height, GL_RGBA, GL_UNSIGNED_BYTE, getData());
 		}
 	}
 	mipmapsharpness = std::min(std::max(sharpness, -maxmipmapsharpness + 0.01f), maxmipmapsharpness - 0.01f);
 	
 	bind();
-	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -mipmapsharpness);
+	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -mipmapsharpness); // negative bias is sharper
 }
 
 float Image::getMipmapSharpness() const
 	
 	if (hasMipmapSupport())
 	{
-		// auto-generate mipmaps when texture is modified, if mipmapping is enabled
+		// tell GL to auto-generate mipmaps when texture is modified, if mipmapping is enabled
 		bool genmipmaps = (filter.mipmap == FILTER_LINEAR) || (filter.mipmap == FILTER_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
 	}
 	
 	if (hasMipmapSupport())
 	{
-		// auto-generate mipmaps when texture is modified, if mipmapping is enabled
+		// tell GL to auto-generate mipmaps when texture is modified, if mipmapping is enabled
 		bool genmipmaps = (filter.mipmap == FILTER_LINEAR) || (filter.mipmap == FILTER_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
 	}

src/modules/graphics/opengl/Image.h

 	/**
 	 * Sets the filter mode.
 	 *
-	 * @param mode The filter mode.
+	 * @param f The filter mode.
 	 **/
 	void setFilter(const Image::Filter &f);
 
 	// Mipmap texture LOD bias value
 	float mipmapsharpness;
 	
+	// Implementation-dependent maximum/minimum sharpness values
 	float maxmipmapsharpness;
 	
 	// The image's filter mode

src/modules/graphics/opengl/wrap_Image.cpp

 {
 	Image *t = luax_checkimage(L, 1);
 	
-	Image::FilterMode min;
-	Image::FilterMode mag;
+	Image::Filter f;
 	
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	
-	if (!Image::getConstant(minstr, min))
+	if (!Image::getConstant(minstr, f.min))
 		return luaL_error(L, "Invalid filter mode: %s", minstr);
-	if (!Image::getConstant(magstr, mag))
+	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 	
-	const Image::Filter curfilter = t->getFilter();
-
-	Image::Filter f;
-	f.min = min;
-	f.mag = mag;
-	f.mipmap = curfilter.mipmap;
+	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
 	{
 	const Image::Filter f = t->getFilter();
 	const char *minstr;
 	const char *magstr;
+	const char *mipmapstr;
 	Image::getConstant(f.min, minstr);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
-	return 2;
-}
-
-int w_Image_setMipmapFilter(lua_State *L)
-{
-	Image *i = luax_checkimage(L, 1);
 	
-	const Image::Filter curfilter = i->getFilter();
-	Image::Filter f;
-	f.min = curfilter.min;
-	f.mag = curfilter.mag;
+	if (Image::getConstant(f.mipmap, mipmapstr))
+		lua_pushstring(L, mipmapstr);
+	else
+		lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
 	
-	if (lua_isnoneornil(L, 2)) // disable mipmapping if no arguments are given
-		f.mipmap = Image::FILTER_NONE;
-	else
-	{
-		const char *filterstr = luaL_checkstring(L, 2);
-		if (!Image::getConstant(filterstr, f.mipmap))
-			return luaL_error(L, "Invalid filter mode: %s", filterstr);
-	}
-	
-	try
-	{
-		i->setFilter(f);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
-	
-	return 0;
-}
-
-int w_Image_getMipmapFilter(lua_State *L)
-{
-	Image *i = luax_checkimage(L, 1);
-	
-	const Image::Filter f = i->getFilter();
-	const char *filterstr;
-	
-	if (Image::getConstant(f.mipmap, filterstr))
-		lua_pushstring(L, filterstr);
-	else
-		lua_pushnil(L); // return nil if mipmap filter is FILTER_NONE
-	
-	return 1;
+	return 3;
 }
 
 int w_Image_setWrap(lua_State *L)
 {
 	Image *i = luax_checkimage(L, 1);
 	
-	Image::WrapMode s;
-	Image::WrapMode t;
+	Image::Wrap w;
 	
 	const char *sstr = luaL_checkstring(L, 2);
 	const char *tstr = luaL_optstring(L, 3, sstr);
 	
-	if (!Image::getConstant(sstr, s))
+	if (!Image::getConstant(sstr, w.s))
 		return luaL_error(L, "Invalid wrap mode: %s", sstr);
-	if (!Image::getConstant(tstr, t))
+	if (!Image::getConstant(tstr, w.t))
 		return luaL_error(L, "Invalid wrap mode, %s", tstr);
 
-	Image::Wrap w;
-	w.s = s;
-	w.t = t;
-	
 	i->setWrap(w);
 	
 	return 0;
 	{ "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 }

src/modules/graphics/opengl/wrap_Image.h

 int w_image_getFilter(lua_State *L);
 int w_Image_setWrap(lua_State *L);
 int w_Image_getWrap(lua_State *L);
-int w_Image_setMipmapFilter(lua_State *L);
-int w_Image_getMipmapFilter(lua_State *L);
 int w_Image_setMipmapSharpness(lua_State *L);
 int w_Image_getMipmapSharpness(lua_State *L);
 extern "C" int luaopen_image(lua_State *L);