Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

fixed shader/camera crash

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.