1 #define GLM_ENABLE_EXPERIMENTAL
2 #include <glm/gtx/component_wise.hpp>
3 #include <glm/gtc/type_precision.hpp>
4 #include <glm/gtc/epsilon.hpp>
5 #include <glm/gtc/constants.hpp>
6 #include <limits>
7
8 namespace compNormalize
9 {
run()10 int run()
11 {
12 int Error(0);
13
14 {
15 glm::vec4 const A = glm::compNormalize<float>(glm::u8vec4(0, 127, 128, 255));
16
17 Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
18 Error += A.y < 0.5f ? 0 : 1;
19 Error += A.z > 0.5f ? 0 : 1;
20 Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
21 }
22
23 {
24 glm::vec4 const A = glm::compNormalize<float>(glm::i8vec4(-128, -1, 0, 127));
25
26 Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
27 Error += A.y < 0.0f ? 0 : 1;
28 Error += A.z > 0.0f ? 0 : 1;
29 Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
30 }
31
32 {
33 glm::vec4 const A = glm::compNormalize<float>(glm::u16vec4(
34 std::numeric_limits<glm::u16>::min(),
35 (std::numeric_limits<glm::u16>::max() >> 1) + 0,
36 (std::numeric_limits<glm::u16>::max() >> 1) + 1,
37 std::numeric_limits<glm::u16>::max()));
38
39 Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
40 Error += A.y < 0.5f ? 0 : 1;
41 Error += A.z > 0.5f ? 0 : 1;
42 Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
43 }
44
45 {
46 glm::vec4 const A = glm::compNormalize<float>(glm::i16vec4(
47 std::numeric_limits<glm::i16>::min(),
48 static_cast<glm::i16>(-1),
49 static_cast<glm::i16>(0),
50 std::numeric_limits<glm::i16>::max()));
51
52 Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
53 Error += A.y < 0.0f ? 0 : 1;
54 Error += A.z > 0.0f ? 0 : 1;
55 Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
56 }
57
58 return Error;
59 }
60 }//namespace compNormalize
61
62 namespace compScale
63 {
run()64 int run()
65 {
66 int Error(0);
67
68 {
69 glm::u8vec4 const A = glm::compScale<glm::u8>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
70
71 Error += A.x == std::numeric_limits<glm::u8>::min() ? 0 : 1;
72 Error += A.y < (std::numeric_limits<glm::u8>::max() >> 2) ? 0 : 1;
73 Error += A.z == 127 ? 0 : 1;
74 Error += A.w == 255 ? 0 : 1;
75 }
76
77 {
78 glm::i8vec4 const A = glm::compScale<glm::i8>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
79
80 Error += A.x == 0 ? 0 : 1;
81 Error += A.y == -128 ? 0 : 1;
82 Error += A.z == 63 ? 0 : 1;
83 Error += A.w == 127 ? 0 : 1;
84 }
85
86 {
87 glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
88
89 Error += A.x == std::numeric_limits<glm::u16>::min() ? 0 : 1;
90 Error += A.y < (std::numeric_limits<glm::u16>::max() >> 2) ? 0 : 1;
91 Error += A.z == 32767 ? 0 : 1;
92 Error += A.w == 65535 ? 0 : 1;
93 }
94
95 {
96 glm::i16vec4 const A = glm::compScale<glm::i16>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
97
98 Error += A.x == 0 ? 0 : 1;
99 Error += A.y == -32768 ? 0 : 1;
100 Error += A.z == 16383 ? 0 : 1;
101 Error += A.w == 32767 ? 0 : 1;
102 }
103
104 return Error;
105 }
106 }// compScale
107
main()108 int main()
109 {
110 int Error(0);
111
112 Error += compNormalize::run();
113 Error += compScale::run();
114
115 return Error;
116 }
117