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