From fda16e27cdcac955c7d62041884df9a787a9e50a Mon Sep 17 00:00:00 2001 From: Alexander Szpakowski Date: Wed, 2 Jan 2013 04:21:22 -0400 Subject: [PATCH] Changed image mipmap api: Image:setFilter now takes an optional third argument (mipmap filter mode), Image:get/setMipmapFilter is removed. --- src/modules/graphics/opengl/Image.cpp | 16 ++--- src/modules/graphics/opengl/Image.h | 3 +- src/modules/graphics/opengl/wrap_Image.cpp | 82 +++++----------------- src/modules/graphics/opengl/wrap_Image.h | 2 - 4 files changed, 29 insertions(+), 74 deletions(-) diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 723876aff..e80c52040 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -152,16 +152,16 @@ void Image::setFilter(const Image::Filter &f) 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); @@ -170,7 +170,7 @@ void Image::setFilter(const Image::Filter &f) 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()); } } @@ -205,7 +205,7 @@ void Image::setMipmapSharpness(float sharpness) 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 @@ -274,7 +274,7 @@ bool Image::loadVolatilePOT() 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); } @@ -308,7 +308,7 @@ bool Image::loadVolatileNPOT() 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); } diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index 9778a878b..d9fc83602 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -97,7 +97,7 @@ public: /** * Sets the filter mode. * - * @param mode The filter mode. + * @param f The filter mode. **/ void setFilter(const Image::Filter &f); @@ -147,6 +147,7 @@ private: // Mipmap texture LOD bias value float mipmapsharpness; + // Implementation-dependent maximum/minimum sharpness values float maxmipmapsharpness; // The image's filter mode diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index 88db24cc4..6e286fd0c 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -51,23 +51,24 @@ int w_Image_setFilter(lua_State *L) { 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 { @@ -87,77 +88,34 @@ int w_Image_getFilter(lua_State *L) 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 (lua_isnoneornil(L, 2)) // disable mipmapping if no arguments are given - f.mipmap = Image::FILTER_NONE; + if (Image::getConstant(f.mipmap, mipmapstr)) + lua_pushstring(L, mipmapstr); else - { - const char *filterstr = luaL_checkstring(L, 2); - if (!Image::getConstant(filterstr, f.mipmap)) - return luaL_error(L, "Invalid filter mode: %s", filterstr); - } + lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled - 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; @@ -204,8 +162,6 @@ 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 f06b73ba8..a6c8d5d6a 100644 --- a/src/modules/graphics/opengl/wrap_Image.h +++ b/src/modules/graphics/opengl/wrap_Image.h @@ -39,8 +39,6 @@ int w_Image_setFilter(lua_State *L); 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);