root/OpenSceneGraph/trunk/examples/osgmultiviewpaging/osgmultiviewpaging.cpp @ 11979

Revision 11979, 7.0 kB (checked in by robert, 4 years ago)

From Mathias Froehlich, "Attached are most of the fixes that are required to build osg on solaris and
hpux. I have skipped irix this time as irix is too dead to keep osg building
there.

As usual, solaris does not like member templates in stl containers.
Some headers missing and link problems due to missing libraries."

Line 
1/* OpenSceneGraph example, osgcompositeviewer.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#include <iostream>
20
21#include <osgUtil/Optimizer>
22#include <osgDB/ReadFile>
23
24#include <osg/Material>
25#include <osg/Geode>
26#include <osg/BlendFunc>
27#include <osg/Depth>
28#include <osg/Projection>
29#include <osg/PolygonOffset>
30#include <osg/MatrixTransform>
31#include <osg/Camera>
32#include <osg/FrontFace>
33
34#include <osgText/Text>
35
36#include <osgGA/TerrainManipulator>
37#include <osgGA/FlightManipulator>
38#include <osgGA/StateSetManipulator>
39#include <osgViewer/ViewerEventHandlers>
40
41#include <osgViewer/CompositeViewer>
42
43#include <osg/io_utils>
44
45class MyPager : public osgDB::DatabasePager
46{
47public:
48 virtual void updateSceneGraph(const osg::FrameStamp& frameStamp)
49 {
50   if (frameStamp.getFrameNumber() % 60 == 0)
51   {
52     osg::Timer_t start = osg::Timer::instance()->tick();
53     osgDB::DatabasePager::updateSceneGraph(frameStamp);
54     double d = osg::Timer::instance()->delta_m(start, osg::Timer::instance()->tick());
55     std::cout << "DatabasePager update took " << d << " ms. Length of active nodes = " << _activePagedLODList->size() << std::endl;
56   }
57 }
58};
59
60int main( int argc, char **argv )
61{
62
63    // use an ArgumentParser object to manage the program arguments.
64    osg::ArgumentParser arguments(&argc,argv);
65
66    // read the scene from the list of file specified commandline args.
67    osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
68
69    if (!scene)
70    {
71        scene = osgDB::readNodeFile("http://www.openscenegraph.org/data/earth_bayarea/earth.ive");
72    }
73
74    if (!scene)
75    {
76        std::cout << argv[0] << ": requires filename argument." << std::endl;
77        return 1;
78    }
79
80    // construct the viewer.
81    osgViewer::CompositeViewer viewer(arguments);
82
83    if (viewer.getNumViews()==0)
84    {
85
86        osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
87        if (!wsi)
88        {
89            osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
90            return 1;
91        }
92
93        unsigned int width, height;
94        wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
95
96        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
97        traits->x = 100;
98        traits->y = 100;
99        traits->width = 1000;
100        traits->height = 800;
101        traits->windowDecoration = true;
102        traits->doubleBuffer = true;
103        traits->sharedContext = 0;
104
105        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
106        if (gc.valid())
107        {
108            osg::notify(osg::INFO)<<"  GraphicsWindow has been created successfully."<<std::endl;
109
110            // need to ensure that the window is cleared make sure that the complete window is set the correct colour
111            // rather than just the parts of the window that are under the camera's viewports
112            gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
113            gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
114        }
115        else
116        {
117            osg::notify(osg::NOTICE)<<"  GraphicsWindow has not been created successfully."<<std::endl;
118        }
119
120        // view one
121        {
122            osgViewer::View* view = new osgViewer::View;
123            view->setName("View one");
124            viewer.addView(view);
125
126            view->setSceneData(scene.get());
127            view->getCamera()->setName("Cam one");
128            view->getCamera()->setViewport(new osg::Viewport(0,0, traits->width/2, traits->height/2));
129            view->getCamera()->setGraphicsContext(gc.get());
130
131            // add the state manipulator
132            osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator;
133            statesetManipulator->setStateSet(view->getCamera()->getOrCreateStateSet());
134
135            view->setCameraManipulator(new osgGA::TerrainManipulator);
136            view->addEventHandler( statesetManipulator.get() );
137
138            view->addEventHandler( new osgViewer::StatsHandler );
139            view->addEventHandler( new osgViewer::HelpHandler );
140            view->addEventHandler( new osgViewer::WindowSizeHandler );
141            view->addEventHandler( new osgViewer::ThreadingHandler );
142            view->addEventHandler( new osgViewer::RecordCameraPathHandler );
143        }
144
145        // view two
146        {
147            osgViewer::View* view = new osgViewer::View;
148            view->setName("View two");
149            viewer.addView(view);
150
151            view->setSceneData(scene.get());
152            view->getCamera()->setName("Cam two");
153            view->getCamera()->setViewport(new osg::Viewport(traits->width/2,0, traits->width/2, traits->height/2));
154            view->getCamera()->setGraphicsContext(gc.get());
155            view->setCameraManipulator(new osgGA::TerrainManipulator);
156
157        }
158
159        // view three
160        {
161            osgViewer::View* view = new osgViewer::View;
162            view->setName("View three");
163            viewer.addView(view);
164
165            view->setSceneData(scene.get());
166
167            view->getCamera()->setName("Cam three");
168            view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0);
169            view->getCamera()->setViewport(new osg::Viewport(0, traits->height/2, traits->width, traits->height/2));
170            view->getCamera()->setGraphicsContext(gc.get());
171            view->setCameraManipulator(new osgGA::TerrainManipulator);
172
173            // attach custom database pager
174            view->setDatabasePager(new MyPager);
175            view->getDatabasePager()->setTargetMaximumNumberOfPageLOD(1);
176        }
177
178    }
179
180
181    while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::CompositeViewer::SingleThreaded); }
182    while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::CompositeViewer::CullDrawThreadPerContext); }
183    while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::CompositeViewer::CullThreadPerCameraDrawThreadPerContext); }
184
185     // run the viewer's main frame loop
186     return viewer.run();
187}
Note: See TracBrowser for help on using the browser.