mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Move getMipmapMode from Canvas to Texture
This commit is contained in:
@@ -37,6 +37,7 @@ Canvas::Canvas(const Settings &settings)
|
|||||||
sRGB = false;
|
sRGB = false;
|
||||||
requestedMSAA = settings.msaa;
|
requestedMSAA = settings.msaa;
|
||||||
|
|
||||||
|
mipmapsMode = settings.mipmaps;
|
||||||
width = settings.width;
|
width = settings.width;
|
||||||
height = settings.height;
|
height = settings.height;
|
||||||
pixelWidth = (int) ((width * settings.dpiScale) + 0.5);
|
pixelWidth = (int) ((width * settings.dpiScale) + 0.5);
|
||||||
@@ -63,10 +64,10 @@ Canvas::Canvas(const Settings &settings)
|
|||||||
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
|
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
|
||||||
throw love::Exception("Readable depth/stencil Canvases with MSAA are not currently supported.");
|
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.");
|
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);
|
mipmapCount = getTotalMipmapCount(pixelWidth, pixelHeight, depth);
|
||||||
|
|
||||||
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
|
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)
|
bool Canvas::getConstant(const char *in, SettingType &out)
|
||||||
{
|
{
|
||||||
return settingTypes.find(in, out);
|
return settingTypes.find(in, out);
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ public:
|
|||||||
Canvas(const Settings &settings);
|
Canvas(const Settings &settings);
|
||||||
virtual ~Canvas();
|
virtual ~Canvas();
|
||||||
|
|
||||||
MipmapsMode getMipmapsMode() const;
|
|
||||||
|
|
||||||
static bool getConstant(const char *in, SettingType &out);
|
static bool getConstant(const char *in, SettingType &out);
|
||||||
static bool getConstant(SettingType in, const char *&out);
|
static bool getConstant(SettingType in, const char *&out);
|
||||||
static const char *getConstant(SettingType in);
|
static const char *getConstant(SettingType in);
|
||||||
@@ -82,9 +80,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
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>::Entry settingTypeEntries[];
|
||||||
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
|
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
|
||||||
|
|
||||||
|
|||||||
@@ -90,13 +90,14 @@ void Image::init(PixelFormat fmt, int w, int h, int dataMipmaps, const Settings
|
|||||||
|
|
||||||
pixelWidth = w;
|
pixelWidth = w;
|
||||||
pixelHeight = h;
|
pixelHeight = h;
|
||||||
|
mipmapsMode = settings.mipmaps ? MIPMAPS_MANUAL : MIPMAPS_NONE;
|
||||||
|
|
||||||
width = (int) (pixelWidth / settings.dpiScale + 0.5);
|
width = (int) (pixelWidth / settings.dpiScale + 0.5);
|
||||||
height = (int) (pixelHeight / settings.dpiScale + 0.5);
|
height = (int) (pixelHeight / settings.dpiScale + 0.5);
|
||||||
|
|
||||||
format = fmt;
|
format = fmt;
|
||||||
|
|
||||||
if (!settings.mipmaps || (isCompressed() && dataMipmaps <= 1))
|
if (mipmapsMode == MIPMAPS_NONE || (isCompressed() && dataMipmaps <= 1))
|
||||||
mipmapCount = 1;
|
mipmapCount = 1;
|
||||||
else
|
else
|
||||||
mipmapCount = getTotalMipmapCount(w, h, depth);
|
mipmapCount = getTotalMipmapCount(w, h, depth);
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ Texture::Texture(TextureType texType)
|
|||||||
, format(PIXELFORMAT_UNKNOWN)
|
, format(PIXELFORMAT_UNKNOWN)
|
||||||
, renderTarget(false)
|
, renderTarget(false)
|
||||||
, readable(true)
|
, readable(true)
|
||||||
|
, mipmapsMode(MIPMAPS_NONE)
|
||||||
, sRGB(false)
|
, sRGB(false)
|
||||||
, width(0)
|
, width(0)
|
||||||
, height(0)
|
, height(0)
|
||||||
@@ -214,6 +215,11 @@ PixelFormat Texture::getPixelFormat() const
|
|||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Texture::MipmapsMode Texture::getMipmapsMode() const
|
||||||
|
{
|
||||||
|
return mipmapsMode;
|
||||||
|
}
|
||||||
|
|
||||||
bool Texture::isRenderTarget() const
|
bool Texture::isRenderTarget() const
|
||||||
{
|
{
|
||||||
return renderTarget;
|
return renderTarget;
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ public:
|
|||||||
|
|
||||||
TextureType getTextureType() const;
|
TextureType getTextureType() const;
|
||||||
PixelFormat getPixelFormat() const;
|
PixelFormat getPixelFormat() const;
|
||||||
|
MipmapsMode getMipmapsMode() const;
|
||||||
|
|
||||||
bool isRenderTarget() const;
|
bool isRenderTarget() const;
|
||||||
bool isReadable() const;
|
bool isReadable() const;
|
||||||
@@ -249,6 +250,8 @@ protected:
|
|||||||
bool renderTarget;
|
bool renderTarget;
|
||||||
bool readable;
|
bool readable;
|
||||||
|
|
||||||
|
MipmapsMode mipmapsMode;
|
||||||
|
|
||||||
bool sRGB;
|
bool sRGB;
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
|
|||||||
@@ -78,21 +78,9 @@ int w_Canvas_renderTo(lua_State *L)
|
|||||||
return 0;
|
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[] =
|
static const luaL_Reg w_Canvas_functions[] =
|
||||||
{
|
{
|
||||||
{ "renderTo", w_Canvas_renderTo },
|
{ "renderTo", w_Canvas_renderTo },
|
||||||
{ "getMipmapMode", w_Canvas_getMipmapMode },
|
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -322,6 +322,16 @@ int w_Texture_getDepthSampleMode(lua_State *L)
|
|||||||
return 1;
|
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)
|
int w_Texture_generateMipmaps(lua_State *L)
|
||||||
{
|
{
|
||||||
Texture *t = luax_checktexture(L, 1);
|
Texture *t = luax_checktexture(L, 1);
|
||||||
@@ -338,7 +348,7 @@ int w_Texture_replacePixels(lua_State *L)
|
|||||||
int mipmap = 0;
|
int mipmap = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 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)
|
if (t->getTextureType() != TEXTURE_2D)
|
||||||
slice = (int) luaL_checkinteger(L, 3) - 1;
|
slice = (int) luaL_checkinteger(L, 3) - 1;
|
||||||
@@ -412,6 +422,7 @@ const luaL_Reg w_Texture_functions[] =
|
|||||||
{ "getWrap", w_Texture_getWrap },
|
{ "getWrap", w_Texture_getWrap },
|
||||||
{ "getFormat", w_Texture_getFormat },
|
{ "getFormat", w_Texture_getFormat },
|
||||||
{ "isReadable", w_Texture_isReadable },
|
{ "isReadable", w_Texture_isReadable },
|
||||||
|
{ "getMipmapMode", w_Texture_getMipmapMode },
|
||||||
{ "getDepthSampleMode", w_Texture_getDepthSampleMode },
|
{ "getDepthSampleMode", w_Texture_getDepthSampleMode },
|
||||||
{ "setDepthSampleMode", w_Texture_setDepthSampleMode },
|
{ "setDepthSampleMode", w_Texture_setDepthSampleMode },
|
||||||
{ "generateMipmaps", w_Texture_generateMipmaps },
|
{ "generateMipmaps", w_Texture_generateMipmaps },
|
||||||
|
|||||||
Reference in New Issue
Block a user