MCPcopy Create free account
hub / github.com/defold/defold / LuaSetTextureData

Function LuaSetTextureData

engine/gui/src/gui_script.cpp:2318–2356  ·  view source on GitHub ↗

set the buffer data for a texture * Set the texture buffer data for a dynamically created texture. * * @name gui.set_texture_data * @param texture [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<

Source from the content-addressed store, hash-verified

2316 * ```
2317 */
2318 static int LuaSetTextureData(lua_State* L)
2319 {
2320 int top = lua_gettop(L);
2321 (void) top;
2322
2323 const dmhash_t name = dmScript::CheckHashOrString(L, 1);
2324 int width = luaL_checkinteger(L, 2);
2325 int height = luaL_checkinteger(L, 3);
2326 const char* type_str = luaL_checkstring(L, 4);
2327 size_t buffer_size;
2328 luaL_checktype(L, 5, LUA_TSTRING);
2329 const char* buffer = lua_tolstring(L, 5, &buffer_size);
2330 Scene* scene = GuiScriptInstance_Check(L);
2331
2332 bool flip = false;
2333 if (top > 5) {
2334 luaL_checktype(L, 6, LUA_TBOOLEAN);
2335 flip = (bool)lua_toboolean(L, 6);
2336 }
2337
2338 // If we don't flip the image, it will appear upside down using OGL texture coords,
2339 // since we will upload the data top-row first instead of bottom-row first.
2340 // This is actually what users expect the flip switch to mean, so we invert the
2341 // flip here so the default case will be to "correctly" flip the image.
2342 flip = !flip;
2343
2344 dmImage::Type type = ToImageType(L, type_str);
2345 dmImage::CompressionType compression_type = ToImageCompressionType(type_str);
2346 Result r = SetDynamicTextureData(scene, name, width, height, type, compression_type, flip, buffer, buffer_size);
2347 if (r == RESULT_OK) {
2348 lua_pushboolean(L, 1);
2349 } else {
2350 dmLogWarning("Failed to set texture data (%d)", r);
2351 lua_pushboolean(L, 0);
2352 }
2353
2354 assert(top + 1 == lua_gettop(L));
2355 return 1;
2356 }
2357
2358 /*# gets the assigned node material
2359 * Returns the material of a node.

Callers

nothing calls this directly

Calls 12

lua_gettopFunction · 0.85
CheckHashOrStringFunction · 0.85
luaL_checkintegerFunction · 0.85
luaL_checktypeFunction · 0.85
lua_tolstringFunction · 0.85
GuiScriptInstance_CheckFunction · 0.85
lua_tobooleanFunction · 0.85
ToImageTypeFunction · 0.85
ToImageCompressionTypeFunction · 0.85
lua_pushbooleanFunction · 0.85
SetDynamicTextureDataFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected