From b95788c1041fa098eafab1f20280df88ba1740c4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 27 Feb 2020 20:19:55 -0400 Subject: [PATCH] Shader:send now returns false if the uniform doesn't exist It also returns false if the uniform exists but was optimized out by the shader compiler. Previously it would cause a Lua error in both situations. --- src/modules/graphics/wrap_Shader.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/modules/graphics/wrap_Shader.cpp b/src/modules/graphics/wrap_Shader.cpp index 2c34727b0..44badcb0d 100644 --- a/src/modules/graphics/wrap_Shader.cpp +++ b/src/modules/graphics/wrap_Shader.cpp @@ -411,14 +411,18 @@ int w_Shader_send(lua_State *L) const Shader::UniformInfo *info = shader->getUniformInfo(name); if (info == nullptr) - return luaL_error(L, "Shader uniform '%s' does not exist.\nA common error is to define but not use the variable.", name); + { + luax_pushboolean(L, false); + return 1; + } - int startidx = 3; - - if (luax_istype(L, startidx, Data::type)) - return w_Shader_sendData(L, startidx, shader, info, false); + if (luax_istype(L, 3, Data::type)) + w_Shader_sendData(L, 3, shader, info, false); else - return w_Shader_sendLuaValues(L, startidx, shader, info, name); + w_Shader_sendLuaValues(L, 3, shader, info, name); + + luax_pushboolean(L, true); + return 1; } int w_Shader_sendColors(lua_State *L) @@ -428,15 +432,21 @@ int w_Shader_sendColors(lua_State *L) const Shader::UniformInfo *info = shader->getUniformInfo(name); if (info == nullptr) - return luaL_error(L, "Shader uniform '%s' does not exist.\nA common error is to define but not use the variable.", name); + { + luax_pushboolean(L, false); + return 1; + } if (info->baseType != Shader::UNIFORM_FLOAT || info->components < 3) return luaL_error(L, "sendColor can only be used on vec3 or vec4 uniforms."); if (luax_istype(L, 3, Data::type)) - return w_Shader_sendData(L, 3, shader, info, true); + w_Shader_sendData(L, 3, shader, info, true); else - return w_Shader_sendFloats(L, 3, shader, info, true); + w_Shader_sendFloats(L, 3, shader, info, true); + + luax_pushboolean(L, true); + return 1; } int w_Shader_hasUniform(lua_State *L)