Move getMipmapMode from Canvas to Texture

This commit is contained in:
Alex Szpakowski
2020-02-04 19:56:19 -04:00
parent 4104c136cf
commit 0304bdf450
7 changed files with 26 additions and 26 deletions
+3 -7
View File
@@ -37,6 +37,7 @@ Canvas::Canvas(const Settings &settings)
sRGB = false;
requestedMSAA = settings.msaa;
mipmapsMode = settings.mipmaps;
width = settings.width;
height = settings.height;
pixelWidth = (int) ((width * settings.dpiScale) + 0.5);
@@ -63,10 +64,10 @@ Canvas::Canvas(const Settings &settings)
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
throw love::Exception("Readable depth/stencil Canvases with MSAA are not currently supported.");
if ((!readable || settings.msaa > 1) && settings.mipmaps != MIPMAPS_NONE)
if ((!readable || settings.msaa > 1) && mipmapsMode != MIPMAPS_NONE)
throw love::Exception("Non-readable and MSAA textures cannot have mipmaps.");
if (settings.mipmaps != MIPMAPS_NONE)
if (mipmapsMode != MIPMAPS_NONE)
mipmapCount = getTotalMipmapCount(pixelWidth, pixelHeight, depth);
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
@@ -102,11 +103,6 @@ Canvas::~Canvas()
{
}
Texture::MipmapsMode Canvas::getMipmapsMode() const
{
return settings.mipmaps;
}
bool Canvas::getConstant(const char *in, SettingType &out)
{
return settingTypes.find(in, out);
-5
View File
@@ -69,8 +69,6 @@ public:
Canvas(const Settings &settings);
virtual ~Canvas();
MipmapsMode getMipmapsMode() const;
static bool getConstant(const char *in, SettingType &out);
static bool getConstant(SettingType in, const char *&out);
static const char *getConstant(SettingType in);
@@ -82,9 +80,6 @@ protected:
private:
static StringMap<MipmapsMode, MIPMAPS_MAX_ENUM>::Entry mipmapEntries[];
static StringMap<MipmapsMode, MIPMAPS_MAX_ENUM> mipmapModes;
static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[];
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
+2 -1
View File
@@ -90,13 +90,14 @@ void Image::init(PixelFormat fmt, int w, int h, int dataMipmaps, const Settings
pixelWidth = w;
pixelHeight = h;
mipmapsMode = settings.mipmaps ? MIPMAPS_MANUAL : MIPMAPS_NONE;
width = (int) (pixelWidth / settings.dpiScale + 0.5);
height = (int) (pixelHeight / settings.dpiScale + 0.5);
format = fmt;
if (!settings.mipmaps || (isCompressed() && dataMipmaps <= 1))
if (mipmapsMode == MIPMAPS_NONE || (isCompressed() && dataMipmaps <= 1))
mipmapCount = 1;
else
mipmapCount = getTotalMipmapCount(w, h, depth);
+6
View File
@@ -164,6 +164,7 @@ Texture::Texture(TextureType texType)
, format(PIXELFORMAT_UNKNOWN)
, renderTarget(false)
, readable(true)
, mipmapsMode(MIPMAPS_NONE)
, sRGB(false)
, width(0)
, height(0)
@@ -214,6 +215,11 @@ PixelFormat Texture::getPixelFormat() const
return format;
}
Texture::MipmapsMode Texture::getMipmapsMode() const
{
return mipmapsMode;
}
bool Texture::isRenderTarget() const
{
return renderTarget;
+3
View File
@@ -194,6 +194,7 @@ public:
TextureType getTextureType() const;
PixelFormat getPixelFormat() const;
MipmapsMode getMipmapsMode() const;
bool isRenderTarget() const;
bool isReadable() const;
@@ -249,6 +250,8 @@ protected:
bool renderTarget;
bool readable;
MipmapsMode mipmapsMode;
bool sRGB;
int width;
-12
View File
@@ -78,21 +78,9 @@ int w_Canvas_renderTo(lua_State *L)
return 0;
}
int w_Canvas_getMipmapMode(lua_State *L)
{
Canvas *c = luax_checkcanvas(L, 1);
const char *str;
if (!Texture::getConstant(c->getMipmapsMode(), str))
return luax_enumerror(L, "mipmap mode", Texture::getConstants(Texture::MIPMAPS_MAX_ENUM), str);
lua_pushstring(L, str);
return 1;
}
static const luaL_Reg w_Canvas_functions[] =
{
{ "renderTo", w_Canvas_renderTo },
{ "getMipmapMode", w_Canvas_getMipmapMode },
{ 0, 0 }
};
+12 -1
View File
@@ -322,6 +322,16 @@ int w_Texture_getDepthSampleMode(lua_State *L)
return 1;
}
int w_Texture_getMipmapMode(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
const char *str;
if (!Texture::getConstant(t->getMipmapsMode(), str))
return luax_enumerror(L, "mipmap mode", Texture::getConstants(Texture::MIPMAPS_MAX_ENUM), str);
lua_pushstring(L, str);
return 1;
}
int w_Texture_generateMipmaps(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
@@ -338,7 +348,7 @@ int w_Texture_replacePixels(lua_State *L)
int mipmap = 0;
int x = 0;
int y = 0;
bool reloadmipmaps = false; // TODO i->getMipmapsSource() == Texture::MIPMAPS_SOURCE_GENERATED;
bool reloadmipmaps = t->getMipmapsMode() == Texture::MIPMAPS_AUTO;
if (t->getTextureType() != TEXTURE_2D)
slice = (int) luaL_checkinteger(L, 3) - 1;
@@ -412,6 +422,7 @@ const luaL_Reg w_Texture_functions[] =
{ "getWrap", w_Texture_getWrap },
{ "getFormat", w_Texture_getFormat },
{ "isReadable", w_Texture_isReadable },
{ "getMipmapMode", w_Texture_getMipmapMode },
{ "getDepthSampleMode", w_Texture_getDepthSampleMode },
{ "setDepthSampleMode", w_Texture_setDepthSampleMode },
{ "generateMipmaps", w_Texture_generateMipmaps },