Mercurial > love-experiments
diff src/modules/image/wrap_Image.cpp @ 1420:2a5ef265e040 image-CompressedData
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
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Thu, 04 Apr 2013 19:09:18 -0300 |
| parents | b7f097053d74 |
| children | 377f9dad7a2d |
line wrap: on
line diff
--- a/src/modules/image/wrap_Image.cpp Mon Apr 01 16:47:45 2013 -0300 +++ b/src/modules/image/wrap_Image.cpp Thu Apr 04 19:09:18 2013 -0300 @@ -93,16 +93,98 @@ 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 };
