00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGETYPETRAITS_H 00026 #define WGETYPETRAITS_H 00027 00028 #include <stdint.h> 00029 00030 #include <osg/Image> 00031 00032 #include "WExportWGE.h" 00033 00034 namespace wge 00035 { 00036 /** 00037 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00038 */ 00039 template< typename T > 00040 class WGE_EXPORT GLType 00041 { 00042 public: 00043 /** 00044 * The best matching OpenGL type for the specified template parameter. 00045 */ 00046 typedef T Type; 00047 00048 /** 00049 * The enum type of OpenGL 00050 */ 00051 static const GLenum TypeEnum = GL_BYTE; 00052 }; 00053 00054 /** 00055 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00056 */ 00057 template <> 00058 class WGE_EXPORT GLType< double > 00059 { 00060 public: 00061 /** 00062 * The best matching OpenGL type for the specified template parameter. 00063 */ 00064 typedef float Type; 00065 00066 /** 00067 * The enum type of OpenGL 00068 */ 00069 static const GLenum TypeEnum = GL_FLOAT; 00070 00071 /** 00072 * The value for full intensity. 00073 * 00074 * \return the full intensity value 00075 */ 00076 static Type FullIntensity(){ return 1.0; } // NOLINT 00077 }; 00078 00079 /** 00080 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00081 */ 00082 template <> 00083 class WGE_EXPORT GLType< float > 00084 { 00085 public: 00086 /** 00087 * The best matching OpenGL type for the specified template parameter. 00088 */ 00089 typedef float Type; 00090 00091 /** 00092 * The enum type of OpenGL 00093 */ 00094 static const GLenum TypeEnum = GL_FLOAT; 00095 00096 /** 00097 * The value for full intensity. 00098 * 00099 * \return the full intensity value 00100 */ 00101 static Type FullIntensity(){ return 1.0; } // NOLINT 00102 }; 00103 00104 /** 00105 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00106 */ 00107 template <> 00108 class WGE_EXPORT GLType< int8_t > 00109 { 00110 public: 00111 /** 00112 * The best matching OpenGL type for the specified template parameter. 00113 */ 00114 typedef int8_t Type; 00115 00116 /** 00117 * The enum type of OpenGL 00118 */ 00119 static const GLenum TypeEnum = GL_BYTE; 00120 00121 /** 00122 * The value for full intensity. 00123 * 00124 * \return the full intensity value 00125 */ 00126 static Type FullIntensity(){ return 127; } // NOLINT 00127 }; 00128 00129 /** 00130 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00131 */ 00132 template <> 00133 class WGE_EXPORT GLType< uint8_t > 00134 { 00135 public: 00136 /** 00137 * The best matching OpenGL type for the specified template parameter. 00138 */ 00139 typedef uint8_t Type; 00140 00141 /** 00142 * The enum type of OpenGL 00143 */ 00144 static const GLenum TypeEnum = GL_UNSIGNED_BYTE; 00145 00146 /** 00147 * The value for full intensity. 00148 * 00149 * \return the full intensity value 00150 */ 00151 static Type FullIntensity(){ return 255; } // NOLINT 00152 }; 00153 00154 /** 00155 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00156 * 00157 * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead. 00158 */ 00159 template <> 00160 class WGE_EXPORT GLType< int16_t > 00161 { 00162 public: 00163 /** 00164 * The best matching OpenGL type for the specified template parameter. 00165 */ 00166 typedef float Type; 00167 00168 /** 00169 * The enum type of OpenGL 00170 */ 00171 static const GLenum TypeEnum = GL_FLOAT; 00172 00173 /** 00174 * The value for full intensity. 00175 * 00176 * \return the full intensity value 00177 */ 00178 static Type FullIntensity(){ return 1.0; } // NOLINT 00179 }; 00180 00181 /** 00182 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00183 * 00184 * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead. 00185 */ 00186 template <> 00187 class WGE_EXPORT GLType< uint16_t > 00188 { 00189 public: 00190 /** 00191 * The best matching OpenGL type for the specified template parameter. 00192 */ 00193 typedef float Type; 00194 00195 /** 00196 * The enum type of OpenGL 00197 */ 00198 static const GLenum TypeEnum = GL_FLOAT; 00199 00200 /** 00201 * The value for full intensity. 00202 * 00203 * \return the full intensity value 00204 */ 00205 static Type FullIntensity(){ return 1.0; } // NOLINT 00206 }; 00207 00208 /** 00209 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00210 * 00211 * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead. 00212 */ 00213 template <> 00214 class WGE_EXPORT GLType< int32_t > 00215 { 00216 public: 00217 /** 00218 * The best matching OpenGL type for the specified template parameter. 00219 */ 00220 typedef float Type; 00221 00222 /** 00223 * The enum type of OpenGL 00224 */ 00225 static const GLenum TypeEnum = GL_FLOAT; 00226 00227 /** 00228 * The value for full intensity. 00229 * 00230 * \return the full intensity value 00231 */ 00232 static Type FullIntensity(){ return 1.0; } // NOLINT 00233 }; 00234 00235 /** 00236 * Class helping to adapt types specified as template parameter into the best matching OpenGL type. 00237 * 00238 * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead. 00239 */ 00240 template <> 00241 class WGE_EXPORT GLType< uint32_t > 00242 { 00243 public: 00244 /** 00245 * The best matching OpenGL type for the specified template parameter. 00246 */ 00247 typedef float Type; 00248 00249 /** 00250 * The enum type of OpenGL 00251 */ 00252 static const GLenum TypeEnum = GL_FLOAT; 00253 00254 /** 00255 * The value for full intensity. 00256 * 00257 * \return the full intensity value 00258 */ 00259 static Type FullIntensity(){ return 1.0; } // NOLINT 00260 }; 00261 } 00262 00263 #endif // WGETYPETRAITS_H 00264