mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
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.
This commit is contained in:
@@ -411,14 +411,18 @@ int w_Shader_send(lua_State *L)
|
|||||||
|
|
||||||
const Shader::UniformInfo *info = shader->getUniformInfo(name);
|
const Shader::UniformInfo *info = shader->getUniformInfo(name);
|
||||||
if (info == nullptr)
|
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, 3, Data::type))
|
||||||
|
w_Shader_sendData(L, 3, shader, info, false);
|
||||||
if (luax_istype(L, startidx, Data::type))
|
|
||||||
return w_Shader_sendData(L, startidx, shader, info, false);
|
|
||||||
else
|
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)
|
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);
|
const Shader::UniformInfo *info = shader->getUniformInfo(name);
|
||||||
if (info == nullptr)
|
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)
|
if (info->baseType != Shader::UNIFORM_FLOAT || info->components < 3)
|
||||||
return luaL_error(L, "sendColor can only be used on vec3 or vec4 uniforms.");
|
return luaL_error(L, "sendColor can only be used on vec3 or vec4 uniforms.");
|
||||||
|
|
||||||
if (luax_istype(L, 3, Data::type))
|
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
|
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)
|
int w_Shader_hasUniform(lua_State *L)
|
||||||
|
|||||||
Reference in New Issue
Block a user