2012-04-21 15:31:20 +02:00
|
|
|
// Canvas with 2D rendering api
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#include "canvas_mgr.hxx"
|
|
|
|
|
2012-11-04 14:18:31 +01:00
|
|
|
#include <Canvas/FGCanvasSystemAdapter.hxx>
|
|
|
|
#include <Cockpit/od_gauge.hxx>
|
2012-10-29 16:15:10 +01:00
|
|
|
#include <Main/fg_props.hxx>
|
2012-11-04 14:18:31 +01:00
|
|
|
#include <Viewer/CameraGroup.hxx>
|
2012-10-29 16:15:10 +01:00
|
|
|
|
2012-11-04 14:18:31 +01:00
|
|
|
#include <simgear/canvas/Canvas.hxx>
|
2012-04-21 15:31:20 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-07-27 13:17:42 +02:00
|
|
|
CanvasMgr::CanvasMgr():
|
2012-11-04 14:18:31 +01:00
|
|
|
simgear::canvas::CanvasMgr
|
|
|
|
(
|
|
|
|
fgGetNode("/canvas/by-index", true),
|
|
|
|
simgear::canvas::SystemAdapterPtr( new canvas::FGCanvasSystemAdapter )
|
|
|
|
)
|
2012-04-21 15:31:20 +02:00
|
|
|
{
|
2012-11-04 14:18:31 +01:00
|
|
|
using simgear::canvas::Canvas;
|
2012-07-27 13:17:42 +02:00
|
|
|
Canvas::addPlacementFactory
|
|
|
|
(
|
|
|
|
"object",
|
|
|
|
boost::bind
|
|
|
|
(
|
|
|
|
&FGODGauge::set_texture,
|
|
|
|
_1,
|
|
|
|
boost::bind(&Canvas::getTexture, _2),
|
|
|
|
boost::bind(&Canvas::getCullCallback, _2)
|
|
|
|
)
|
|
|
|
);
|
2012-04-21 15:31:20 +02:00
|
|
|
}
|
|
|
|
|
2012-07-04 13:15:12 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2012-11-04 14:18:31 +01:00
|
|
|
unsigned int CanvasMgr::getCanvasTexId(size_t index) const
|
2012-07-04 13:15:12 +02:00
|
|
|
{
|
2012-11-04 14:18:31 +01:00
|
|
|
simgear::canvas::CanvasPtr canvas = getCanvas(index);
|
2012-08-09 14:50:20 +02:00
|
|
|
|
2012-11-04 14:18:31 +01:00
|
|
|
if( !canvas )
|
|
|
|
return 0;
|
2012-07-04 13:15:12 +02:00
|
|
|
|
2012-11-04 14:18:31 +01:00
|
|
|
osg::Texture2D* tex = canvas->getTexture();
|
|
|
|
if( !tex )
|
2012-08-09 14:50:20 +02:00
|
|
|
return 0;
|
2012-11-04 14:18:31 +01:00
|
|
|
|
|
|
|
// osgViewer::Viewer::Contexts contexts;
|
|
|
|
// globals->get_renderer()->getViewer()->getContexts(contexts);
|
|
|
|
//
|
|
|
|
// if( contexts.empty() )
|
|
|
|
// return 0;
|
|
|
|
|
|
|
|
osg::Camera* guiCamera =
|
|
|
|
flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
|
|
|
|
|
|
|
|
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
|
|
|
|
if( !state )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
osg::Texture::TextureObject* tobj =
|
|
|
|
tex->getTextureObject( state->getContextID() );
|
|
|
|
if( !tobj )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return tobj->_id;
|
2012-04-21 15:31:20 +02:00
|
|
|
}
|