OpenWalnut  1.5.0dev
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 <memory>
29 #include <string>
30 
31 #include <osg/Uniform>
32 
33 #include "../callbacks/WGEPropertyUniformCallback.h"
34 #include "WGEUniformTypeTraits.h"
35 
36 
37 /**
38  * Class implementing a uniform which can be controlled by a property instance. This is mainly a convenience class for
39  * WGEPropertyUniformCallback (which is used here).
40  *
41  * \tparam the class used as controlling mechanism. The class needs to be a std::shared_ptr to a type supporting get() method: T->get()
42  * returns the value (bool, int, double, WPosition supported). For other types specialize the template.
43  */
44 template< typename T >
45 class WGEPropertyUniform: public osg::Uniform
46 {
47 public:
48  /**
49  * Convenience typedef for an osg::ref_ptr
50  */
51  typedef osg::ref_ptr< WGEPropertyUniform > RefPtr;
52 
53  /**
54  * Convenience typedef for an osg::ref_ptr; const
55  */
56  typedef osg::ref_ptr< const WGEPropertyUniform > ConstRefPtr;
57 
58  /**
59  * Creates a new uniform with controlled by the specified property.
60  *
61  * \param name the name of the uniform; consider our style guide for uniform names.
62  * \param property the property controlling it
63  */
64  WGEPropertyUniform( std::string name, T property );
65 
66  /**
67  * Destructor.
68  */
69  virtual ~WGEPropertyUniform();
70 
71  /**
72  * The type which is used for this uniform.
73  */
75 
76 protected:
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(), typename WGEPropertyUniform< T >::UniformType() ),
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 
This class is an OSG Callback which allows uniforms to be controlled by properties.
wge::UniformType< typename T::element_type::ValueType >::Type UniformType
The type which is used for this uniform.
Class implementing a uniform which can be controlled by a property instance.
osg::ref_ptr< const WGEPropertyUniform > ConstRefPtr
Convenience typedef for an osg::ref_ptr; const.
T m_property
The property controlling the uniform.
virtual ~WGEPropertyUniform()
Destructor.
WGEPropertyUniform(std::string name, T property)
Creates a new uniform with controlled by the specified property.
WGEPropertyUniformCallback< T >::UniformType UniformType
The type which is used for this uniform.
std::string m_name
The name of the uniform.
osg::ref_ptr< WGEPropertyUniform > RefPtr
Convenience typedef for an osg::ref_ptr.