OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGESHADERPROPERTYDEFINE_H 00026 #define WGESHADERPROPERTYDEFINE_H 00027 00028 #include <string> 00029 #include <iostream> 00030 00031 #include <boost/shared_ptr.hpp> 00032 #include <boost/signals2.hpp> 00033 00034 #include "../../common/WPropertyTypes.h" 00035 #include "../../common/WPropertyVariable.h" 00036 00037 #include "WGEShaderDefine.h" 00038 00039 00040 00041 /** 00042 * This class is able to provide arbitrary values as define statements in GLSL code. Unlike WGEShaderDefine, it is automatically controlled by a 00043 * 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 00044 * you need the first behavior, use WGEShaderDefineOptions or WGEShaderPropertyDefineOptions. 00045 */ 00046 template< typename PropertyType = WPropBool > 00047 class WGEShaderPropertyDefine: public WGEShaderDefine< typename PropertyType::element_type::ValueType > 00048 { 00049 public: 00050 /** 00051 * Shared pointer for this class. 00052 */ 00053 typedef boost::shared_ptr< WGEShaderPropertyDefine< PropertyType > > SPtr; 00054 00055 /** 00056 * A const shared pointer for this class. 00057 */ 00058 typedef boost::shared_ptr< const WGEShaderPropertyDefine< PropertyType > > ConstSPtr; 00059 00060 /** 00061 * Constructs a define with a given name and initial value. 00062 * 00063 * \param name name of the define 00064 * \param prop the property controlling this define 00065 */ 00066 WGEShaderPropertyDefine( std::string name, PropertyType prop ); 00067 00068 /** 00069 * Destructor. 00070 */ 00071 virtual ~WGEShaderPropertyDefine(); 00072 00073 protected: 00074 private: 00075 /** 00076 * The associated property. 00077 */ 00078 PropertyType m_property; 00079 00080 /** 00081 * Sets the value depending on the current value of the property. 00082 */ 00083 void setNewValue(); 00084 00085 /** 00086 * The connection between the prop and the define 00087 */ 00088 boost::signals2::connection m_connection; 00089 }; 00090 00091 template< typename PropertyType > 00092 WGEShaderPropertyDefine< PropertyType >::WGEShaderPropertyDefine( std::string name, PropertyType prop ): 00093 WGEShaderDefine< typename PropertyType::element_type::ValueType >( name, prop->get() ), 00094 m_property( prop ) 00095 { 00096 // initialize 00097 m_connection = prop->getValueChangeCondition()->subscribeSignal( boost::bind( &WGEShaderPropertyDefine< PropertyType >::setNewValue, this ) ); 00098 } 00099 00100 template< typename PropertyType > 00101 WGEShaderPropertyDefine< PropertyType >::~WGEShaderPropertyDefine() 00102 { 00103 // cleanup 00104 m_connection.disconnect(); 00105 } 00106 00107 template< typename PropertyType > 00108 void WGEShaderPropertyDefine< PropertyType >::setNewValue() 00109 { 00110 WGEShaderDefine< typename PropertyType::element_type::ValueType >::setValue( m_property->get() ); 00111 } 00112 00113 #endif // WGESHADERPROPERTYDEFINE_H 00114