Index: code/branches/usability/src/libraries/tools/Shader.cc
===================================================================
--- code/branches/usability/src/libraries/tools/Shader.cc	(revision 7970)
+++ code/branches/usability/src/libraries/tools/Shader.cc	(revision 7972)
@@ -53,22 +53,9 @@
 
         this->scenemanager_ = scenemanager;
-        this->compositorInstance_ = 0;
         this->bVisible_ = true;
         this->bLoadCompositor_ = GameMode::showsGraphics();
-        this->bViewportInitialized_ = true;
-
-        if (this->bLoadCompositor_ && Ogre::Root::getSingletonPtr())
-        {
-            Shader::bLoadedCgPlugin_s = false;
-            const Ogre::Root::PluginInstanceList& plugins = Ogre::Root::getSingleton().getInstalledPlugins();
-            for (size_t i = 0; i < plugins.size(); ++i)
-            {
-                if (plugins[i]->getName() == "Cg Program Manager")
-                {
-                    Shader::bLoadedCgPlugin_s = true;
-                    break;
-                }
-            }
-        }
+
+        static bool hasCgProgramManager = Shader::hasCgProgramManager();
+        Shader::bLoadedCgPlugin_s = hasCgProgramManager;
 
         this->bLoadCompositor_ &= Shader::bLoadedCgPlugin_s;
@@ -77,23 +64,16 @@
     Shader::~Shader()
     {
-        if (this->compositorInstance_ && this->bLoadCompositor_)
-        {
-            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
-            assert(viewport);
-            Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_);
-        }
-
-    }
-
-    void Shader::setSceneManager(Ogre::SceneManager* scenemanager)
-    {
-        this->scenemanager_ = scenemanager;
-//        this->bViewportInitialized_ = false;
+        if (this->compositorInstance_ && GraphicsManager::getInstance().getViewport())
+            Ogre::CompositorManager::getSingleton().removeCompositor(GraphicsManager::getInstance().getViewport(), this->compositorName_);
     }
 
     void Shader::cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera)
     {
-        if (!this->scenemanager_ || (viewport != this->scenemanager_->getCurrentViewport() && this->scenemanager_->getCurrentViewport() != NULL))
+        if (!this->bLoadCompositor_ || !this->scenemanager_)
             return;
+
+        // load the compositor if not already done
+        if (!this->compositorName_.empty() && !this->compositorInstance_)
+            this->changedCompositorName(viewport);
 
         // update compositor in viewport (shader should only be active if the current camera is in the same scene as the shader)
@@ -108,42 +88,38 @@
         // 1.7.2
 
-
         if (oldCamera && this->scenemanager_ == oldCamera->getSceneManager())
-            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, false);
+            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, false);
 
         if (viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager())
-            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->isVisible());
-    }
-/*
-    void Shader::tick(float dt)
-    {
-        SUPER(Shader, tick, dt);
-
-        if (this->bLoadCompositor_ && !this->bViewportInitialized_ && this->scenemanager_ && this->scenemanager_->getCurrentViewport())
-        {
-            this->bViewportInitialized_ = true;
-            this->updateVisibility();
-        }
-    }
-*/
-    void Shader::changedCompositor()
+            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, this->isVisible());
+    }
+
+    void Shader::changedCompositorName()
+    {
+        // For the moment, we get the viewport always from the graphics manager
+        // TODO: Try to support multiple viewports - note however that scenemanager_->getCurrentViewport() returns NULL
+        //       after switching to a camera in a different scene (only for the first time this scene is displayed though)
+        this->changedCompositorName(GraphicsManager::getInstance().getViewport());
+    }
+
+    void Shader::changedCompositorName(Ogre::Viewport* viewport)
     {
         if (this->bLoadCompositor_)
         {
-            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
             assert(viewport);
-            if (!this->oldcompositor_.empty())
-            {
-                Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->oldcompositor_);
+            if (!this->oldcompositorName_.empty())
+            {
+                Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->oldcompositorName_);
                 this->compositorInstance_ = 0;
             }
-            if (!this->compositor_.empty())
-            {
-                this->compositorInstance_ = Ogre::CompositorManager::getSingleton().addCompositor(viewport, this->compositor_);
+            if (!this->compositorName_.empty())
+            {
+                this->compositorInstance_ = Ogre::CompositorManager::getSingleton().addCompositor(viewport, this->compositorName_);
                 if (!this->compositorInstance_)
-                    COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositor_ << "\"." << std::endl;
-                //Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible());
-            }
-            this->oldcompositor_ = this->compositor_;
+                    COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositorName_ << "\"." << std::endl;
+                else if (viewport->getCamera())
+                    Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositorName_, this->isVisible() && viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager());
+            }
+            this->oldcompositorName_ = this->compositorName_;
         }
     }
@@ -151,6 +127,6 @@
     void Shader::updateVisibility()
     {
-        if (this->compositorInstance_ && this->scenemanager_)
-            this->compositorInstance_->setEnabled(this->scenemanager_->getCurrentViewport() && this->isVisible());
+        if (this->compositorInstance_)
+            Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, this->isVisible());
     }
 
@@ -159,8 +135,8 @@
         if (Shader::_setParameter(material, technique, pass, parameter, value))
         {
-            if (this->bViewportInitialized_ && this->compositorInstance_ && this->isVisible())
-            {
-                this->compositorInstance_->setEnabled(false);
-                this->compositorInstance_->setEnabled(true);
+            if (this->compositorInstance_ && this->isVisible())
+            {
+                Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, false);
+                Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, true);
             }
         }
@@ -171,13 +147,13 @@
         if (Shader::_setParameter(material, technique, pass, parameter, value))
         {
-            if (this->bViewportInitialized_ && this->compositorInstance_ && this->isVisible())
-            {
-                this->compositorInstance_->setEnabled(false);
-                this->compositorInstance_->setEnabled(true);
-            }
-        }
-    }
-
-    bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value)
+            if (this->compositorInstance_ && this->isVisible())
+            {
+                Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, false);
+                Ogre::CompositorManager::getSingleton().setCompositorEnabled(GraphicsManager::getInstance().getViewport(), this->compositorName_, true);
+            }
+        }
+    }
+
+    /* static */ bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value)
     {
         ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter);
@@ -204,5 +180,5 @@
     }
 
-    bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value)
+    /* static */ bool Shader::_setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value)
     {
         ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter);
@@ -229,5 +205,5 @@
     }
 
-    float Shader::getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
+    /* static */ float Shader::getParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
     {
         ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter);
@@ -243,5 +219,5 @@
     }
 
-    bool Shader::getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
+    /* static */ bool Shader::getParameterIsFloat(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
     {
         ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter);
@@ -252,5 +228,5 @@
     }
 
-    bool Shader::getParameterIsInt(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
+    /* static */ bool Shader::getParameterIsInt(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
     {
         ParameterPointer* pointer = Shader::getParameterPointer(material, technique, pass, parameter);
@@ -261,5 +237,5 @@
     }
 
-    Shader::ParameterPointer* Shader::getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
+    /* static */ Shader::ParameterPointer* Shader::getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
     {
         if (!GameMode::showsGraphics() || !Shader::bLoadedCgPlugin_s)
@@ -351,3 +327,15 @@
         return 0;
     }
+
+    /* static */ bool Shader::hasCgProgramManager()
+    {
+        if (Ogre::Root::getSingletonPtr())
+        {
+            const Ogre::Root::PluginInstanceList& plugins = Ogre::Root::getSingleton().getInstalledPlugins();
+            for (size_t i = 0; i < plugins.size(); ++i)
+                if (plugins[i]->getName() == "Cg Program Manager")
+                    return true;
+        }
+        return false;
+    }
 }
Index: code/branches/usability/src/libraries/tools/Shader.h
===================================================================
--- code/branches/usability/src/libraries/tools/Shader.h	(revision 7970)
+++ code/branches/usability/src/libraries/tools/Shader.h	(revision 7972)
@@ -65,17 +65,19 @@
             void updateVisibility();
 
-            inline void setCompositor(const std::string& compositor)
+            inline void setCompositorName(const std::string& name)
             {
-                if (this->compositor_ != compositor)
+                if (this->compositorName_ != name)
                 {
-                    this->compositor_ = compositor;
-                    this->changedCompositor();
+                    this->compositorName_ = name;
+                    this->changedCompositorName();
                 }
             }
-            inline const std::string& getCompositor() const
-                { return this->compositor_; }
-            void changedCompositor();
+            inline const std::string& getCompositorName() const
+                { return this->compositorName_; }
+            void changedCompositorName();
+            void changedCompositorName(Ogre::Viewport* viewport);
 
-            void setSceneManager(Ogre::SceneManager* scenemanager);
+            inline void setSceneManager(Ogre::SceneManager* scenemanager)
+                { this->scenemanager_ = scenemanager; }
             inline Ogre::SceneManager* getSceneManager() const
                 { return this->scenemanager_; }
@@ -94,11 +96,12 @@
 
         private:
+            static bool hasCgProgramManager();
+
             Ogre::SceneManager* scenemanager_;
             Ogre::CompositorInstance* compositorInstance_;
             bool bVisible_;
             bool bLoadCompositor_;
-            bool bViewportInitialized_;
-            std::string compositor_;
-            std::string oldcompositor_;
+            std::string compositorName_;
+            std::string oldcompositorName_;
 
             static MaterialMap parameters_s;
Index: code/branches/usability/src/orxonox/graphics/GlobalShader.cc
===================================================================
--- code/branches/usability/src/orxonox/graphics/GlobalShader.cc	(revision 7970)
+++ code/branches/usability/src/orxonox/graphics/GlobalShader.cc	(revision 7972)
@@ -61,5 +61,5 @@
         SUPER(GlobalShader, XMLPort, xmlelement, mode);
 
-        XMLPortParamExtern(GlobalShader, Shader, &this->shader_, "compositor", setCompositor, getCompositor, xmlelement, mode);
+        XMLPortParamExtern(GlobalShader, Shader, &this->shader_, "compositor", setCompositorName, getCompositorName, xmlelement, mode);
     }
 
@@ -67,5 +67,5 @@
     {
         registerVariable(this->bVisible_,                                         VariableDirection::ToClient, new NetworkCallback<GlobalShader>(this, &GlobalShader::changedVisibility));
-        registerVariable(const_cast<std::string&>(this->shader_.getCompositor()), VariableDirection::ToClient, new NetworkCallback<Shader>(&this->shader_, &Shader::changedCompositor));
+        registerVariable(const_cast<std::string&>(this->shader_.getCompositorName()), VariableDirection::ToClient, new NetworkCallback<Shader>(&this->shader_, &Shader::changedCompositorName));
     }
 
Index: code/branches/usability/src/orxonox/graphics/GlobalShader.h
===================================================================
--- code/branches/usability/src/orxonox/graphics/GlobalShader.h	(revision 7970)
+++ code/branches/usability/src/orxonox/graphics/GlobalShader.h	(revision 7972)
@@ -53,5 +53,4 @@
         private:
             void registerVariables();
-            void changedCompositor();
 
             Shader shader_;
