comparison src/modules/image/wrap_CompressedData.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
children 5b9ebe6a9a7e
comparison
equal deleted inserted replaced
1419:edd946442f86 1420:2a5ef265e040
1 /**
2 * Copyright (c) 2006-2013 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21 #include "wrap_CompressedData.h"
22 #include "common/wrap_Data.h"
23
24 namespace love
25 {
26 namespace image
27 {
28
29 CompressedData *luax_checkcompresseddata(lua_State *L, int idx)
30 {
31 return luax_checktype<CompressedData>(L, idx, "CompressedData", IMAGE_COMPRESSED_DATA_T);
32 }
33
34 int w_CompressedData_getWidth(lua_State *L)
35 {
36 CompressedData *t = luax_checkcompresseddata(L, 1);
37 int miplevel = luaL_optinteger(L, 2, 1);
38 int width = 0;
39 try
40 {
41 width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);
42 }
43 catch (love::Exception &e)
44 {
45 return luaL_error(L, "%s", e.what());
46 }
47 lua_pushinteger(L, width);
48 return 1;
49 }
50
51 int w_CompressedData_getHeight(lua_State *L)
52 {
53 CompressedData *t = luax_checkcompresseddata(L, 1);
54 int miplevel = luaL_optinteger(L, 2, 1);
55 int height = 0;
56 try
57 {
58 height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);
59 }
60 catch (love::Exception &e)
61 {
62 return luaL_error(L, "%s", e.what());
63 }
64 lua_pushinteger(L, height);
65 return 1;
66 }
67
68 int w_CompressedData_getDimensions(lua_State *L)
69 {
70 CompressedData *t = luax_checkcompresseddata(L, 1);
71 int miplevel = luaL_optinteger(L, 2, 1);
72 int width = 0, height = 0;
73 try
74 {
75 width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);
76 height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);
77 }
78 catch (love::Exception &e)
79 {
80 return luaL_error(L, "%s", e.what());
81 }
82 lua_pushinteger(L, width);
83 lua_pushinteger(L, height);
84 return 2;
85 }
86
87 int w_CompressedData_getNumMipmaps(lua_State *L)
88 {
89 CompressedData *t = luax_checkcompresseddata(L, 1);
90 lua_pushinteger(L, t->getNumMipmaps());
91 return 1;
92 }
93
94 int w_CompressedData_getType(lua_State *L)
95 {
96 CompressedData *t = luax_checkcompresseddata(L, 1);
97
98 image::CompressedData::TextureType type = t->getType();
99 const char *str;
100
101 if (image::CompressedData::getConstant(type, str))
102 lua_pushstring(L, str);
103 else
104 lua_pushstring(L, "unknown");
105
106 return 1;
107 }
108
109 static const luaL_Reg functions[] =
110 {
111 // Data
112 { "getPointer", w_Data_getPointer },
113 { "getSize", w_Data_getSize },
114
115 { "getWidth", w_CompressedData_getWidth },
116 { "getHeight", w_CompressedData_getHeight },
117 { "getDimensions", w_CompressedData_getDimensions },
118 { "getNumMipmaps", w_CompressedData_getNumMipmaps },
119 { "getType", w_CompressedData_getType },
120 { 0, 0 },
121 };
122
123 extern "C" int luaopen_compresseddata(lua_State *L)
124 {
125 return luax_register_type(L, "CompressedData", functions);
126 }
127
128 } // image
129 } // love