OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #include "../WExportWGE.h"
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 
75 private:
76 
77  /**
78  * The associated property.
79  */
80  PropertyType m_property;
81 
82  /**
83  * Sets the value depending on the current value of the property.
84  */
85  void setNewValue();
86 
87  /**
88  * The connection between the prop and the define
89  */
90  boost::signals2::connection m_connection;
91 };
92 
93 template< typename PropertyType >
95  WGEShaderDefine< typename PropertyType::element_type::ValueType >( name, prop->get() ),
96  m_property( prop )
97 {
98  // initialize
99  m_connection = prop->getValueChangeCondition()->subscribeSignal( boost::bind( &WGEShaderPropertyDefine< PropertyType >::setNewValue, this ) );
100 }
101 
102 template< typename PropertyType >
104 {
105  // cleanup
106  m_connection.disconnect();
107 }
108 
109 template< typename PropertyType >
111 {
113 }
114 
115 #endif // WGESHADERPROPERTYDEFINE_H
116