mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Renamed CompressedData:getType to CompressedData:getFormat
This commit is contained in:
@@ -157,7 +157,7 @@ void Image::drawg(love::graphics::Geometry *geom, float x, float y, float angle,
|
||||
|
||||
void Image::uploadCompressedMipmaps()
|
||||
{
|
||||
if (!isCompressed() || !cdata || !hasCompressedTextureSupport(cdata->getType()))
|
||||
if (!isCompressed() || !cdata || !hasCompressedTextureSupport(cdata->getFormat()))
|
||||
return;
|
||||
|
||||
bind();
|
||||
@@ -180,7 +180,7 @@ void Image::uploadCompressedMipmaps()
|
||||
{
|
||||
glCompressedTexImage2DARB(GL_TEXTURE_2D,
|
||||
i,
|
||||
getCompressedFormat(cdata->getType()),
|
||||
getCompressedFormat(cdata->getFormat()),
|
||||
cdata->getWidth(i),
|
||||
cdata->getHeight(i),
|
||||
0,
|
||||
@@ -251,7 +251,7 @@ void Image::checkMipmapsCreated()
|
||||
if (mipmapsCreated || filter.mipmap == FILTER_NONE || usingDefaultTexture)
|
||||
return;
|
||||
|
||||
if (isCompressed() && cdata && hasCompressedTextureSupport(cdata->getType()))
|
||||
if (isCompressed() && cdata && hasCompressedTextureSupport(cdata->getFormat()))
|
||||
uploadCompressedMipmaps();
|
||||
else if (data)
|
||||
createMipmaps();
|
||||
@@ -362,10 +362,10 @@ void Image::unload()
|
||||
|
||||
bool Image::loadVolatile()
|
||||
{
|
||||
if (isCompressed() && cdata && !hasCompressedTextureSupport(cdata->getType()))
|
||||
if (isCompressed() && cdata && !hasCompressedTextureSupport(cdata->getFormat()))
|
||||
{
|
||||
const char *str;
|
||||
if (image::CompressedData::getConstant(cdata->getType(), str))
|
||||
if (image::CompressedData::getConstant(cdata->getFormat(), str))
|
||||
{
|
||||
throw love::Exception("Cannot create image: "
|
||||
"%s compressed images are not supported on this system.", str);
|
||||
@@ -424,7 +424,7 @@ bool Image::loadVolatilePOT()
|
||||
|
||||
glCompressedTexImage2DARB(GL_TEXTURE_2D,
|
||||
0,
|
||||
getCompressedFormat(cdata->getType()),
|
||||
getCompressedFormat(cdata->getFormat()),
|
||||
cdata->getWidth(0),
|
||||
cdata->getHeight(0),
|
||||
0,
|
||||
@@ -488,7 +488,7 @@ bool Image::loadVolatileNPOT()
|
||||
|
||||
if (isCompressed() && cdata)
|
||||
{
|
||||
GLenum format = getCompressedFormat(cdata->getType());
|
||||
GLenum format = getCompressedFormat(cdata->getFormat());
|
||||
glCompressedTexImage2DARB(GL_TEXTURE_2D,
|
||||
0,
|
||||
format,
|
||||
@@ -548,7 +548,7 @@ bool Image::refresh()
|
||||
|
||||
if (isCompressed() && cdata)
|
||||
{
|
||||
GLenum format = getCompressedFormat(cdata->getType());
|
||||
GLenum format = getCompressedFormat(cdata->getFormat());
|
||||
glCompressedTexSubImage2DARB(GL_TEXTURE_2D,
|
||||
0,
|
||||
0, 0,
|
||||
@@ -671,23 +671,23 @@ bool Image::isCompressed() const
|
||||
return compressed;
|
||||
}
|
||||
|
||||
GLenum Image::getCompressedFormat(image::CompressedData::TextureType type) const
|
||||
GLenum Image::getCompressedFormat(image::CompressedData::Format format) const
|
||||
{
|
||||
switch (type)
|
||||
switch (format)
|
||||
{
|
||||
case image::CompressedData::TYPE_DXT1:
|
||||
case image::CompressedData::FORMAT_DXT1:
|
||||
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case image::CompressedData::TYPE_DXT3:
|
||||
case image::CompressedData::FORMAT_DXT3:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case image::CompressedData::TYPE_DXT5:
|
||||
case image::CompressedData::FORMAT_DXT5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case image::CompressedData::TYPE_BC4:
|
||||
case image::CompressedData::FORMAT_BC4:
|
||||
return GL_COMPRESSED_RED_RGTC1;
|
||||
case image::CompressedData::TYPE_BC4s:
|
||||
case image::CompressedData::FORMAT_BC4s:
|
||||
return GL_COMPRESSED_SIGNED_RED_RGTC1;
|
||||
case image::CompressedData::TYPE_BC5:
|
||||
case image::CompressedData::FORMAT_BC5:
|
||||
return GL_COMPRESSED_RG_RGTC2;
|
||||
case image::CompressedData::TYPE_BC5s:
|
||||
case image::CompressedData::FORMAT_BC5s:
|
||||
return GL_COMPRESSED_SIGNED_RG_RGTC2;
|
||||
default:
|
||||
return GL_RGBA8;
|
||||
@@ -719,21 +719,21 @@ bool Image::hasCompressedTextureSupport()
|
||||
return GLEE_VERSION_1_3 || GLEE_ARB_texture_compression;
|
||||
}
|
||||
|
||||
bool Image::hasCompressedTextureSupport(image::CompressedData::TextureType type)
|
||||
bool Image::hasCompressedTextureSupport(image::CompressedData::Format format)
|
||||
{
|
||||
if (!hasCompressedTextureSupport())
|
||||
return false;
|
||||
|
||||
switch (type)
|
||||
switch (format)
|
||||
{
|
||||
case image::CompressedData::TYPE_DXT1:
|
||||
case image::CompressedData::TYPE_DXT3:
|
||||
case image::CompressedData::TYPE_DXT5:
|
||||
case image::CompressedData::FORMAT_DXT1:
|
||||
case image::CompressedData::FORMAT_DXT3:
|
||||
case image::CompressedData::FORMAT_DXT5:
|
||||
return GLEE_EXT_texture_compression_s3tc;
|
||||
case image::CompressedData::TYPE_BC4:
|
||||
case image::CompressedData::TYPE_BC4s:
|
||||
case image::CompressedData::TYPE_BC5:
|
||||
case image::CompressedData::TYPE_BC5s:
|
||||
case image::CompressedData::FORMAT_BC4:
|
||||
case image::CompressedData::FORMAT_BC4s:
|
||||
case image::CompressedData::FORMAT_BC5:
|
||||
case image::CompressedData::FORMAT_BC5s:
|
||||
return (GLEE_VERSION_3_0 || GLEE_ARB_texture_compression_rgtc || GLEE_EXT_texture_compression_rgtc);
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
static bool hasMipmapSharpnessSupport();
|
||||
|
||||
static bool hasCompressedTextureSupport();
|
||||
static bool hasCompressedTextureSupport(image::CompressedData::TextureType type);
|
||||
static bool hasCompressedTextureSupport(image::CompressedData::Format format);
|
||||
|
||||
private:
|
||||
|
||||
@@ -206,7 +206,7 @@ private:
|
||||
static FilterMode defaultMipmapFilter;
|
||||
static float defaultMipmapSharpness;
|
||||
|
||||
GLenum getCompressedFormat(image::CompressedData::TextureType type) const;
|
||||
GLenum getCompressedFormat(image::CompressedData::Format format) const;
|
||||
|
||||
}; // Image
|
||||
|
||||
|
||||
@@ -1084,11 +1084,11 @@ int w_isSupported(lua_State *L)
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_DXT:
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::TYPE_DXT5))
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5))
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_BC5:
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::TYPE_BC5))
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5))
|
||||
supported = false;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace image
|
||||
{
|
||||
|
||||
CompressedData::CompressedData()
|
||||
: type(TYPE_UNKNOWN)
|
||||
: format(FORMAT_UNKNOWN)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ int CompressedData::getHeight(int miplevel) const
|
||||
return dataImages[miplevel].height;
|
||||
}
|
||||
|
||||
CompressedData::TextureType CompressedData::getType() const
|
||||
CompressedData::Format CompressedData::getFormat() const
|
||||
{
|
||||
return type;
|
||||
return format;
|
||||
}
|
||||
|
||||
void CompressedData::checkMipmapLevelExists(int miplevel) const
|
||||
@@ -99,29 +99,29 @@ void CompressedData::checkMipmapLevelExists(int miplevel) const
|
||||
throw love::Exception("Mipmap level %d does not exist", miplevel);
|
||||
}
|
||||
|
||||
bool CompressedData::getConstant(const char *in, CompressedData::TextureType &out)
|
||||
bool CompressedData::getConstant(const char *in, CompressedData::Format &out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
bool CompressedData::getConstant(CompressedData::TextureType in, const char *&out)
|
||||
bool CompressedData::getConstant(CompressedData::Format in, const char *&out)
|
||||
{
|
||||
return types.find(in, out);
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<CompressedData::TextureType, CompressedData::TYPE_MAX_ENUM>::Entry CompressedData::typeEntries[] =
|
||||
StringMap<CompressedData::Format, CompressedData::FORMAT_MAX_ENUM>::Entry CompressedData::formatEntries[] =
|
||||
{
|
||||
{"unknown", CompressedData::TYPE_UNKNOWN},
|
||||
{"dxt1", CompressedData::TYPE_DXT1},
|
||||
{"dxt3", CompressedData::TYPE_DXT3},
|
||||
{"dxt5", CompressedData::TYPE_DXT5},
|
||||
{"bc4", CompressedData::TYPE_BC4},
|
||||
{"bc4s", CompressedData::TYPE_BC4s},
|
||||
{"bc5", CompressedData::TYPE_BC5},
|
||||
{"bc5s", CompressedData::TYPE_BC5s},
|
||||
{"unknown", CompressedData::FORMAT_UNKNOWN},
|
||||
{"dxt1", CompressedData::FORMAT_DXT1},
|
||||
{"dxt3", CompressedData::FORMAT_DXT3},
|
||||
{"dxt5", CompressedData::FORMAT_DXT5},
|
||||
{"bc4", CompressedData::FORMAT_BC4},
|
||||
{"bc4s", CompressedData::FORMAT_BC4s},
|
||||
{"bc5", CompressedData::FORMAT_BC5},
|
||||
{"bc5s", CompressedData::FORMAT_BC5s},
|
||||
};
|
||||
|
||||
StringMap<CompressedData::TextureType, CompressedData::TYPE_MAX_ENUM> CompressedData::types(CompressedData::typeEntries, sizeof(CompressedData::typeEntries));
|
||||
StringMap<CompressedData::Format, CompressedData::FORMAT_MAX_ENUM> CompressedData::formats(CompressedData::formatEntries, sizeof(CompressedData::formatEntries));
|
||||
|
||||
} // image
|
||||
} // love
|
||||
|
||||
@@ -43,18 +43,18 @@ class CompressedData : public Data
|
||||
{
|
||||
public:
|
||||
|
||||
// Types of compressed image data.
|
||||
enum TextureType
|
||||
// Recognized compressed image data formats.
|
||||
enum Format
|
||||
{
|
||||
TYPE_UNKNOWN,
|
||||
TYPE_DXT1,
|
||||
TYPE_DXT3,
|
||||
TYPE_DXT5,
|
||||
TYPE_BC4,
|
||||
TYPE_BC4s,
|
||||
TYPE_BC5,
|
||||
TYPE_BC5s,
|
||||
TYPE_MAX_ENUM
|
||||
FORMAT_UNKNOWN,
|
||||
FORMAT_DXT1,
|
||||
FORMAT_DXT3,
|
||||
FORMAT_DXT5,
|
||||
FORMAT_BC4,
|
||||
FORMAT_BC4s,
|
||||
FORMAT_BC5,
|
||||
FORMAT_BC5s,
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
// Compressed image data can have multiple mipmap levels, each represented
|
||||
@@ -102,16 +102,16 @@ public:
|
||||
int getHeight(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the type of the compressed data.
|
||||
* Gets the format of the compressed data.
|
||||
**/
|
||||
TextureType getType() const;
|
||||
Format getFormat() const;
|
||||
|
||||
static bool getConstant(const char *in, TextureType &out);
|
||||
static bool getConstant(TextureType in, const char *&out);
|
||||
static bool getConstant(const char *in, Format &out);
|
||||
static bool getConstant(Format in, const char *&out);
|
||||
|
||||
protected:
|
||||
|
||||
TextureType type;
|
||||
Format format;
|
||||
|
||||
// Texture info for each mipmap level.
|
||||
std::vector<SubImage> dataImages;
|
||||
@@ -120,8 +120,8 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM> types;
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formats;
|
||||
|
||||
}; // CompressedData
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ void CompressedData::load(love::filesystem::FileData *data)
|
||||
{
|
||||
// SubImage vector will be populated by a parser.
|
||||
std::vector<SubImage> parsedimages;
|
||||
TextureType textype = TYPE_UNKNOWN;
|
||||
Format texformat = FORMAT_UNKNOWN;
|
||||
|
||||
if (ddsHandler::canParse(data))
|
||||
textype = ddsHandler::parse(data, parsedimages);
|
||||
texformat = ddsHandler::parse(data, parsedimages);
|
||||
|
||||
if (textype == TYPE_UNKNOWN)
|
||||
if (texformat == FORMAT_UNKNOWN)
|
||||
throw love::Exception("Could not parse compressed data: Unknown format.");
|
||||
|
||||
if (parsedimages.size() == 0)
|
||||
@@ -64,7 +64,7 @@ void CompressedData::load(love::filesystem::FileData *data)
|
||||
}
|
||||
|
||||
dataImages = parsedimages;
|
||||
type = textype;
|
||||
format = texformat;
|
||||
}
|
||||
|
||||
bool CompressedData::isCompressed(love::filesystem::FileData *data)
|
||||
|
||||
@@ -40,21 +40,21 @@ bool ddsHandler::canParse(const filesystem::FileData *data)
|
||||
return dds::isCompressedDDS(data->getData(), data->getSize());
|
||||
}
|
||||
|
||||
CompressedData::TextureType ddsHandler::parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images)
|
||||
CompressedData::Format ddsHandler::parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images)
|
||||
{
|
||||
if (!dds::isDDS(data->getData(), data->getSize()))
|
||||
throw love::Exception("Could not decode compressed data (not a DDS file?)");
|
||||
|
||||
CompressedData::TextureType textype = CompressedData::TYPE_UNKNOWN;
|
||||
CompressedData::Format texformat = CompressedData::FORMAT_UNKNOWN;
|
||||
|
||||
try
|
||||
{
|
||||
// Attempt to parse the dds file.
|
||||
dds::Parser parser(data->getData(), data->getSize());
|
||||
|
||||
textype = convertFormat(parser.getFormat());
|
||||
texformat = convertFormat(parser.getFormat());
|
||||
|
||||
if (textype == CompressedData::TYPE_UNKNOWN)
|
||||
if (texformat == CompressedData::FORMAT_UNKNOWN)
|
||||
throw love::Exception("Could not parse compressed data: Unsupported format.");
|
||||
|
||||
if (parser.getMipmapCount() == 0)
|
||||
@@ -88,32 +88,32 @@ CompressedData::TextureType ddsHandler::parse(filesystem::FileData *data, std::v
|
||||
throw love::Exception(e.what());
|
||||
}
|
||||
|
||||
return textype;
|
||||
return texformat;
|
||||
}
|
||||
|
||||
CompressedData::TextureType ddsHandler::convertFormat(dds::Format ddsformat)
|
||||
CompressedData::Format ddsHandler::convertFormat(dds::Format ddsformat)
|
||||
{
|
||||
switch (ddsformat)
|
||||
{
|
||||
case dds::FORMAT_DXT1:
|
||||
return CompressedData::TYPE_DXT1;
|
||||
return CompressedData::FORMAT_DXT1;
|
||||
case dds::FORMAT_DXT3:
|
||||
return CompressedData::TYPE_DXT3;
|
||||
return CompressedData::FORMAT_DXT3;
|
||||
case dds::FORMAT_DXT5:
|
||||
return CompressedData::TYPE_DXT5;
|
||||
return CompressedData::FORMAT_DXT5;
|
||||
case dds::FORMAT_BC4:
|
||||
return CompressedData::TYPE_BC4;
|
||||
return CompressedData::FORMAT_BC4;
|
||||
case dds::FORMAT_BC4s:
|
||||
return CompressedData::TYPE_BC4s;
|
||||
return CompressedData::FORMAT_BC4s;
|
||||
case dds::FORMAT_BC5:
|
||||
return CompressedData::TYPE_BC5;
|
||||
return CompressedData::FORMAT_BC5;
|
||||
case dds::FORMAT_BC5s:
|
||||
return CompressedData::TYPE_BC5s;
|
||||
return CompressedData::FORMAT_BC5s;
|
||||
default:
|
||||
return CompressedData::TYPE_UNKNOWN;
|
||||
return CompressedData::FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
return CompressedData::TYPE_UNKNOWN;
|
||||
return CompressedData::FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
} // magpie
|
||||
|
||||
@@ -58,13 +58,13 @@ public:
|
||||
* @param[in] data The data to parse.
|
||||
* @param[out] images The list of sub-images (including byte data for each)
|
||||
* parsed from the file data.
|
||||
* @return The type of CompressedData.
|
||||
* @return The format of the CompressedData.
|
||||
**/
|
||||
static CompressedData::TextureType parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images);
|
||||
static CompressedData::Format parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images);
|
||||
|
||||
private:
|
||||
|
||||
static CompressedData::TextureType convertFormat(dds::Format ddsformat);
|
||||
static CompressedData::Format convertFormat(dds::Format ddsformat);
|
||||
|
||||
}; // ddsHandler
|
||||
|
||||
|
||||
@@ -147,14 +147,14 @@ int w_CompressedData_getMipmapCount(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_CompressedData_getType(lua_State *L)
|
||||
int w_CompressedData_getFormat(lua_State *L)
|
||||
{
|
||||
CompressedData *t = luax_checkcompresseddata(L, 1);
|
||||
|
||||
image::CompressedData::TextureType type = t->getType();
|
||||
image::CompressedData::Format format = t->getFormat();
|
||||
const char *str;
|
||||
|
||||
if (image::CompressedData::getConstant(type, str))
|
||||
if (image::CompressedData::getConstant(format, str))
|
||||
lua_pushstring(L, str);
|
||||
else
|
||||
lua_pushstring(L, "unknown");
|
||||
@@ -173,7 +173,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getHeight", w_CompressedData_getHeight },
|
||||
{ "getDimensions", w_CompressedData_getDimensions },
|
||||
{ "getMipmapCount", w_CompressedData_getMipmapCount },
|
||||
{ "getType", w_CompressedData_getType },
|
||||
{ "getFormat", w_CompressedData_getFormat },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ int w_CompressedData_getWidth(lua_State *L);
|
||||
int w_CompressedData_getHeight(lua_State *L);
|
||||
int w_CompressedData_getDimensions(lua_State *L);
|
||||
int w_CompressedData_getMipmapCount(lua_State *L);
|
||||
int w_CompressedData_getType(lua_State *L);
|
||||
int w_CompressedData_getFormat(lua_State *L);
|
||||
extern "C" int luaopen_compresseddata(lua_State *L);
|
||||
|
||||
} // image
|
||||
|
||||
Reference in New Issue
Block a user