half_float.hpp
00001 
00002 // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
00004 // Created : 2009-04-29
00005 // Updated : 2010-02-07
00006 // Licence : This source is under MIT License
00007 // File    : glm/gtc/half_float.hpp
00009 
00010 #ifndef glm_gtc_half_float
00011 #define glm_gtc_half_float
00012 
00013 // Dependency:
00014 #include "../glm.hpp"
00015 
00016 #if(defined(GLM_MESSAGES) && !defined(glm_ext))
00017 #       pragma message("GLM: GLM_GTC_half_float extension included")
00018 #endif
00019 
00020 namespace glm{
00021 namespace detail
00022 {
00023 #ifndef _MSC_EXTENSIONS
00024         template <>
00025         struct tvec2<thalf>
00026         {
00027                 enum ctor{null};
00028                 typedef thalf value_type;
00029                 typedef std::size_t size_type;
00030                 static size_type value_size();
00031                 GLM_FUNC_DECL size_type length() const;
00032 
00033                 typedef tvec2<thalf> type;
00034                 typedef tvec2<bool> bool_type;
00035 
00037                 // Data
00038 
00039                 thalf x, y;
00040 
00042                 // Accesses
00043 
00044                 thalf & operator[](size_type i);
00045                 thalf const & operator[](size_type i) const;
00046 
00048                 // Implicit basic constructors
00049 
00050                 tvec2();
00051                 tvec2(tvec2<thalf> const & v);
00052 
00054                 // Explicit basic constructors
00055 
00056                 explicit tvec2(ctor);
00057                 explicit tvec2(
00058                         thalf const & s);
00059                 explicit tvec2(
00060                         thalf const & s1, 
00061                         thalf const & s2);
00062 
00064                 // Swizzle constructors
00065 
00066                 tvec2(tref2<thalf> const & r);
00067 
00069                 // Convertion scalar constructors
00070 
00072                 template <typename U> 
00073                 explicit tvec2(U const & x);
00075                 template <typename U, typename V> 
00076                 explicit tvec2(U const & x, V const & y);                       
00077 
00079                 // Convertion vector constructors
00080 
00082                 template <typename U> 
00083                 explicit tvec2(tvec2<U> const & v);
00085                 template <typename U> 
00086                 explicit tvec2(tvec3<U> const & v);
00088                 template <typename U> 
00089                 explicit tvec2(tvec4<U> const & v);
00090 
00092                 // Unary arithmetic operators
00093 
00094                 tvec2<thalf>& operator= (tvec2<thalf> const & v);
00095 
00096                 tvec2<thalf>& operator+=(thalf const & s);
00097                 tvec2<thalf>& operator+=(tvec2<thalf> const & v);
00098                 tvec2<thalf>& operator-=(thalf const & s);
00099                 tvec2<thalf>& operator-=(tvec2<thalf> const & v);
00100                 tvec2<thalf>& operator*=(thalf const & s);
00101                 tvec2<thalf>& operator*=(tvec2<thalf> const & v);
00102                 tvec2<thalf>& operator/=(thalf const & s);
00103                 tvec2<thalf>& operator/=(tvec2<thalf> const & v);
00104                 tvec2<thalf>& operator++();
00105                 tvec2<thalf>& operator--();
00106 
00108                 // Swizzle operators
00109 
00110                 thalf swizzle(comp X) const;
00111                 tvec2<thalf> swizzle(comp X, comp Y) const;
00112                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00113                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00114                 tref2<thalf> swizzle(comp X, comp Y);
00115         };
00116 
00117         template <>
00118         struct tvec3<thalf>
00119         {
00120                 enum ctor{null};
00121                 typedef thalf value_type;
00122                 typedef std::size_t size_type;
00123                 static size_type value_size();
00124                 GLM_FUNC_DECL size_type length() const;
00125 
00126                 typedef tvec3<thalf> type;
00127                 typedef tvec3<bool> bool_type;
00128 
00130                 // Data
00131 
00132                 thalf x, y, z;
00133 
00135                 // Accesses
00136 
00137                 thalf & operator[](size_type i);
00138                 thalf const & operator[](size_type i) const;
00139 
00141                 // Implicit basic constructors
00142 
00143                 tvec3();
00144                 tvec3(tvec3<thalf> const & v);
00145 
00147                 // Explicit basic constructors
00148 
00149                 explicit tvec3(ctor);
00150                 explicit tvec3(
00151                         thalf const & s);
00152                 explicit tvec3(
00153                         thalf const & s1, 
00154                         thalf const & s2, 
00155                         thalf const & s3);
00156 
00158                 // Swizzle constructors
00159 
00160                 tvec3(tref3<thalf> const & r);
00161 
00163                 // Convertion scalar constructors
00164 
00166                 template <typename U> 
00167                 explicit tvec3(U const & x);
00169                 template <typename U, typename V, typename W> 
00170                 explicit tvec3(U const & x, V const & y, W const & z);                  
00171 
00173                 // Convertion vector constructors
00174 
00176                 template <typename A, typename B> 
00177                 explicit tvec3(tvec2<A> const & v, B const & s);
00179                 template <typename A, typename B> 
00180                 explicit tvec3(A const & s, tvec2<B> const & v);
00182                 template <typename U> 
00183                 explicit tvec3(tvec3<U> const & v);
00185                 template <typename U> 
00186                 explicit tvec3(tvec4<U> const & v);
00187 
00189                 // Unary arithmetic operators
00190 
00191                 tvec3<thalf>& operator= (tvec3<thalf> const & v);
00192 
00193                 tvec3<thalf>& operator+=(thalf const & s);
00194                 tvec3<thalf>& operator+=(tvec3<thalf> const & v);
00195                 tvec3<thalf>& operator-=(thalf const & s);
00196                 tvec3<thalf>& operator-=(tvec3<thalf> const & v);
00197                 tvec3<thalf>& operator*=(thalf const & s);
00198                 tvec3<thalf>& operator*=(tvec3<thalf> const & v);
00199                 tvec3<thalf>& operator/=(thalf const & s);
00200                 tvec3<thalf>& operator/=(tvec3<thalf> const & v);
00201                 tvec3<thalf>& operator++();
00202                 tvec3<thalf>& operator--();
00203 
00205                 // Swizzle operators
00206 
00207                 thalf swizzle(comp X) const;
00208                 tvec2<thalf> swizzle(comp X, comp Y) const;
00209                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00210                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00211                 tref3<thalf> swizzle(comp X, comp Y, comp Z);
00212         };
00213 
00214         template <>
00215         struct tvec4<thalf>
00216         {
00217                 enum ctor{null};
00218                 typedef thalf value_type;
00219                 typedef std::size_t size_type;
00220                 static size_type value_size();
00221                 GLM_FUNC_DECL size_type length() const;
00222 
00223                 typedef tvec4<thalf> type;
00224                 typedef tvec4<bool> bool_type;
00225 
00227                 // Data
00228 
00229                 thalf x, y, z, w;
00230 
00232                 // Accesses
00233 
00234                 thalf & operator[](size_type i);
00235                 thalf const & operator[](size_type i) const;
00236 
00238                 // Implicit basic constructors
00239 
00240                 tvec4();
00241                 tvec4(tvec4<thalf> const & v);
00242 
00244                 // Explicit basic constructors
00245 
00246                 explicit tvec4(ctor);
00247                 explicit tvec4(
00248                         thalf const & s);
00249                 explicit tvec4(
00250                         thalf const & s0, 
00251                         thalf const & s1, 
00252                         thalf const & s2, 
00253                         thalf const & s3);
00254 
00256                 // Swizzle constructors
00257 
00258                 tvec4(tref4<thalf> const & r);
00259 
00261                 // Convertion scalar constructors
00262 
00264                 template <typename U> 
00265                 explicit tvec4(U const & x);
00267                 template <typename A, typename B, typename C, typename D> 
00268                 explicit tvec4(A const & x, B const & y, C const & z, D const & w);                     
00269 
00271                 // Convertion vector constructors
00272 
00274                 template <typename A, typename B, typename C> 
00275                 explicit tvec4(tvec2<A> const & v, B const & s1, C const & s2);
00277                 template <typename A, typename B, typename C> 
00278                 explicit tvec4(A const & s1, tvec2<B> const & v, C const & s2);
00280                 template <typename A, typename B, typename C> 
00281                 explicit tvec4(A const & s1, B const & s2, tvec2<C> const & v);
00283                 template <typename A, typename B> 
00284                 explicit tvec4(tvec3<A> const & v, B const & s);
00286                 template <typename A, typename B> 
00287                 explicit tvec4(A const & s, tvec3<B> const & v);
00289                 template <typename A, typename B> 
00290                 explicit tvec4(tvec2<A> const & v1, tvec2<B> const & v2);
00292                 template <typename U> 
00293                 explicit tvec4(tvec4<U> const & v);
00294 
00296                 // Unary arithmetic operators
00297 
00298                 tvec4<thalf>& operator= (tvec4<thalf> const & v);
00299 
00300                 tvec4<thalf>& operator+=(thalf const & s);
00301                 tvec4<thalf>& operator+=(tvec4<thalf> const & v);
00302                 tvec4<thalf>& operator-=(thalf const & s);
00303                 tvec4<thalf>& operator-=(tvec4<thalf> const & v);
00304                 tvec4<thalf>& operator*=(thalf const & s);
00305                 tvec4<thalf>& operator*=(tvec4<thalf> const & v);
00306                 tvec4<thalf>& operator/=(thalf const & s);
00307                 tvec4<thalf>& operator/=(tvec4<thalf> const & v);
00308                 tvec4<thalf>& operator++();
00309                 tvec4<thalf>& operator--();
00310 
00312                 // Swizzle operators
00313 
00314                 thalf swizzle(comp X) const;
00315                 tvec2<thalf> swizzle(comp X, comp Y) const;
00316                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00317                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00318                 tref4<thalf> swizzle(comp X, comp Y, comp Z, comp W);
00319         };
00320 #endif//_MSC_EXTENSIONS
00321 }
00322 //namespace detail
00323 
00324 namespace gtc{
00325 namespace half_float 
00326 {
00329 
00332         typedef detail::thalf                                   half;
00333 
00336         typedef detail::tvec2<detail::thalf>    hvec2;
00337 
00340         typedef detail::tvec3<detail::thalf>    hvec3;
00341 
00344         typedef detail::tvec4<detail::thalf>    hvec4;
00345 
00348         typedef detail::tmat2x2<detail::thalf>  hmat2;
00349     
00352         typedef detail::tmat3x3<detail::thalf>  hmat3;
00353 
00356         typedef detail::tmat4x4<detail::thalf>  hmat4;
00357 
00360         typedef detail::tmat2x2<detail::thalf>  hmat2x2;
00361     
00364         typedef detail::tmat2x3<detail::thalf>  hmat2x3;
00365     
00368         typedef detail::tmat2x4<detail::thalf>  hmat2x4;
00369 
00372         typedef detail::tmat3x2<detail::thalf>  hmat3x2;
00373     
00376         typedef detail::tmat3x3<detail::thalf>  hmat3x3;
00377     
00380         typedef detail::tmat3x4<detail::thalf>  hmat3x4;
00381 
00384         typedef detail::tmat4x2<detail::thalf>  hmat4x2;    
00385 
00388         typedef detail::tmat4x3<detail::thalf>  hmat4x3;
00389     
00392         typedef detail::tmat4x4<detail::thalf>  hmat4x4;
00393     
00395 
00396 }// namespace half_float
00397 }// namespace gtc
00398 }// namespace glm
00399 
00400 #include "half_float.inl"
00401 
00402 namespace glm{using namespace gtc::half_float;}
00403 
00404 #endif//glm_gtc_half_float