1 // Canvas with 2D rendering api
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
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.
19 #include "canvas_mgr.hxx"
21 #include <Canvas/FGCanvasSystemAdapter.hxx>
22 #include <Cockpit/od_gauge.hxx>
23 #include <Main/fg_props.hxx>
24 #include <Scripting/NasalModelData.hxx>
25 #include <Viewer/CameraGroup.hxx>
27 #include <simgear/canvas/Canvas.hxx>
29 namespace sc = simgear::canvas;
31 //------------------------------------------------------------------------------
32 static sc::Placements addSceneObjectPlacement( SGPropertyNode* placement,
33 sc::CanvasPtr canvas )
35 int module_id = placement->getIntValue("module-id", -1);
37 return sc::Placements();
39 FGNasalModelData* model_data =
40 FGNasalModelData::getByModuleId( static_cast<unsigned int>(module_id) );
43 return sc::Placements();
45 if( !model_data->getNode() )
46 return sc::Placements();
48 return FGODGauge::set_texture
50 model_data->getNode(),
53 canvas->getCullCallback(),
58 //------------------------------------------------------------------------------
59 CanvasMgr::CanvasMgr():
60 simgear::canvas::CanvasMgr
62 fgGetNode("/canvas/by-index", true),
63 sc::SystemAdapterPtr( new canvas::FGCanvasSystemAdapter )
68 &CanvasMgr::handleModelReinit,
69 fgGetNode("/sim/signals/model-reinit", true)
72 sc::Canvas::addPlacementFactory
77 &FGODGauge::set_aircraft_texture,
79 boost::bind(&sc::Canvas::getTexture, _2),
80 boost::bind(&sc::Canvas::getCullCallback, _2),
85 sc::Canvas::addPlacementFactory("scenery-object", &addSceneObjectPlacement);
88 //------------------------------------------------------------------------------
90 CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const
92 osg::Texture2D* tex = canvas->getTexture();
96 // osgViewer::Viewer::Contexts contexts;
97 // globals->get_renderer()->getViewer()->getContexts(contexts);
99 // if( contexts.empty() )
102 static osg::Camera* guiCamera =
103 flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
105 osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
109 osg::Texture::TextureObject* tobj =
110 tex->getTextureObject( state->getContextID() );
117 //----------------------------------------------------------------------------
118 void CanvasMgr::handleModelReinit(SGPropertyNode*)
120 for(size_t i = 0; i < _elements.size(); ++i)
121 boost::static_pointer_cast<sc::Canvas>(_elements[i])
122 ->reloadPlacements("object");