Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound6/src/libraries/tools/Shader.h @ 8662

Last change on this file since 8662 was 7976, checked in by landauf, 14 years ago

rewrote parameter changing implementation of Shader
added documentation

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Shader_H__
30#define _Shader_H__
31
32#include "tools/ToolsPrereqs.h"
33
34#include <map>
35#include <string>
36#include <vector>
37
38#include <OgreCompositorInstance.h>
39
40#include "util/OgreForwardRefs.h"
41#include "core/ViewportEventListener.h"
42
43namespace orxonox
44{
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
50    {
51        public:
52            Shader(Ogre::SceneManager* scenemanager = 0);
53            virtual ~Shader();
54
55            /// Defines if the shader is visible or not.
56            inline void setVisible(bool bVisible)
57            {
58                if (this->bVisible_ != bVisible)
59                {
60                    this->bVisible_ = bVisible;
61                    this->updateVisibility();
62                }
63            }
64            /// Returns whether or not the shader is visible.
65            inline bool isVisible() const
66                { return this->bVisible_; }
67            void updateVisibility();
68
69            /// Defines the compositor's name (located in a .compositor file).
70            inline void setCompositorName(const std::string& name)
71            {
72                if (this->compositorName_ != name)
73                {
74                    this->compositorName_ = name;
75                    this->changedCompositorName();
76                }
77            }
78            /// Returns the compositor's name.
79            inline const std::string& getCompositorName() const
80                { return this->compositorName_; }
81            void changedCompositorName();
82            void changedCompositorName(Ogre::Viewport* viewport);
83
84            /// Sets the scenemanager (usually provided in the constructor, but can be set later). Shouldn't be changed once it's set.
85            inline void setSceneManager(Ogre::SceneManager* scenemanager)
86                { this->scenemanager_ = scenemanager; }
87            /// Returns the scene manager.
88            inline Ogre::SceneManager* getSceneManager() const
89                { return this->scenemanager_; }
90
91            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
92
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);
95
96            virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr);
97
98        private:
99            static bool hasCgProgramManager();
100
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)
107
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
126    };
127}
128
129#endif /* _Shader_H__ */
Note: See TracBrowser for help on using the repository browser.