type_vec4.hpp

00001 
00002 // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
00004 // Created : 2008-08-22
00005 // Updated : 2010-02-03
00006 // Licence : This source is under MIT License
00007 // File    : glm/core/type_tvec4.hpp
00009 
00010 #ifndef glm_core_type_gentype4
00011 #define glm_core_type_gentype4
00012 
00013 #include "type_vec.hpp"
00014 #include "type_float.hpp"
00015 #include "type_int.hpp"
00016 #include "type_size.hpp"
00017 #include "_swizzle.hpp"
00018 
00019 namespace glm{
00020 namespace detail
00021 {
00022         template <typename T> struct tref2;
00023         template <typename T> struct tref3;
00024         template <typename T> struct tref4;
00025         template <typename T> struct tvec2;
00026         template <typename T> struct tvec3;
00027 
00030         template <typename T>
00031         struct tvec4
00032         {
00033                 enum ctor{null};
00034 
00035                 typedef T value_type;
00036                 typedef std::size_t size_type;
00037                 GLM_FUNC_DECL size_type length() const;
00038                 static GLM_FUNC_DECL size_type value_size();
00039 
00040                 typedef tvec4<T> type;
00041                 typedef tvec4<bool> bool_type;
00042 
00044                 // Data
00045 
00046 #       if(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
00047                 value_type x, y, z, w;
00048 #       elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT)
00049                 union 
00050                 {
00051                         struct{value_type x, y, z, w;};
00052                         struct{value_type r, g, b, a;};
00053                         struct{value_type s, t, p, q;};
00054                 };
00055 #       else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES)
00056                 union {value_type x, r, s;};
00057                 union {value_type y, g, t;};
00058                 union {value_type z, b, p;};
00059                 union {value_type w, a, q;};
00060 #       endif//GLM_COMPONENT
00061 
00063                 // Accesses
00064 
00065                 GLM_FUNC_DECL value_type & operator[](size_type i);
00066                 GLM_FUNC_DECL value_type const & operator[](size_type i) const;
00067 
00069                 // Implicit basic constructors
00070 
00071                 GLM_FUNC_DECL tvec4();
00072                 GLM_FUNC_DECL tvec4(type const & v);
00073 
00075                 // Explicit basic constructors
00076 
00077                 GLM_FUNC_DECL explicit tvec4(
00078                         ctor);
00079                 GLM_FUNC_DECL explicit tvec4(
00080                         value_type const & s);
00081                 GLM_FUNC_DECL explicit tvec4(
00082                         value_type const & s0, 
00083                         value_type const & s1, 
00084                         value_type const & s2, 
00085                         value_type const & s3);
00086 
00088                 // Swizzle constructors
00089 
00090                 GLM_FUNC_DECL tvec4(tref4<T> const & r);
00091 
00093                 // Convertion scalar constructors
00094 
00096                 template <typename U> 
00097                 GLM_FUNC_DECL explicit tvec4(
00098                         U const & x);
00100                 template <typename A, typename B, typename C, typename D> 
00101                 GLM_FUNC_DECL explicit tvec4(
00102                         A const & x, 
00103                         B const & y, 
00104                         C const & z, 
00105                         D const & w);                   
00106 
00108                 // Convertion vector constructors
00109 
00111                 template <typename A, typename B, typename C> 
00112                 GLM_FUNC_DECL explicit tvec4(tvec2<A> const & v, B const & s1, C const & s2);
00114                 template <typename A, typename B, typename C> 
00115                 GLM_FUNC_DECL explicit tvec4(A const & s1, tvec2<B> const & v, C const & s2);
00117                 template <typename A, typename B, typename C> 
00118                 GLM_FUNC_DECL explicit tvec4(A const & s1, B const & s2, tvec2<C> const & v);
00120                 template <typename A, typename B> 
00121                 GLM_FUNC_DECL explicit tvec4(tvec3<A> const & v, B const & s);
00123                 template <typename A, typename B> 
00124                 GLM_FUNC_DECL explicit tvec4(A const & s, tvec3<B> const & v);
00126                 template <typename A, typename B> 
00127                 GLM_FUNC_DECL explicit tvec4(tvec2<A> const & v1, tvec2<B> const & v2);
00129                 template <typename U> 
00130                 GLM_FUNC_DECL explicit tvec4(tvec4<U> const & v);
00131 
00133                 // Unary arithmetic operators
00134 
00135                 GLM_FUNC_DECL tvec4<T> & operator= (tvec4<T> const & v);
00136                 template <typename U>
00137                 GLM_FUNC_DECL tvec4<T> & operator= (tvec4<U> const & v);
00138 
00139                 template <typename U>
00140                 GLM_FUNC_DECL tvec4<T> & operator+=(U const & s);
00141                 template <typename U>
00142                 GLM_FUNC_DECL tvec4<T> & operator+=(tvec4<U> const & v);
00143                 template <typename U>
00144                 GLM_FUNC_DECL tvec4<T> & operator-=(U const & s);
00145                 template <typename U>
00146                 GLM_FUNC_DECL tvec4<T> & operator-=(tvec4<U> const & v);
00147                 template <typename U>
00148                 GLM_FUNC_DECL tvec4<T> & operator*=(U const & s);
00149                 template <typename U>
00150                 GLM_FUNC_DECL tvec4<T> & operator*=(tvec4<U> const & v);
00151                 template <typename U>
00152                 GLM_FUNC_DECL tvec4<T> & operator/=(U const & s);
00153                 template <typename U>
00154                 GLM_FUNC_DECL tvec4<T> & operator/=(tvec4<U> const & v);
00155                 GLM_FUNC_DECL tvec4<T> & operator++();
00156                 GLM_FUNC_DECL tvec4<T> & operator--();
00157 
00159                 // Unary bit operators
00160 
00161                 template <typename U>
00162                 GLM_FUNC_DECL tvec4<T> & operator%= (U const & s);
00163                 template <typename U>
00164                 GLM_FUNC_DECL tvec4<T> & operator%= (tvec4<U> const & v);
00165                 template <typename U>
00166                 GLM_FUNC_DECL tvec4<T> & operator&= (U const & s);
00167                 template <typename U>
00168                 GLM_FUNC_DECL tvec4<T> & operator&= (tvec4<U> const & v);
00169                 template <typename U>
00170                 GLM_FUNC_DECL tvec4<T> & operator|= (U const & s);
00171                 template <typename U>
00172                 GLM_FUNC_DECL tvec4<T> & operator|= (tvec4<U> const & v);
00173                 template <typename U>
00174                 GLM_FUNC_DECL tvec4<T> & operator^= (U const & s);
00175                 template <typename U>
00176                 GLM_FUNC_DECL tvec4<T> & operator^= (tvec4<U> const & v);
00177                 template <typename U>
00178                 GLM_FUNC_DECL tvec4<T> & operator<<=(U const & s);
00179                 template <typename U>
00180                 GLM_FUNC_DECL tvec4<T> & operator<<=(tvec4<U> const & v);
00181                 template <typename U>
00182                 GLM_FUNC_DECL tvec4<T> & operator>>=(U const & s);
00183                 template <typename U>
00184                 GLM_FUNC_DECL tvec4<T> & operator>>=(tvec4<U> const & v);
00185 
00187                 // Swizzle operators
00188 
00189                 GLM_FUNC_DECL value_type swizzle(comp X) const;
00190                 GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
00191                 GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
00192                 GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
00193                 GLM_FUNC_DECL tref4<T> swizzle(comp X, comp Y, comp Z, comp W);
00194         };
00195 
00196         template <typename T>
00197         struct tref4
00198         {
00199                 GLM_FUNC_DECL tref4(T & x, T & y, T & z, T & w);
00200                 GLM_FUNC_DECL tref4(tref4<T> const & r);
00201                 GLM_FUNC_DECL tref4(tvec4<T> const & v);
00202 
00203                 GLM_FUNC_DECL tref4<T> & operator= (tref4<T> const & r);
00204                 GLM_FUNC_DECL tref4<T> & operator= (tvec4<T> const & v);
00205 
00206                 T & x;
00207                 T & y;
00208                 T & z;
00209                 T & w;
00210         };
00211 
00212         GLM_DETAIL_IS_VECTOR(tvec4);
00213 }//namespace detail
00214 
00215 namespace core{
00216 namespace type{
00217 namespace precision
00218 {
00223         typedef detail::tvec4<highp_float>              highp_vec4;
00224 
00229         typedef detail::tvec4<mediump_float>    mediump_vec4;
00230 
00235         typedef detail::tvec4<lowp_float>               lowp_vec4;
00236 
00241         typedef detail::tvec4<highp_int>                highp_ivec4;
00242 
00247         typedef detail::tvec4<mediump_int>              mediump_ivec4;
00248 
00253         typedef detail::tvec4<lowp_int>                 lowp_ivec4;
00254 
00259         typedef detail::tvec4<highp_uint>               highp_uvec4;
00260 
00265         typedef detail::tvec4<mediump_uint>             mediump_uvec4;
00266 
00271         typedef detail::tvec4<lowp_uint>                lowp_uvec4;
00272 
00273 }//namespace precision
00274 }//namespace type
00275 }//namespace core
00276 }//namespace glm
00277 
00278 #ifndef GLM_EXTERNAL_TEMPLATE
00279 #include "type_vec4.inl"
00280 #endif//GLM_EXTERNAL_TEMPLATE
00281 
00282 #endif//glm_core_type_gentype4