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

Function RenderScript_Clear

engine/render/src/render/render_script.cpp:1588–1643  ·  view source on GitHub ↗

clears the active render target * Clear buffers in the currently enabled render target with specified value. If the render target has been created with multiple * color attachments, all buffers will be cleared with the same value. * * @name render.clear * @param buffers [type:table] table with keys specifying which buffers to clear and values set to clear values. Available

Source from the content-addressed store, hash-verified

1586 * ```
1587 */
1588 int RenderScript_Clear(lua_State* L)
1589 {
1590 RenderScriptInstance* i = RenderScriptInstance_Check(L);
1591 luaL_checktype(L, 1, LUA_TTABLE);
1592
1593 int top = lua_gettop(L);
1594 (void)top;
1595
1596 uint32_t flags = 0;
1597
1598 dmVMath::Vector4 color(0.0f, 0.0f, 0.0f, 0.0f);
1599 float depth = 0.0f;
1600 uint32_t stencil = 0;
1601
1602 lua_pushnil(L);
1603 while (lua_next(L, 1))
1604 {
1605 uint32_t buffer_type = luaL_checkinteger(L, -2);
1606 flags |= buffer_type;
1607
1608 if (buffer_type == dmGraphics::BUFFER_TYPE_COLOR0_BIT)
1609 {
1610 color = *dmScript::CheckVector4(L, -1);
1611 }
1612 else if (buffer_type == dmGraphics::BUFFER_TYPE_DEPTH_BIT)
1613 {
1614 depth = (float) luaL_checkinteger(L, -1);
1615 }
1616 else if (buffer_type == dmGraphics::BUFFER_TYPE_STENCIL_BIT)
1617 {
1618 stencil = (uint32_t) luaL_checkinteger(L, -1);
1619 }
1620 else
1621 {
1622 lua_pop(L, 2);
1623 assert(top == lua_gettop(L));
1624 return luaL_error(L, "Unknown buffer type supplied to %s.clear.", RENDER_SCRIPT_LIB_NAME);
1625 }
1626 lua_pop(L, 1);
1627 }
1628 assert(top == lua_gettop(L));
1629
1630 uint32_t clear_color = 0;
1631 clear_color |= ((uint8_t)(color.getX() * 255.0f)) << 0;
1632 clear_color |= ((uint8_t)(color.getY() * 255.0f)) << 8;
1633 clear_color |= ((uint8_t)(color.getZ() * 255.0f)) << 16;
1634 clear_color |= ((uint8_t)(color.getW() * 255.0f)) << 24;
1635
1636 union float_to_uint32_t {float f; uint32_t i;};
1637 float_to_uint32_t ftoi;
1638 ftoi.f = depth;
1639 if (InsertCommand(i, Command(COMMAND_TYPE_CLEAR, flags, clear_color, ftoi.i, stencil)))
1640 return 0;
1641 else
1642 return luaL_error(L, "Command buffer is full (%d).", i->m_CommandBuffer.Capacity());
1643 }
1644
1645 // Take a Lua registry reference to prevent the constant buffer

Callers

nothing calls this directly

Calls 15

luaL_checktypeFunction · 0.85
lua_gettopFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
luaL_checkintegerFunction · 0.85
CheckVector4Function · 0.85
luaL_errorFunction · 0.85
InsertCommandFunction · 0.85
CommandClass · 0.70
assertFunction · 0.50
getXMethod · 0.45

Tested by

no test coverage detected