comparison 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
comparison
equal deleted inserted replaced
1419:edd946442f86 1420:2a5ef265e040
91 } 91 }
92 luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t); 92 luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t);
93 return 1; 93 return 1;
94 } 94 }
95 95
96 int w_newCompressedData(lua_State *L)
97 {
98 // Case 1: Data
99 if (luax_istype(L, 1, DATA_T))
100 {
101 Data *d = luax_checktype<Data>(L, 1, "Data", DATA_T);
102
103 CompressedData *t = 0;
104 try
105 {
106 t = instance->newCompressedData(d);
107 }
108 catch (love::Exception &e)
109 {
110 return luaL_error(L, "%s", e.what());
111 }
112 luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
113
114 return 1;
115 }
116
117 // Case 2: String/File.
118
119 // Convert to File, if necessary.
120 if (lua_isstring(L, 1))
121 luax_convobj(L, 1, "filesystem", "newFile");
122
123 love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
124
125 CompressedData *t = 0;
126 try
127 {
128 t = instance->newCompressedData(file);
129 }
130 catch (love::Exception &e)
131 {
132 return luaL_error(L, "%s", e.what());
133 }
134 luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
135
136 return 1;
137 }
138
139 int w_isCompressed(lua_State *L)
140 {
141 if (luax_istype(L, 1, DATA_T))
142 {
143 Data *d = luax_checktype<Data>(L, 1, "Data", DATA_T);
144 try
145 {
146 bool compressed = instance->isCompressed(d);
147 luax_pushboolean(L, compressed);
148 }
149 catch (love::Exception &e)
150 {
151 return luaL_error(L, "%s", e.what());
152 }
153 return 1;
154 }
155
156 // Convert to File, if necessary.
157 if (lua_isstring(L, 1))
158 luax_convobj(L, 1, "filesystem", "newFile");
159
160 filesystem::File *file = luax_checktype<filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
161
162 try
163 {
164 bool compressed = instance->isCompressed(file);
165 luax_pushboolean(L, compressed);
166 }
167 catch (love::Exception &e)
168 {
169 return luaL_error(L, "%s", e.what());
170 }
171
172 return 1;
173 }
174
96 // List of functions to wrap. 175 // List of functions to wrap.
97 static const luaL_Reg functions[] = 176 static const luaL_Reg functions[] =
98 { 177 {
99 { "newImageData", w_newImageData }, 178 { "newImageData", w_newImageData },
179 { "newCompressedData", w_newCompressedData },
180 { "isCompressed", w_isCompressed },
100 { 0, 0 } 181 { 0, 0 }
101 }; 182 };
102 183
103 static const lua_CFunction types[] = 184 static const lua_CFunction types[] =
104 { 185 {
105 luaopen_imagedata, 186 luaopen_imagedata,
187 luaopen_compresseddata,
106 0 188 0
107 }; 189 };
108 190
109 extern "C" int luaopen_love_image(lua_State *L) 191 extern "C" int luaopen_love_image(lua_State *L)
110 { 192 {