diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index 6f5752e9..d7943873 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -158,7 +158,7 @@ namespace detail template <> GLM_FUNC_QUALIFIER detail::thalf floor(detail::thalf const& x) { - return detail::thalf(::std::floor(float(x))); + return detail::thalf(::std::floor(x.toFloat())); } template diff --git a/glm/core/type_half.hpp b/glm/core/type_half.hpp index efc2dd33..445487c2 100644 --- a/glm/core/type_half.hpp +++ b/glm/core/type_half.hpp @@ -53,7 +53,7 @@ namespace detail // Cast //operator float(); - GLM_FUNC_DECL operator float() const; + //GLM_FUNC_DECL operator float() const; //operator double(); //operator double() const; @@ -89,6 +89,30 @@ namespace detail thalf operator++ (thalf const & s, int); + bool operator==( + detail::thalf const & x, + detail::thalf const & y); + + bool operator!=( + detail::thalf const & x, + detail::thalf const & y); + + bool operator<( + detail::thalf const & x, + detail::thalf const & y); + + bool operator<=( + detail::thalf const & x, + detail::thalf const & y); + + bool operator>( + detail::thalf const & x, + detail::thalf const & y); + + bool operator>=( + detail::thalf const & x, + detail::thalf const & y); + }//namespace detail }//namespace glm diff --git a/glm/core/type_half.inl b/glm/core/type_half.inl index 98b55ea6..cf720575 100644 --- a/glm/core/type_half.inl +++ b/glm/core/type_half.inl @@ -250,7 +250,9 @@ namespace detail // Assemble the half from s, e and m. // - return hdata(s | (e << 10) | (m >> 13)); + hdata Hdata(s | (e << 10) | (m >> 13)); + + return Hdata; } } @@ -273,10 +275,10 @@ namespace detail // return toFloat(); //} - GLM_FUNC_QUALIFIER thalf::operator float() const - { - return toFloat32(this->data); - } + //GLM_FUNC_QUALIFIER thalf::operator float() const + //{ + // return toFloat32(this->data); + //} //GLM_FUNC_QUALIFIER half::operator double() //{ @@ -338,38 +340,92 @@ namespace detail GLM_FUNC_QUALIFIER detail::thalf operator+ (detail::thalf const & s1, detail::thalf const & s2) { - return detail::thalf(float(s1) + float(s2)); + return detail::thalf(s1.toFloat() + s2.toFloat()); } GLM_FUNC_QUALIFIER detail::thalf operator- (detail::thalf const & s1, detail::thalf const & s2) { - return detail::thalf(float(s1) - float(s2)); + return detail::thalf(s1.toFloat() - s2.toFloat()); } GLM_FUNC_QUALIFIER detail::thalf operator* (detail::thalf const & s1, detail::thalf const & s2) { - return detail::thalf(float(s1) * float(s2)); + return detail::thalf(s1.toFloat() * s2.toFloat()); } GLM_FUNC_QUALIFIER detail::thalf operator/ (detail::thalf const & s1, detail::thalf const & s2) { - return detail::thalf(float(s1) / float(s2)); + return detail::thalf(s1.toFloat() / s2.toFloat()); } // Unary constant operators GLM_FUNC_QUALIFIER detail::thalf operator- (detail::thalf const & s) { - return detail::thalf(-float(s)); + return detail::thalf(-s.toFloat()); } GLM_FUNC_QUALIFIER detail::thalf operator-- (detail::thalf const & s, int) { - return detail::thalf(float(s) - 1.0f); + return detail::thalf(s.toFloat() - 1.0f); } GLM_FUNC_QUALIFIER detail::thalf operator++ (detail::thalf const & s, int) { - return detail::thalf(float(s) + 1.0f); + return detail::thalf(s.toFloat() + 1.0f); + } + + GLM_FUNC_QUALIFIER bool operator== + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x._data() == y._data(); + } + + GLM_FUNC_QUALIFIER bool operator!= + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x._data() != y._data(); + } + + GLM_FUNC_QUALIFIER bool operator< + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x.toFloat() < y.toFloat(); + } + + GLM_FUNC_QUALIFIER bool operator<= + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x.toFloat() <= y.toFloat(); + } + + GLM_FUNC_QUALIFIER bool operator> + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x.toFloat() > y.toFloat(); + } + + GLM_FUNC_QUALIFIER bool operator>= + ( + detail::thalf const & x, + detail::thalf const & y + ) + { + return x.toFloat() >= y.toFloat(); } }//namespace detail diff --git a/glm/core/type_vec2.inl b/glm/core/type_vec2.inl index ba1dcbca..0b14ecf1 100644 --- a/glm/core/type_vec2.inl +++ b/glm/core/type_vec2.inl @@ -142,11 +142,11 @@ namespace detail template GLM_FUNC_QUALIFIER tvec2::tvec2 ( - U const & x, - V const & y + U const & a, + V const & b ) : - x(value_type(x)), - y(value_type(y)) + x(value_type(a)), + y(value_type(b)) {} ////////////////////////////////////// diff --git a/glm/gtc/half_float.hpp b/glm/gtc/half_float.hpp index 8cb6689d..39a5abeb 100644 --- a/glm/gtc/half_float.hpp +++ b/glm/gtc/half_float.hpp @@ -47,7 +47,7 @@ namespace glm{ namespace detail { -#ifndef _MSC_EXTENSIONS +#if 1 //ndef _MSC_EXTENSIONS template <> struct tvec2 { diff --git a/glm/gtc/half_float.inl b/glm/gtc/half_float.inl index 2d20f8a0..086c88fb 100644 --- a/glm/gtc/half_float.inl +++ b/glm/gtc/half_float.inl @@ -29,7 +29,7 @@ namespace glm{ namespace detail{ -#ifndef _MSC_EXTENSIONS +#if 1 //ndef _MSC_EXTENSIONS ////////////////////////////////////// // hvec2 diff --git a/glm/gtx/multiple.inl b/glm/gtx/multiple.inl index 72d9f4a1..00fff8b4 100644 --- a/glm/gtx/multiple.inl +++ b/glm/gtx/multiple.inl @@ -29,12 +29,15 @@ GLM_FUNC_QUALIFIER genType higherMultiple template <> GLM_FUNC_QUALIFIER detail::thalf higherMultiple ( - detail::thalf const & Source, - detail::thalf const & Multiple + detail::thalf const & SourceH, + detail::thalf const & MultipleH ) { - int Tmp = int(float(Source)) % int(float(Multiple)); - return Tmp ? Source + Multiple - detail::thalf(float(Tmp)) : Source; + float Source = SourceH.toFloat(); + float Multiple = MultipleH.toFloat(); + + int Tmp = int(float(Source)) % int(); + return detail::thalf(Tmp ? Source + Multiple - float(Tmp) : Source); } template <> @@ -115,12 +118,15 @@ GLM_FUNC_QUALIFIER genType lowerMultiple template <> GLM_FUNC_QUALIFIER detail::thalf lowerMultiple ( - detail::thalf const & Source, - detail::thalf const & Multiple + detail::thalf const & SourceH, + detail::thalf const & MultipleH ) { + float Source = SourceH.toFloat(); + float Multiple = MultipleH.toFloat(); + int Tmp = int(float(Source)) % int(float(Multiple)); - return Tmp ? Source - detail::thalf(float(Tmp)) : Source; + return detail::thalf(Tmp ? Source - float(Tmp) : Source); } template <> diff --git a/glm/gtx/string_cast.inl b/glm/gtx/string_cast.inl index 62a3ac8c..caffdd5e 100644 --- a/glm/gtx/string_cast.inl +++ b/glm/gtx/string_cast.inl @@ -43,7 +43,7 @@ namespace detail GLM_FUNC_QUALIFIER std::string to_string(detail::thalf const & x) { - return detail::format("half(%2.4f)", float(x)); + return detail::format("half(%2.4f)", x.toFloat()); } GLM_FUNC_QUALIFIER std::string to_string(float x) @@ -111,7 +111,7 @@ namespace detail detail::tvec2 const & v ) { - return detail::format("hvec2(%2.4f, %2.4f)", float(v.x), float(v.y)); + return detail::format("hvec2(%2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat()); } template <> @@ -120,7 +120,7 @@ namespace detail detail::tvec3 const & v ) { - return detail::format("hvec3(%2.4f, %2.4f, %2.4f)", float(v.x), float(v.y), float(v.z)); + return detail::format("hvec3(%2.4f, %2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat(), v.z.toFloat()); } template <> @@ -129,7 +129,7 @@ namespace detail detail::tvec4 const & v ) { - return detail::format("hvec4(%2.4f, %2.4f, %2.4f, %2.4f)", float(v.x), float(v.y), float(v.z), float(v.w)); + return detail::format("hvec4(%2.4f, %2.4f, %2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat(), v.z.toFloat(), v.w.toFloat()); } //////////////////////////////// @@ -261,115 +261,106 @@ namespace detail detail::tmat2x2 const & m ) { - detail::tmat2x2 x(m); return detail::format("hmat2x2((%f, %f), (%f, %f))", - x[0][0], x[0][1], - x[1][0], x[1][1]); + m[0][0].toFloat(), m[0][1].toFloat(), + m[1][0].toFloat(), m[1][1].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat2x3 const & m + detail::tmat2x3 const & x ) { - detail::tmat2x3 x(m); return detail::format("hmat2x3((%f, %f, %f), (%f, %f, %f))", - x[0][0], x[0][1], x[0][2], - x[1][0], x[1][1], x[1][2]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat2x4 const & m + detail::tmat2x4 const & x ) { - detail::tmat2x4 x(m); return detail::format("hmat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))", - x[0][0], x[0][1], x[0][2], x[0][3], - x[1][0], x[1][1], x[1][2], x[1][3]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat3x2 const & m + detail::tmat3x2 const & x ) { - detail::tmat3x2 x(m); return detail::format("hmat3x2((%f, %f), (%f, %f), (%f, %f))", - x[0][0], x[0][1], - x[1][0], x[1][1], - x[2][0], x[2][1]); + x[0][0].toFloat(), x[0][1].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat3x3 const & m + detail::tmat3x3 const & x ) { - detail::tmat3x3 x(m); return detail::format("hmat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))", - x[0][0], x[0][1], x[0][2], - x[1][0], x[1][1], x[1][2], - x[2][0], x[2][1], x[2][2]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat3x4 const & m + detail::tmat3x4 const & x ) { - detail::tmat3x4 x(m); return detail::format("hmat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))", - x[0][0], x[0][1], x[0][2], x[0][3], - x[1][0], x[1][1], x[1][2], x[1][3], - x[2][0], x[2][1], x[2][2], x[2][3]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(), x[2][3].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat4x2 const & m + detail::tmat4x2 const & x ) { - detail::tmat4x2 x(m); return detail::format("hmat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))", - x[0][0], x[0][1], - x[1][0], x[1][1], - x[2][0], x[2][1], - x[3][0], x[3][1]); + x[0][0].toFloat(), x[0][1].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat(), + x[3][0].toFloat(), x[3][1].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat4x3 const & m + detail::tmat4x3 const & x ) { - detail::tmat4x3 x(m); return detail::format("hmat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))", - x[0][0], x[0][1], x[0][2], - x[1][0], x[1][1], x[1][2], - x[2][0], x[2][1], x[2][2], - x[3][0], x[3][1], x[3][2]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(), + x[3][0].toFloat(), x[3][1].toFloat(), x[3][2].toFloat()); } template <> GLM_FUNC_QUALIFIER std::string to_string ( - detail::tmat4x4 const & m + detail::tmat4x4 const & x ) { - detail::tmat4x4 x(m); return detail::format("hmat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))", - x[0][0], x[0][1], x[0][2], x[0][3], - x[1][0], x[1][1], x[1][2], x[1][3], - x[2][0], x[2][1], x[2][2], x[2][3], - x[3][0], x[3][1], x[3][2], x[3][3]); + x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(), + x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat(), + x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(), x[2][3].toFloat(), + x[3][0].toFloat(), x[3][1].toFloat(), x[3][2].toFloat(), x[3][3].toFloat()); } //////////////////////////////// diff --git a/test/core/core_func_packing.cpp b/test/core/core_func_packing.cpp index 48198314..3f3006cf 100644 --- a/test/core/core_func_packing.cpp +++ b/test/core/core_func_packing.cpp @@ -16,12 +16,17 @@ int test_packUnorm2x16() { int Error = 0; - +/* std::vector A; A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 0.0f))); A.push_back(glm::hvec2(glm::half( 0.5f), glm::half( 0.7f))); A.push_back(glm::hvec2(glm::half( 0.1f), glm::half( 0.2f))); - +*/ + std::vector A; + A.push_back(glm::vec2(1.0f, 0.0f)); + A.push_back(glm::vec2(0.5f, 0.7f)); + A.push_back(glm::vec2(0.1f, 0.2f)); + for(std::size_t i = 0; i < A.size(); ++i) { glm::vec2 B(A[i]); @@ -37,12 +42,17 @@ int test_packUnorm2x16() int test_packSnorm2x16() { int Error = 0; - +/* std::vector A; A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 0.0f))); A.push_back(glm::hvec2(glm::half(-0.5f), glm::half(-0.7f))); A.push_back(glm::hvec2(glm::half(-0.1f), glm::half( 0.1f))); - +*/ + std::vector A; + A.push_back(glm::vec2( 1.0f, 0.0f)); + A.push_back(glm::vec2(-0.5f,-0.7f)); + A.push_back(glm::vec2(-0.1f, 0.1f)); + for(std::size_t i = 0; i < A.size(); ++i) { glm::vec2 B(A[i]); @@ -98,12 +108,17 @@ int test_packSnorm4x8() int test_packHalf2x16() { int Error = 0; - +/* std::vector A; A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 2.0f))); A.push_back(glm::hvec2(glm::half(-1.0f), glm::half(-2.0f))); A.push_back(glm::hvec2(glm::half(-1.1f), glm::half( 1.1f))); - +*/ + std::vector A; + A.push_back(glm::vec2( 1.0f, 2.0f)); + A.push_back(glm::vec2(-1.0f,-2.0f)); + A.push_back(glm::vec2(-1.1f, 1.1f)); + for(std::size_t i = 0; i < A.size(); ++i) { glm::vec2 B(A[i]); diff --git a/test/core/core_type_half.cpp b/test/core/core_type_half.cpp index 8ea358eb..e432b9af 100644 --- a/test/core/core_type_half.cpp +++ b/test/core/core_type_half.cpp @@ -18,14 +18,14 @@ int main() glm::half B(2.0f); glm::half C = A + B; glm::half D(C); - float E = D; - int F = float(C); + float E = D.toFloat(); + int F = C.toFloat(); Result += float(F) == E ? 0 : 1; glm::half G = B * C; glm::half H = G / C; H += glm::half(1.0f); - double J = H; - int I = float(H); + double J = H.toFloat(); + int I = H.toFloat(); Result += J == 3.0 ? 0 : 1; Result += I == 3 ? 0 : 1; diff --git a/test/gtc/gtc_half_float.cpp b/test/gtc/gtc_half_float.cpp index 4690aacd..dca3624f 100644 --- a/test/gtc/gtc_half_float.cpp +++ b/test/gtc/gtc_half_float.cpp @@ -139,7 +139,10 @@ int test_half_ctor_vec2() int Error = 0; { - glm::hvec2 A(1, 2); + glm::hvec2 A; + A.x = glm::half(1); + A.y = glm::half(2); + //glm::hvec2 A(1, 2); glm::hvec2 B(A); glm::vec2 C(1, 2); glm::hvec2 D(C);