Fix integer overflow for bigger textures
This commit is contained in:
parent
3e4ee48bf1
commit
779618e45d
1 changed files with 6 additions and 2 deletions
|
@ -111,6 +111,10 @@ struct Vec2 {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T> int sign(T val) {
|
||||||
|
return (T(0) < val) - (val < T(0));
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<char>& getGradientBuffer(size_t size) {
|
std::vector<char>& getGradientBuffer(size_t size) {
|
||||||
static std::vector<char> buffer;
|
static std::vector<char> buffer;
|
||||||
if (buffer.size() < size)
|
if (buffer.size() < size)
|
||||||
|
@ -469,10 +473,10 @@ void renderRectangleGradient(bool interlaced,
|
||||||
|
|
||||||
// check, if the point (x, y) is left or right of the vectors
|
// check, if the point (x, y) is left or right of the vectors
|
||||||
// 'a' and 'b'. if the point is on the same side for both 'a' and
|
// 'a' and 'b'. if the point is on the same side for both 'a' and
|
||||||
// 'b' (a.cross() is equal to b.cross()) then use the y_gradient,
|
// 'b' (a.cross() is equal to b.cross()) then use the x_gradient,
|
||||||
// otherwise use y_gradient
|
// otherwise use y_gradient
|
||||||
|
|
||||||
if ((a.cross(x, y) * b.cross(x, b.y + y)) < 0) {
|
if (sign(a.cross(x, y)) * sign(b.cross(x, b.y + y)) < 0) {
|
||||||
rgba[i] = x_gradient[x];
|
rgba[i] = x_gradient[x];
|
||||||
} else {
|
} else {
|
||||||
rgba[i] = y_gradient[y];
|
rgba[i] = y_gradient[y];
|
||||||
|
|
Loading…
Reference in a new issue