OpenWalnut  1.4.0
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 <osg/Vec2>
30 
31 #include "../../common/math/linearAlgebra/WVectorFixed.h"
32 #include "../../common/math/WInterval.h"
33 
34 class WItemSelector;
35 
36 namespace wge
37 {
38  /**
39  * Class helping to adapt types specified as template parameter into the best matching osg::Uniform (GLSL) type. This is useful especially for
40  * property-types to uniform type conversion.
41  * \note: bool map to bool, int to int, unsigned int to unsigned int. Unallowed types like std::string will then cause compilation errors as
42  * osg::Uniform does not offer proper constructors/setters for these types.
43  */
44  template< typename T >
46  {
47  public:
48  /**
49  * The best matching GLSL uniform type for the specified template parameter.
50  */
51  typedef T Type;
52  };
53 
54  /**
55  * Maps doubles to floats as only floats are allowed in uniforms.
56  */
57  template<>
58  class UniformType< double >
59  {
60  public:
61  /**
62  * The best matching GLSL uniform type for the specified template parameter.
63  */
64  typedef float Type;
65  };
66 
67  /**
68  * Maps WVector3d/WPosition to osg::Vec3.
69  */
70  template<>
72  {
73  public:
74  /**
75  * The best matching GLSL uniform type for the specified template parameter.
76  */
77  typedef osg::Vec3 Type;
78  };
79 
80  /**
81  * Maps Selection Properties to ints.
82  */
83  template<>
85  {
86  public:
87  /**
88  * The best matching GLSL uniform type for the specified template parameter.
89  */
90  typedef int Type;
91  };
92 
93  /**
94  * Maps Selection Properties to ints.
95  */
96  template<>
98  {
99  public:
100  /**
101  * The best matching GLSL uniform type for the specified template parameter.
102  */
103  typedef osg::Vec2 Type;
104  };
105 
106  /**
107  * Create an instance of the uniform target type given some input type.
108  *
109  * \tparam InType the input type
110  * \param in the input value
111  *
112  * \return the resulting uniform type
113  */
114  template< typename InType >
115  typename UniformType< InType >::Type toUniformType( const InType& in )
116  {
117  return static_cast< typename UniformType< InType >::Type >( in );
118  }
119 
120  /**
121  * Creates an OSG vec2 when an interval is inserted.
122  *
123  * \param in the interval to convert
124  *
125  * \return the vector
126  */
127  osg::Vec2 toUniformType( const WIntervalDouble& in );
128 }
129 
130 #endif // WGEUNIFORMTYPETRAITS_H