/* * Copyright 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MATH_VEC4_H_ #define MATH_VEC4_H_ #include #include #include #include namespace filament { namespace math { // ------------------------------------------------------------------------------------- namespace details { template class MATH_EMPTY_BASES TVec4 : public TVecProductOperators, public TVecAddOperators, public TVecUnaryOperators, public TVecComparisonOperators, public TVecFunctions { public: typedef T value_type; typedef T& reference; typedef T const& const_reference; typedef size_t size_type; static constexpr size_t SIZE = 4; union { T v[SIZE] MATH_CONSTEXPR_INIT; TVec2 xy, st, rg; TVec3 xyz, stp, rgb; struct { union { T x, s, r; }; union { TVec2 yz, tp, gb; TVec3 yzw, tpq, gba; struct { union { T y, t, g; }; union { TVec2 zw, pq, ba; struct { T z, w; }; struct { T p, q; }; struct { T b, a; }; }; }; }; }; }; inline constexpr size_type size() const { return SIZE; } // array access inline constexpr T const& operator[](size_t i) const noexcept { assert(i < SIZE); return v[i]; } inline constexpr T& operator[](size_t i) noexcept { assert(i < SIZE); return v[i]; } // constructors // default constructor MATH_DEFAULT_CTOR_CONSTEXPR TVec4() noexcept MATH_DEFAULT_CTOR // handles implicit conversion to a tvec4. must not be explicit. template> constexpr TVec4(A v) noexcept : v{ T(v), T(v), T(v), T(v) } {} template> constexpr TVec4(A x, B y, C z, D w) noexcept : v{ T(x), T(y), T(z), T(w) } {} template> constexpr TVec4(const TVec2& v, B z, C w) noexcept : v{ T(v[0]), T(v[1]), T(z), T(w) } {} template> constexpr TVec4(const TVec2& v, const TVec2& w) noexcept : v{ T(v[0]), T(v[1]), T(w[0]), T(w[1]) } {} template> constexpr TVec4(const TVec3& v, B w) noexcept : v{ T(v[0]), T(v[1]), T(v[2]), T(w) } {} template> constexpr TVec4(const TVec4& v) noexcept : v{ T(v[0]), T(v[1]), T(v[2]), T(v[3]) } {} }; } // namespace details // ---------------------------------------------------------------------------------------- template> using vec4 = details::TVec4; using double4 = vec4; using float4 = vec4; using half4 = vec4; using int4 = vec4; using uint4 = vec4; using short4 = vec4; using ushort4 = vec4; using byte4 = vec4; using ubyte4 = vec4; using bool4 = vec4; // ---------------------------------------------------------------------------------------- } // namespace math } // namespace filament #endif // MATH_VEC4_H_