Changeset 7976 for code/branches/usability/src/libraries/tools/Shader.h
- Timestamp:
- Feb 27, 2011, 1:05:59 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/tools/Shader.h
r7972 r7976 36 36 #include <vector> 37 37 38 #include <OgreCompositorInstance.h> 39 38 40 #include "util/OgreForwardRefs.h" 39 41 #include "core/ViewportEventListener.h" … … 41 43 namespace orxonox 42 44 { 43 class _ToolsExport Shader : public ViewportEventListener 45 /** 46 @brief Shader is a wrapper class around Ogre::CompositorInstance. It provides some 47 functions to easily change the visibility and parameters for shader programs. 48 */ 49 class _ToolsExport Shader : public ViewportEventListener, public Ogre::CompositorInstance::Listener 44 50 { 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 51 public: 52 52 Shader(Ogre::SceneManager* scenemanager = 0); 53 53 virtual ~Shader(); 54 54 55 /// Defines if the shader is visible or not. 55 56 inline void setVisible(bool bVisible) 56 57 { … … 61 62 } 62 63 } 64 /// Returns whether or not the shader is visible. 63 65 inline bool isVisible() const 64 66 { return this->bVisible_; } 65 67 void updateVisibility(); 66 68 69 /// Defines the compositor's name (located in a .compositor file). 67 70 inline void setCompositorName(const std::string& name) 68 71 { … … 73 76 } 74 77 } 78 /// Returns the compositor's name. 75 79 inline const std::string& getCompositorName() const 76 80 { return this->compositorName_; } … … 78 82 void changedCompositorName(Ogre::Viewport* viewport); 79 83 84 /// Sets the scenemanager (usually provided in the constructor, but can be set later). Shouldn't be changed once it's set. 80 85 inline void setSceneManager(Ogre::SceneManager* scenemanager) 81 86 { this->scenemanager_ = scenemanager; } 87 /// Returns the scene manager. 82 88 inline Ogre::SceneManager* getSceneManager() const 83 89 { return this->scenemanager_; } … … 85 91 virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera); 86 92 87 void setParameter( const std::string& material,size_t technique, size_t pass, const std::string& parameter, float value);88 void setParameter( const std::string& material,size_t technique, size_t pass, const std::string& parameter, int value);93 void setParameter(size_t technique, size_t pass, const std::string& parameter, float value); 94 void setParameter(size_t technique, size_t pass, const std::string& parameter, int value); 89 95 90 static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value); 91 static bool _setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value); 92 static float getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter); 93 static bool getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter); 94 static bool getParameterIsInt (const std::string& material, size_t technique, size_t pass, const std::string& parameter); 95 static ParameterPointer* getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter); 96 virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr); 96 97 97 98 private: 98 99 static bool hasCgProgramManager(); 99 100 100 Ogre::SceneManager* scenemanager_; 101 Ogre::CompositorInstance* compositorInstance_; 102 bool bVisible_; 103 bool bLoadCompositor_; 104 std::string compositorName_; 105 std::string oldcompositorName_; 101 Ogre::SceneManager* scenemanager_; ///< The scenemanager for which the shader is active 102 Ogre::CompositorInstance* compositorInstance_; ///< The compositor instance representing the wrapped compositor 103 bool bVisible_; ///< True if the shader should be visible 104 bool bLoadCompositor_; ///< True if the compositor should be loaded (usually false if no graphics) 105 std::string compositorName_; ///< The name of the current compositor 106 std::string oldcompositorName_; ///< The name of the previous compositor (used to unregister) 106 107 107 static MaterialMap parameters_s; 108 static bool bLoadedCgPlugin_s; 108 private: 109 void addAsListener(); 110 111 /// Helper struct to store parameters for shader programs. 112 struct ParameterContainer 113 { 114 size_t technique_; ///< The ID of the technique 115 size_t pass_; ///< The ID of the pass 116 std::string parameter_; ///< The name of the parameter 117 118 int valueInt_; ///< The desired int value of the parameter 119 float valueFloat_; ///< The desired float value of the parameter 120 121 MT_Type::Value valueType_; ///< The type of the parameter (currently only int or float) 122 }; 123 124 std::list<ParameterContainer> parameters_; ///< The list of parameters that should be set on the next update 125 bool registeredAsListener_; ///< True if the shader should register itself as listener at the compositor 109 126 }; 110 127 }
Note: See TracChangeset
for help on using the changeset viewer.