swizzle.hpp
00001 
00002 // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
00004 // Created : 2010-02-20
00005 // Updated : 2010-02-20
00006 // Licence : This source is under MIT License
00007 // File    : glm/gtc/swizzle.hpp
00009 // Dependency:
00010 // - GLM core
00012 
00013 #ifndef glm_gtc_swizzle
00014 #define glm_gtc_swizzle
00015 
00016 // Dependency:
00017 #include "../glm.hpp"
00018 #include "../gtc/type_precision.hpp"
00019 
00020 #if(defined(GLM_MESSAGES) && !defined(glm_ext))
00021 #       pragma message("GLM: GLM_GTC_swizzle extension included")
00022 #endif
00023 
00024 namespace glm{
00025 namespace gtc{
00026 namespace swizzle 
00027 {
00028         using namespace gtc::half_float;
00029 
00030         template <typename T, template <typename> class vecType>
00031         T const & swizzle(      
00032                 vecType<T> const & v,
00033                 comp x);
00034 
00035         template <typename T, template <typename> class vecType>
00036         detail::tvec2<T> const & swizzle(
00037                 vecType<T> const & v,
00038                 comp x, comp y);
00039 
00040         template <typename T, template <typename> class vecType>
00041         detail::tvec3<T> const & swizzle(
00042                 vecType<T> const & v,
00043                 comp x, comp y, comp z);
00044 
00045         template <typename T, template <typename> class vecType>
00046         detail::tvec4<T> const & swizzle(
00047                 vecType<T> const & v,
00048                 comp x, comp y, comp z, comp w);
00049 
00050         template <typename T, template <typename> class vecType>
00051         T & swizzle(
00052                 vecType<T> & v,
00053                 comp x);
00054 
00055         template <typename T, template <typename> class vecType>
00056         detail::tref2<T> swizzle(
00057                 vecType<T> & v,
00058                 comp x, comp y);
00059 
00060         template <typename T, template <typename> class vecType>
00061         detail::tref3<T> swizzle(
00062                 vecType<T> & v,
00063                 comp x, comp y, comp z);
00064 
00065         template <typename T, template <typename> class vecType>
00066         detail::tref4<T> swizzle(
00067                 vecType<T> & v,
00068                 comp x, comp y, comp z, comp w);
00069 
00070 #       define static_swizzle1_const(TYPE, SIZE)                                                        \
00071                 template <comp x>                                                                               \
00072                 GLM_FUNC_QUALIFIER TYPE swizzle(detail::tvec##SIZE<TYPE> const & v)     \
00073                 {return v[x];}                                                                                  
00074                                                                                                                                 
00075 #       define static_swizzle1_ref(TYPE, SIZE)                                                                  \
00076                 template <comp x>                                                                                                       \
00077                 GLM_FUNC_QUALIFIER TYPE& swizzle(detail::tvec##SIZE<TYPE> & v)          \
00078                 {return v[x];}
00079 
00080         static_swizzle1_ref(detail::float16, 2)
00081         static_swizzle1_ref(detail::float16, 3)
00082         static_swizzle1_ref(detail::float16, 4)
00083         static_swizzle1_ref(detail::float32, 2)
00084         static_swizzle1_ref(detail::float32, 3)
00085         static_swizzle1_ref(detail::float32, 4)
00086         static_swizzle1_ref(detail::float64, 2)
00087         static_swizzle1_ref(detail::float64, 3)
00088         static_swizzle1_ref(detail::float64, 4)
00089 
00090         static_swizzle1_ref(detail::int8,  2)
00091         static_swizzle1_ref(detail::int8,  3)
00092         static_swizzle1_ref(detail::int8,  4)
00093         static_swizzle1_ref(detail::int16, 2)
00094         static_swizzle1_ref(detail::int16, 3)
00095         static_swizzle1_ref(detail::int16, 4)
00096         static_swizzle1_ref(detail::int32, 2)
00097         static_swizzle1_ref(detail::int32, 3)
00098         static_swizzle1_ref(detail::int32, 4)
00099         static_swizzle1_ref(detail::int64, 2)
00100         static_swizzle1_ref(detail::int64, 3)
00101         static_swizzle1_ref(detail::int64, 4)
00102 
00103         static_swizzle1_ref(detail::uint8,  2)
00104         static_swizzle1_ref(detail::uint8,  3)
00105         static_swizzle1_ref(detail::uint8,  4)
00106         static_swizzle1_ref(detail::uint16, 2)
00107         static_swizzle1_ref(detail::uint16, 3)
00108         static_swizzle1_ref(detail::uint16, 4)
00109         static_swizzle1_ref(detail::uint32, 2)
00110         static_swizzle1_ref(detail::uint32, 3)
00111         static_swizzle1_ref(detail::uint32, 4)
00112         static_swizzle1_ref(detail::uint64, 2)
00113         static_swizzle1_ref(detail::uint64, 3)
00114         static_swizzle1_ref(detail::uint64, 4)
00115 /*
00116 #       define static_swizzle2_const(TYPE) \
00117                 template <comp x, comp y> \
00118                 GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
00119                 {return TYPE(v[x], v[y]);}
00120 
00121 #       define static_swizzle3_const(TYPE) \
00122                 template <comp x, comp y, comp z> \
00123                 GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
00124                 {return TYPE(v[x], v[y], v[z]);}
00125 
00126 #       define static_swizzle4_const(TYPE) \
00127                 template <comp x, comp y, comp z, comp w> \
00128                 GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
00129                 {return TYPE(v[x], v[y], v[z], v[w]);}
00130 */
00131 
00132 #       define static_swizzle2_const(TYPE, SIZE)                                                                        \
00133                 template <comp x, comp y>                                                                                               \
00134                 GLM_FUNC_QUALIFIER detail::tvec2<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v)      \
00135                 {return detail::tvec2<TYPE>(v[x], v[y]);}
00136 
00137 #       define static_swizzle3_const(TYPE, SIZE)                                                                        \
00138                 template <comp x, comp y, comp z>                                                                               \
00139                 GLM_FUNC_QUALIFIER detail::tvec3<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v)      \
00140                 {return detail::tvec3<TYPE>(v[x], v[y], v[z]);}
00141 
00142 #       define static_swizzle4_const(TYPE, SIZE)                                                                        \
00143                 template <comp x, comp y, comp z, comp w>                                                               \
00144                 GLM_FUNC_QUALIFIER detail::tvec4<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v)      \
00145                 {return detail::tvec4<TYPE>(v[x], v[y], v[z], v[w]);}
00146 
00147 
00148         static_swizzle2_const(glm::f16, 2)
00149         static_swizzle2_const(glm::f16, 3)
00150         static_swizzle2_const(glm::f16, 4)
00151         static_swizzle2_const(glm::f32, 2)
00152         static_swizzle2_const(glm::f32, 3)
00153         static_swizzle2_const(glm::f32, 4)
00154         static_swizzle2_const(glm::f64, 2)
00155         static_swizzle2_const(glm::f64, 3)
00156         static_swizzle2_const(glm::f64, 4)
00157 
00158         static_swizzle2_const(glm::i8, 2)
00159         static_swizzle2_const(glm::i8, 3)
00160         static_swizzle2_const(glm::i8, 4)
00161         static_swizzle2_const(glm::i16, 2)
00162         static_swizzle2_const(glm::i16, 3)
00163         static_swizzle2_const(glm::i16, 4)
00164         static_swizzle2_const(glm::i32, 2)
00165         static_swizzle2_const(glm::i32, 3)
00166         static_swizzle2_const(glm::i32, 4)
00167         static_swizzle2_const(glm::i64, 2)
00168         static_swizzle2_const(glm::i64, 3)
00169         static_swizzle2_const(glm::i64, 4)
00170 
00171         static_swizzle2_const(glm::u8, 2)
00172         static_swizzle2_const(glm::u8, 3)
00173         static_swizzle2_const(glm::u8, 4)
00174         static_swizzle2_const(glm::u16, 2)
00175         static_swizzle2_const(glm::u16, 3)
00176         static_swizzle2_const(glm::u16, 4)
00177         static_swizzle2_const(glm::u32, 2)
00178         static_swizzle2_const(glm::u32, 3)
00179         static_swizzle2_const(glm::u32, 4)
00180         static_swizzle2_const(glm::u64, 2)
00181         static_swizzle2_const(glm::u64, 3)
00182         static_swizzle2_const(glm::u64, 4)
00183 
00184         static_swizzle3_const(glm::f16, 2)
00185         static_swizzle3_const(glm::f16, 3)
00186         static_swizzle3_const(glm::f16, 4)
00187         static_swizzle3_const(glm::f32, 2)
00188         static_swizzle3_const(glm::f32, 3)
00189         static_swizzle3_const(glm::f32, 4)
00190         static_swizzle3_const(glm::f64, 2)
00191         static_swizzle3_const(glm::f64, 3)
00192         static_swizzle3_const(glm::f64, 4)
00193 
00194         static_swizzle3_const(glm::i8, 2)
00195         static_swizzle3_const(glm::i8, 3)
00196         static_swizzle3_const(glm::i8, 4)
00197         static_swizzle3_const(glm::i16, 2)
00198         static_swizzle3_const(glm::i16, 3)
00199         static_swizzle3_const(glm::i16, 4)
00200         static_swizzle3_const(glm::i32, 2)
00201         static_swizzle3_const(glm::i32, 3)
00202         static_swizzle3_const(glm::i32, 4)
00203         static_swizzle3_const(glm::i64, 2)
00204         static_swizzle3_const(glm::i64, 3)
00205         static_swizzle3_const(glm::i64, 4)
00206 
00207         static_swizzle3_const(glm::u8, 2)
00208         static_swizzle3_const(glm::u8, 3)
00209         static_swizzle3_const(glm::u8, 4)
00210         static_swizzle3_const(glm::u16, 2)
00211         static_swizzle3_const(glm::u16, 3)
00212         static_swizzle3_const(glm::u16, 4)
00213         static_swizzle3_const(glm::u32, 2)
00214         static_swizzle3_const(glm::u32, 3)
00215         static_swizzle3_const(glm::u32, 4)
00216         static_swizzle3_const(glm::u64, 2)
00217         static_swizzle3_const(glm::u64, 3)
00218         static_swizzle3_const(glm::u64, 4)
00219 
00220         static_swizzle4_const(glm::f16, 2)
00221         static_swizzle4_const(glm::f16, 3)
00222         static_swizzle4_const(glm::f16, 4)
00223         static_swizzle4_const(glm::f32, 2)
00224         static_swizzle4_const(glm::f32, 3)
00225         static_swizzle4_const(glm::f32, 4)
00226         static_swizzle4_const(glm::f64, 2)
00227         static_swizzle4_const(glm::f64, 3)
00228         static_swizzle4_const(glm::f64, 4)
00229 
00230         static_swizzle4_const(glm::i8, 2)
00231         static_swizzle4_const(glm::i8, 3)
00232         static_swizzle4_const(glm::i8, 4)
00233         static_swizzle4_const(glm::i16, 2)
00234         static_swizzle4_const(glm::i16, 3)
00235         static_swizzle4_const(glm::i16, 4)
00236         static_swizzle4_const(glm::i32, 2)
00237         static_swizzle4_const(glm::i32, 3)
00238         static_swizzle4_const(glm::i32, 4)
00239         static_swizzle4_const(glm::i64, 2)
00240         static_swizzle4_const(glm::i64, 3)
00241         static_swizzle4_const(glm::i64, 4)
00242 
00243         static_swizzle4_const(glm::u8, 2)
00244         static_swizzle4_const(glm::u8, 3)
00245         static_swizzle4_const(glm::u8, 4)
00246         static_swizzle4_const(glm::u16, 2)
00247         static_swizzle4_const(glm::u16, 3)
00248         static_swizzle4_const(glm::u16, 4)
00249         static_swizzle4_const(glm::u32, 2)
00250         static_swizzle4_const(glm::u32, 3)
00251         static_swizzle4_const(glm::u32, 4)
00252         static_swizzle4_const(glm::u64, 2)
00253         static_swizzle4_const(glm::u64, 3)
00254         static_swizzle4_const(glm::u64, 4)
00255 
00256 #       define static_swizzle2_ref(TYPE, SIZE) \
00257                 template <glm::comp x, glm::comp y> \
00258                 GLM_FUNC_QUALIFIER glm::detail::tref2<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
00259                 {return glm::detail::tref2<TYPE>(v[x], v[y]);}  
00260 
00261 #       define static_swizzle3_ref(TYPE, SIZE) \
00262                 template <glm::comp x, glm::comp y, glm::comp z> \
00263                 GLM_FUNC_QUALIFIER glm::detail::tref3<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
00264                 {return glm::detail::tref3<TYPE>(v[x], v[y], v[z]);}    
00265 
00266 #       define static_swizzle4_ref(TYPE, SIZE) \
00267                 template <glm::comp x, glm::comp y, glm::comp z, glm::comp w> \
00268                 GLM_FUNC_QUALIFIER glm::detail::tref4<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
00269                 {return glm::detail::tref4<TYPE>(v[x], v[y], v[z], v[w]);}      
00270 
00271         static_swizzle2_ref(glm::f16, 2)
00272         static_swizzle2_ref(glm::f16, 3)
00273         static_swizzle2_ref(glm::f16, 4)
00274         static_swizzle2_ref(glm::f32, 2)
00275         static_swizzle2_ref(glm::f32, 3)
00276         static_swizzle2_ref(glm::f32, 4)
00277         static_swizzle2_ref(glm::f64, 2)
00278         static_swizzle2_ref(glm::f64, 3)
00279         static_swizzle2_ref(glm::f64, 4)
00280 
00281         static_swizzle2_ref(glm::i8, 2)
00282         static_swizzle2_ref(glm::i8, 3)
00283         static_swizzle2_ref(glm::i8, 4)
00284         static_swizzle2_ref(glm::i16, 2)
00285         static_swizzle2_ref(glm::i16, 3)
00286         static_swizzle2_ref(glm::i16, 4)
00287         static_swizzle2_ref(glm::i32, 2)
00288         static_swizzle2_ref(glm::i32, 3)
00289         static_swizzle2_ref(glm::i32, 4)
00290         static_swizzle2_ref(glm::i64, 2)
00291         static_swizzle2_ref(glm::i64, 3)
00292         static_swizzle2_ref(glm::i64, 4)
00293 
00294         static_swizzle2_ref(glm::u8, 2)
00295         static_swizzle2_ref(glm::u8, 3)
00296         static_swizzle2_ref(glm::u8, 4)
00297         static_swizzle2_ref(glm::u16, 2)
00298         static_swizzle2_ref(glm::u16, 3)
00299         static_swizzle2_ref(glm::u16, 4)
00300         static_swizzle2_ref(glm::u32, 2)
00301         static_swizzle2_ref(glm::u32, 3)
00302         static_swizzle2_ref(glm::u32, 4)
00303         static_swizzle2_ref(glm::u64, 2)
00304         static_swizzle2_ref(glm::u64, 3)
00305         static_swizzle2_ref(glm::u64, 4)
00306 
00307         static_swizzle3_ref(glm::f16, 3)
00308         static_swizzle3_ref(glm::f16, 4)
00309         static_swizzle3_ref(glm::f32, 3)
00310         static_swizzle3_ref(glm::f32, 4)
00311         static_swizzle3_ref(glm::f64, 3)
00312         static_swizzle3_ref(glm::f64, 4)
00313 
00314         static_swizzle3_ref(glm::i8, 3)
00315         static_swizzle3_ref(glm::i8, 4)
00316         static_swizzle3_ref(glm::i16, 3)
00317         static_swizzle3_ref(glm::i16, 4)
00318         static_swizzle3_ref(glm::i32, 3)
00319         static_swizzle3_ref(glm::i32, 4)
00320         static_swizzle3_ref(glm::i64, 3)
00321         static_swizzle3_ref(glm::i64, 4)
00322 
00323         static_swizzle3_ref(glm::u8, 3)
00324         static_swizzle3_ref(glm::u8, 4)
00325         static_swizzle3_ref(glm::u16, 3)
00326         static_swizzle3_ref(glm::u16, 4)
00327         static_swizzle3_ref(glm::u32, 3)
00328         static_swizzle3_ref(glm::u32, 4)
00329         static_swizzle3_ref(glm::u64, 3)
00330         static_swizzle3_ref(glm::u64, 4)
00331 
00332         static_swizzle4_ref(glm::f16, 4)
00333         static_swizzle4_ref(glm::f32, 4)
00334         static_swizzle4_ref(glm::f64, 4)
00335 
00336         static_swizzle4_ref(glm::i8, 4)
00337         static_swizzle4_ref(glm::i16, 4)
00338         static_swizzle4_ref(glm::i32, 4)
00339         static_swizzle4_ref(glm::i64, 4)
00340 
00341         static_swizzle4_ref(glm::u8, 4)
00342         static_swizzle4_ref(glm::u16, 4)
00343         static_swizzle4_ref(glm::u32, 4)
00344         static_swizzle4_ref(glm::u64, 4)
00345 
00346 }//namespace swizzle
00347 }//namespace gtc
00348 }//namespace glm
00349 
00350 #include "swizzle.inl"
00351 
00352 namespace glm{using namespace gtc::swizzle;}
00353 
00354 #endif//glm_gtc_swizzle