Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2396 for code/branches


Ignore:
Timestamp:
Dec 10, 2008, 6:37:31 PM (16 years ago)
Author:
landauf
Message:

fixed shader/camera crash

Location:
code/branches/objecthierarchy2/src/orxonox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/CameraManager.cc

    r2369 r2396  
    2929#include "CameraManager.h"
    3030
     31#include <OgreSceneManager.h>
    3132#include <OgreViewport.h>
    32 #include <OgreSceneManager.h>
    3333#include <OgreCamera.h>
     34#include <OgreCompositorManager.h>
     35#include <OgreResource.h>
    3436
    3537#include "core/Core.h"
     38#include "core/Iterator.h"
    3639#include "objects/worldentities/Camera.h"
    3740#include "objects/Scene.h"
     41#include "tools/Shader.h"
    3842#include "util/String.h"
    3943
     
    5761
    5862        if (this->fallbackCamera_)
    59         {
    6063            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
    61 COUT(0) << "remove camera-manager" << std::endl;
    62         }
    6364    }
    6465
     
    8384            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
    8485            this->fallbackCamera_ = 0;
    85 COUT(0) << "remove fallback camera" << std::endl;
    8686        }
    8787
    88         camera->setFocus(this->viewport_);
     88        camera->setFocus();
    8989
    9090        // make sure we don't add it twice
     
    110110            // set new focus if possible
    111111            if (this->cameraList_.size() > 0)
    112                 this->cameraList_.front()->setFocus(this->viewport_);
     112                this->cameraList_.front()->setFocus();
    113113            else
    114114            {
    115115                // there are no more cameras, create a fallback
    116116                if (!this->fallbackCamera_)
    117                 {
    118 COUT(0) << "create fallback camera" << std::endl;
    119117                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
    120                 }
    121                 this->viewport_->setCamera(this->fallbackCamera_);
    122 COUT(0) << "use fallback camera" << std::endl;
     118                this->useCamera(this->fallbackCamera_);
    123119            }
    124120        }
     
    128124        }
    129125    }
     126
     127    void CameraManager::useCamera(Ogre::Camera* camera)
     128    {
     129        // This workaround is needed to avoid weird behaviour with active compositors while
     130        // switching the camera (like freezing the image)
     131        //
     132        // Last known Ogre version needing this workaround:
     133        // 1.4.8
     134
     135        // deactivate all compositors
     136        {
     137            Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
     138            while (iterator.hasMoreElements())
     139                Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
     140        }
     141
     142        this->viewport_->setCamera(camera);
     143
     144        // reactivate all visible compositors
     145        {
     146            for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
     147                it->updateVisibility();
     148        }
     149    }
    130150}
  • code/branches/objecthierarchy2/src/orxonox/CameraManager.h

    r2369 r2396  
    5757            static CameraManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    5858
     59            void useCamera(Ogre::Camera* camera);
     60
    5961        private:
    6062            CameraManager(const CameraManager&);
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc

    r2350 r2396  
    101101        }
    102102
     103        this->playerManager_ = new PlayerManager();
     104
    103105        if (Core::isMaster())
    104106        {
    105107            // create the global LevelManager
    106108            this->levelManager_ = new LevelManager();
    107             this->playerManager_ = new PlayerManager();
    108109
    109110            // reset game speed to normal
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Camera.cc

    r2369 r2396  
    3636#include <OgreSceneManager.h>
    3737#include <OgreSceneNode.h>
    38 #include <OgreViewport.h>
    39 #include <OgreCompositorManager.h>
    40 #include <OgreResource.h>
    4138
    4239#include "util/Exception.h"
     
    4441#include "core/ConfigValueIncludes.h"
    4542#include "objects/Scene.h"
    46 #include "tools/Shader.h"
    4743#include "CameraManager.h"
    4844
     
    5450    {
    5551        RegisterObject(Camera);
    56 COUT(0) << this << ": created camera" << std::endl;
     52
    5753        if (!this->getScene() || !this->getScene()->getSceneManager())
    5854            ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");
     
    8076            this->getScene()->getSceneManager()->destroyCamera(this->camera_);
    8177        }
    82 COUT(0) << this << ": destroyed camera" << std::endl;
    8378    }
    8479
     
    123118    void Camera::removeFocus()
    124119    {
    125 COUT(0) << this << ": remove focus" << std::endl;
    126120        this->bHasFocus_ = false;
    127121    }
    128122
    129     void Camera::setFocus(Ogre::Viewport* viewport)
     123    void Camera::setFocus()
    130124    {
    131         // This workaround is needed to avoid weird behaviour with active compositors while
    132         // switching the camera (like freezing the image)
    133         //
    134         // Last known Ogre version needing this workaround:
    135         // 1.4.8
    136 
    137         // deactivate all compositors
    138         {
    139             Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
    140             while (iterator.hasMoreElements())
    141                 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, iterator.getNext()->getName(), false);
    142         }
    143 
    144125        this->bHasFocus_ = true;
    145         viewport->setCamera(this->camera_);
    146 COUT(0) << this << ": set focus" << std::endl;
    147 
    148         // reactivate all visible compositors
    149         {
    150             for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
    151                 it->updateVisibility();
    152         }
     126        CameraManager::getInstance().useCamera(this->camera_);
    153127    }
    154128}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Camera.h

    r2171 r2396  
    6262        private:
    6363            void removeFocus();
    64             void setFocus(Ogre::Viewport* viewport);
     64            void setFocus();
    6565            void configvaluecallback_changedNearClipDistance();
    6666
  • code/branches/objecthierarchy2/src/orxonox/tools/Shader.cc

    r2361 r2396  
    8383    Shader::~Shader()
    8484    {
    85 /*
    86         if (this->isInitialized() && this->bLoadCompositor_ && this->compositor_ != "")
     85
     86        if (this->bLoadCompositor_ && this->compositorInstance_)
    8787        {
    8888            Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
     
    9090            Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_);
    9191        }
    92 */
     92
    9393    }
    9494
Note: See TracChangeset for help on using the changeset viewer.