sets shader constants in a material * Sets shader constants in a material, if the constants exist. * * @name material.set_constants * * @param path [type:hash|string] The path to the resource * @param constants [type:table] A table keyed by constant name with args tables as values. Constants can be partially updated. Supported entries: * * `type` * : [t
| 823 | * ``` |
| 824 | */ |
| 825 | static int SetMaterialConstant(lua_State* L, MaterialResource* material_res, dmhash_t name_hash, int args_index) |
| 826 | { |
| 827 | args_index = args_index < 0 ? lua_gettop(L) + args_index + 1 : args_index; |
| 828 | |
| 829 | dmRender::HConstant constant; |
| 830 | if (!dmRender::GetMaterialProgramConstant(material_res->m_Material, name_hash, constant)) |
| 831 | { |
| 832 | return luaL_error(L, "Material constant '%s' not found", dmHashReverseSafe64(name_hash)); |
| 833 | } |
| 834 | |
| 835 | luaL_checktype(L, args_index, LUA_TTABLE); |
| 836 | lua_pushvalue(L, args_index); |
| 837 | |
| 838 | dmRenderDDF::MaterialDesc::ConstantType type_from_value = dmRender::GetConstantType(constant); |
| 839 | |
| 840 | g_MaterialModule.m_ScratchValues.SetSize(0); |
| 841 | |
| 842 | GetConstantValuesFromLua(L, &type_from_value, &g_MaterialModule.m_ScratchValues); |
| 843 | |
| 844 | if (g_MaterialModule.m_ScratchValues.Size() != 0) |
| 845 | { |
| 846 | dmRender::SetMaterialProgramConstant(material_res->m_Material, name_hash, |
| 847 | g_MaterialModule.m_ScratchValues.Begin(), g_MaterialModule.m_ScratchValues.Size()); |
| 848 | } |
| 849 | |
| 850 | if (dmRender::GetConstantType(constant) != type_from_value) |
| 851 | { |
| 852 | dmRender::SetMaterialProgramConstantType(material_res->m_Material, name_hash, type_from_value); |
| 853 | } |
| 854 | |
| 855 | lua_pop(L, 1); |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int Material_SetConstants(lua_State* L) |
| 861 | { |
no test coverage detected