Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/tools/Shader.h @ 10418

Last change on this file since 10418 was 9550, checked in by landauf, 12 years ago

merged testing branch back to trunk. unbelievable it took me 13 months to finish this chore…

  • Property svn:eol-style set to native
File size: 5.0 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 <list>
35#include <string>
36#include <OgreCompositorInstance.h>
37
38#include "util/MultiType.h"
39#include "core/ViewportEventListener.h"
40
41namespace orxonox
42{
43    /**
44        @brief Shader is a wrapper class around Ogre::CompositorInstance. It provides some
45        functions to easily change the visibility and parameters for shader programs.
46    */
47    class _ToolsExport Shader : public ViewportEventListener, public Ogre::CompositorInstance::Listener
48    {
49        public:
50            Shader(Ogre::SceneManager* scenemanager = 0);
51            virtual ~Shader();
52
53            /// Defines if the shader is visible or not.
54            inline void setVisible(bool bVisible)
55            {
56                if (this->bVisible_ != bVisible)
57                {
58                    this->bVisible_ = bVisible;
59                    this->updateVisibility();
60                }
61            }
62            /// Returns whether or not the shader is visible.
63            inline bool isVisible() const
64                { return this->bVisible_; }
65            void updateVisibility();
66
67            /// Defines the compositor's name (located in a .compositor file).
68            inline void setCompositorName(const std::string& name)
69            {
70                if (this->compositorName_ != name)
71                {
72                    this->compositorName_ = name;
73                    this->changedCompositorName();
74                }
75            }
76            /// Returns the compositor's name.
77            inline const std::string& getCompositorName() const
78                { return this->compositorName_; }
79            void changedCompositorName();
80            void changedCompositorName(Ogre::Viewport* viewport);
81
82            /// Sets the scenemanager (usually provided in the constructor, but can be set later). Shouldn't be changed once it's set.
83            inline void setSceneManager(Ogre::SceneManager* scenemanager)
84                { this->scenemanager_ = scenemanager; }
85            /// Returns the scene manager.
86            inline Ogre::SceneManager* getSceneManager() const
87                { return this->scenemanager_; }
88
89            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
90
91            void setParameter(size_t technique, size_t pass, const std::string& parameter, float value);
92            void setParameter(size_t technique, size_t pass, const std::string& parameter, int value);
93
94            virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr);
95
96        private:
97            static bool hasCgProgramManager();
98
99            Ogre::SceneManager* scenemanager_;              ///< The scenemanager for which the shader is active
100            Ogre::CompositorInstance* compositorInstance_;  ///< The compositor instance representing the wrapped compositor
101            bool bVisible_;                                 ///< True if the shader should be visible
102            bool bLoadCompositor_;                          ///< True if the compositor should be loaded (usually false if no graphics)
103            std::string compositorName_;                    ///< The name of the current compositor
104            std::string oldcompositorName_;                 ///< The name of the previous compositor (used to unregister)
105
106        private:
107            void addAsListener();
108
109            /// Helper struct to store parameters for shader programs.
110            struct ParameterContainer
111            {
112                size_t technique_;          ///< The ID of the technique
113                size_t pass_;               ///< The ID of the pass
114                std::string parameter_;     ///< The name of the parameter
115
116                MultiType value_;           ///< The desired value of the parameter
117            };
118
119            std::list<ParameterContainer> parameters_;  ///< The list of parameters that should be set on the next update
120            bool registeredAsListener_;                 ///< True if the shader should register itself as listener at the compositor
121    };
122}
123
124#endif /* _Shader_H__ */
Note: See TracBrowser for help on using the repository browser.