Changeset 8079 for code/trunk/src/libraries/tools/Shader.h
- Timestamp:
- Mar 15, 2011, 9:47:11 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/tools/Shader.h
r5781 r8079 36 36 #include <vector> 37 37 38 #include <OgreCompositorInstance.h> 39 40 #include "util/MultiType.h" 38 41 #include "util/OgreForwardRefs.h" 39 #include " tools/interfaces/Tickable.h"42 #include "core/ViewportEventListener.h" 40 43 41 44 namespace orxonox 42 45 { 43 class _ToolsExport Shader : public Tickable 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 44 51 { 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 52 public: 52 53 Shader(Ogre::SceneManager* scenemanager = 0); 53 54 virtual ~Shader(); 54 55 55 virtual void tick(float dt); 56 56 /// Defines if the shader is visible or not. 57 57 inline void setVisible(bool bVisible) 58 58 { … … 63 63 } 64 64 } 65 /// Returns whether or not the shader is visible. 65 66 inline bool isVisible() const 66 67 { return this->bVisible_; } 67 68 void updateVisibility(); 68 69 69 inline void setCompositor(const std::string& compositor) 70 /// Defines the compositor's name (located in a .compositor file). 71 inline void setCompositorName(const std::string& name) 70 72 { 71 if (this->compositor _ != compositor)73 if (this->compositorName_ != name) 72 74 { 73 this->compositor _ = compositor;74 this->changedCompositor ();75 this->compositorName_ = name; 76 this->changedCompositorName(); 75 77 } 76 78 } 77 inline const std::string& getCompositor() const 78 { return this->compositor_; } 79 void changedCompositor(); 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); 80 84 81 void setSceneManager(Ogre::SceneManager* scenemanager); 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. 82 89 inline Ogre::SceneManager* getSceneManager() const 83 90 { return this->scenemanager_; } 84 91 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); 92 virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera); 87 93 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 void setParameter(size_t technique, size_t pass, const std::string& parameter, float value); 95 void setParameter(size_t technique, size_t pass, const std::string& parameter, int value); 96 97 virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr); 94 98 95 99 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_; 100 static bool hasCgProgramManager(); 103 101 104 static MaterialMap parameters_s; 105 static bool bLoadedCgPlugin_s; 102 Ogre::SceneManager* scenemanager_; ///< The scenemanager for which the shader is active 103 Ogre::CompositorInstance* compositorInstance_; ///< The compositor instance representing the wrapped compositor 104 bool bVisible_; ///< True if the shader should be visible 105 bool bLoadCompositor_; ///< True if the compositor should be loaded (usually false if no graphics) 106 std::string compositorName_; ///< The name of the current compositor 107 std::string oldcompositorName_; ///< The name of the previous compositor (used to unregister) 108 109 private: 110 void addAsListener(); 111 112 /// Helper struct to store parameters for shader programs. 113 struct ParameterContainer 114 { 115 size_t technique_; ///< The ID of the technique 116 size_t pass_; ///< The ID of the pass 117 std::string parameter_; ///< The name of the parameter 118 119 int valueInt_; ///< The desired int value of the parameter 120 float valueFloat_; ///< The desired float value of the parameter 121 122 MT_Type::Value valueType_; ///< The type of the parameter (currently only int or float) 123 }; 124 125 std::list<ParameterContainer> parameters_; ///< The list of parameters that should be set on the next update 126 bool registeredAsListener_; ///< True if the shader should register itself as listener at the compositor 106 127 }; 107 128 }
Note: See TracChangeset
for help on using the changeset viewer.