OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGETypeTraits.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGETYPETRAITS_H
26 #define WGETYPETRAITS_H
27 
28 #include <stdint.h>
29 
30 #include <osg/Image>
31 
32 #include "WExportWGE.h"
33 
34 namespace wge
35 {
36  /**
37  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
38  */
39  template< typename T >
40  class WGE_EXPORT GLType
41  {
42  public:
43  /**
44  * The best matching OpenGL type for the specified template parameter.
45  */
46  typedef T Type;
47 
48  /**
49  * The enum type of OpenGL
50  */
51  static const GLenum TypeEnum = GL_BYTE;
52  };
53 
54  /**
55  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
56  */
57  template <>
58  class WGE_EXPORT GLType< double >
59  {
60  public:
61  /**
62  * The best matching OpenGL type for the specified template parameter.
63  */
64  typedef float Type;
65 
66  /**
67  * The enum type of OpenGL
68  */
69  static const GLenum TypeEnum = GL_FLOAT;
70 
71  /**
72  * The value for full intensity.
73  *
74  * \return the full intensity value
75  */
76  static Type FullIntensity(){ return 1.0; } // NOLINT
77  };
78 
79  /**
80  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
81  */
82  template <>
83  class WGE_EXPORT GLType< float >
84  {
85  public:
86  /**
87  * The best matching OpenGL type for the specified template parameter.
88  */
89  typedef float Type;
90 
91  /**
92  * The enum type of OpenGL
93  */
94  static const GLenum TypeEnum = GL_FLOAT;
95 
96  /**
97  * The value for full intensity.
98  *
99  * \return the full intensity value
100  */
101  static Type FullIntensity(){ return 1.0; } // NOLINT
102  };
103 
104  /**
105  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
106  */
107  template <>
108  class WGE_EXPORT GLType< int8_t >
109  {
110  public:
111  /**
112  * The best matching OpenGL type for the specified template parameter.
113  */
114  typedef int8_t Type;
115 
116  /**
117  * The enum type of OpenGL
118  */
119  static const GLenum TypeEnum = GL_BYTE;
120 
121  /**
122  * The value for full intensity.
123  *
124  * \return the full intensity value
125  */
126  static Type FullIntensity(){ return 127; } // NOLINT
127  };
128 
129  /**
130  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
131  */
132  template <>
133  class WGE_EXPORT GLType< uint8_t >
134  {
135  public:
136  /**
137  * The best matching OpenGL type for the specified template parameter.
138  */
139  typedef uint8_t Type;
140 
141  /**
142  * The enum type of OpenGL
143  */
144  static const GLenum TypeEnum = GL_UNSIGNED_BYTE;
145 
146  /**
147  * The value for full intensity.
148  *
149  * \return the full intensity value
150  */
151  static Type FullIntensity(){ return 255; } // NOLINT
152  };
153 
154  /**
155  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
156  *
157  * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead.
158  */
159  template <>
160  class WGE_EXPORT GLType< int16_t >
161  {
162  public:
163  /**
164  * The best matching OpenGL type for the specified template parameter.
165  */
166  typedef float Type;
167 
168  /**
169  * The enum type of OpenGL
170  */
171  static const GLenum TypeEnum = GL_FLOAT;
172 
173  /**
174  * The value for full intensity.
175  *
176  * \return the full intensity value
177  */
178  static Type FullIntensity(){ return 1.0; } // NOLINT
179  };
180 
181  /**
182  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
183  *
184  * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead.
185  */
186  template <>
187  class WGE_EXPORT GLType< uint16_t >
188  {
189  public:
190  /**
191  * The best matching OpenGL type for the specified template parameter.
192  */
193  typedef float Type;
194 
195  /**
196  * The enum type of OpenGL
197  */
198  static const GLenum TypeEnum = GL_FLOAT;
199 
200  /**
201  * The value for full intensity.
202  *
203  * \return the full intensity value
204  */
205  static Type FullIntensity(){ return 1.0; } // NOLINT
206  };
207 
208  /**
209  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
210  *
211  * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead.
212  */
213  template <>
214  class WGE_EXPORT GLType< int32_t >
215  {
216  public:
217  /**
218  * The best matching OpenGL type for the specified template parameter.
219  */
220  typedef float Type;
221 
222  /**
223  * The enum type of OpenGL
224  */
225  static const GLenum TypeEnum = GL_FLOAT;
226 
227  /**
228  * The value for full intensity.
229  *
230  * \return the full intensity value
231  */
232  static Type FullIntensity(){ return 1.0; } // NOLINT
233  };
234 
235  /**
236  * Class helping to adapt types specified as template parameter into the best matching OpenGL type.
237  *
238  * \note integral types get downscaled to float. This is done for easiness but might be better if the real type is used instead.
239  */
240  template <>
241  class WGE_EXPORT GLType< uint32_t >
242  {
243  public:
244  /**
245  * The best matching OpenGL type for the specified template parameter.
246  */
247  typedef float Type;
248 
249  /**
250  * The enum type of OpenGL
251  */
252  static const GLenum TypeEnum = GL_FLOAT;
253 
254  /**
255  * The value for full intensity.
256  *
257  * \return the full intensity value
258  */
259  static Type FullIntensity(){ return 1.0; } // NOLINT
260  };
261 }
262 
263 #endif // WGETYPETRAITS_H
264