OpenWalnut  1.4.0
WGEShaderPreprocessor.h
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 WGESHADERPREPROCESSOR_H
00026 #define WGESHADERPREPROCESSOR_H
00027 
00028 #include <string>
00029 
00030 #include <boost/shared_ptr.hpp>
00031 
00032 #include "../../common/WCondition.h"
00033 
00034 
00035 
00036 /**
00037  * Base class for each preprocessing possible to shader code. This is useful to derive your own preprocessor which might be able to implement
00038  * some tricky "metaprogramming" for GLSL or similar. Another possibility are defines. In addition, it implements an update notification
00039  * mechanism which forces associated WGEShader to reload. This is useful for preprocessors that can be modified dynamically.
00040  */
00041 class WGEShaderPreprocessor  // NOLINT
00042 {
00043 public:
00044     /**
00045      * Shared pointer for this class.
00046      */
00047     typedef boost::shared_ptr< WGEShaderPreprocessor > SPtr;
00048 
00049     /**
00050      * A const shared pointer for this class.
00051      */
00052     typedef boost::shared_ptr< const WGEShaderPreprocessor > ConstSPtr;
00053 
00054     /**
00055      * Default constructor.
00056      */
00057     WGEShaderPreprocessor();
00058 
00059     /**
00060      * Destructor.
00061      */
00062     virtual ~WGEShaderPreprocessor();
00063 
00064     /**
00065      * Returns the condition denoting a change in this preprocessor filter. WGEShader subscribes this and rebuilds all related shaders if needed.
00066      *
00067      * \return the condition firing whenever the preprocessor updates.
00068      */
00069     virtual WCondition::SPtr getChangeCondition() const;
00070 
00071     /**
00072      * Process the whole code. It is not allowed to modify some internal state in this function because it might be called by several shaders.
00073      *
00074      * \param code the code to process
00075      * \param file the filename of the shader currently processed. Should be used for debugging output.
00076      *
00077      * \return the resulting new code
00078      */
00079     virtual std::string process( const std::string& file, const std::string& code ) const = 0;
00080 
00081     /**
00082      * (De-)activates the preprocessor. An inactive preprocessor does not modify the shader code.
00083      *
00084      * \param active true if preprocessor should be active
00085      */
00086     void setActive( bool active = true );
00087 
00088     /**
00089      * If the preprocessor is active, this returns true.
00090      *
00091      * \return if active: true
00092      */
00093     bool getActive() const;
00094 
00095 protected:
00096     /**
00097      * Fires m_updateCondition which should denote an update in the preprocessor filter.
00098      */
00099     virtual void updated();
00100 
00101 private:
00102     /**
00103      * The condition fires on every call of updated().
00104      */
00105     WCondition::SPtr m_updateCondition;
00106 
00107     /**
00108      * If true the preprocessor is active.
00109      */
00110     bool m_active;
00111 };
00112 
00113 #endif  // WGESHADERPREPROCESSOR_H
00114