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
| 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. |
nothing calls this directly
no test coverage detected