diff options
Diffstat (limited to 'src/mesa/main/macros.h')
-rw-r--r-- | src/mesa/main/macros.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index 4bb17d8d174..880c6564e18 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -184,6 +184,28 @@ static inline GLfloat UINT_AS_FLT(GLuint u) return tmp.f; } +/** + * Convert a floating point value to an unsigned fixed point value. + * + * \param frac_bits The number of bits used to store the fractional part. + */ +static INLINE uint32_t +U_FIXED(float value, uint32_t frac_bits) +{ + value *= (1 << frac_bits); + return value < 0 ? 0 : value; +} + +/** + * Convert a floating point value to an signed fixed point value. + * + * \param frac_bits The number of bits used to store the fractional part. + */ +static INLINE uint32_t +S_FIXED(float value, uint32_t frac_bits) +{ + return value * (1 << frac_bits); +} /*@}*/ |