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