OpenWalnut  1.4.0
WGEShaderPreprocessor.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 WGESHADERPREPROCESSOR_H
26 #define WGESHADERPREPROCESSOR_H
27 
28 #include <string>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 #include "../../common/WCondition.h"
35 
36 
37 
38 /**
39  * Base class for each preprocessing possible to shader code. This is useful to derive your own preprocessor which might be able to implement
40  * some tricky "metaprogramming" for GLSL or similar. Another possibility are defines. In addition, it implements an update notification
41  * mechanism which forces associated WGEShader to reload. This is useful for preprocessors that can be modified dynamically.
42  */
43 class WGEShaderPreprocessor // NOLINT
44 {
45 public:
46  /**
47  * Shared pointer for this class.
48  */
49  typedef boost::shared_ptr< WGEShaderPreprocessor > SPtr;
50 
51  /**
52  * A const shared pointer for this class.
53  */
54  typedef boost::shared_ptr< const WGEShaderPreprocessor > ConstSPtr;
55 
56  /**
57  * Default constructor.
58  */
60 
61  /**
62  * Destructor.
63  */
64  virtual ~WGEShaderPreprocessor();
65 
66  /**
67  * Returns the condition denoting a change in this preprocessor filter. WGEShader subscribes this and rebuilds all related shaders if needed.
68  *
69  * \return the condition firing whenever the preprocessor updates.
70  */
71  virtual WCondition::SPtr getChangeCondition() const;
72 
73  /**
74  * Process the whole code. It is not allowed to modify some internal state in this function because it might be called by several shaders.
75  *
76  * \param code the code to process
77  * \param file the filename of the shader currently processed. Should be used for debugging output.
78  *
79  * \return the resulting new code
80  */
81  virtual std::string process( const std::string& file, const std::string& code ) const = 0;
82 
83  /**
84  * (De-)activates the preprocessor. An inactive preprocessor does not modify the shader code.
85  *
86  * \param active true if preprocessor should be active
87  */
88  void setActive( bool active = true );
89 
90  /**
91  * If the preprocessor is active, this returns true.
92  *
93  * \return if active: true
94  */
95  bool getActive() const;
96 
97 protected:
98  /**
99  * Fires m_updateCondition which should denote an update in the preprocessor filter.
100  */
101  virtual void updated();
102 
103 private:
104  /**
105  * The condition fires on every call of updated().
106  */
108 
109  /**
110  * If true the preprocessor is active.
111  */
112  bool m_active;
113 };
114 
115 #endif // WGESHADERPREPROCESSOR_H
116 
void setActive(bool active=true)
(De-)activates the preprocessor.
virtual std::string process(const std::string &file, const std::string &code) const =0
Process the whole code.
bool getActive() const
If the preprocessor is active, this returns true.
virtual ~WGEShaderPreprocessor()
Destructor.
WGEShaderPreprocessor()
Default constructor.
virtual void updated()
Fires m_updateCondition which should denote an update in the preprocessor filter. ...
WCondition::SPtr m_updateCondition
The condition fires on every call of updated().
bool m_active
If true the preprocessor is active.
Base class for each preprocessing possible to shader code.
boost::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
boost::shared_ptr< const WGEShaderPreprocessor > ConstSPtr
A const shared pointer for this class.
boost::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
Definition: WCondition.h:54
virtual WCondition::SPtr getChangeCondition() const
Returns the condition denoting a change in this preprocessor filter.