Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 27, 2011, 1:05:59 AM (14 years ago)
Author:
landauf
Message:

rewrote parameter changing implementation of Shader
added documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/tools/Shader.h

    r7972 r7976  
    3636#include <vector>
    3737
     38#include <OgreCompositorInstance.h>
     39
    3840#include "util/OgreForwardRefs.h"
    3941#include "core/ViewportEventListener.h"
     
    4143namespace orxonox
    4244{
    43     class _ToolsExport Shader : public ViewportEventListener
     45    /**
     46        @brief Shader is a wrapper class around Ogre::CompositorInstance. It provides some
     47        functions to easily change the visibility and parameters for shader programs.
     48    */
     49    class _ToolsExport Shader : public ViewportEventListener, public Ogre::CompositorInstance::Listener
    4450    {
    45         typedef std::pair<bool, void*>                  ParameterPointer;
    46         typedef std::map<std::string, ParameterPointer> ParameterMap;
    47         typedef std::vector<ParameterMap>               PassVector;
    48         typedef std::vector<PassVector>                 TechniqueVector;
    49         typedef std::map<std::string, TechniqueVector>  MaterialMap;
    50 
    5151        public:
    5252            Shader(Ogre::SceneManager* scenemanager = 0);
    5353            virtual ~Shader();
    5454
     55            /// Defines if the shader is visible or not.
    5556            inline void setVisible(bool bVisible)
    5657            {
     
    6162                }
    6263            }
     64            /// Returns whether or not the shader is visible.
    6365            inline bool isVisible() const
    6466                { return this->bVisible_; }
    6567            void updateVisibility();
    6668
     69            /// Defines the compositor's name (located in a .compositor file).
    6770            inline void setCompositorName(const std::string& name)
    6871            {
     
    7376                }
    7477            }
     78            /// Returns the compositor's name.
    7579            inline const std::string& getCompositorName() const
    7680                { return this->compositorName_; }
     
    7882            void changedCompositorName(Ogre::Viewport* viewport);
    7983
     84            /// Sets the scenemanager (usually provided in the constructor, but can be set later). Shouldn't be changed once it's set.
    8085            inline void setSceneManager(Ogre::SceneManager* scenemanager)
    8186                { this->scenemanager_ = scenemanager; }
     87            /// Returns the scene manager.
    8288            inline Ogre::SceneManager* getSceneManager() const
    8389                { return this->scenemanager_; }
     
    8591            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
    8692
    87             void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
    88             void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
     93            void setParameter(size_t technique, size_t pass, const std::string& parameter, float value);
     94            void setParameter(size_t technique, size_t pass, const std::string& parameter, int value);
    8995
    90             static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
    91             static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
    92             static float getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
    93             static bool  getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
    94             static bool  getParameterIsInt  (const std::string& material, size_t technique, size_t pass, const std::string& parameter);
    95             static ParameterPointer* getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
     96            virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr);
    9697
    9798        private:
    9899            static bool hasCgProgramManager();
    99100
    100             Ogre::SceneManager* scenemanager_;
    101             Ogre::CompositorInstance* compositorInstance_;
    102             bool bVisible_;
    103             bool bLoadCompositor_;
    104             std::string compositorName_;
    105             std::string oldcompositorName_;
     101            Ogre::SceneManager* scenemanager_;              ///< The scenemanager for which the shader is active
     102            Ogre::CompositorInstance* compositorInstance_;  ///< The compositor instance representing the wrapped compositor
     103            bool bVisible_;                                 ///< True if the shader should be visible
     104            bool bLoadCompositor_;                          ///< True if the compositor should be loaded (usually false if no graphics)
     105            std::string compositorName_;                    ///< The name of the current compositor
     106            std::string oldcompositorName_;                 ///< The name of the previous compositor (used to unregister)
    106107
    107             static MaterialMap parameters_s;
    108             static bool bLoadedCgPlugin_s;
     108        private:
     109            void addAsListener();
     110
     111            /// Helper struct to store parameters for shader programs.
     112            struct ParameterContainer
     113            {
     114                size_t technique_;          ///< The ID of the technique
     115                size_t pass_;               ///< The ID of the pass
     116                std::string parameter_;     ///< The name of the parameter
     117
     118                int valueInt_;              ///< The desired int value of the parameter
     119                float valueFloat_;          ///< The desired float value of the parameter
     120
     121                MT_Type::Value valueType_;  ///< The type of the parameter (currently only int or float)
     122            };
     123
     124            std::list<ParameterContainer> parameters_;  ///< The list of parameters that should be set on the next update
     125            bool registeredAsListener_;                 ///< True if the shader should register itself as listener at the compositor
    109126    };
    110127}
Note: See TracChangeset for help on using the changeset viewer.