mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
- added a new CompressedData type to love.image - added love.image.isCompressed(file or data) - love.graphics.newImage automatically tests for compression when loading a file - added love.graphics.isSupported strings for DXT, BC5, and BC7 Compressed textures meant to be used on the GPU offer huge performance gains when - loading the texture from a file - loading the texture from RAM to VRAM - loading mipmaps - rendering --HG-- branch : image-CompressedData
This commit is contained in:
@@ -93,16 +93,98 @@ int w_newImageData(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newCompressedData(lua_State *L)
|
||||
{
|
||||
// Case 1: Data
|
||||
if (luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
Data *d = luax_checktype<Data>(L, 1, "Data", DATA_T);
|
||||
|
||||
CompressedData *t = 0;
|
||||
try
|
||||
{
|
||||
t = instance->newCompressedData(d);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Case 2: String/File.
|
||||
|
||||
// Convert to File, if necessary.
|
||||
if (lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
|
||||
CompressedData *t = 0;
|
||||
try
|
||||
{
|
||||
t = instance->newCompressedData(file);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_isCompressed(lua_State *L)
|
||||
{
|
||||
if (luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
Data *d = luax_checktype<Data>(L, 1, "Data", DATA_T);
|
||||
try
|
||||
{
|
||||
bool compressed = instance->isCompressed(d);
|
||||
luax_pushboolean(L, compressed);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Convert to File, if necessary.
|
||||
if (lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
filesystem::File *file = luax_checktype<filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
|
||||
try
|
||||
{
|
||||
bool compressed = instance->isCompressed(file);
|
||||
luax_pushboolean(L, compressed);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "newImageData", w_newImageData },
|
||||
{ "newCompressedData", w_newCompressedData },
|
||||
{ "isCompressed", w_isCompressed },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] =
|
||||
{
|
||||
luaopen_imagedata,
|
||||
luaopen_compresseddata,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user