1 /////////////////////////////////////////////////////////////////////////////////// 2 /// OpenGL Mathematics (glm.g-truc.net) 3 /// 4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) 5 /// Permission is hereby granted, free of charge, to any person obtaining a copy 6 /// of this software and associated documentation files (the "Software"), to deal 7 /// in the Software without restriction, including without limitation the rights 8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 /// copies of the Software, and to permit persons to whom the Software is 10 /// furnished to do so, subject to the following conditions: 11 /// 12 /// The above copyright notice and this permission notice shall be included in 13 /// all copies or substantial portions of the Software. 14 /// 15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 /// THE SOFTWARE. 22 /// 23 /// @ref core 24 /// @file glm/core/_vectorize.hpp 25 /// @date 2011-10-14 / 2011-10-14 26 /// @author Christophe Riccio 27 /////////////////////////////////////////////////////////////////////////////////// 28 29 #ifndef GLM_CORE_DETAIL_INCLUDED 30 #define GLM_CORE_DETAIL_INCLUDED 31 32 #include "type_vec1.hpp" 33 #include "type_vec2.hpp" 34 #include "type_vec3.hpp" 35 #include "type_vec4.hpp" 36 37 #define VECTORIZE1_VEC(func) \ 38 template <typename T, precision P> \ 39 GLM_FUNC_QUALIFIER detail::tvec1<T, P> func( \ 40 detail::tvec1<T, P> const & v) \ 41 { \ 42 return detail::tvec1<T, P>( \ 43 func(v.x)); \ 44 } 45 46 #define VECTORIZE2_VEC(func) \ 47 template <typename T, precision P> \ 48 GLM_FUNC_QUALIFIER detail::tvec2<T, P> func( \ 49 detail::tvec2<T, P> const & v) \ 50 { \ 51 return detail::tvec2<T, P>( \ 52 func(v.x), \ 53 func(v.y)); \ 54 } 55 56 #define VECTORIZE3_VEC(func) \ 57 template <typename T, precision P> \ 58 GLM_FUNC_QUALIFIER detail::tvec3<T, P> func( \ 59 detail::tvec3<T, P> const & v) \ 60 { \ 61 return detail::tvec3<T, P>( \ 62 func(v.x), \ 63 func(v.y), \ 64 func(v.z)); \ 65 } 66 67 #define VECTORIZE4_VEC(func) \ 68 template <typename T, precision P> \ 69 GLM_FUNC_QUALIFIER detail::tvec4<T, P> func( \ 70 detail::tvec4<T, P> const & v) \ 71 { \ 72 return detail::tvec4<T, P>( \ 73 func(v.x), \ 74 func(v.y), \ 75 func(v.z), \ 76 func(v.w)); \ 77 } 78 79 #define VECTORIZE_VEC(func) \ 80 VECTORIZE1_VEC(func) \ 81 VECTORIZE2_VEC(func) \ 82 VECTORIZE3_VEC(func) \ 83 VECTORIZE4_VEC(func) 84 85 #define VECTORIZE1_VEC_SCA(func) \ 86 template <typename T, precision P> \ 87 GLM_FUNC_QUALIFIER detail::tvec1<T, P> func \ 88 ( \ 89 detail::tvec1<T, P> const & x, \ 90 T const & y \ 91 ) \ 92 { \ 93 return detail::tvec1<T, P>( \ 94 func(x.x, y)); \ 95 } 96 97 #define VECTORIZE2_VEC_SCA(func) \ 98 template <typename T, precision P> \ 99 GLM_FUNC_QUALIFIER detail::tvec2<T, P> func \ 100 ( \ 101 detail::tvec2<T, P> const & x, \ 102 T const & y \ 103 ) \ 104 { \ 105 return detail::tvec2<T, P>( \ 106 func(x.x, y), \ 107 func(x.y, y)); \ 108 } 109 110 #define VECTORIZE3_VEC_SCA(func) \ 111 template <typename T, precision P> \ 112 GLM_FUNC_QUALIFIER detail::tvec3<T, P> func \ 113 ( \ 114 detail::tvec3<T, P> const & x, \ 115 T const & y \ 116 ) \ 117 { \ 118 return detail::tvec3<T, P>( \ 119 func(x.x, y), \ 120 func(x.y, y), \ 121 func(x.z, y)); \ 122 } 123 124 #define VECTORIZE4_VEC_SCA(func) \ 125 template <typename T, precision P> \ 126 GLM_FUNC_QUALIFIER detail::tvec4<T, P> func \ 127 ( \ 128 detail::tvec4<T, P> const & x, \ 129 T const & y \ 130 ) \ 131 { \ 132 return detail::tvec4<T, P>( \ 133 func(x.x, y), \ 134 func(x.y, y), \ 135 func(x.z, y), \ 136 func(x.w, y)); \ 137 } 138 139 #define VECTORIZE_VEC_SCA(func) \ 140 VECTORIZE1_VEC_SCA(func) \ 141 VECTORIZE2_VEC_SCA(func) \ 142 VECTORIZE3_VEC_SCA(func) \ 143 VECTORIZE4_VEC_SCA(func) 144 145 #define VECTORIZE2_VEC_VEC(func) \ 146 template <typename T, precision P> \ 147 GLM_FUNC_QUALIFIER detail::tvec2<T, P> func \ 148 ( \ 149 detail::tvec2<T, P> const & x, \ 150 detail::tvec2<T, P> const & y \ 151 ) \ 152 { \ 153 return detail::tvec2<T, P>( \ 154 func(x.x, y.x), \ 155 func(x.y, y.y)); \ 156 } 157 158 #define VECTORIZE3_VEC_VEC(func) \ 159 template <typename T, precision P> \ 160 GLM_FUNC_QUALIFIER detail::tvec3<T, P> func \ 161 ( \ 162 detail::tvec3<T, P> const & x, \ 163 detail::tvec3<T, P> const & y \ 164 ) \ 165 { \ 166 return detail::tvec3<T, P>( \ 167 func(x.x, y.x), \ 168 func(x.y, y.y), \ 169 func(x.z, y.z)); \ 170 } 171 172 #define VECTORIZE4_VEC_VEC(func) \ 173 template <typename T, precision P> \ 174 GLM_FUNC_QUALIFIER detail::tvec4<T, P> func \ 175 ( \ 176 detail::tvec4<T, P> const & x, \ 177 detail::tvec4<T, P> const & y \ 178 ) \ 179 { \ 180 return detail::tvec4<T, P>( \ 181 func(x.x, y.x), \ 182 func(x.y, y.y), \ 183 func(x.z, y.z), \ 184 func(x.w, y.w)); \ 185 } 186 187 #define VECTORIZE_VEC_VEC(func) \ 188 VECTORIZE2_VEC_VEC(func) \ 189 VECTORIZE3_VEC_VEC(func) \ 190 VECTORIZE4_VEC_VEC(func) 191 192 namespace glm{ 193 namespace detail 194 { 195 template<bool C> 196 struct If 197 { 198 template<typename F, typename T> 199 static GLM_FUNC_QUALIFIER T apply(F functor, const T& val) 200 { 201 return functor(val); 202 } 203 }; 204 205 template<> 206 struct If<false> 207 { 208 template<typename F, typename T> 209 static GLM_FUNC_QUALIFIER T apply(F, const T& val) 210 { 211 return val; 212 } 213 }; 214 }//namespace detail 215 }//namespace glm 216 217 #endif//GLM_CORE_DETAIL_INCLUDED 218