create new texture * Dynamically create a new texture. * * @name gui.new_texture * @param texture_id [type:string|hash] texture id * @param width [type:number] texture width * @param height [type:number] texture height * @param type [type:string|constant] texture type * * - `"rgb"` - RGB * - `"rgba"` - RGBA * - `"l"` - LUMINANCE
| 2185 | * ``` |
| 2186 | */ |
| 2187 | static int LuaNewTexture(lua_State* L) |
| 2188 | { |
| 2189 | int top = lua_gettop(L); |
| 2190 | (void) top; |
| 2191 | |
| 2192 | const dmhash_t name = dmScript::CheckHashOrString(L, 1); |
| 2193 | |
| 2194 | int width = luaL_checkinteger(L, 2); |
| 2195 | int height = luaL_checkinteger(L, 3); |
| 2196 | const char* type_str = luaL_checkstring(L, 4); |
| 2197 | size_t buffer_size; |
| 2198 | luaL_checktype(L, 5, LUA_TSTRING); |
| 2199 | const char* buffer = lua_tolstring(L, 5, &buffer_size); |
| 2200 | Scene* scene = GuiScriptInstance_Check(L); |
| 2201 | |
| 2202 | bool flip = false; |
| 2203 | if (top > 5) |
| 2204 | { |
| 2205 | luaL_checktype(L, 6, LUA_TBOOLEAN); |
| 2206 | flip = (bool)lua_toboolean(L, 6); |
| 2207 | } |
| 2208 | |
| 2209 | // If we don't flip the image, it will appear upside down using OGL texture coords, |
| 2210 | // since we will upload the data top-row first instead of bottom-row first. |
| 2211 | // This is actually what users expect the flip switch to mean, so we invert the |
| 2212 | // flip here so the default case will be to "correctly" flip the image. |
| 2213 | flip = !flip; |
| 2214 | |
| 2215 | dmImage::Type type = ToImageType(L, type_str); |
| 2216 | dmImage::CompressionType compression_type = ToImageCompressionType(type_str); |
| 2217 | Result r = NewDynamicTexture(scene, name, width, height, type, compression_type, flip, buffer, buffer_size); |
| 2218 | |
| 2219 | if (r == RESULT_OK) |
| 2220 | { |
| 2221 | lua_pushboolean(L, 1); |
| 2222 | lua_pushnil(L); |
| 2223 | } |
| 2224 | else |
| 2225 | { |
| 2226 | lua_pushboolean(L, 0); |
| 2227 | lua_pushnumber(L, r); |
| 2228 | } |
| 2229 | |
| 2230 | assert(top + 2 == lua_gettop(L)); |
| 2231 | return 2; |
| 2232 | } |
| 2233 | |
| 2234 | /*# delete texture |
| 2235 | * Delete a dynamically created texture. |
nothing calls this directly
no test coverage detected