- Timestamp:
- Feb 26, 2011, 8:50:06 PM (14 years ago)
- Location:
- code/branches/usability/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/tools/Shader.cc
r7966 r7972 53 53 54 54 this->scenemanager_ = scenemanager; 55 this->compositorInstance_ = 0;56 55 this->bVisible_ = true; 57 56 this->bLoadCompositor_ = GameMode::showsGraphics(); 58 this->bViewportInitialized_ = true; 59 60 if (this->bLoadCompositor_ && Ogre::Root::getSingletonPtr()) 61 { 62 Shader::bLoadedCgPlugin_s = false; 63 const Ogre::Root::PluginInstanceList& plugins = Ogre::Root::getSingleton().getInstalledPlugins(); 64 for (size_t i = 0; i < plugins.size(); ++i) 65 { 66 if (plugins[i]->getName() == "Cg Program Manager") 67 { 68 Shader::bLoadedCgPlugin_s = true; 69 break; 70 } 71 } 72 } 57 58 static bool hasCgProgramManager = Shader::hasCgProgramManager(); 59 Shader::bLoadedCgPlugin_s = hasCgProgramManager; 73 60 74 61 this->bLoadCompositor_ &= Shader::bLoadedCgPlugin_s; … … 77 64 Shader::~Shader() 78 65 { 79 if (this->compositorInstance_ && this->bLoadCompositor_) 80 { 81 Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport(); 82 assert(viewport); 83 Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_); 84 } 85 86 } 87 88 void Shader::setSceneManager(Ogre::SceneManager* scenemanager) 89 { 90 this->scenemanager_ = scenemanager; 91 // this->bViewportInitialized_ = false; 66 if (this->compositorInstance_ && GraphicsManager::getInstance().getViewport()) 67 Ogre::CompositorManager::getSingleton().removeCompositor(GraphicsManager::getInstance().getViewport(), this->compositorName_); 92 68 } 93 69 94 70 void Shader::cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera) 95 71 { 96 if (!this-> scenemanager_ || (viewport != this->scenemanager_->getCurrentViewport() && this->scenemanager_->getCurrentViewport() != NULL))72 if (!this->bLoadCompositor_ || !this->scenemanager_) 97 73 return; 74 75 // load the compositor if not already done 76 if (!this->compositorName_.empty() && !this->compositorInstance_) 77 this->changedCompositorName(viewport); 98 78 99 79 // update compositor in viewport (shader should only be active if the current camera is in the same scene as the shader) … … 108 88 // 1.7.2 109 89 110 111 90 if (oldCamera && this->scenemanager_ == oldCamera->getSceneManager()) 112 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor _, false);91 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, false); 113 92 114 93 if (viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager()) 115 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->isVisible()); 116 } 117 /* 118 void Shader::tick(float dt) 119 { 120 SUPER(Shader, tick, dt); 121 122 if (this->bLoadCompositor_ && !this->bViewportInitialized_ && this->scenemanager_ && this->scenemanager_->getCurrentViewport()) 123 { 124 this->bViewportInitialized_ = true; 125 this->updateVisibility(); 126 } 127 } 128 */ 129 void Shader::changedCompositor() 94 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, this->isVisible()); 95 } 96 97 void Shader::changedCompositorName() 98 { 99 // For the moment, we get the viewport always from the graphics manager 100 // TODO: Try to support multiple viewports - note however that scenemanager_->getCurrentViewport() returns NULL 101 // after switching to a camera in a different scene (only for the first time this scene is displayed though) 102 this->changedCompositorName(GraphicsManager::getInstance().getViewport()); 103 } 104 105 void Shader::changedCompositorName(Ogre::Viewport* viewport) 130 106 { 131 107 if (this->bLoadCompositor_) 132 108 { 133 Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();134 109 assert(viewport); 135 if (!this->oldcompositor _.empty())136 { 137 Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->oldcompositor _);110 if (!this->oldcompositorName_.empty()) 111 { 112 Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->oldcompositorName_); 138 113 this->compositorInstance_ = 0; 139 114 } 140 if (!this->compositor _.empty())141 { 142 this->compositorInstance_ = Ogre::CompositorManager::getSingleton().addCompositor(viewport, this->compositor _);115 if (!this->compositorName_.empty()) 116 { 117 this->compositorInstance_ = Ogre::CompositorManager::getSingleton().addCompositor(viewport, this->compositorName_); 143 118 if (!this->compositorInstance_) 144 COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositor_ << "\"." << std::endl; 145 //Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible()); 146 } 147 this->oldcompositor_ = this->compositor_; 119 COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositorName_ << "\"." << std::endl; 120 else if (viewport->getCamera()) 121 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, this->isVisible() && viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager()); 122 } 123 this->oldcompositorName_ = this->compositorName_; 148 124 } 149 125 } … … 151 127 void Shader::updateVisibility() 152 128 { 153 if (this->compositorInstance_ && this->scenemanager_)154 this->compositorInstance_->setEnabled(this->scenemanager_->getCurrentViewport() &&this->isVisible());129 if (this->compositorInstance_) 130 Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, this->isVisible()); 155 131 } 156 132 … … 159 135 if (Shader::_setParameter(material, technique, pass, parameter, value)) 160 136 { 161 if (this-> bViewportInitialized_ && this->compositorInstance_ && this->isVisible())162 { 163 this->compositorInstance_->setEnabled(false);164 this->compositorInstance_->setEnabled(true);137 if (this->compositorInstance_ && this->isVisible()) 138 { 139 Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, false); 140 Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, true); 165 141 } 166 142 } … … 171 147 if (Shader::_setParameter(material, technique, pass, parameter, value)) 172 148 { 173 if (this-> bViewportInitialized_ && this->compositorInstance_ && this->isVisible())174 { 175 this->compositorInstance_->setEnabled(false);176 this->compositorInstance_->setEnabled(true);177 } 178 } 179 } 180 181 bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value)149 if (this->compositorInstance_ && this->isVisible()) 150 { 151 Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, false); 152 Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, true); 153 } 154 } 155 } 156 157 /* static */ bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value) 182 158 { 183 159 ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter); … … 204 180 } 205 181 206 bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value)182 /* static */ bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value) 207 183 { 208 184 ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter); … … 229 205 } 230 206 231 float Shader::getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter)207 /* static */ float Shader::getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter) 232 208 { 233 209 ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter); … … 243 219 } 244 220 245 bool Shader::getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter)221 /* static */ bool Shader::getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter) 246 222 { 247 223 ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter); … … 252 228 } 253 229 254 bool Shader::getParameterIsInt(const std::string& material, size_t technique, size_t pass, const std::string& parameter)230 /* static */ bool Shader::getParameterIsInt(const std::string& material, size_t technique, size_t pass, const std::string& parameter) 255 231 { 256 232 ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter); … … 261 237 } 262 238 263 Shader::ParameterPointer* Shader::getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter)239 /* static */ Shader::ParameterPointer* Shader::getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter) 264 240 { 265 241 if (!GameMode::showsGraphics() || !Shader::bLoadedCgPlugin_s) … … 351 327 return 0; 352 328 } 329 330 /* static */ bool Shader::hasCgProgramManager() 331 { 332 if (Ogre::Root::getSingletonPtr()) 333 { 334 const Ogre::Root::PluginInstanceList& plugins = Ogre::Root::getSingleton().getInstalledPlugins(); 335 for (size_t i = 0; i < plugins.size(); ++i) 336 if (plugins[i]->getName() == "Cg Program Manager") 337 return true; 338 } 339 return false; 340 } 353 341 } -
code/branches/usability/src/libraries/tools/Shader.h
r7966 r7972 65 65 void updateVisibility(); 66 66 67 inline void setCompositor (const std::string& compositor)67 inline void setCompositorName(const std::string& name) 68 68 { 69 if (this->compositor _ != compositor)69 if (this->compositorName_ != name) 70 70 { 71 this->compositor _ = compositor;72 this->changedCompositor ();71 this->compositorName_ = name; 72 this->changedCompositorName(); 73 73 } 74 74 } 75 inline const std::string& getCompositor() const 76 { return this->compositor_; } 77 void changedCompositor(); 75 inline const std::string& getCompositorName() const 76 { return this->compositorName_; } 77 void changedCompositorName(); 78 void changedCompositorName(Ogre::Viewport* viewport); 78 79 79 void setSceneManager(Ogre::SceneManager* scenemanager); 80 inline void setSceneManager(Ogre::SceneManager* scenemanager) 81 { this->scenemanager_ = scenemanager; } 80 82 inline Ogre::SceneManager* getSceneManager() const 81 83 { return this->scenemanager_; } … … 94 96 95 97 private: 98 static bool hasCgProgramManager(); 99 96 100 Ogre::SceneManager* scenemanager_; 97 101 Ogre::CompositorInstance* compositorInstance_; 98 102 bool bVisible_; 99 103 bool bLoadCompositor_; 100 bool bViewportInitialized_; 101 std::string compositor_; 102 std::string oldcompositor_; 104 std::string compositorName_; 105 std::string oldcompositorName_; 103 106 104 107 static MaterialMap parameters_s; -
code/branches/usability/src/orxonox/graphics/GlobalShader.cc
r5781 r7972 61 61 SUPER(GlobalShader, XMLPort, xmlelement, mode); 62 62 63 XMLPortParamExtern(GlobalShader, Shader, &this->shader_, "compositor", setCompositor , getCompositor, xmlelement, mode);63 XMLPortParamExtern(GlobalShader, Shader, &this->shader_, "compositor", setCompositorName, getCompositorName, xmlelement, mode); 64 64 } 65 65 … … 67 67 { 68 68 registerVariable(this->bVisible_, VariableDirection::ToClient, new NetworkCallback<GlobalShader>(this, &GlobalShader::changedVisibility)); 69 registerVariable(const_cast<std::string&>(this->shader_.getCompositor ()), VariableDirection::ToClient, new NetworkCallback<Shader>(&this->shader_, &Shader::changedCompositor));69 registerVariable(const_cast<std::string&>(this->shader_.getCompositorName()), VariableDirection::ToClient, new NetworkCallback<Shader>(&this->shader_, &Shader::changedCompositorName)); 70 70 } 71 71 -
code/branches/usability/src/orxonox/graphics/GlobalShader.h
r7163 r7972 53 53 private: 54 54 void registerVariables(); 55 void changedCompositor();56 55 57 56 Shader shader_;
Note: See TracChangeset
for help on using the changeset viewer.