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

Function SetMaterialConstant

engine/gamesys/src/gamesys/scripts/script_material.cpp:825–858  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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 {

Callers 7

Material_SetConstantsFunction · 0.70
CompMeshSetPropertyFunction · 0.50
CompLabelSetPropertyFunction · 0.50
CompSpriteSetPropertyFunction · 0.50
CompModelSetPropertyFunction · 0.50
CompTileGridSetPropertyFunction · 0.50

Calls 13

lua_gettopFunction · 0.85
luaL_errorFunction · 0.85
dmHashReverseSafe64Function · 0.85
luaL_checktypeFunction · 0.85
lua_pushvalueFunction · 0.85
GetConstantTypeFunction · 0.85
GetConstantValuesFromLuaFunction · 0.85
SetSizeMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected