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 {
00022         namespace test{
00023                 bool main_gtc_half_float();
00024         }//namespace 
00025         namespace detail
00026         {
00027 #ifndef _MSC_EXTENSIONS
00028                 template <>
00029                 struct tvec2<thalf>
00030                 {
00031                         enum ctor{null};
00032                         typedef thalf value_type;
00033                         typedef std::size_t size_type;
00034                         static size_type value_size();
00035 
00036                         typedef tvec2<thalf> type;
00037                         typedef tvec2<bool> bool_type;
00038 
00040                         // Data
00041 
00042                         thalf x, y;
00043 
00045                         // Accesses
00046 
00047                         thalf & operator[](size_type i);
00048                         thalf const & operator[](size_type i) const;
00049 
00051                         // Implicit basic constructors
00052 
00053                         tvec2();
00054                         tvec2(tvec2<thalf> const & v);
00055 
00057                         // Explicit basic constructors
00058 
00059                         explicit tvec2(ctor);
00060                         explicit tvec2(
00061                                 thalf const & s);
00062                         explicit tvec2(
00063                                 thalf const & s1, 
00064                                 thalf const & s2);
00065 
00067                         // Swizzle constructors
00068 
00069                         tvec2(tref2<thalf> const & r);
00070 
00072                         // Convertion scalar constructors
00073 
00075                         template <typename U> 
00076                         explicit tvec2(U const & x);
00078                         template <typename U, typename V> 
00079                         explicit tvec2(U const & x, V const & y);                       
00080 
00082                         // Convertion vector constructors
00083 
00085                         template <typename U> 
00086                         explicit tvec2(tvec2<U> const & v);
00088                         template <typename U> 
00089                         explicit tvec2(tvec3<U> const & v);
00091                         template <typename U> 
00092                         explicit tvec2(tvec4<U> const & v);
00093 
00095                         // Unary arithmetic operators
00096 
00097                         tvec2<thalf>& operator= (tvec2<thalf> const & v);
00098 
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*=(thalf const & s);
00104                         tvec2<thalf>& operator*=(tvec2<thalf> const & v);
00105                         tvec2<thalf>& operator/=(thalf const & s);
00106                         tvec2<thalf>& operator/=(tvec2<thalf> const & v);
00107                         tvec2<thalf>& operator++();
00108                         tvec2<thalf>& operator--();
00109 
00111                         // Swizzle operators
00112 
00113                         thalf swizzle(comp X) const;
00114                         tvec2<thalf> swizzle(comp X, comp Y) const;
00115                         tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00116                         tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00117                         tref2<thalf> swizzle(comp X, comp Y);
00118                 };
00119 
00120                 template <>
00121                 struct tvec3<thalf>
00122                 {
00123                         enum ctor{null};
00124                         typedef thalf value_type;
00125                         typedef std::size_t size_type;
00126                         static size_type value_size();
00127 
00128                         typedef tvec3<thalf> type;
00129                         typedef tvec3<bool> bool_type;
00130 
00132                         // Data
00133 
00134                         thalf x, y, z;
00135 
00137                         // Accesses
00138 
00139                         thalf & operator[](size_type i);
00140                         thalf const & operator[](size_type i) const;
00141 
00143                         // Implicit basic constructors
00144 
00145                         tvec3();
00146                         tvec3(tvec3<thalf> const & v);
00147 
00149                         // Explicit basic constructors
00150 
00151                         explicit tvec3(ctor);
00152                         explicit tvec3(
00153                                 thalf const & s);
00154                         explicit tvec3(
00155                                 thalf const & s1, 
00156                                 thalf const & s2, 
00157                                 thalf const & s3);
00158 
00160                         // Swizzle constructors
00161 
00162                         tvec3(tref3<thalf> const & r);
00163 
00165                         // Convertion scalar constructors
00166 
00168                         template <typename U> 
00169                         explicit tvec3(U const & x);
00171                         template <typename U, typename V, typename W> 
00172                         explicit tvec3(U const & x, V const & y, W const & z);                  
00173 
00175                         // Convertion vector constructors
00176 
00178                         template <typename A, typename B> 
00179                         explicit tvec3(tvec2<A> const & v, B const & s);
00181                         template <typename A, typename B> 
00182                         explicit tvec3(A const & s, tvec2<B> const & v);
00184                         template <typename U> 
00185                         explicit tvec3(tvec3<U> const & v);
00187                         template <typename U> 
00188                         explicit tvec3(tvec4<U> const & v);
00189 
00191                         // Unary arithmetic operators
00192 
00193                         tvec3<thalf>& operator= (tvec3<thalf> const & v);
00194 
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/=(thalf const & s);
00202                         tvec3<thalf>& operator/=(tvec3<thalf> const & v);
00203                         tvec3<thalf>& operator++();
00204                         tvec3<thalf>& operator--();
00205 
00207                         // Swizzle operators
00208 
00209                         thalf swizzle(comp X) const;
00210                         tvec2<thalf> swizzle(comp X, comp Y) const;
00211                         tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00212                         tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00213                         tref3<thalf> swizzle(comp X, comp Y, comp Z);
00214                 };
00215 
00216                 template <>
00217                 struct tvec4<thalf>
00218                 {
00219                         enum ctor{null};
00220                         typedef thalf value_type;
00221                         typedef std::size_t size_type;
00222                         static size_type value_size();
00223 
00224                         typedef tvec4<thalf> type;
00225                         typedef tvec4<bool> bool_type;
00226 
00228                         // Data
00229 
00230                         thalf x, y, z, w;
00231 
00233                         // Accesses
00234 
00235                         thalf & operator[](size_type i);
00236                         thalf const & operator[](size_type i) const;
00237 
00239                         // Implicit basic constructors
00240 
00241                         tvec4();
00242                         tvec4(tvec4<thalf> const & v);
00243 
00245                         // Explicit basic constructors
00246 
00247                         explicit tvec4(ctor);
00248                         explicit tvec4(
00249                                 thalf const & s);
00250                         explicit tvec4(
00251                                 thalf const & s0, 
00252                                 thalf const & s1, 
00253                                 thalf const & s2, 
00254                                 thalf const & s3);
00255 
00257                         // Swizzle constructors
00258 
00259                         tvec4(tref4<thalf> const & r);
00260 
00262                         // Convertion scalar constructors
00263 
00265                         template <typename U> 
00266                         explicit tvec4(U const & x);
00268                         template <typename A, typename B, typename C, typename D> 
00269                         explicit tvec4(A const & x, B const & y, C const & z, D const & w);                     
00270 
00272                         // Convertion vector constructors
00273 
00275                         template <typename A, typename B, typename C> 
00276                         explicit tvec4(tvec2<A> const & v, B const & s1, C const & s2);
00278                         template <typename A, typename B, typename C> 
00279                         explicit tvec4(A const & s1, tvec2<B> const & v, C const & s2);
00281                         template <typename A, typename B, typename C> 
00282                         explicit tvec4(A const & s1, B const & s2, tvec2<C> const & v);
00284                         template <typename A, typename B> 
00285                         explicit tvec4(tvec3<A> const & v, B const & s);
00287                         template <typename A, typename B> 
00288                         explicit tvec4(A const & s, tvec3<B> const & v);
00290                         template <typename A, typename B> 
00291                         explicit tvec4(tvec2<A> const & v1, tvec2<B> const & v2);
00293                         template <typename U> 
00294                         explicit tvec4(tvec4<U> const & v);
00295 
00297                         // Unary arithmetic operators
00298 
00299                         tvec4<thalf>& operator= (tvec4<thalf> const & v);
00300 
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*=(thalf const & s);
00306                         tvec4<thalf>& operator*=(tvec4<thalf> const & v);
00307                         tvec4<thalf>& operator/=(thalf const & s);
00308                         tvec4<thalf>& operator/=(tvec4<thalf> const & v);
00309                         tvec4<thalf>& operator++();
00310                         tvec4<thalf>& operator--();
00311 
00313                         // Swizzle operators
00314 
00315                         thalf swizzle(comp X) const;
00316                         tvec2<thalf> swizzle(comp X, comp Y) const;
00317                         tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
00318                         tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
00319                         tref4<thalf> swizzle(comp X, comp Y, comp Z, comp W);
00320                 };
00321 #endif//_MSC_EXTENSIONS
00322         }
00323         //namespace detail
00324 
00325         namespace gtc{
00327         namespace half_float
00328         {
00331 
00334                 typedef detail::thalf                                   half;
00335 
00338                 typedef detail::tvec2<detail::thalf>    hvec2;
00339 
00342                 typedef detail::tvec3<detail::thalf>    hvec3;
00343 
00346                 typedef detail::tvec4<detail::thalf>    hvec4;
00347 
00350                 typedef detail::tmat2x2<detail::thalf>  hmat2;
00351 
00354                 typedef detail::tmat3x3<detail::thalf>  hmat3;
00355 
00358                 typedef detail::tmat4x4<detail::thalf>  hmat4;
00359 
00361 
00362         }//namespace half_float
00363         }//namespace gtc
00364 }//namespace glm
00365 
00366 #include "half_float.inl"
00367 
00368 namespace glm{using namespace gtc::half_float;}
00369 
00370 #endif//glm_gtc_half_float