From 9762710b856ff8bc8113e0f3c3132e8db014670f Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 3 Apr 2016 19:01:27 -1000 Subject: [PATCH] Add color self-clamp --- include/zeus/CColor.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/zeus/CColor.hpp b/include/zeus/CColor.hpp index f803440..ab94f92 100644 --- a/include/zeus/CColor.hpp +++ b/include/zeus/CColor.hpp @@ -320,6 +320,17 @@ public: CColor toGrayscale() { return {sqrtF((r * r + g * g + b * b) / 3), a}; } + + /** + * @brief Clamps to GPU-safe RGBA values [0,1] + */ + void Clamp() + { + this->r = std::min(1.f, std::max(0.f, this->r)); + this->g = std::min(1.f, std::max(0.f, this->g)); + this->b = std::min(1.f, std::max(0.f, this->b)); + this->a = std::min(1.f, std::max(0.f, this->a)); + } }; static inline CColor operator+(float lhs, const CColor& rhs)