3 #include "OSGSimpleGeometry.h"
4 #include "OSGPassiveWindow.h"
5 #include "OSGSimpleSceneManager.h"
6 #include "OSGSceneFileHandler.h"
8 #include "OSGDrawable.h"
9 #include "OSGPerfMonitorForeground.h"
10 #include "OSGPerfMonitor.h"
11 #include "OSGPerfMonitorGuard.h"
12 #include "OSGBaseFunctions.h"
14 #include "OSGTextureBaseChunk.h"
15 #include "OSGMaterialChunk.h"
16 #include <boost/assign/list_of.hpp>
19 OSG::SimpleSceneManagerRefPtr
mgr(NULL
);
20 OSG::RenderActionRefPtr
act(NULL
);
22 OSG::PassiveWindowRecPtr pwin
;
23 OSG::PerfMonitorForegroundRecPtr perfmon_fg
;
27 void doStuff(); // Function to just do some things to analyze
33 OSG::PerfMonitor::the()->updateFrame(); // Have to update the stats each "frame"
41 // react to size changes
42 void reshape(int w
, int h
)
48 // react to mouse button presses
49 void mouse(int button
, int state
, int x
, int y
)
52 mgr
->mouseButtonRelease(button
, x
, y
);
54 mgr
->mouseButtonPress(button
, x
, y
);
59 // react to mouse motions with pressed buttons
60 void motion(int x
, int y
)
68 void keyboard(unsigned char k
, int, int)
78 perfmon_fg
->cycleMode(-1);
81 perfmon_fg
->cycleMode();
85 mgr
->setStatistics(!mgr
->getStatistics());
88 // Output help about the controls
89 // - If you add an option, please add it here too.
94 std::cerr
<< "\nControls:"
95 << "ESC: Exit application\n"
96 << "m/M: Switch stat mode.\n"
97 << "s: Cycle stats display.\n"
105 int main(int argc
, char **argv
)
107 OSG::osgInit(argc
,argv
);
108 OSG::PerfMonitor::the()->enable(true); // Enable performance monitoring
111 glutInit(&argc
, argv
);
113 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
115 glutInitWindowSize(500, 500);
116 glutCreateWindow("PerfMonitor FG Test");
118 glutReshapeFunc(reshape
);
119 glutDisplayFunc(display
);
120 glutIdleFunc(display
);
121 glutMouseFunc(mouse
);
122 glutMotionFunc(motion
);
123 glutKeyboardFunc(keyboard
);
125 pwin
=OSG::PassiveWindow::create();
129 OSG::NodeUnrecPtr scene
;
133 scene
= OSG::Node::create();
134 OSG::GroupUnrecPtr g
= OSG::Group::create();
138 for(OSG::UInt16 i
= 1; i
< argc
; ++i
)
139 scene
->addChild(OSG::SceneFileHandler::the()->read(argv
[i
]));
143 scene
= OSG::makeTorus(.5, 3, 16, 16);
146 // create the SimpleSceneManager helper
147 mgr
= OSG::SimpleSceneManager::create();
149 // create the window and initial camera/viewport
150 mgr
->setWindow(pwin
);
151 // tell the manager what to manage
152 mgr
->setRoot (scene
);
154 OSG::Thread::getCurrentChangeList()->commitChanges();
156 // show the whole scene
159 // add the statistics forground
161 perfmon_fg
= OSG::PerfMonitorForeground::create();
162 pwin
->getPort(0)->addForeground(perfmon_fg
);
164 //statfg->setMaxSize(25);
165 //statfg->setColor(Color4f(0,1,0,0.7));
167 act
= OSG::RenderAction::create();
177 void randWork(unsigned baseTime
, unsigned randMax
, std::string name
)
179 OSG::PerfMonitorGuard
g(name
);
180 unsigned rand_time
= unsigned(OSG::osgRand() * float(randMax
));
181 OSG::osgSleep(baseTime
+ rand_time
);
184 void recursiveFunc(unsigned depth
=3)
186 OSG::PerfMonitorGuard
g("recursiveFunc");
189 //std::cout << "depth: " << depth << std::endl;
194 { recursiveFunc(depth
-1); }
199 static float x
=0; // Value to influence the work
200 static float x_inc
=0.01f
;
202 if ((x
<=0.0) || (x
>=1.0))
208 OSG::PerfMonitorGuard
gG("doStuff");
211 OSG::PerfMonitorGuard
g("Work1");
213 randWork(unsigned(10.0*x
), 1, "10*x");
214 randWork(unsigned(10.0*(1.0-x
)), 1, "10*(1-x)");
218 OSG::PerfMonitorGuard
g("Work2");
220 randWork(unsigned(5.0*x
), 1, "5x-1");
221 randWork(2, 10, "2-10");
225 OSG::PerfMonitorGuard
g("Work3");
227 randWork( 1, unsigned(5.0*x
), "1-5x");
228 randWork(2, 0, "2-0");
232 OSG::PerfMonitorGuard
g("Work4");
237 OSG::PerfMonitorGuard
g("Work5");
242 OSG::PerfMonitorGuard
g("Work6");
247 OSG::PerfMonitorGuard
g("Work7");