Make random number usage platform independent
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuVectorUtil.hpp
index e21fb2e..0797463 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "tcuDefs.hpp"
 #include "tcuVector.hpp"
+#include "deRandom.hpp"
 #include "deMeta.hpp"
 #include "deMath.h"
 #include "deInt32.h"
@@ -37,7 +38,7 @@ namespace tcu
 
 static const float PI = 3.141592653589793238f;
 
-#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_WIN32 && DE_COMPILER == DE_COMPILER_CLANG)
+#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_QNX) || (DE_OS == DE_OS_WIN32 && DE_COMPILER == DE_COMPILER_CLANG)
 inline float abs                       (float f) { return deFloatAbs(f); }
 #endif
 
@@ -368,6 +369,32 @@ static inline Vector<T, Size> absDiff (const Vector<T, Size>& a, const Vector<T,
        return res;
 }
 
+template<typename T, int Size>
+inline tcu::Vector<T, Size> randomVector (de::Random& rnd, const tcu::Vector<T, Size>& minValue, const tcu::Vector<T, Size>& maxValue)
+{
+       tcu::Vector<T, Size> res;
+
+       for (int ndx = 0; ndx < Size; ndx++)
+               res[ndx] = de::randomScalar<T>(rnd, minValue[ndx], maxValue[ndx]);
+
+       return res;
+}
+
+inline Vector<float, 2> randomVec2 (de::Random& rnd)
+{
+       return randomVector<float, 2>(rnd, tcu::Vector<float, 2>(0.0f), tcu::Vector<float, 2>(1.0f));
+}
+
+inline Vector<float, 3> randomVec3 (de::Random& rnd)
+{
+       return randomVector<float, 3>(rnd, tcu::Vector<float, 3>(0.0f), tcu::Vector<float, 3>(1.0f));
+}
+
+inline Vector<float, 4> randomVec4 (de::Random& rnd)
+{
+       return randomVector<float, 4>(rnd, tcu::Vector<float, 4>(0.0f), tcu::Vector<float, 4>(1.0f));
+}
+
 // Macros for component-wise ops.
 
 #define TCU_DECLARE_VECTOR_UNARY_FUNC(FUNC_NAME, OP_NAME)      \