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