Orxonox  0.0.5 Codename: Arcturus
Shader.h
Go to the documentation of this file.
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"
40 
41 namespace orxonox
42 {
47  class _ToolsExport Shader : public ViewportEventListener, public Ogre::CompositorInstance::Listener
48  {
49  public:
50  Shader(Ogre::SceneManager* scenemanager = nullptr);
51  virtual ~Shader();
52 
54  inline void setVisible(bool bVisible)
55  {
56  if (this->bVisible_ != bVisible)
57  {
58  this->bVisible_ = bVisible;
59  this->updateVisibility();
60  }
61  }
63  inline bool isVisible() const
64  { return this->bVisible_; }
65  void updateVisibility();
66 
68  inline void setCompositorName(const std::string& name)
69  {
70  if (this->compositorName_ != name)
71  {
72  this->compositorName_ = name;
73  this->changedCompositorName();
74  }
75  }
77  inline const std::string& getCompositorName() const
78  { return this->compositorName_; }
79  void changedCompositorName();
80  void changedCompositorName(Ogre::Viewport* viewport);
81 
83  inline void setSceneManager(Ogre::SceneManager* scenemanager)
84  { this->scenemanager_ = scenemanager; }
86  inline Ogre::SceneManager* getSceneManager() const
87  { return this->scenemanager_; }
88 
89  virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera) override;
90 
91  void setParameter(unsigned short technique, unsigned short pass, const std::string& parameter, float value);
92  void setParameter(unsigned short technique, unsigned short pass, const std::string& parameter, int value);
93 
94  virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr) override;
95 
96  private:
97  static bool hasCgProgramManager();
98 
99  Ogre::SceneManager* scenemanager_;
100  Ogre::CompositorInstance* compositorInstance_;
101  bool bVisible_;
105 
106  private:
107  void addAsListener();
108 
111  {
112  unsigned short technique_;
113  unsigned short pass_;
115 
117  };
118 
119  std::list<ParameterContainer> parameters_;
121  };
122 }
123 
124 #endif /* _Shader_H__ */
bool registeredAsListener_
True if the shader should register itself as listener at the compositor.
Definition: Shader.h:120
unsigned short pass_
The ID of the pass.
Definition: Shader.h:113
bool bVisible_
True if the shader should be visible.
Definition: Shader.h:101
::std::string string
Definition: gtest-port.h:756
Ogre::SceneManager * getSceneManager() const
Returns the scene manager.
Definition: Shader.h:86
unsigned short technique_
The ID of the technique.
Definition: Shader.h:112
Shared library macros, enums, constants and forward declarations for the tools module ...
#define _ToolsExport
Definition: ToolsPrereqs.h:59
std::string compositorName_
The name of the current compositor.
Definition: Shader.h:103
Definition: ViewportEventListener.h:39
void setCompositorName(const std::string &name)
Defines the compositor&#39;s name (located in a .compositor file).
Definition: Shader.h:68
Shader is a wrapper class around Ogre::CompositorInstance.
Definition: Shader.h:47
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Declaration of the MultiType and some helper constructs.
const std::string & getCompositorName() const
Returns the compositor&#39;s name.
Definition: Shader.h:77
The MultiType can hold a value of many possible types and convert them to other types.
Definition: MultiType.h:130
bool isVisible() const
Returns whether or not the shader is visible.
Definition: Shader.h:63
std::string parameter_
The name of the parameter.
Definition: Shader.h:114
Ogre::SceneManager * scenemanager_
The scenemanager for which the shader is active.
Definition: Shader.h:99
Ogre::CompositorInstance * compositorInstance_
The compositor instance representing the wrapped compositor.
Definition: Shader.h:100
std::string oldcompositorName_
The name of the previous compositor (used to unregister)
Definition: Shader.h:104
void setSceneManager(Ogre::SceneManager *scenemanager)
Sets the scenemanager (usually provided in the constructor, but can be set later). Shouldn&#39;t be changed once it&#39;s set.
Definition: Shader.h:83
std::list< ParameterContainer > parameters_
The list of parameters that should be set on the next update.
Definition: Shader.h:119
Helper struct to store parameters for shader programs.
Definition: Shader.h:110
MultiType value_
The desired value of the parameter.
Definition: Shader.h:116
bool bLoadCompositor_
True if the compositor should be loaded (usually false if no graphics)
Definition: Shader.h:102
void setVisible(bool bVisible)
Defines if the shader is visible or not.
Definition: Shader.h:54