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 
00032                 typedef tvec2<thalf> type;
00033                 typedef tvec2<bool> bool_type;
00034 
00036                 // Data
00037 
00038                 thalf x, y;
00039 
00041                 // Accesses
00042 
00043                 thalf & operator[](size_type i);
00044                 thalf const & operator[](size_type i) const;
00045 
00047                 // Implicit basic constructors
00048 
00049                 tvec2();
00050                 tvec2(tvec2<thalf> const & v);
00051 
00053                 // Explicit basic constructors
00054 
00055                 explicit tvec2(ctor);
00056                 explicit tvec2(
00057                         thalf const & s);
00058                 explicit tvec2(
00059                         thalf const & s1, 
00060                         thalf const & s2);
00061 
00063                 // Swizzle constructors
00064 
00065                 tvec2(tref2<thalf> const & r);
00066 
00068                 // Convertion scalar constructors
00069 
00071                 template <typename U> 
00072                 explicit tvec2(U const & x);
00074                 template <typename U, typename V> 
00075                 explicit tvec2(U const & x, V const & y);                       
00076 
00078                 // Convertion vector constructors
00079 
00081                 template <typename U> 
00082                 explicit tvec2(tvec2<U> const & v);
00084                 template <typename U> 
00085                 explicit tvec2(tvec3<U> const & v);
00087                 template <typename U> 
00088                 explicit tvec2(tvec4<U> const & v);
00089 
00091                 // Unary arithmetic operators
00092 
00093                 tvec2<thalf>& operator= (tvec2<thalf> const & v);
00094 
00095                 tvec2<thalf>& operator+=(thalf const & s);
00096                 tvec2<thalf>& operator+=(tvec2<thalf> const & v);
00097                 tvec2<thalf>& operator-=(thalf const & s);
00098                 tvec2<thalf>& operator-=(tvec2<thalf> const & v);
00099                 tvec2<thalf>& operator*=(thalf const & s);
00100                 tvec2<thalf>& operator*=(tvec2<thalf> const & v);
00101                 tvec2<thalf>& operator/=(thalf const & s);
00102                 tvec2<thalf>& operator/=(tvec2<thalf> const & v);
00103                 tvec2<thalf>& operator++();
00104                 tvec2<thalf>& operator--();
00105 
00107                 // Swizzle operators
00108 
00109                 thalf swizzle(comp X) const;
00110                 tvec2<thalf> swizzle(comp X, comp Y) const;
00111                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00112                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00113                 tref2<thalf> swizzle(comp X, comp Y);
00114         };
00115 
00116         template <>
00117         struct tvec3<thalf>
00118         {
00119                 enum ctor{null};
00120                 typedef thalf value_type;
00121                 typedef std::size_t size_type;
00122                 static size_type value_size();
00123 
00124                 typedef tvec3<thalf> type;
00125                 typedef tvec3<bool> bool_type;
00126 
00128                 // Data
00129 
00130                 thalf x, y, z;
00131 
00133                 // Accesses
00134 
00135                 thalf & operator[](size_type i);
00136                 thalf const & operator[](size_type i) const;
00137 
00139                 // Implicit basic constructors
00140 
00141                 tvec3();
00142                 tvec3(tvec3<thalf> const & v);
00143 
00145                 // Explicit basic constructors
00146 
00147                 explicit tvec3(ctor);
00148                 explicit tvec3(
00149                         thalf const & s);
00150                 explicit tvec3(
00151                         thalf const & s1, 
00152                         thalf const & s2, 
00153                         thalf const & s3);
00154 
00156                 // Swizzle constructors
00157 
00158                 tvec3(tref3<thalf> const & r);
00159 
00161                 // Convertion scalar constructors
00162 
00164                 template <typename U> 
00165                 explicit tvec3(U const & x);
00167                 template <typename U, typename V, typename W> 
00168                 explicit tvec3(U const & x, V const & y, W const & z);                  
00169 
00171                 // Convertion vector constructors
00172 
00174                 template <typename A, typename B> 
00175                 explicit tvec3(tvec2<A> const & v, B const & s);
00177                 template <typename A, typename B> 
00178                 explicit tvec3(A const & s, tvec2<B> const & v);
00180                 template <typename U> 
00181                 explicit tvec3(tvec3<U> const & v);
00183                 template <typename U> 
00184                 explicit tvec3(tvec4<U> const & v);
00185 
00187                 // Unary arithmetic operators
00188 
00189                 tvec3<thalf>& operator= (tvec3<thalf> const & v);
00190 
00191                 tvec3<thalf>& operator+=(thalf const & s);
00192                 tvec3<thalf>& operator+=(tvec3<thalf> const & v);
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++();
00200                 tvec3<thalf>& operator--();
00201 
00203                 // Swizzle operators
00204 
00205                 thalf swizzle(comp X) const;
00206                 tvec2<thalf> swizzle(comp X, comp Y) const;
00207                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00208                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00209                 tref3<thalf> swizzle(comp X, comp Y, comp Z);
00210         };
00211 
00212         template <>
00213         struct tvec4<thalf>
00214         {
00215                 enum ctor{null};
00216                 typedef thalf value_type;
00217                 typedef std::size_t size_type;
00218                 static size_type value_size();
00219 
00220                 typedef tvec4<thalf> type;
00221                 typedef tvec4<bool> bool_type;
00222 
00224                 // Data
00225 
00226                 thalf x, y, z, w;
00227 
00229                 // Accesses
00230 
00231                 thalf & operator[](size_type i);
00232                 thalf const & operator[](size_type i) const;
00233 
00235                 // Implicit basic constructors
00236 
00237                 tvec4();
00238                 tvec4(tvec4<thalf> const & v);
00239 
00241                 // Explicit basic constructors
00242 
00243                 explicit tvec4(ctor);
00244                 explicit tvec4(
00245                         thalf const & s);
00246                 explicit tvec4(
00247                         thalf const & s0, 
00248                         thalf const & s1, 
00249                         thalf const & s2, 
00250                         thalf const & s3);
00251 
00253                 // Swizzle constructors
00254 
00255                 tvec4(tref4<thalf> const & r);
00256 
00258                 // Convertion scalar constructors
00259 
00261                 template <typename U> 
00262                 explicit tvec4(U const & x);
00264                 template <typename A, typename B, typename C, typename D> 
00265                 explicit tvec4(A const & x, B const & y, C const & z, D const & w);                     
00266 
00268                 // Convertion vector constructors
00269 
00271                 template <typename A, typename B, typename C> 
00272                 explicit tvec4(tvec2<A> const & v, B const & s1, C const & s2);
00274                 template <typename A, typename B, typename C> 
00275                 explicit tvec4(A const & s1, tvec2<B> const & v, C const & s2);
00277                 template <typename A, typename B, typename C> 
00278                 explicit tvec4(A const & s1, B const & s2, tvec2<C> const & v);
00280                 template <typename A, typename B> 
00281                 explicit tvec4(tvec3<A> const & v, B const & s);
00283                 template <typename A, typename B> 
00284                 explicit tvec4(A const & s, tvec3<B> const & v);
00286                 template <typename A, typename B> 
00287                 explicit tvec4(tvec2<A> const & v1, tvec2<B> const & v2);
00289                 template <typename U> 
00290                 explicit tvec4(tvec4<U> const & v);
00291 
00293                 // Unary arithmetic operators
00294 
00295                 tvec4<thalf>& operator= (tvec4<thalf> const & v);
00296 
00297                 tvec4<thalf>& operator+=(thalf const & s);
00298                 tvec4<thalf>& operator+=(tvec4<thalf> const & v);
00299                 tvec4<thalf>& operator-=(thalf const & s);
00300                 tvec4<thalf>& operator-=(tvec4<thalf> const & v);
00301                 tvec4<thalf>& operator*=(thalf const & s);
00302                 tvec4<thalf>& operator*=(tvec4<thalf> const & v);
00303                 tvec4<thalf>& operator/=(thalf const & s);
00304                 tvec4<thalf>& operator/=(tvec4<thalf> const & v);
00305                 tvec4<thalf>& operator++();
00306                 tvec4<thalf>& operator--();
00307 
00309                 // Swizzle operators
00310 
00311                 thalf swizzle(comp X) const;
00312                 tvec2<thalf> swizzle(comp X, comp Y) const;
00313                 tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00314                 tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00315                 tref4<thalf> swizzle(comp X, comp Y, comp Z, comp W);
00316         };
00317 #endif//_MSC_EXTENSIONS
00318 }
00319 //namespace detail
00320 
00321 namespace gtc{
00322 namespace half_float 
00323 {
00326 
00329         typedef detail::thalf                                   half;
00330 
00333         typedef detail::tvec2<detail::thalf>    hvec2;
00334 
00337         typedef detail::tvec3<detail::thalf>    hvec3;
00338 
00341         typedef detail::tvec4<detail::thalf>    hvec4;
00342 
00345         typedef detail::tmat2x2<detail::thalf>  hmat2;
00346 
00349         typedef detail::tmat3x3<detail::thalf>  hmat3;
00350 
00353         typedef detail::tmat4x4<detail::thalf>  hmat4;
00354 
00356 
00357 }// namespace half_float
00358 }// namespace gtc
00359 }// namespace glm
00360 
00361 #include "half_float.inl"
00362 
00363 namespace glm{using namespace gtc::half_float;}
00364 
00365 #endif//glm_gtc_half_float