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 WGEPROPERTYUNIFORM_H 00026 #define WGEPROPERTYUNIFORM_H 00027 00028 #include <string> 00029 00030 #include <osg/Uniform> 00031 00032 #include "../callbacks/WGEPropertyUniformCallback.h" 00033 #include "WGEUniformTypeTraits.h" 00034 00035 00036 /** 00037 * Class implementing a uniform which can be controlled by a property instance. This is mainly a convenience class for 00038 * WGEPropertyUniformCallback (which is used here). 00039 * 00040 * \tparam the class used as controlling mechanism. The class needs to be a boost::shared_ptr to a type supporting get() method: T->get() 00041 * returns the value (bool, int, double, WPosition supported). For other types specialize the template. 00042 */ 00043 template< typename T > 00044 class WGEPropertyUniform: public osg::Uniform 00045 { 00046 public: 00047 /** 00048 * Convenience typedef for an osg::ref_ptr 00049 */ 00050 typedef osg::ref_ptr< WGEPropertyUniform > RefPtr; 00051 00052 /** 00053 * Convenience typedef for an osg::ref_ptr; const 00054 */ 00055 typedef osg::ref_ptr< const WGEPropertyUniform > ConstRefPtr; 00056 00057 /** 00058 * Creates a new uniform with controlled by the specified property. 00059 * 00060 * \param name the name of the uniform; consider our style guide for uniform names. 00061 * \param property the property controlling it 00062 */ 00063 WGEPropertyUniform( std::string name, T property ); 00064 00065 /** 00066 * Destructor. 00067 */ 00068 virtual ~WGEPropertyUniform(); 00069 00070 /** 00071 * The type which is used for this uniform. 00072 */ 00073 typedef typename WGEPropertyUniformCallback< T >::UniformType UniformType; 00074 00075 protected: 00076 /** 00077 * The property controlling the uniform. 00078 */ 00079 T m_property; 00080 00081 /** 00082 * The name of the uniform. 00083 */ 00084 std::string m_name; 00085 private: 00086 }; 00087 00088 template < typename T > 00089 WGEPropertyUniform< T >::WGEPropertyUniform( std::string name, T property ): 00090 osg::Uniform( name.c_str(), typename WGEPropertyUniform< T >::UniformType() ), 00091 m_property( property ), 00092 m_name( name ) 00093 { 00094 // simply create a new callback and add it 00095 setUpdateCallback( new WGEPropertyUniformCallback< T >( property ) ); 00096 } 00097 00098 template < typename T > 00099 WGEPropertyUniform< T >::~WGEPropertyUniform() 00100 { 00101 // clean up 00102 } 00103 00104 #endif // WGEPROPERTYUNIFORM_H 00105