OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGEUniformTypeTraits.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 WGEUNIFORMTYPETRAITS_H
26 #define WGEUNIFORMTYPETRAITS_H
27 
28 #include <osg/Vec3>
29 #include "../../common/math/linearAlgebra/WLinearAlgebra.h"
30 
31 #include "../WExportWGE.h"
32 
33 class WItemSelector;
34 
35 namespace wge
36 {
37  /**
38  * Class helping to adapt types specified as template parameter into the best matching osg::Uniform (GLSL) type. This is useful especially for
39  * property-types to uniform type conversion.
40  * \note: bool map to bool, int to int, unsigned int to unsigned int. Unallowed types like std::string will then cause compilation errors as
41  * osg::uniform does not offer proper constructors/setters for these types.
42  */
43  template< typename T >
44  class WGE_EXPORT UniformType
45  {
46  public:
47  /**
48  * The best matching GLSL uniform type for the specified template parameter.
49  */
50  typedef T Type;
51  };
52 
53  /**
54  * Maps doubles to floats as only floats are allowed in uniforms.
55  */
56  template<>
57  class WGE_EXPORT UniformType< double >
58  {
59  public:
60  /**
61  * The best matching GLSL uniform type for the specified template parameter.
62  */
63  typedef float Type;
64  };
65 
66  /**
67  * Maps WVector3d/WPosition to osg::Vec3.
68  */
69  template<>
70  class WGE_EXPORT UniformType< WVector3d >
71  {
72  public:
73  /**
74  * The best matching GLSL uniform type for the specified template parameter.
75  */
76  typedef osg::Vec3 Type;
77  };
78 
79  /**
80  * Maps Selection Properties to ints.
81  */
82  template<>
83  class WGE_EXPORT UniformType< WItemSelector >
84  {
85  public:
86  /**
87  * The best matching GLSL uniform type for the specified template parameter.
88  */
89  typedef int Type;
90  };
91 }
92 
93 #endif // WGEUNIFORMTYPETRAITS_H