Simplier repro case for #594

This commit is contained in:
Christophe Riccio 2017-01-04 23:28:07 +01:00
parent 353d4ea7b7
commit d9d222555f

View File

@ -17,117 +17,41 @@ enum precision
defaultp = highp
};
template<precision P>
struct is_aligned
{
static const bool value = false;
};
template<>
struct is_aligned<aligned_lowp>
{
static const bool value = true;
};
template<>
struct is_aligned<aligned_mediump>
{
static const bool value = true;
};
template<>
struct is_aligned<aligned_highp>
{
static const bool value = true;
};
template<typename T, precision P = defaultp> struct vec2;
template<typename T>
struct _swizzle_base0
{
protected:
T& elem(size_t i){ return (reinterpret_cast<T*>(_buffer))[i]; }
T const& elem(size_t i) const{ return (reinterpret_cast<const T*>(_buffer))[i]; }
char _buffer[1];
};
template<typename T, precision P, int E0, int E1, int E2, int E3, bool Aligned>
template<typename T, precision P, int E0, int E1, int E2, int E3>
struct _swizzle_base1 : public _swizzle_base0<T>
{
};
template<typename T, precision P, int E0, int E1, bool Aligned>
struct _swizzle_base1<T, P, E0,E1,-1,-2, Aligned> : public _swizzle_base0<T>
template<typename T, precision P, int E0, int E1>
struct _swizzle_base1<T, P, E0,E1,-1,-2> : public _swizzle_base0<T>
{
vec2<T, P> operator ()() const { return vec2<T, P>(this->elem(E0), this->elem(E1)); }
};
template<typename T, precision P, int E0, int E1, int E2, int E3, int DUPLICATE_ELEMENTS>
struct _swizzle_base2 : public _swizzle_base1<T, P, E0,E1,E2,E3, is_aligned<P>::value>
struct _swizzle_base2 : public _swizzle_base1<T, P, E0,E1,E2,E3>
{
_swizzle_base2& operator= (const T& t)
{
for (int i = 0; i < 2; ++i)
(*this)[i] = t;
return *this;
}
_swizzle_base2& operator= (vec2<T, P> 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<typename U>
void _apply_op(vec2<T, P> 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<typename T, precision P, int E0, int E1, int E2, int E3>
struct _swizzle_base2<T, P, E0,E1,E2,E3, 1> : public _swizzle_base1<T, P, E0,E1,E2,E3, is_aligned<P>::value>
struct _swizzle_base2<T, P, E0,E1,E2,E3, 1> : public _swizzle_base1<T, P, E0,E1,E2,E3>
{
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<typename T, precision P, int E0, int E1, int E2, int E3>
struct _swizzle : public _swizzle_base2<T, P, E0, E1, E2, E3, (E0 == E1 || E0 == E2 || E0 == E3 || E1 == E2 || E1 == E3 || E2 == E3)>
{
typedef _swizzle_base2<T, P, E0, E1, E2, E3, (E0 == E1 || E0 == E2 || E0 == E3 || E1 == E2 || E1 == E3 || E2 == E3)> base_type;
using base_type::operator=;
operator vec2<T, P> () const { return (*this)(); }
};
template<typename T, precision P>
@ -139,21 +63,8 @@ struct vec2
union
{
struct{ T x, y; };
struct{ T r, g; };
struct{ T s, t; };
struct { T x, y; };
struct { _swizzle<T, P, 0,0,-1,-2> xx; };
struct { _swizzle<T, P, 0,0,-1,-2> xy; };
struct { _swizzle<T, P, 0,0,-1,-2> yy; };
struct { _swizzle<T, P, 0,0,-1,-2> yx; };
struct { _swizzle<T, P, 0,0,-1,-2> rr; };
struct { _swizzle<T, P, 0,0,-1,-2> rg; };
struct { _swizzle<T, P, 0,0,-1,-2> gr; };
struct { _swizzle<T, P, 0,0,-1,-2> gg; };
struct { _swizzle<T, P, 0,0,-1,-2> ss; };
struct { _swizzle<T, P, 0,0,-1,-2> st; };
struct { _swizzle<T, P, 0,0,-1,-2> ts; };
struct { _swizzle<T, P, 0,0,-1,-2> tt; };
};
};