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

Function RenderScript_RenderTarget

engine/render/src/render/render_script.cpp:901–1075  ·  view source on GitHub ↗

creates a new render target * Creates a new render target according to the supplied * specification table. * * The table should contain keys specifying which buffers should be created * with what parameters. Each buffer key should have a table value consisting * of parameters. The following parameter keys are available: * * Key | Values

Source from the content-addressed store, hash-verified

899 *
900 */
901 int RenderScript_RenderTarget(lua_State* L)
902 {
903 DM_LUA_STACK_CHECK(L, 1);
904
905 RenderScriptInstance* i = RenderScriptInstance_Check(L);
906
907 // Legacy support
908 int table_index = 2;
909 if (lua_istable(L, 1))
910 {
911 table_index = 1;
912 }
913
914 const char* required_keys[] = { "format", "width", "height" };
915 const int required_keys_count = sizeof(required_keys) / sizeof(required_keys[0]);
916 uint32_t buffer_type_flags = 0;
917 luaL_checktype(L, table_index, LUA_TTABLE);
918
919 dmGraphics::RenderTargetCreationParams params = {};
920
921 lua_pushnil(L); // [-0,+1 = 1] first key
922 while (lua_next(L, table_index)) // [-1,+2 = 2] pop key, push key-value (buffer_type and table)
923 {
924 dmGraphics::BufferType buffer_type = CheckBufferType(L, -2);
925 buffer_type_flags |= (uint32_t) buffer_type;
926 dmGraphics::TextureParams* p = 0;
927 dmGraphics::TextureCreationParams* cp = 0;
928 lua_Integer width = 0;
929 lua_Integer height = 0;
930
931 if (dmGraphics::IsColorBufferType(buffer_type))
932 {
933 uint32_t color_index = dmGraphics::GetBufferTypeIndex(buffer_type);
934 p = &params.m_ColorBufferParams[color_index];
935 cp = &params.m_ColorBufferCreationParams[color_index];
936
937 params.m_ColorBufferLoadOps[color_index] = dmGraphics::ATTACHMENT_OP_DONT_CARE;
938 params.m_ColorBufferStoreOps[color_index] = dmGraphics::ATTACHMENT_OP_STORE;
939 }
940 else if (buffer_type == dmGraphics::BUFFER_TYPE_DEPTH_BIT)
941 {
942 p = &params.m_DepthBufferParams;
943 cp = &params.m_DepthBufferCreationParams;
944 }
945 else if (buffer_type == dmGraphics::BUFFER_TYPE_STENCIL_BIT)
946 {
947 p = &params.m_StencilBufferParams;
948 cp = &params.m_StencilBufferCreationParams;
949 }
950 else
951 {
952 lua_pop(L, 2); // [-2,+0 = 0] pop key-value pair
953 return DM_LUA_ERROR("Invalid buffer type supplied to %s.render_target: (%d)", RENDER_SCRIPT_LIB_NAME, (uint32_t) buffer_type);
954 }
955
956 luaL_checktype(L, -1, LUA_TTABLE);
957
958 // Verify that required keys are supplied

Callers

nothing calls this directly

Calls 15

luaL_checktypeFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
CheckBufferTypeFunction · 0.85
IsColorBufferTypeFunction · 0.85
GetBufferTypeIndexFunction · 0.85
lua_pushstringFunction · 0.85
lua_gettableFunction · 0.85
luaL_checkintegerFunction · 0.85
CheckRenderTargetSizeFunction · 0.85
NewRenderTargetFunction · 0.85

Tested by

no test coverage detected