sets shader constants in a compute program * Sets shader constants in a compute program, if the constants exist. * * @name compute.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
| 458 | * ``` |
| 459 | */ |
| 460 | static int SetComputeConstant(lua_State* L, ComputeResource* compute_res, dmhash_t name_hash, int args_index) |
| 461 | { |
| 462 | args_index = args_index < 0 ? lua_gettop(L) + args_index + 1 : args_index; |
| 463 | |
| 464 | dmRender::HConstant constant; |
| 465 | if (!dmRender::GetComputeProgramConstant(compute_res->m_Program, name_hash, constant)) |
| 466 | { |
| 467 | return luaL_error(L, "Compute program constant '%s' not found", dmHashReverseSafe64(name_hash)); |
| 468 | } |
| 469 | |
| 470 | luaL_checktype(L, args_index, LUA_TTABLE); |
| 471 | lua_pushvalue(L, args_index); |
| 472 | |
| 473 | g_ComputeModule.m_ScratchValues.SetSize(0); |
| 474 | |
| 475 | dmRenderDDF::MaterialDesc::ConstantType type_from_value = dmRender::GetConstantType(constant); |
| 476 | |
| 477 | GetConstantValuesFromLua(L, &type_from_value, &g_ComputeModule.m_ScratchValues); |
| 478 | |
| 479 | if (g_ComputeModule.m_ScratchValues.Size() != 0) |
| 480 | { |
| 481 | dmRender::SetComputeProgramConstant(compute_res->m_Program, name_hash, |
| 482 | g_ComputeModule.m_ScratchValues.Begin(), g_ComputeModule.m_ScratchValues.Size()); |
| 483 | } |
| 484 | |
| 485 | if (dmRender::GetConstantType(constant) != type_from_value) |
| 486 | { |
| 487 | dmRender::SetComputeProgramConstantType(compute_res->m_Program, name_hash, type_from_value); |
| 488 | } |
| 489 | |
| 490 | lua_pop(L, 1); |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int Compute_SetConstants(lua_State* L) |
| 495 | { |
no test coverage detected