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 #include "../WExportWGE.h" 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 00075 private: 00076 00077 /** 00078 * The associated property. 00079 */ 00080 PropertyType m_property; 00081 00082 /** 00083 * Sets the value depending on the current value of the property. 00084 */ 00085 void setNewValue(); 00086 00087 /** 00088 * The connection between the prop and the define 00089 */ 00090 boost::signals2::connection m_connection; 00091 }; 00092 00093 template< typename PropertyType > 00094 WGEShaderPropertyDefine< PropertyType >::WGEShaderPropertyDefine( std::string name, PropertyType prop ): 00095 WGEShaderDefine< typename PropertyType::element_type::ValueType >( name, prop->get() ), 00096 m_property( prop ) 00097 { 00098 // initialize 00099 m_connection = prop->getValueChangeCondition()->subscribeSignal( boost::bind( &WGEShaderPropertyDefine< PropertyType >::setNewValue, this ) ); 00100 } 00101 00102 template< typename PropertyType > 00103 WGEShaderPropertyDefine< PropertyType >::~WGEShaderPropertyDefine() 00104 { 00105 // cleanup 00106 m_connection.disconnect(); 00107 } 00108 00109 template< typename PropertyType > 00110 void WGEShaderPropertyDefine< PropertyType >::setNewValue() 00111 { 00112 WGEShaderDefine< typename PropertyType::element_type::ValueType >::setValue( m_property->get() ); 00113 } 00114 00115 #endif // WGESHADERPROPERTYDEFINE_H 00116