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