Commit dc4ae86d by Nicolas Capens

Reduce math function duplication.

Change-Id: If0fe05eff397c8d88753fb2b1a1852722c73602e Reviewed-on: https://swiftshader-review.googlesource.com/4979Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 7155963e
...@@ -174,6 +174,11 @@ namespace sw ...@@ -174,6 +174,11 @@ namespace sw
return x; return x;
} }
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
inline int ceilPow2(int x) inline int ceilPow2(int x)
{ {
int i = 1; int i = 1;
......
...@@ -44,16 +44,8 @@ inline unsigned int ceilPow2(unsigned int x) ...@@ -44,16 +44,8 @@ inline unsigned int ceilPow2(unsigned int x)
return x; return x;
} }
template<typename T, typename MIN, typename MAX> using sw::clamp;
inline T clamp(T x, MIN min, MAX max) using sw::clamp01;
{
return x < min ? min : (x > max ? max : x);
}
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
template<const int n> template<const int n>
inline unsigned int unorm(float x) inline unsigned int unorm(float x)
......
...@@ -44,16 +44,8 @@ inline unsigned int ceilPow2(unsigned int x) ...@@ -44,16 +44,8 @@ inline unsigned int ceilPow2(unsigned int x)
return x; return x;
} }
template<typename T, typename MIN, typename MAX> using sw::clamp;
inline T clamp(T x, MIN min, MAX max) using sw::clamp01;
{
return x < min ? min : (x > max ? max : x);
}
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
template<const int n> template<const int n>
inline unsigned int unorm(float x) inline unsigned int unorm(float x)
......
...@@ -44,24 +44,9 @@ inline unsigned int ceilPow2(unsigned int x) ...@@ -44,24 +44,9 @@ inline unsigned int ceilPow2(unsigned int x)
return x; return x;
} }
template<typename T, typename MIN, typename MAX> using sw::swap;
inline T clamp(T x, MIN min, MAX max) using sw::clamp;
{ using sw::clamp01;
return x < min ? min : (x > max ? max : x);
}
template<class T>
inline void swap(T &a, T &b)
{
T t = a;
a = b;
b = t;
}
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
template<const int n> template<const int n>
inline unsigned int unorm(float x) inline unsigned int unorm(float x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment