OpenWalnut  1.5.0dev
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 WMatrix4d to osg::Matrixd.
82  */
83  template<>
85  {
86  public:
87  /**
88  * The best matching GLSL uniform type for the specified template parameter.
89  */
90  typedef osg::Matrixd 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 int Type;
104  };
105 
106  /**
107  * Maps Selection Properties to ints.
108  */
109  template<>
111  {
112  public:
113  /**
114  * The best matching GLSL uniform type for the specified template parameter.
115  */
116  typedef osg::Vec2 Type;
117  };
118 
119  /**
120  * Create an instance of the uniform target type given some input type.
121  *
122  * \tparam InType the input type
123  * \param in the input value
124  *
125  * \return the resulting uniform type
126  */
127  template< typename InType >
128  typename UniformType< InType >::Type toUniformType( const InType& in )
129  {
130  return static_cast< typename UniformType< InType >::Type >( in );
131  }
132 
133  /**
134  * Creates an OSG vec2 when an interval is inserted.
135  *
136  * \param in the interval to convert
137  *
138  * \return the vector
139  */
140  osg::Vec2 toUniformType( const WIntervalDouble& in );
141 }
142 
143 #endif // WGEUNIFORMTYPETRAITS_H
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:53
osg::Vec2 Type
The best matching GLSL uniform type for the specified template parameter.
int Type
The best matching GLSL uniform type for the specified template parameter.
osg::Matrixd Type
The best matching GLSL uniform type for the specified template parameter.
osg::Vec3 Type
The best matching GLSL uniform type for the specified template parameter.
float Type
The best matching GLSL uniform type for the specified template parameter.
Class helping to adapt types specified as template parameter into the best matching osg::Uniform (GLS...
T Type
The best matching GLSL uniform type for the specified template parameter.
Extend the wge utils namespace with additional methods relating WDataTexture3D.
osg::Vec2 toUniformType(const WIntervalDouble &in)
Creates an OSG vec2 when an interval is inserted.