OpenWalnut 1.2.5
WGEUniformTypeTraits.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 WGEUNIFORMTYPETRAITS_H
00026 #define WGEUNIFORMTYPETRAITS_H
00027 
00028 #include <osg/Vec3>
00029 #include "../../common/math/linearAlgebra/WLinearAlgebra.h"
00030 
00031 #include "../WExportWGE.h"
00032 
00033 class WItemSelector;
00034 
00035 namespace wge
00036 {
00037     /**
00038      * Class helping to adapt types specified as template parameter into the best matching osg::Uniform (GLSL) type. This is useful especially for
00039      * property-types to uniform type conversion.
00040      * \note: bool map to bool, int to int, unsigned int to unsigned int. Unallowed types like std::string will then cause compilation errors as
00041      * osg::uniform does not offer proper constructors/setters for these types.
00042      */
00043     template< typename T >
00044     class WGE_EXPORT UniformType
00045     {
00046     public:
00047         /**
00048          * The best matching GLSL uniform type for the specified template parameter.
00049          */
00050         typedef T Type;
00051     };
00052 
00053     /**
00054      * Maps doubles to floats as only floats are allowed in uniforms.
00055      */
00056     template<>
00057     class WGE_EXPORT UniformType< double >
00058     {
00059     public:
00060         /**
00061          * The best matching GLSL uniform type for the specified template parameter.
00062          */
00063         typedef float Type;
00064     };
00065 
00066     /**
00067      * Maps WVector3d/WPosition to osg::Vec3.
00068      */
00069     template<>
00070     class WGE_EXPORT UniformType< WVector3d >
00071     {
00072     public:
00073         /**
00074          * The best matching GLSL uniform type for the specified template parameter.
00075          */
00076         typedef osg::Vec3 Type;
00077     };
00078 
00079     /**
00080      * Maps Selection Properties to ints.
00081      */
00082     template<>
00083     class WGE_EXPORT UniformType< WItemSelector >
00084     {
00085     public:
00086         /**
00087          * The best matching GLSL uniform type for the specified template parameter.
00088          */
00089         typedef int Type;
00090     };
00091 }
00092 
00093 #endif  // WGEUNIFORMTYPETRAITS_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends