mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Changed image mipmap api: Image:setFilter now takes an optional third argument (mipmap filter mode), Image:get/setMipmapFilter is removed.
This commit is contained in:
@@ -152,16 +152,16 @@ void Image::setFilter(const Image::Filter &f)
|
|||||||
if (f.mipmap == FILTER_NEAREST || f.mipmap == FILTER_LINEAR)
|
if (f.mipmap == FILTER_NEAREST || f.mipmap == FILTER_LINEAR)
|
||||||
{
|
{
|
||||||
if (!hasMipmapSupport())
|
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))
|
if (width != next_p2(width) || height != next_p2(height))
|
||||||
throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
|
throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
|
||||||
|
|
||||||
GLboolean aremipmapscreated;
|
GLboolean mipmapscreated;
|
||||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&aremipmapscreated);
|
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
|
||||||
|
|
||||||
// generate mipmaps for this image if we haven't already
|
// generate mipmaps for this image if we haven't already
|
||||||
if (!aremipmapscreated)
|
if (!mipmapscreated)
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
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)
|
else if (GLEE_EXT_framebuffer_object)
|
||||||
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||||
else
|
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());
|
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);
|
mipmapsharpness = std::min(std::max(sharpness, -maxmipmapsharpness + 0.01f), maxmipmapsharpness - 0.01f);
|
||||||
|
|
||||||
bind();
|
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
|
float Image::getMipmapSharpness() const
|
||||||
@@ -274,7 +274,7 @@ bool Image::loadVolatilePOT()
|
|||||||
|
|
||||||
if (hasMipmapSupport())
|
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);
|
bool genmipmaps = (filter.mipmap == FILTER_LINEAR) || (filter.mipmap == FILTER_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ bool Image::loadVolatileNPOT()
|
|||||||
|
|
||||||
if (hasMipmapSupport())
|
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);
|
bool genmipmaps = (filter.mipmap == FILTER_LINEAR) || (filter.mipmap == FILTER_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, genmipmaps ? GL_TRUE : GL_FALSE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Sets the filter mode.
|
* Sets the filter mode.
|
||||||
*
|
*
|
||||||
* @param mode The filter mode.
|
* @param f The filter mode.
|
||||||
**/
|
**/
|
||||||
void setFilter(const Image::Filter &f);
|
void setFilter(const Image::Filter &f);
|
||||||
|
|
||||||
@@ -147,6 +147,7 @@ private:
|
|||||||
// Mipmap texture LOD bias value
|
// Mipmap texture LOD bias value
|
||||||
float mipmapsharpness;
|
float mipmapsharpness;
|
||||||
|
|
||||||
|
// Implementation-dependent maximum/minimum sharpness values
|
||||||
float maxmipmapsharpness;
|
float maxmipmapsharpness;
|
||||||
|
|
||||||
// The image's filter mode
|
// The image's filter mode
|
||||||
|
|||||||
@@ -51,23 +51,24 @@ int w_Image_setFilter(lua_State *L)
|
|||||||
{
|
{
|
||||||
Image *t = luax_checkimage(L, 1);
|
Image *t = luax_checkimage(L, 1);
|
||||||
|
|
||||||
Image::FilterMode min;
|
Image::Filter f;
|
||||||
Image::FilterMode mag;
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (!Image::getConstant(minstr, min))
|
if (!Image::getConstant(minstr, f.min))
|
||||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
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);
|
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||||
|
|
||||||
const Image::Filter curfilter = t->getFilter();
|
if (lua_isnoneornil(L, 4))
|
||||||
|
f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given
|
||||||
Image::Filter f;
|
else
|
||||||
f.min = min;
|
{
|
||||||
f.mag = mag;
|
const char *mipmapstr = luaL_checkstring(L, 4);
|
||||||
f.mipmap = curfilter.mipmap;
|
if (!Image::getConstant(mipmapstr, f.mipmap))
|
||||||
|
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -87,77 +88,34 @@ int w_Image_getFilter(lua_State *L)
|
|||||||
const Image::Filter f = t->getFilter();
|
const Image::Filter f = t->getFilter();
|
||||||
const char *minstr;
|
const char *minstr;
|
||||||
const char *magstr;
|
const char *magstr;
|
||||||
|
const char *mipmapstr;
|
||||||
Image::getConstant(f.min, minstr);
|
Image::getConstant(f.min, minstr);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_Image_setMipmapFilter(lua_State *L)
|
if (Image::getConstant(f.mipmap, mipmapstr))
|
||||||
{
|
lua_pushstring(L, mipmapstr);
|
||||||
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;
|
|
||||||
else
|
else
|
||||||
{
|
lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
|
||||||
const char *filterstr = luaL_checkstring(L, 2);
|
|
||||||
if (!Image::getConstant(filterstr, f.mipmap))
|
|
||||||
return luaL_error(L, "Invalid filter mode: %s", filterstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
return 3;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_Image_setWrap(lua_State *L)
|
int w_Image_setWrap(lua_State *L)
|
||||||
{
|
{
|
||||||
Image *i = luax_checkimage(L, 1);
|
Image *i = luax_checkimage(L, 1);
|
||||||
|
|
||||||
Image::WrapMode s;
|
Image::Wrap w;
|
||||||
Image::WrapMode t;
|
|
||||||
|
|
||||||
const char *sstr = luaL_checkstring(L, 2);
|
const char *sstr = luaL_checkstring(L, 2);
|
||||||
const char *tstr = luaL_optstring(L, 3, sstr);
|
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);
|
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);
|
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||||
|
|
||||||
Image::Wrap w;
|
|
||||||
w.s = s;
|
|
||||||
w.t = t;
|
|
||||||
|
|
||||||
i->setWrap(w);
|
i->setWrap(w);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -204,8 +162,6 @@ 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 }
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ int w_Image_setFilter(lua_State *L);
|
|||||||
int w_image_getFilter(lua_State *L);
|
int w_image_getFilter(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_setMipmapFilter(lua_State *L);
|
|
||||||
int w_Image_getMipmapFilter(lua_State *L);
|
|
||||||
int w_Image_setMipmapSharpness(lua_State *L);
|
int w_Image_setMipmapSharpness(lua_State *L);
|
||||||
int w_Image_getMipmapSharpness(lua_State *L);
|
int w_Image_getMipmapSharpness(lua_State *L);
|
||||||
extern "C" int luaopen_image(lua_State *L);
|
extern "C" int luaopen_image(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user