diff options
author | Kenneth Graunke <[email protected]> | 2013-07-07 18:44:12 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2013-10-13 00:10:44 -0700 |
commit | 67601da24c98a13a1a349b4e3df38ad10ff812bb (patch) | |
tree | 4ec599ed0a19cd43ce4e954960f9de946dbdafb2 /src/mesa/main/macros.h | |
parent | 1a82081db6e57eaa74f852ed8acb391a7f4c2ca6 (diff) |
mesa: Move U_FIXED/S_FIXED macros from i965 to macros.h.
These make it easy to convert a floating point value to a fixed point
numbers. The second parameter is the number of bits used for the
fractional part of the number.
It looks like core Mesa has similar functions already, but none that
allows an arbitrary number of fractional bits. The more generic version
is probably useful to everyone.
r600g apparently has an identical copy of the S_FIXED macro, but doesn't
include this file. I'm not sure what to do about that, so I'm just
going to leave it for now.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
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); +} /*@}*/ |