1 // Viewer.hxx -- alternative flightgear viewer application
3 // Copyright (C) 2009 - 2012 Mathias Froehlich
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "Drawable.hxx"
29 class Drawable::_ResizedCallback : public osg::GraphicsContext::ResizedCallback {
31 _ResizedCallback(Drawable* drawable) :
34 virtual ~_ResizedCallback()
36 virtual void resizedImplementation(osg::GraphicsContext*, int x, int y, int width, int height)
38 SGSharedPtr<Drawable> drawable = _drawable.lock();
39 if (!drawable.valid())
41 drawable->resize(x, y, width, height);
43 SGWeakPtr<Drawable> _drawable;
46 Drawable::Drawable(const std::string& name) :
60 Drawable::attachSlaveCamera(SlaveCamera* slaveCamera)
64 _slaveCameraList.push_back(slaveCamera);
68 Drawable::resize(int x, int y, int width, int height)
70 unsigned numCameras = _slaveCameraList.size();
73 _graphicsContext->resizedImplementation(x, y, width, height);
76 _slaveCameraList.front()->setViewport(SGVec4i(0, 0, width, height));
81 Drawable::realize(Viewer& viewer)
83 if (_graphicsContext.valid())
85 _graphicsContext = _realizeImplementation(viewer);
86 if (!_graphicsContext.valid())
88 _graphicsContext->setResizedCallback(new _ResizedCallback(this));
93 Drawable::_realizeImplementation(Viewer& viewer)
95 osg::ref_ptr<osg::GraphicsContext::Traits> traits = _getTraits(viewer);
96 return viewer.createGraphicsContext(traits.get());
99 osg::ref_ptr<osg::GraphicsContext::Traits>
100 Drawable::_getTraits(Viewer& viewer)
102 osg::GraphicsContext::ScreenIdentifier screenIdentifier;
103 screenIdentifier.setScreenIdentifier(_screenIdentifier);
105 osg::ref_ptr<osg::GraphicsContext::Traits> traits;
106 traits = viewer.getTraits(screenIdentifier);
108 // The window name as displayed by the window manager
109 traits->windowName = getName();
111 traits->x = _position[0];
112 traits->y = _position[1];
114 traits->width = _size[0];
115 traits->height = _size[1];
118 traits->windowDecoration = !_fullscreen;
119 if (_slaveCameraList.size() <= 1)
120 traits->supportsResize = true;
122 traits->supportsResize = false;
123 traits->pbuffer = _offscreen;
128 } // namespace fgviewer