Browse Source

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.
Alex Szpakowski 5 years ago
parent
commit
b95788c104
1 changed files with 19 additions and 9 deletions
  1. 19 9
      src/modules/graphics/wrap_Shader.cpp

+ 19 - 9
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);
-
-	int startidx = 3;
+	{
+		luax_pushboolean(L, false);
+		return 1;
+	}
 
-	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)