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

Function RenderScript_EnableMaterial

engine/render/src/render/render_script.cpp:2731–2764  ·  view source on GitHub ↗

enables a material * If another material was already enabled, it will be automatically disabled * and the specified material is used instead. * * The name of the material must be specified in the ".render" resource set * in the "game.project" setting. * * @name render.enable_material * @param material_id [type:string|hash] material id to enable * @examp

Source from the content-addressed store, hash-verified

2729 * ```
2730 */
2731 static int RenderScript_EnableMaterial(lua_State* L)
2732 {
2733 DM_LUA_STACK_CHECK(L, 0);
2734
2735 RenderScriptInstance* i = RenderScriptInstance_Check(L);
2736 if (!lua_isnil(L, 1))
2737 {
2738 dmhash_t material_id = dmScript::CheckHashOrString(L, 1);
2739 RenderResource* render_resource = i->m_RenderResources.Get(material_id);
2740
2741 if (render_resource == 0x0)
2742 {
2743 return DM_LUA_ERROR("Could not find material '%s'", dmHashReverseSafe64(material_id));
2744 }
2745 else if (render_resource->m_Type != RENDER_RESOURCE_TYPE_MATERIAL)
2746 {
2747 return DM_LUA_ERROR("Render resource is not a material.");
2748 }
2749
2750 HMaterial material = (HMaterial) render_resource->m_Resource;
2751 if (InsertCommand(i, Command(COMMAND_TYPE_ENABLE_MATERIAL, (uint64_t)material)))
2752 {
2753 return 0;
2754 }
2755 else
2756 {
2757 return DM_LUA_ERROR("Command buffer is full (%d).", i->m_CommandBuffer.Capacity());
2758 }
2759 }
2760 else
2761 {
2762 return DM_LUA_ERROR("%s.enable_material was supplied nil as material.", RENDER_SCRIPT_LIB_NAME);
2763 }
2764 }
2765
2766 /*# disables the currently enabled material
2767 * If a material is currently enabled, disable it.

Callers

nothing calls this directly

Calls 7

CheckHashOrStringFunction · 0.85
dmHashReverseSafe64Function · 0.85
InsertCommandFunction · 0.85
CommandClass · 0.70
GetMethod · 0.45
CapacityMethod · 0.45

Tested by

no test coverage detected