mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Clamp all color arguments to [0, 1] in cases where values outside that range don't make sense (fixed-point color values & sRGB colors). Closes issue #1315.
--HG-- branch : minor
This commit is contained in:
@@ -947,7 +947,7 @@ bool Font::hasGlyph(uint32 glyph) const
|
||||
if (r->hasGlyph(glyph))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -955,7 +955,7 @@ bool Font::hasGlyphs(const std::string &text) const
|
||||
{
|
||||
if (text.size() == 0)
|
||||
return false;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
|
||||
@@ -973,7 +973,7 @@ bool Font::hasGlyphs(const std::string &text) const
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -984,9 +984,9 @@ void Font::setFallbacks(const std::vector<Font *> &fallbacks)
|
||||
if (f->rasterizers[0]->getDataType() != this->rasterizers[0]->getDataType())
|
||||
throw love::Exception("Font fallbacks must be of the same font type.");
|
||||
}
|
||||
|
||||
|
||||
rasterizers.resize(1);
|
||||
|
||||
|
||||
// NOTE: this won't invalidate already-rasterized glyphs.
|
||||
for (const Font *f : fallbacks)
|
||||
rasterizers.push_back(f->rasterizers[0]);
|
||||
|
||||
@@ -2445,10 +2445,10 @@ int w_points(lua_State *L)
|
||||
positions[i].x = luax_checkfloat(L, -6);
|
||||
positions[i].y = luax_checkfloat(L, -5);
|
||||
|
||||
colors[i].r = (float) luaL_optnumber(L, -4, 1.0);
|
||||
colors[i].g = (float) luaL_optnumber(L, -3, 1.0);
|
||||
colors[i].b = (float) luaL_optnumber(L, -2, 1.0);
|
||||
colors[i].a = (float) luaL_optnumber(L, -1, 1.0);
|
||||
colors[i].r = (float) luax_optnumberclamped01(L, -4, 1.0);
|
||||
colors[i].g = (float) luax_optnumberclamped01(L, -3, 1.0);
|
||||
colors[i].b = (float) luax_optnumberclamped01(L, -2, 1.0);
|
||||
colors[i].a = (float) luax_optnumberclamped01(L, -1, 1.0);
|
||||
|
||||
lua_pop(L, 7);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ static inline size_t writeUnorm8Data(lua_State *L, int startidx, int components,
|
||||
uint8 *componentdata = (uint8 *) data;
|
||||
|
||||
for (int i = 0; i < components; i++)
|
||||
componentdata[i] = (uint8) (luaL_optnumber(L, startidx + i, 1.0) * 255.0);
|
||||
componentdata[i] = (uint8) (luax_optnumberclamped01(L, startidx + i, 1.0) * 255.0);
|
||||
|
||||
return sizeof(uint8) * components;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ static inline size_t writeUnorm16Data(lua_State *L, int startidx, int components
|
||||
uint16 *componentdata = (uint16 *) data;
|
||||
|
||||
for (int i = 0; i < components; i++)
|
||||
componentdata[i] = (uint16) (luaL_optnumber(L, startidx + i, 1.0) * 65535.0);
|
||||
componentdata[i] = (uint16) (luax_optnumberclamped01(L, startidx + i, 1.0) * 65535.0);
|
||||
|
||||
return sizeof(uint16) * components;
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ static int _getCount(lua_State *L, int startidx, const Shader::UniformInfo *info
|
||||
return std::min(std::max(lua_gettop(L) - startidx + 1, 1), info->count);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename luaT, luaT (*checknum)(lua_State *, int)>
|
||||
static void _updateNumbers(lua_State *L, int startidx, T *values, int components, int count)
|
||||
{
|
||||
if (components == 1)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
values[i] = (T) luaL_checknumber(L, startidx + i);
|
||||
values[i] = (T) checknum(L, startidx + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -69,7 +69,7 @@ static void _updateNumbers(lua_State *L, int startidx, T *values, int components
|
||||
for (int k = 1; k <= components; k++)
|
||||
{
|
||||
lua_rawgeti(L, startidx + i, k);
|
||||
values[i * components + k - 1] = (T) luaL_checknumber(L, -1);
|
||||
values[i * components + k - 1] = (T) checknum(L, -1);
|
||||
}
|
||||
|
||||
lua_pop(L, components);
|
||||
@@ -83,7 +83,10 @@ int w_Shader_sendFloats(lua_State *L, int startidx, Shader *shader, const Shader
|
||||
int components = info->components;
|
||||
float *values = info->floats;
|
||||
|
||||
_updateNumbers(L, startidx, values, components, count);
|
||||
if (colors)
|
||||
_updateNumbers<float, lua_Number, luax_checknumberclamped01>(L, startidx, values, components, count);
|
||||
else
|
||||
_updateNumbers<float, lua_Number, luaL_checknumber>(L, startidx, values, components, count);
|
||||
|
||||
if (colors && graphics::isGammaCorrect())
|
||||
{
|
||||
@@ -104,7 +107,7 @@ int w_Shader_sendFloats(lua_State *L, int startidx, Shader *shader, const Shader
|
||||
int w_Shader_sendInts(lua_State *L, int startidx, Shader *shader, const Shader::UniformInfo *info)
|
||||
{
|
||||
int count = _getCount(L, startidx, info);
|
||||
_updateNumbers(L, startidx, info->ints, info->components, count);
|
||||
_updateNumbers<int, lua_Integer, luaL_checkinteger>(L, startidx, info->ints, info->components, count);
|
||||
luax_catchexcept(L, [&]() { shader->updateUniform(info, count); });
|
||||
return 0;
|
||||
}
|
||||
@@ -112,7 +115,7 @@ int w_Shader_sendInts(lua_State *L, int startidx, Shader *shader, const Shader::
|
||||
int w_Shader_sendUnsignedInts(lua_State *L, int startidx, Shader *shader, const Shader::UniformInfo *info)
|
||||
{
|
||||
int count = _getCount(L, startidx, info);
|
||||
_updateNumbers(L, startidx, info->uints, info->components, count);
|
||||
_updateNumbers<unsigned int, lua_Integer, luaL_checkinteger>(L, startidx, info->uints, info->components, count);
|
||||
luax_catchexcept(L, [&]() { shader->updateUniform(info, count); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user