OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGEShaderDefineOptions.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGESHADERDEFINEOPTIONS_H
26 #define WGESHADERDEFINEOPTIONS_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 #include "WGEShaderPreprocessor.h"
34 
35 #include "../WExportWGE.h"
36 
37 /**
38  * 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
39  * of WGEShaderDefine if many mutual exclusive options should be handled comfortably.
40  *
41  * \note: operations on the option list are not thread-safe.
42  */
44 {
45 public:
46 
47  /**
48  * Shared pointer for this class.
49  */
50  typedef boost::shared_ptr< WGEShaderDefineOptions > SPtr;
51 
52  /**
53  * A const shared pointer for this class.
54  */
55  typedef boost::shared_ptr< const WGEShaderDefineOptions > ConstSPtr;
56 
57  /**
58  * The type of the index list
59  */
60  typedef std::vector< size_t > IdxList;
61 
62  /**
63  * Create a new instance of this class. The first option is mandatory and is set as default.
64  *
65  * \param first fist option. Is default.
66  * \param option2 another option
67  * \param option3 another option
68  * \param option4 another option
69  * \param option5 another option
70  * \param option6 another option
71  * \param option7 another option
72  * \param option8 another option
73  * \param option9 another option
74  * \param option10 another option
75  */
76  WGEShaderDefineOptions( std::string first,
77  std::string option2 = "", std::string option3 = "", std::string option4 = "", std::string option5 = "",
78  std::string option6 = "", std::string option7 = "", std::string option8 = "", std::string option9 = "",
79  std::string option10 = "" );
80 
81  /**
82  * Create a new instance of this class. The first option is mandatory and is set as default.
83  *
84  * \param options the list of options. Must have a size greater 0.
85  */
86  explicit WGEShaderDefineOptions( std::vector< std::string > options );
87 
88  /**
89  * Destructor.
90  */
91  virtual ~WGEShaderDefineOptions();
92 
93  /**
94  * Process the whole code. It is not allowed to modify some internal state in this function because it might be called by several shaders.
95  *
96  * \param code the code to process
97  * \param file the filename of the shader currently processed. Should be used for debugging output.
98  *
99  * \return the resulting new code
100  */
101  virtual std::string process( const std::string& file, const std::string& code ) const;
102 
103  /**
104  * Returns the currently active option as index.
105  *
106  * \return the index of the active option
107  */
108  const IdxList& getActiveOptions() const;
109 
110  /**
111  * Returns the name of the specified option.
112  *
113  * \param idx the index
114  *
115  * \return the name
116  */
117  std::string getOptionName( size_t idx ) const;
118 
119  /**
120  * Activates the option specified.
121  *
122  * \param idx the option index to activate
123  * \param exclusive if true, all active options get deactivated and the specified one will be the only active one afterwards
124  */
125  void activateOption( size_t idx, bool exclusive = true );
126 
127  /**
128  * De-activates the specified option. If it is not activated, nothing happens.
129  *
130  * \param idx the option to deactivate
131  */
132  void dactivateOption( size_t idx );
133 
134  /**
135  * Activates all the options.
136  */
137  void activateAllOptions();
138 
139  /**
140  * De-activates all the options.
141  */
142  void deactivateAllOptions();
143 
144  /**
145  * 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
146  * in the list, nothing happens.
147  *
148  * \param opt the option name.
149  */
150  void addOption( std::string opt );
151 
152 protected:
153 
154  /**
155  * Sets the specified index list as the new activation list. Triggers an update.
156  *
157  * \param newList the ne list getting copied to the internal activation list.
158  */
159  void setActivationList( const IdxList& newList );
160 
161 private:
162 
163  /**
164  * The list of options.
165  */
166  std::vector< std::string > m_options;
167 
168  /**
169  * The currently selected options.
170  */
172 };
173 
174 #endif // WGESHADERDEFINEOPTIONS_H
175