Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/Shader.h @ 9840

Last change on this file since 9840 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
RevLine 
[2350]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
[5693]32#include "tools/ToolsPrereqs.h"
[3196]33
[8729]34#include <list>
[3196]35#include <string>
[8079]36#include <OgreCompositorInstance.h>
37
38#include "util/MultiType.h"
39#include "core/ViewportEventListener.h"
[2350]40
41namespace orxonox
42{
[8079]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
[2350]48    {
49        public:
50            Shader(Ogre::SceneManager* scenemanager = 0);
51            virtual ~Shader();
52
[8079]53            /// Defines if the shader is visible or not.
[2350]54            inline void setVisible(bool bVisible)
55            {
56                if (this->bVisible_ != bVisible)
57                {
58                    this->bVisible_ = bVisible;
59                    this->updateVisibility();
60                }
61            }
[8079]62            /// Returns whether or not the shader is visible.
[2350]63            inline bool isVisible() const
64                { return this->bVisible_; }
65            void updateVisibility();
66
[8079]67            /// Defines the compositor's name (located in a .compositor file).
68            inline void setCompositorName(const std::string& name)
[2350]69            {
[8079]70                if (this->compositorName_ != name)
[2350]71                {
[8079]72                    this->compositorName_ = name;
73                    this->changedCompositorName();
[2350]74                }
75            }
[8079]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);
[2350]81
[8079]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.
[2350]86            inline Ogre::SceneManager* getSceneManager() const
87                { return this->scenemanager_; }
88
[8079]89            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
[2350]90
[8079]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);
[2350]93
[8079]94            virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr);
95
[2350]96        private:
[8079]97            static bool hasCgProgramManager();
[2358]98
[8079]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
[9550]116                MultiType value_;           ///< The desired value of the parameter
[8079]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
[2350]121    };
122}
123
124#endif /* _Shader_H__ */
Note: See TracBrowser for help on using the repository browser.