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

Function GetBuffer

engine/gamesys/src/gamesys/scripts/script_resource.cpp:3287–3307  ·  view source on GitHub ↗

get resource buffer * gets the buffer from a resource * * @name resource.get_buffer * * @param path [type:hash|string] The path to the resource * @return buffer [type:buffer] The resource buffer * * @examples * How to get the data from a buffer * * ```lua * function init(self) * * local res_path = go.get("#mesh", "vertices") * local buf = resource.get_buffer(res_path) *

Source from the content-addressed store, hash-verified

3285 * ```
3286 */
3287static int GetBuffer(lua_State* L)
3288{
3289 int top = lua_gettop(L);
3290 dmhash_t path_hash = dmScript::CheckHashOrString(L, 1);
3291
3292 void* resource = CheckResource(L, g_ResourceModule.m_Factory, path_hash, "bufferc");
3293
3294 dmGameSystem::BufferResource* buffer_resource = (dmGameSystem::BufferResource*)resource;
3295
3296 if (!dmBuffer::IsBufferValid(buffer_resource->m_Buffer))
3297 {
3298 return luaL_error(L, "The buffer handle is invalid");
3299 }
3300
3301 dmResource::IncRef(g_ResourceModule.m_Factory, buffer_resource);
3302 dmScript::LuaHBuffer luabuf(g_ResourceModule.m_Factory, (void*)buffer_resource);
3303 PushBuffer(L, luabuf);
3304
3305 assert(top + 1 == lua_gettop(L));
3306 return 1;
3307}
3308
3309/*# set resource buffer
3310 * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object

Callers 5

RenderBatchFunction · 0.50
RenderBatchWorldVSFunction · 0.50
RenderBatchFunction · 0.50
RenderBatchFunction · 0.50

Calls 8

lua_gettopFunction · 0.85
CheckHashOrStringFunction · 0.85
CheckResourceFunction · 0.85
IsBufferValidFunction · 0.85
luaL_errorFunction · 0.85
IncRefFunction · 0.85
PushBufferFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected