OpenWalnut  1.5.0dev
WGEShaderPropertyDefine.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 WGESHADERPROPERTYDEFINE_H
26 #define WGESHADERPROPERTYDEFINE_H
27 
28 #include <iostream>
29 #include <memory>
30 #include <string>
31 
32 #include <boost/signals2.hpp>
33 
34 #include "../../common/WPropertyTypes.h"
35 #include "../../common/WPropertyVariable.h"
36 #include "WGEShaderDefine.h"
37 
38 
39 
40 /**
41  * This class is able to provide arbitrary values as define statements in GLSL code. Unlike WGEShaderDefine, it is automatically controlled by a
42  * WPropertyVariable. You might hope that WPropBool define and undefine this thing. Thats not the case. A WPropBool causes this to be 0 or 1. If
43  * you need the first behavior, use WGEShaderDefineOptions or WGEShaderPropertyDefineOptions.
44  */
45 template< typename PropertyType = WPropBool >
46 class WGEShaderPropertyDefine: public WGEShaderDefine< typename PropertyType::element_type::ValueType >
47 {
48 public:
49  /**
50  * Shared pointer for this class.
51  */
52  typedef std::shared_ptr< WGEShaderPropertyDefine< PropertyType > > SPtr;
53 
54  /**
55  * A const shared pointer for this class.
56  */
57  typedef std::shared_ptr< const WGEShaderPropertyDefine< PropertyType > > ConstSPtr;
58 
59  /**
60  * Constructs a define with a given name and initial value.
61  *
62  * \param name name of the define
63  * \param prop the property controlling this define
64  */
65  WGEShaderPropertyDefine( std::string name, PropertyType prop );
66 
67  /**
68  * Destructor.
69  */
70  virtual ~WGEShaderPropertyDefine();
71 
72 protected:
73 private:
74  /**
75  * The associated property.
76  */
77  PropertyType m_property;
78 
79  /**
80  * Sets the value depending on the current value of the property.
81  */
82  void setNewValue();
83 
84  /**
85  * The connection between the prop and the define
86  */
87  boost::signals2::connection m_connection;
88 };
89 
90 template< typename PropertyType >
92  WGEShaderDefine< typename PropertyType::element_type::ValueType >( name, prop->get() ),
93  m_property( prop )
94 {
95  // initialize
96  m_connection = prop->getValueChangeCondition()->subscribeSignal( boost::bind( &WGEShaderPropertyDefine< PropertyType >::setNewValue, this ) );
97 }
98 
99 template< typename PropertyType >
101 {
102  // cleanup
103  m_connection.disconnect();
104 }
105 
106 template< typename PropertyType >
108 {
110 }
111 
112 #endif // WGESHADERPROPERTYDEFINE_H
113 
This class is able to provide arbitrary values as define statements in GLSL code.
void setValue(const ValueType &value)
Sets the new value for this define.
This class is able to provide arbitrary values as define statements in GLSL code.
std::shared_ptr< WGEShaderPropertyDefine< PropertyType > > SPtr
Shared pointer for this class.
virtual ~WGEShaderPropertyDefine()
Destructor.
boost::signals2::connection m_connection
The connection between the prop and the define.
std::shared_ptr< const WGEShaderPropertyDefine< PropertyType > > ConstSPtr
A const shared pointer for this class.
WGEShaderPropertyDefine(std::string name, PropertyType prop)
Constructs a define with a given name and initial value.
PropertyType m_property
The associated property.
void setNewValue()
Sets the value depending on the current value of the property.