OpenWalnut  1.4.0
WGEShaderDefineOptions.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 WGESHADERDEFINEOPTIONS_H
00026 #define WGESHADERDEFINEOPTIONS_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #include "WGEShaderPreprocessor.h"
00034 
00035 
00036 
00037 /**
00038  * This GLSL preprocessor is able to set one define from a list of defines depending on the active option. You should prefer this class instead
00039  * of WGEShaderDefine if many mutual exclusive options should be handled comfortably.
00040  *
00041  * \note: operations on the option list are not thread-safe.
00042  */
00043 class WGEShaderDefineOptions: public WGEShaderPreprocessor
00044 {
00045 public:
00046     /**
00047      * Shared pointer for this class.
00048      */
00049     typedef boost::shared_ptr< WGEShaderDefineOptions > SPtr;
00050 
00051     /**
00052      * A const shared pointer for this class.
00053      */
00054     typedef boost::shared_ptr< const WGEShaderDefineOptions > ConstSPtr;
00055 
00056     /**
00057      * The type of the index list
00058      */
00059     typedef std::vector< size_t > IdxList;
00060 
00061     /**
00062      * Create a new instance of this class. The first option is mandatory and is set as default.
00063      *
00064      * \param first fist option. Is default.
00065      * \param option2 another option
00066      * \param option3 another option
00067      * \param option4 another option
00068      * \param option5 another option
00069      * \param option6 another option
00070      * \param option7 another option
00071      * \param option8 another option
00072      * \param option9 another option
00073      * \param option10 another option
00074      */
00075     WGEShaderDefineOptions( std::string first,
00076                             std::string option2 = "", std::string option3 = "", std::string option4 = "", std::string option5 = "",
00077                             std::string option6 = "", std::string option7 = "", std::string option8 = "", std::string option9 = "",
00078                             std::string option10 = "" );
00079 
00080     /**
00081      * Create a new instance of this class. The first option is mandatory and is set as default.
00082      *
00083      * \param options the list of options. Must have a size greater 0.
00084      */
00085     explicit WGEShaderDefineOptions( std::vector< std::string > options );
00086 
00087     /**
00088      * Destructor.
00089      */
00090     virtual ~WGEShaderDefineOptions();
00091 
00092     /**
00093      * Process the whole code. It is not allowed to modify some internal state in this function because it might be called by several shaders.
00094      *
00095      * \param code the code to process
00096      * \param file the filename of the shader currently processed. Should be used for debugging output.
00097      *
00098      * \return the resulting new code
00099      */
00100     virtual std::string process( const std::string& file, const std::string& code ) const;
00101 
00102     /**
00103      * Returns the currently active option as index.
00104      *
00105      * \return the index of the active option
00106      */
00107     const IdxList& getActiveOptions() const;
00108 
00109     /**
00110      * Returns the name of the specified option.
00111      *
00112      * \param idx the index
00113      *
00114      * \return the name
00115      */
00116     std::string getOptionName( size_t idx ) const;
00117 
00118     /**
00119      * Activates the option specified.
00120      *
00121      * \param idx the option index to activate
00122      * \param exclusive if true, all active options get deactivated and the specified one will be the only active one afterwards
00123      */
00124     void activateOption( size_t idx, bool exclusive = true );
00125 
00126     /**
00127      * De-activates the specified option. If it is not activated, nothing happens.
00128      *
00129      * \param idx the option to deactivate
00130      */
00131     void deactivateOption( size_t idx );
00132 
00133     /**
00134      * Activates all the options.
00135      */
00136     void activateAllOptions();
00137 
00138     /**
00139      * De-activates all the options.
00140      */
00141     void deactivateAllOptions();
00142 
00143     /**
00144      * Adds the specified string as option which is inserted to the code as "#define NAME" if active. Must be a unique name. If it already exists
00145      * in the list, nothing happens.
00146      *
00147      * \param opt the option name.
00148      */
00149     void addOption( std::string opt );
00150 
00151 protected:
00152     /**
00153      * Sets the specified index list as the new activation list. Triggers an update.
00154      *
00155      * \param newList the ne list getting copied to the internal activation list.
00156      */
00157     void setActivationList( const IdxList& newList );
00158 
00159 private:
00160     /**
00161      * The list of options.
00162      */
00163     std::vector< std::string > m_options;
00164 
00165     /**
00166      * The currently selected options.
00167      */
00168     IdxList m_idx;
00169 };
00170 
00171 #endif  // WGESHADERDEFINEOPTIONS_H
00172