OpenWalnut  1.4.0
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 #ifndef Q_MOC_RUN
32 #include <boost/shared_ptr.hpp>
33 #endif
34 
35 #include "WGEShaderPreprocessor.h"
36 
37 
38 
39 /**
40  * 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
41  * of WGEShaderDefine if many mutual exclusive options should be handled comfortably.
42  *
43  * \note: operations on the option list are not thread-safe.
44  */
46 {
47 public:
48  /**
49  * Shared pointer for this class.
50  */
51  typedef boost::shared_ptr< WGEShaderDefineOptions > SPtr;
52 
53  /**
54  * A const shared pointer for this class.
55  */
56  typedef boost::shared_ptr< const WGEShaderDefineOptions > ConstSPtr;
57 
58  /**
59  * The type of the index list
60  */
61  typedef std::vector< size_t > IdxList;
62 
63  /**
64  * Create a new instance of this class. The first option is mandatory and is set as default.
65  *
66  * \param first fist option. Is default.
67  * \param option2 another option
68  * \param option3 another option
69  * \param option4 another option
70  * \param option5 another option
71  * \param option6 another option
72  * \param option7 another option
73  * \param option8 another option
74  * \param option9 another option
75  * \param option10 another option
76  */
77  WGEShaderDefineOptions( std::string first,
78  std::string option2 = "", std::string option3 = "", std::string option4 = "", std::string option5 = "",
79  std::string option6 = "", std::string option7 = "", std::string option8 = "", std::string option9 = "",
80  std::string option10 = "" );
81 
82  /**
83  * Create a new instance of this class. The first option is mandatory and is set as default.
84  *
85  * \param options the list of options. Must have a size greater 0.
86  */
87  explicit WGEShaderDefineOptions( std::vector< std::string > options );
88 
89  /**
90  * Destructor.
91  */
92  virtual ~WGEShaderDefineOptions();
93 
94  /**
95  * Process the whole code. It is not allowed to modify some internal state in this function because it might be called by several shaders.
96  *
97  * \param code the code to process
98  * \param file the filename of the shader currently processed. Should be used for debugging output.
99  *
100  * \return the resulting new code
101  */
102  virtual std::string process( const std::string& file, const std::string& code ) const;
103 
104  /**
105  * Returns the currently active option as index.
106  *
107  * \return the index of the active option
108  */
109  const IdxList& getActiveOptions() const;
110 
111  /**
112  * Returns the name of the specified option.
113  *
114  * \param idx the index
115  *
116  * \return the name
117  */
118  std::string getOptionName( size_t idx ) const;
119 
120  /**
121  * Activates the option specified.
122  *
123  * \param idx the option index to activate
124  * \param exclusive if true, all active options get deactivated and the specified one will be the only active one afterwards
125  */
126  void activateOption( size_t idx, bool exclusive = true );
127 
128  /**
129  * De-activates the specified option. If it is not activated, nothing happens.
130  *
131  * \param idx the option to deactivate
132  */
133  void deactivateOption( size_t idx );
134 
135  /**
136  * Activates all the options.
137  */
138  void activateAllOptions();
139 
140  /**
141  * De-activates all the options.
142  */
143  void deactivateAllOptions();
144 
145  /**
146  * 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
147  * in the list, nothing happens.
148  *
149  * \param opt the option name.
150  */
151  void addOption( std::string opt );
152 
153 protected:
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  * The list of options.
164  */
165  std::vector< std::string > m_options;
166 
167  /**
168  * The currently selected options.
169  */
170  IdxList m_idx;
171 };
172 
173 #endif // WGESHADERDEFINEOPTIONS_H
174 
virtual std::string process(const std::string &file, const std::string &code) const
Process the whole code.
void activateOption(size_t idx, bool exclusive=true)
Activates the option specified.
virtual ~WGEShaderDefineOptions()
Destructor.
IdxList m_idx
The currently selected options.
void activateAllOptions()
Activates all the options.
std::vector< std::string > m_options
The list of options.
boost::shared_ptr< const WGEShaderDefineOptions > ConstSPtr
A const shared pointer for this class.
void deactivateAllOptions()
De-activates all the options.
boost::shared_ptr< WGEShaderDefineOptions > SPtr
Shared pointer for this class.
void deactivateOption(size_t idx)
De-activates the specified option.
void setActivationList(const IdxList &newList)
Sets the specified index list as the new activation list.
std::string getOptionName(size_t idx) const
Returns the name of the specified option.
Base class for each preprocessing possible to shader code.
This GLSL preprocessor is able to set one define from a list of defines depending on the active optio...
std::vector< size_t > IdxList
The type of the index list.
const IdxList & getActiveOptions() const
Returns the currently active option as index.
WGEShaderDefineOptions(std::string first, std::string option2="", std::string option3="", std::string option4="", std::string option5="", std::string option6="", std::string option7="", std::string option8="", std::string option9="", std::string option10="")
Create a new instance of this class.
void addOption(std::string opt)
Adds the specified string as option which is inserted to the code as "#define NAME" if active...