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