WGEPropertyUniform.h

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 #include "../WExportWGE.h"
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     /**
00078      * The property controlling the uniform.
00079      */
00080     T m_property;
00081 
00082     /**
00083      * The name of the uniform.
00084      */
00085     std::string m_name;
00086 private:
00087 };
00088 
00089 template < typename T >
00090 WGEPropertyUniform< T >::WGEPropertyUniform( std::string name, T property ):
00091     osg::Uniform( name.c_str(), static_cast< typename WGEPropertyUniform< T >::UniformType >( property->get() ) ),
00092     m_property( property ),
00093     m_name( name )
00094 {
00095     // simply create a new callback and add it
00096     setUpdateCallback( new WGEPropertyUniformCallback< T >( property ) );
00097 }
00098 
00099 template < typename T >
00100 WGEPropertyUniform< T >::~WGEPropertyUniform()
00101 {
00102     // clean up
00103 }
00104 
00105 #endif  // WGEPROPERTYUNIFORM_H
00106 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends