Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/libraries/tools/Shader.h @ 7966

Last change on this file since 7966 was 7966, checked in by landauf, 13 years ago

some changes related to camera switching:

  • added ViewportEventListener (currently only listens to camera changes in a viewport)
  • Shader now correctly updates its visibility if the camera changes the scene
  • (the same lines of code also fix the weird Ogre behavior which was originally fixed in CameraManager)
  • GraphicsManager also updates the GUIManager's camera
  • if all cameras are destroyed, CameraManager now officially switches to NULL camera
  • Property svn:eol-style set to native
File size: 4.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 "util/OgreForwardRefs.h"
39#include "core/ViewportEventListener.h"
40
41namespace orxonox
42{
43    class _ToolsExport Shader : public ViewportEventListener
44    {
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
51        public:
52            Shader(Ogre::SceneManager* scenemanager = 0);
53            virtual ~Shader();
54
55            inline void setVisible(bool bVisible)
56            {
57                if (this->bVisible_ != bVisible)
58                {
59                    this->bVisible_ = bVisible;
60                    this->updateVisibility();
61                }
62            }
63            inline bool isVisible() const
64                { return this->bVisible_; }
65            void updateVisibility();
66
67            inline void setCompositor(const std::string& compositor)
68            {
69                if (this->compositor_ != compositor)
70                {
71                    this->compositor_ = compositor;
72                    this->changedCompositor();
73                }
74            }
75            inline const std::string& getCompositor() const
76                { return this->compositor_; }
77            void changedCompositor();
78
79            void setSceneManager(Ogre::SceneManager* scenemanager);
80            inline Ogre::SceneManager* getSceneManager() const
81                { return this->scenemanager_; }
82
83            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
84
85            void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
86            void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
87
88            static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
89            static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
90            static float getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
91            static bool  getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
92            static bool  getParameterIsInt  (const std::string& material, size_t technique, size_t pass, const std::string& parameter);
93            static ParameterPointer* getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter);
94
95        private:
96            Ogre::SceneManager* scenemanager_;
97            Ogre::CompositorInstance* compositorInstance_;
98            bool bVisible_;
99            bool bLoadCompositor_;
100            bool bViewportInitialized_;
101            std::string compositor_;
102            std::string oldcompositor_;
103
104            static MaterialMap parameters_s;
105            static bool bLoadedCgPlugin_s;
106    };
107}
108
109#endif /* _Shader_H__ */
Note: See TracBrowser for help on using the repository browser.