diff --git a/test/bug/bug_ms_vec_static.cpp b/test/bug/bug_ms_vec_static.cpp index 06390235..aed6e51c 100644 --- a/test/bug/bug_ms_vec_static.cpp +++ b/test/bug/bug_ms_vec_static.cpp @@ -1,8 +1,166 @@ -#define GLM_FORCE_SWIZZLE -#include +enum precision +{ + packed_highp, + packed_mediump, + packed_lowp, + + aligned_highp, + aligned_mediump, + aligned_lowp, + aligned = aligned_highp, + + highp = packed_highp, + mediump = packed_mediump, + lowp = packed_lowp, + packed = packed_highp, + + defaultp = highp +}; + +template +struct is_aligned +{ + static const bool value = false; +}; + +template<> +struct is_aligned +{ + static const bool value = true; +}; + +template<> +struct is_aligned +{ + static const bool value = true; +}; + +template<> +struct is_aligned +{ + static const bool value = true; +}; + +template struct vec2; + +template +struct _swizzle_base0 +{ +protected: + T& elem(size_t i){ return (reinterpret_cast(_buffer))[i]; } + T const& elem(size_t i) const{ return (reinterpret_cast(_buffer))[i]; } + + char _buffer[1]; +}; + +template +struct _swizzle_base1 : public _swizzle_base0 +{ +}; + +template +struct _swizzle_base1 : public _swizzle_base0 +{ + vec2 operator ()() const { return vec2(this->elem(E0), this->elem(E1)); } +}; + +template +struct _swizzle_base2 : public _swizzle_base1::value> +{ + _swizzle_base2& operator= (const T& t) + { + for (int i = 0; i < 2; ++i) + (*this)[i] = t; + return *this; + } + + _swizzle_base2& operator= (vec2 const& that) + { + struct op { + void operator() (T& e, T& t) { e = t; } + }; + _apply_op(that, op()); + return *this; + } + + T& operator[](size_t i) + { + const int offset_dst[4] = { E0, E1, E2, E3 }; + return this->elem(offset_dst[i]); + } + T operator[](size_t i) const + { + const int offset_dst[4] = { E0, E1, E2, E3 }; + return this->elem(offset_dst[i]); + } + +protected: + template + void _apply_op(vec2 const& that, U op) + { + T t[N]; + for (int i = 0; i < N; ++i) + t[i] = that[i]; + for (int i = 0; i < N; ++i) + op( (*this)[i], t[i] ); + } +}; + +template +struct _swizzle_base2 : public _swizzle_base1::value> +{ + struct Stub {}; + + _swizzle_base2& operator= (Stub const &) { return *this; } + + T operator[] (size_t i) const + { + const int offset_dst[4] = { E0, E1, E2, E3 }; + return this->elem(offset_dst[i]); + } +}; + +template +struct _swizzle : public _swizzle_base2 +{ + typedef _swizzle_base2 base_type; + + using base_type::operator=; + + operator vec2 () const { return (*this)(); } +}; + +template +struct vec2 +{ + constexpr vec2(T x, T y) : + x(x), y(y) + {} + + union + { + struct{ T x, y; }; + struct{ T r, g; }; + struct{ T s, t; }; + struct { _swizzle xx; }; + struct { _swizzle xy; }; + struct { _swizzle yy; }; + struct { _swizzle yx; }; + struct { _swizzle rr; }; + struct { _swizzle rg; }; + struct { _swizzle gr; }; + struct { _swizzle gg; }; + struct { _swizzle ss; }; + struct { _swizzle st; }; + struct { _swizzle ts; }; + struct { _swizzle tt; }; + }; +}; + +typedef vec2 float2; // Visual C++ has a bug generating the error: fatal error C1001: An internal error has occurred in the compiler. -glm::vec2 const Bar(1.f, 1.f); +float2 const Bar(1.f, 1.f); int main() {