Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver2/src/orxonox/CameraManager.cc @ 8328

Last change on this file since 8328 was 7879, checked in by landauf, 14 years ago

moved compositor unloading to avoid crashes in rare cases
disabled compositor unloading for Ogre 1.7.0+ which fixes some issues with shaders

I'm unsure if this belongs into GSLevel anyway, since it's resource related and removeAll() requires quite some attention to be called in the right place.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Benjamin Knecht
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "CameraManager.h"
30
31#include <OgreSceneManager.h>
32#include <OgreViewport.h>
33#include <OgreCompositorManager.h>
34
35#include "util/StringUtils.h"
36#include "util/ScopedSingletonManager.h"
37#include "core/GameMode.h"
38#include "core/GraphicsManager.h"
39#include "core/GUIManager.h"
40#include "core/ObjectList.h"
41#include "tools/Shader.h"
42#include "graphics/Camera.h"
43#include "Scene.h"
44
45namespace orxonox
46{
47    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
48
49    CameraManager::CameraManager()
50        : viewport_(GraphicsManager::getInstance().getViewport())
51    {
52        assert(GameMode::showsGraphics());
53    }
54
55    CameraManager::~CameraManager()
56    {
57        GUIManager::getInstance().setCamera(0);
58    }
59
60    Camera* CameraManager::getActiveCamera() const
61    {
62        if (!this->cameraList_.empty())
63            return this->cameraList_.front();
64        else
65            return 0;
66    }
67
68    void CameraManager::requestFocus(Camera* camera)
69    {
70        // notify old camera (if it exists)
71        if (!this->cameraList_.empty())
72            this->cameraList_.front()->removeFocus();
73
74        camera->setFocus();
75
76        // make sure we don't add it twice
77        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
78            if ((*it) == camera)
79                this->cameraList_.erase(it++);
80            else
81                ++it;
82        // add to list
83        this->cameraList_.push_front(camera);
84    }
85
86    void CameraManager::releaseFocus(Camera* camera)
87    {
88        // notify the cam of releasing the focus
89        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
90        {
91            camera->removeFocus();
92            this->cameraList_.pop_front();
93
94            // set new focus if possible
95            if (!this->cameraList_.empty())
96                this->cameraList_.front()->setFocus();
97        }
98        else
99            this->cameraList_.remove(camera);
100    }
101
102    void CameraManager::useCamera(Ogre::Camera* camera)
103    {
104        // This workaround is needed to avoid weird behaviour with active compositors while
105        // switching the camera (like freezing the image)
106        //
107        // Last known Ogre version needing this workaround:
108        // 1.4.8
109        // 1.7.2
110
111        // deactivate all compositors
112        {
113            Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
114            while (iterator.hasMoreElements())
115                Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
116        }
117
118        this->viewport_->setCamera(camera);
119        GUIManager::getInstance().setCamera(camera);
120
121        // reactivate all visible compositors
122        {
123            for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
124                it->updateVisibility();
125        }
126    }
127}
Note: See TracBrowser for help on using the repository browser.