OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGEPropertyUniform.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 WGEPROPERTYUNIFORM_H
26 #define WGEPROPERTYUNIFORM_H
27 
28 #include <string>
29 
30 #include <osg/Uniform>
31 
32 #include "../callbacks/WGEPropertyUniformCallback.h"
33 #include "WGEUniformTypeTraits.h"
34 #include "../WExportWGE.h"
35 
36 /**
37  * Class implementing a uniform which can be controlled by a property instance. This is mainly a convenience class for
38  * WGEPropertyUniformCallback (which is used here).
39  *
40  * \tparam the class used as controlling mechanism. The class needs to be a boost::shared_ptr to a type supporting get() method: T->get()
41  * returns the value (bool, int, double, WPosition supported). For other types specialize the template.
42  */
43 template< typename T >
44 class WGEPropertyUniform: public osg::Uniform
45 {
46 public:
47  /**
48  * Convenience typedef for an osg::ref_ptr
49  */
50  typedef osg::ref_ptr< WGEPropertyUniform > RefPtr;
51 
52  /**
53  * Convenience typedef for an osg::ref_ptr; const
54  */
55  typedef osg::ref_ptr< const WGEPropertyUniform > ConstRefPtr;
56 
57  /**
58  * Creates a new uniform with controlled by the specified property.
59  *
60  * \param name the name of the uniform; consider our style guide for uniform names.
61  * \param property the property controlling it
62  */
63  WGEPropertyUniform( std::string name, T property );
64 
65  /**
66  * Destructor.
67  */
68  virtual ~WGEPropertyUniform();
69 
70  /**
71  * The type which is used for this uniform.
72  */
74 
75 protected:
76 
77  /**
78  * The property controlling the uniform.
79  */
81 
82  /**
83  * The name of the uniform.
84  */
85  std::string m_name;
86 private:
87 };
88 
89 template < typename T >
90 WGEPropertyUniform< T >::WGEPropertyUniform( std::string name, T property ):
91  osg::Uniform( name.c_str(), static_cast< typename WGEPropertyUniform< T >::UniformType >( property->get() ) ),
92  m_property( property ),
93  m_name( name )
94 {
95  // simply create a new callback and add it
96  setUpdateCallback( new WGEPropertyUniformCallback< T >( property ) );
97 }
98 
99 template < typename T >
101 {
102  // clean up
103 }
104 
105 #endif // WGEPROPERTYUNIFORM_H
106