Initial on screen stats support
This commit is contained in:
parent
d3ce4825d8
commit
b47ef11d74
@ -184,25 +184,22 @@ endif
|
|||||||
APPLICATION_DIRS = \
|
APPLICATION_DIRS = \
|
||||||
osgversion
|
osgversion
|
||||||
|
|
||||||
|
APPLICATION_DIRS += osgarchive \
|
||||||
|
osgconv \
|
||||||
|
osgviewer \
|
||||||
|
|
||||||
|
ifeq ($(GDAL_INSTALLED),yes)
|
||||||
|
APPLICATION_DIRS += osgdem
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(PRODUCER_INSTALLED),yes)
|
ifeq ($(PRODUCER_INSTALLED),yes)
|
||||||
|
|
||||||
APPLICATION_DIRS += osgarchive \
|
APPLICATION_DIRS += osgproducerviewer
|
||||||
osgconv \
|
|
||||||
osgviewer \
|
|
||||||
|
|
||||||
ifeq ($(GDAL_INSTALLED),yes)
|
|
||||||
APPLICATION_DIRS += osgdem
|
|
||||||
endif
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
EXAMPLE_DIRS = \
|
||||||
EXAMPLE_DIRS =
|
osganimate \
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(PRODUCER_INSTALLED),yes)
|
|
||||||
|
|
||||||
EXAMPLE_DIRS += osganimate \
|
|
||||||
osgautotransform \
|
osgautotransform \
|
||||||
osgbillboard \
|
osgbillboard \
|
||||||
osgblendequation \
|
osgblendequation \
|
||||||
@ -276,17 +273,16 @@ ifeq ($(PRODUCER_INSTALLED),yes)
|
|||||||
osgvolume \
|
osgvolume \
|
||||||
osgwindows \
|
osgwindows \
|
||||||
|
|
||||||
ifeq ($(COMPILE_INTROSPECTION),yes)
|
|
||||||
EXAMPLE_DIRS += osgintrospection
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(GDAL_INSTALLED),yes)
|
ifeq ($(COMPILE_INTROSPECTION),yes)
|
||||||
EXAMPLE_DIRS += osgphotoalbum
|
EXAMPLE_DIRS += osgintrospection
|
||||||
EXAMPLE_DIRS += osgbluemarble
|
endif
|
||||||
EXAMPLE_DIRS += osgsimulation
|
|
||||||
EXAMPLE_DIRS += osgfadetext
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
ifeq ($(GDAL_INSTALLED),yes)
|
||||||
|
EXAMPLE_DIRS += osgphotoalbum
|
||||||
|
EXAMPLE_DIRS += osgbluemarble
|
||||||
|
EXAMPLE_DIRS += osgsimulation
|
||||||
|
EXAMPLE_DIRS += osgfadetext
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GLUT_INSTALLED),yes)
|
ifeq ($(GLUT_INSTALLED),yes)
|
||||||
|
@ -366,10 +366,34 @@ Package=<4>
|
|||||||
Project_Dep_Name Core osgGA
|
Project_Dep_Name Core osgGA
|
||||||
End Project Dependency
|
End Project Dependency
|
||||||
Begin Project Dependency
|
Begin Project Dependency
|
||||||
Project_Dep_Name Core osgProducer
|
Project_Dep_Name Core osgViewer
|
||||||
End Project Dependency
|
End Project Dependency
|
||||||
Begin Project Dependency
|
Begin Project Dependency
|
||||||
Project_Dep_Name Core osgViewer
|
Project_Dep_Name Core osgUtil
|
||||||
|
End Project Dependency
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "Application osgproducerviewer"=.\applications\osgproducerviewer\osgproducerviewer.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
Begin Project Dependency
|
||||||
|
Project_Dep_Name Core osg
|
||||||
|
End Project Dependency
|
||||||
|
Begin Project Dependency
|
||||||
|
Project_Dep_Name Core osgDB
|
||||||
|
End Project Dependency
|
||||||
|
Begin Project Dependency
|
||||||
|
Project_Dep_Name Core osgGA
|
||||||
|
End Project Dependency
|
||||||
|
Begin Project Dependency
|
||||||
|
Project_Dep_Name Core osgProducer
|
||||||
End Project Dependency
|
End Project Dependency
|
||||||
Begin Project Dependency
|
Begin Project Dependency
|
||||||
Project_Dep_Name Core osgUtil
|
Project_Dep_Name Core osgUtil
|
||||||
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
MTL=midl.exe
|
MTL=midl.exe
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c
|
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c
|
||||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
@ -68,7 +68,7 @@ LINK32=link.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
MTL=midl.exe
|
MTL=midl.exe
|
||||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c
|
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c
|
||||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
|
@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
|
|||||||
CXXFILES =\
|
CXXFILES =\
|
||||||
osgviewer.cpp\
|
osgviewer.cpp\
|
||||||
|
|
||||||
LIBS += -losgViewer -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
LIBS += -losgViewer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
INSTFILES = \
|
INSTFILES = \
|
||||||
$(CXXFILES)\
|
$(CXXFILES)\
|
||||||
|
@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
|
|||||||
CXXFILES =\
|
CXXFILES =\
|
||||||
osgviewer.cpp\
|
osgviewer.cpp\
|
||||||
|
|
||||||
LIBS += -losgViewer -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
LIBS += -losgViewer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
EXEC = osgviewer
|
EXEC = osgviewer
|
||||||
|
|
||||||
|
@ -12,127 +12,12 @@
|
|||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
#include <osgUtil/Optimizer>
|
#include <osgUtil/Optimizer>
|
||||||
#include <osg/CoordinateSystemNode>
|
#include <osg/CoordinateSystemNode>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
#include <osg/Switch>
|
||||||
//
|
#include <osgText/Text>
|
||||||
// osgProducer version (see osgViewer version in next section below)
|
|
||||||
|
|
||||||
#include <osgProducer/Viewer>
|
|
||||||
int main_osgProducer(osg::ArgumentParser& arguments)
|
|
||||||
{
|
|
||||||
// set up the usage document, in case we need to print out how to use this program.
|
|
||||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
|
||||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
|
||||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings.");
|
|
||||||
|
|
||||||
|
|
||||||
// construct the viewer.
|
|
||||||
osgProducer::Viewer viewer(arguments);
|
|
||||||
|
|
||||||
// set up the value with sensible default event handlers.
|
|
||||||
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
|
|
||||||
|
|
||||||
// get details on keyboard and mouse bindings used by the viewer.
|
|
||||||
viewer.getUsage(*arguments.getApplicationUsage());
|
|
||||||
|
|
||||||
// if user request help write it out to cout.
|
|
||||||
bool helpAll = arguments.read("--help-all");
|
|
||||||
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
|
|
||||||
((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
|
|
||||||
((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
|
|
||||||
if (helpType)
|
|
||||||
{
|
|
||||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// report any errors if they have occurred when parsing the program arguments.
|
|
||||||
if (arguments.errors())
|
|
||||||
{
|
|
||||||
arguments.writeErrorMessages(std::cout);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.argc()<=1)
|
|
||||||
{
|
|
||||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Timer_t start_tick = osg::Timer::instance()->tick();
|
|
||||||
|
|
||||||
// read the scene from the list of file specified command line args.
|
|
||||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
|
||||||
|
|
||||||
// if no model has been successfully loaded report failure.
|
|
||||||
if (!loadedModel)
|
|
||||||
{
|
|
||||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// any option left unread are converted into errors to write out later.
|
|
||||||
arguments.reportRemainingOptionsAsUnrecognized();
|
|
||||||
|
|
||||||
// report any errors if they have occurred when parsing the program arguments.
|
|
||||||
if (arguments.errors())
|
|
||||||
{
|
|
||||||
arguments.writeErrorMessages(std::cout);
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Timer_t end_tick = osg::Timer::instance()->tick();
|
|
||||||
|
|
||||||
std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
// optimize the scene graph, remove redundant nodes and state etc.
|
|
||||||
osgUtil::Optimizer optimizer;
|
|
||||||
optimizer.optimize(loadedModel.get());
|
|
||||||
|
|
||||||
// pass the loaded scene graph to the viewer.
|
|
||||||
viewer.setSceneData(loadedModel.get());
|
|
||||||
|
|
||||||
// create the windows and run the threads.
|
|
||||||
viewer.realize();
|
|
||||||
|
|
||||||
while( !viewer.done() )
|
|
||||||
{
|
|
||||||
// wait for all cull and draw threads to complete.
|
|
||||||
viewer.sync();
|
|
||||||
|
|
||||||
// update the scene by traversing it with the the update visitor which will
|
|
||||||
// call all node update callbacks and animations.
|
|
||||||
viewer.update();
|
|
||||||
|
|
||||||
// fire off the cull and draw traversals of the scene.
|
|
||||||
viewer.frame();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for all cull and draw threads to complete.
|
|
||||||
viewer.sync();
|
|
||||||
|
|
||||||
// run a clean up frame to delete all OpenGL objects.
|
|
||||||
viewer.cleanup_frame();
|
|
||||||
|
|
||||||
// wait for all the clean up frame to complete.
|
|
||||||
viewer.sync();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// osgViewer version
|
|
||||||
|
|
||||||
#include <osgViewer/Viewer>
|
#include <osgViewer/Viewer>
|
||||||
|
|
||||||
#include <osgGA/TrackballManipulator>
|
#include <osgGA/TrackballManipulator>
|
||||||
#include <osgGA/FlightManipulator>
|
#include <osgGA/FlightManipulator>
|
||||||
#include <osgGA/DriveManipulator>
|
#include <osgGA/DriveManipulator>
|
||||||
@ -141,6 +26,8 @@ int main_osgProducer(osg::ArgumentParser& arguments)
|
|||||||
#include <osgGA/AnimationPathManipulator>
|
#include <osgGA/AnimationPathManipulator>
|
||||||
#include <osgGA/TerrainManipulator>
|
#include <osgGA/TerrainManipulator>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class ThreadingHandler : public osgGA::GUIEventHandler
|
class ThreadingHandler : public osgGA::GUIEventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -204,7 +91,20 @@ class StatsHandler : public osgGA::GUIEventHandler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StatsHandler() {}
|
StatsHandler():
|
||||||
|
_statsType(NO_STATS),
|
||||||
|
_frameRateChildNum(0),
|
||||||
|
_viewerChildNum(0),
|
||||||
|
_sceneChildNum(0) {}
|
||||||
|
|
||||||
|
enum StatsType
|
||||||
|
{
|
||||||
|
NO_STATS = 0,
|
||||||
|
FRAME_RATE = 1,
|
||||||
|
VIEWER_STATS = 2,
|
||||||
|
SCENE_STATS = 3,
|
||||||
|
LAST = 4
|
||||||
|
};
|
||||||
|
|
||||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||||
{
|
{
|
||||||
@ -216,6 +116,54 @@ public:
|
|||||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||||
{
|
{
|
||||||
if (ea.getKey()=='s')
|
if (ea.getKey()=='s')
|
||||||
|
{
|
||||||
|
if (viewer->getStats())
|
||||||
|
{
|
||||||
|
if (!_camera.valid())
|
||||||
|
{
|
||||||
|
setUpCamera(viewer);
|
||||||
|
setUpScene(viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
++_statsType;
|
||||||
|
|
||||||
|
if (_statsType==LAST) _statsType = NO_STATS;
|
||||||
|
|
||||||
|
switch(_statsType)
|
||||||
|
{
|
||||||
|
case(NO_STATS):
|
||||||
|
{
|
||||||
|
_camera->setNodeMask(0x0);
|
||||||
|
_switch->setAllChildrenOff();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(FRAME_RATE):
|
||||||
|
{
|
||||||
|
_camera->setNodeMask(0xffffffff);
|
||||||
|
_switch->setValue(_frameRateChildNum, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(VIEWER_STATS):
|
||||||
|
{
|
||||||
|
_camera->setNodeMask(0xffffffff);
|
||||||
|
_switch->setValue(_viewerChildNum, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(SCENE_STATS):
|
||||||
|
{
|
||||||
|
_switch->setValue(_sceneChildNum, true);
|
||||||
|
_camera->setNodeMask(0xffffffff);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (ea.getKey()=='S')
|
||||||
{
|
{
|
||||||
if (viewer->getStats())
|
if (viewer->getStats())
|
||||||
{
|
{
|
||||||
@ -224,17 +172,218 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case(osgGA::GUIEventAdapter::FRAME):
|
||||||
|
{
|
||||||
|
update(viewer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUpCamera(osgViewer::Viewer* viewer)
|
||||||
|
{
|
||||||
|
osgViewer::Viewer::Windows windows;
|
||||||
|
viewer->getWindows(windows);
|
||||||
|
|
||||||
|
if (windows.empty()) return;
|
||||||
|
|
||||||
|
osgViewer::GraphicsWindow* window = windows.front();
|
||||||
|
|
||||||
|
_camera = new osg::Camera;
|
||||||
|
_camera->setGraphicsContext(window);
|
||||||
|
_camera->setViewport(0, 0, window->getTraits()->width, window->getTraits()->height);
|
||||||
|
|
||||||
|
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||||
|
_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||||
|
_camera->setViewMatrix(osg::Matrix::identity());
|
||||||
|
|
||||||
|
// only clear the depth buffer
|
||||||
|
_camera->setClearMask(0);
|
||||||
|
|
||||||
|
viewer->setUpRenderingSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _done;
|
struct TextDrawCallback : public virtual osg::Drawable::DrawCallback
|
||||||
|
{
|
||||||
|
TextDrawCallback(osg::Stats* stats, const std::string name, int frameDelta):
|
||||||
|
_stats(stats),
|
||||||
|
_attributeName(name),
|
||||||
|
_frameDelta(frameDelta) {}
|
||||||
|
|
||||||
|
/** do customized draw code.*/
|
||||||
|
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
|
||||||
|
{
|
||||||
|
osgText::Text* text = (osgText::Text*)drawable;
|
||||||
|
|
||||||
|
int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber();
|
||||||
|
|
||||||
|
double value;
|
||||||
|
if (_stats->getAttribute( frameNumber+_frameDelta, _attributeName, value))
|
||||||
|
{
|
||||||
|
sprintf(_tmpText,"%4.2f",value);
|
||||||
|
text->setText(_tmpText);
|
||||||
|
}
|
||||||
|
|
||||||
|
text->drawImplementation(renderInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::Stats* _stats;
|
||||||
|
std::string _attributeName;
|
||||||
|
int _frameDelta;
|
||||||
|
mutable char _tmpText[128];
|
||||||
|
};
|
||||||
|
|
||||||
|
void setUpScene(osgViewer::Viewer* viewer)
|
||||||
|
{
|
||||||
|
_switch = new osg::Switch;
|
||||||
|
_camera->addChild(_switch.get());
|
||||||
|
|
||||||
|
osg::StateSet* stateset = _switch->getOrCreateStateSet();
|
||||||
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||||
|
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
||||||
|
|
||||||
|
std::string font("fonts/arial.ttf");
|
||||||
|
|
||||||
|
float leftPos = 10.0f;
|
||||||
|
float characterSize = 20.0f;
|
||||||
|
|
||||||
|
osg::Vec3 pos(leftPos,1000.0f,0.0f);
|
||||||
|
|
||||||
|
osg::Vec4 colorFR(1.0f,1.0f,1.0f,1.0f);
|
||||||
|
osg::Vec4 colorUpdate( 0.0f,1.0f,0.0f,1.0f);
|
||||||
|
osg::Vec4 colorCull( 0.0f,1.0f,1.0f,1.0f);
|
||||||
|
osg::Vec4 colorDraw( 1.0f,1.0f,0.0f,1.0f);
|
||||||
|
osg::Vec4 colorGPU( 1.0f,0.5f,0.0f,1.0f);
|
||||||
|
|
||||||
|
|
||||||
|
// frame rate stats
|
||||||
|
{
|
||||||
|
osg::Geode* geode = new osg::Geode();
|
||||||
|
|
||||||
|
std::string font("fonts/arial.ttf");
|
||||||
|
|
||||||
|
// turn lighting off for the text and disable depth test to ensure its always ontop.
|
||||||
|
|
||||||
|
{
|
||||||
|
_frameRateLabel = new osgText::Text;
|
||||||
|
geode->addDrawable( _frameRateLabel.get() );
|
||||||
|
|
||||||
|
_frameRateLabel->setColor(colorFR);
|
||||||
|
_frameRateLabel->setFont(font);
|
||||||
|
_frameRateLabel->setCharacterSize(characterSize);
|
||||||
|
_frameRateLabel->setPosition(pos);
|
||||||
|
_frameRateLabel->setText("Frame Rate: ");
|
||||||
|
|
||||||
|
pos.x() = _frameRateLabel->getBound().xMax();
|
||||||
|
|
||||||
|
_frameRateValue = new osgText::Text;
|
||||||
|
geode->addDrawable( _frameRateValue.get() );
|
||||||
|
|
||||||
|
_frameRateValue->setColor(colorFR);
|
||||||
|
_frameRateValue->setFont(font);
|
||||||
|
_frameRateValue->setCharacterSize(characterSize);
|
||||||
|
_frameRateValue->setPosition(pos);
|
||||||
|
_frameRateValue->setText("0.0");
|
||||||
|
|
||||||
|
_frameRateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Frame rate",-1));
|
||||||
|
|
||||||
|
pos.y() -= characterSize*1.5f;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
_frameRateChildNum = _switch->getNumChildren();
|
||||||
|
_switch->addChild(geode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// viewer stats
|
||||||
|
{
|
||||||
|
pos.x() = leftPos;
|
||||||
|
|
||||||
|
osg::Geode* geode = new osg::Geode();
|
||||||
|
|
||||||
|
{
|
||||||
|
osgText::Text* text = new osgText::Text;
|
||||||
|
geode->addDrawable( text );
|
||||||
|
|
||||||
|
text->setFont(font);
|
||||||
|
text->setPosition(pos);
|
||||||
|
text->setText("Viewer Stats ");
|
||||||
|
|
||||||
|
pos.y() -= characterSize*1.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
_viewerChildNum = _switch->getNumChildren();
|
||||||
|
_switch->addChild(geode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scene stats
|
||||||
|
{
|
||||||
|
pos.x() = leftPos;
|
||||||
|
|
||||||
|
osg::Geode* geode = new osg::Geode();
|
||||||
|
|
||||||
|
{
|
||||||
|
osgText::Text* text = new osgText::Text;
|
||||||
|
geode->addDrawable( text );
|
||||||
|
|
||||||
|
text->setFont(font);
|
||||||
|
text->setPosition(pos);
|
||||||
|
text->setText("Scene Stats ");
|
||||||
|
|
||||||
|
pos.y() -= characterSize*1.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sceneChildNum = _switch->getNumChildren();
|
||||||
|
_switch->addChild(geode, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(osgViewer::Viewer* viewer)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
|
||||||
|
osg::Stats* stats = viewer->getStats();
|
||||||
|
if (!stats || _statsType==NO_STATS) return;
|
||||||
|
|
||||||
|
int frameNumber = viewer->getFrameStamp()->getFrameNumber();
|
||||||
|
|
||||||
|
char tmpText[128];
|
||||||
|
double frameRate = 0.0;
|
||||||
|
|
||||||
|
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||||
|
if (stats->getAttribute(frameNumber-1, "Frame rate", frameRate))
|
||||||
|
{
|
||||||
|
sprintf(tmpText,"%4.2f",frameRate);
|
||||||
|
_frameRateValue->setText(tmpText);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int _statsType;
|
||||||
|
osg::ref_ptr<osg::Camera> _camera;
|
||||||
|
osg::ref_ptr<osg::Switch> _switch;
|
||||||
|
|
||||||
|
unsigned int _frameRateChildNum;
|
||||||
|
osg::ref_ptr<osgText::Text> _frameRateLabel;
|
||||||
|
osg::ref_ptr<osgText::Text> _frameRateValue;
|
||||||
|
|
||||||
|
unsigned int _viewerChildNum;
|
||||||
|
|
||||||
|
unsigned int _sceneChildNum;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main_osgViewer(osg::ArgumentParser& arguments)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
// use an ArgumentParser object to manage the program arguments.
|
||||||
|
osg::ArgumentParser arguments(&argc,argv);
|
||||||
|
|
||||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
||||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||||
@ -338,20 +487,3 @@ int main_osgViewer(osg::ArgumentParser& arguments)
|
|||||||
|
|
||||||
return viewer.run();
|
return viewer.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
|
||||||
{
|
|
||||||
// use an ArgumentParser object to manage the program arguments.
|
|
||||||
osg::ArgumentParser arguments(&argc,argv);
|
|
||||||
|
|
||||||
if (arguments.read("--osgProducer"))
|
|
||||||
{
|
|
||||||
return main_osgProducer(arguments);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return main_osgViewer(arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class OSG_EXPORT View : public virtual osg::Referenced
|
|||||||
|
|
||||||
|
|
||||||
/** Set the master camera of the view. */
|
/** Set the master camera of the view. */
|
||||||
void setCamera(osg::Camera* camera) { _camera = camera; }
|
void setCamera(osg::Camera* camera);
|
||||||
|
|
||||||
/** Get the master camera of the view. */
|
/** Get the master camera of the view. */
|
||||||
osg::Camera* getCamera() { return _camera.get(); }
|
osg::Camera* getCamera() { return _camera.get(); }
|
||||||
|
@ -74,7 +74,7 @@ bool Stats::getAttribute(int frameNumber, const std::string& attributeName, doub
|
|||||||
|
|
||||||
const AttributeMap& attributeMap = _attributeMapList[index];
|
const AttributeMap& attributeMap = _attributeMapList[index];
|
||||||
AttributeMap::const_iterator itr = attributeMap.find(attributeName);
|
AttributeMap::const_iterator itr = attributeMap.find(attributeName);
|
||||||
if (itr != attributeMap.end()) return false;
|
if (itr == attributeMap.end()) return false;
|
||||||
|
|
||||||
value = itr->second;
|
value = itr->second;
|
||||||
return true;
|
return true;
|
||||||
|
@ -53,6 +53,15 @@ View::~View()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::setCamera(osg::Camera* camera)
|
||||||
|
{
|
||||||
|
if (_camera.valid()) _camera->setView(0);
|
||||||
|
|
||||||
|
_camera = camera;
|
||||||
|
|
||||||
|
if (_camera.valid()) _camera->setView(this);
|
||||||
|
}
|
||||||
|
|
||||||
void View::updateSlaves()
|
void View::updateSlaves()
|
||||||
{
|
{
|
||||||
for(unsigned int i=0; i<_slaves.size(); ++i)
|
for(unsigned int i=0; i<_slaves.size(); ++i)
|
||||||
|
@ -477,6 +477,8 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi
|
|||||||
|
|
||||||
void SceneView::cull()
|
void SceneView::cull()
|
||||||
{
|
{
|
||||||
|
if (_camera->getNodeMask()==0) return;
|
||||||
|
|
||||||
_renderInfo.setView(_camera->getView());
|
_renderInfo.setView(_camera->getView());
|
||||||
|
|
||||||
// update the active uniforms
|
// update the active uniforms
|
||||||
@ -693,7 +695,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
|||||||
|
|
||||||
renderStage->setViewport(getViewport());
|
renderStage->setViewport(getViewport());
|
||||||
renderStage->setClearColor(getClearColor());
|
renderStage->setClearColor(getClearColor());
|
||||||
|
renderStage->setClearMask(_camera->getClearMask());
|
||||||
|
|
||||||
switch(_lightingMode)
|
switch(_lightingMode)
|
||||||
{
|
{
|
||||||
@ -812,6 +814,7 @@ void SceneView::flushDeletedGLObjects(double& availableTime)
|
|||||||
|
|
||||||
void SceneView::draw()
|
void SceneView::draw()
|
||||||
{
|
{
|
||||||
|
if (_camera->getNodeMask()==0) return;
|
||||||
|
|
||||||
osg::State* state = _renderInfo.getState();
|
osg::State* state = _renderInfo.getState();
|
||||||
|
|
||||||
|
@ -533,6 +533,57 @@ struct CompositeViewerRenderingOperation : public osg::GraphicsOperation
|
|||||||
|
|
||||||
void CompositeViewer::setUpRenderingSupport()
|
void CompositeViewer::setUpRenderingSupport()
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
|
_cameraSceneViewMap.clear();
|
||||||
|
|
||||||
|
Contexts contexts;
|
||||||
|
getContexts(contexts);
|
||||||
|
|
||||||
|
osg::FrameStamp* frameStamp = getFrameStamp();
|
||||||
|
|
||||||
|
for(Contexts::iterator gcitr = contexts.begin();
|
||||||
|
gcitr != contexts.end();
|
||||||
|
++gcitr)
|
||||||
|
{
|
||||||
|
(*gcitr)->removeAllOperations();
|
||||||
|
|
||||||
|
osg::GraphicsContext* gc = *gcitr;
|
||||||
|
osg::GraphicsContext::Cameras& cameras = gc->getCameras();
|
||||||
|
osg::State* state = gc->getState();
|
||||||
|
|
||||||
|
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
|
||||||
|
citr != cameras.end();
|
||||||
|
++citr)
|
||||||
|
{
|
||||||
|
osg::Camera* camera = *citr;
|
||||||
|
osgViewer::View* view = dynamic_cast<osgViewer::View*>(camera->getView());
|
||||||
|
osgViewer::Scene* scene = view ? view->getScene() : 0;
|
||||||
|
|
||||||
|
osg::DisplaySettings* ds = view ? view->getDisplaySettings() : 0;
|
||||||
|
if (!ds) ds = osg::DisplaySettings::instance();
|
||||||
|
|
||||||
|
osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0;
|
||||||
|
|
||||||
|
camera->setStats(new osg::Stats("Camera"));
|
||||||
|
|
||||||
|
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
|
||||||
|
_cameraSceneViewMap[camera] = sceneView;
|
||||||
|
|
||||||
|
sceneView->setGlobalStateSet(view ? view->getCamera()->getStateSet() : 0);
|
||||||
|
sceneView->setDefaults();
|
||||||
|
sceneView->setDisplaySettings(ds);
|
||||||
|
sceneView->setCamera(camera);
|
||||||
|
sceneView->setState(state);
|
||||||
|
sceneView->setFrameStamp(frameStamp);
|
||||||
|
|
||||||
|
if (dp) dp->setCompileGLObjectsForContextID(state->getContextID(), true);
|
||||||
|
|
||||||
|
gc->add(new CompositeViewerRenderingOperation(sceneView, dp));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
osg::FrameStamp* frameStamp = getFrameStamp();
|
osg::FrameStamp* frameStamp = getFrameStamp();
|
||||||
|
|
||||||
// what should we do with the old sceneViews?
|
// what should we do with the old sceneViews?
|
||||||
@ -549,8 +600,6 @@ void CompositeViewer::setUpRenderingSupport()
|
|||||||
(*citr)->removeAllOperations();
|
(*citr)->removeAllOperations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(Views::iterator itr = _views.begin();
|
for(Views::iterator itr = _views.begin();
|
||||||
itr != _views.end();
|
itr != _views.end();
|
||||||
++itr)
|
++itr)
|
||||||
@ -601,7 +650,7 @@ void CompositeViewer::setUpRenderingSupport()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -533,28 +533,72 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation
|
|||||||
|
|
||||||
void Viewer::setUpRenderingSupport()
|
void Viewer::setUpRenderingSupport()
|
||||||
{
|
{
|
||||||
osg::FrameStamp* frameStamp = getFrameStamp();
|
#if 1
|
||||||
|
|
||||||
// what should we do with the old sceneViews?
|
|
||||||
_cameraSceneViewMap.clear();
|
_cameraSceneViewMap.clear();
|
||||||
|
|
||||||
Contexts contexts;
|
Contexts contexts;
|
||||||
getContexts(contexts);
|
getContexts(contexts);
|
||||||
|
|
||||||
// clear out all the previously assigned operations
|
osg::FrameStamp* frameStamp = getFrameStamp();
|
||||||
for(Contexts::iterator citr = contexts.begin();
|
|
||||||
citr != contexts.end();
|
|
||||||
++citr)
|
|
||||||
{
|
|
||||||
(*citr)->removeAllOperations();
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
||||||
osgDB::DatabasePager* dp = _scene.valid() ? _scene->getDatabasePager() : 0;
|
osgDB::DatabasePager* dp = _scene.valid() ? _scene->getDatabasePager() : 0;
|
||||||
|
|
||||||
|
for(Contexts::iterator gcitr = contexts.begin();
|
||||||
|
gcitr != contexts.end();
|
||||||
|
++gcitr)
|
||||||
|
{
|
||||||
|
(*gcitr)->removeAllOperations();
|
||||||
|
|
||||||
|
osg::GraphicsContext* gc = *gcitr;
|
||||||
|
osg::GraphicsContext::Cameras& cameras = gc->getCameras();
|
||||||
|
osg::State* state = gc->getState();
|
||||||
|
|
||||||
|
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
|
||||||
|
citr != cameras.end();
|
||||||
|
++citr)
|
||||||
|
{
|
||||||
|
osg::Camera* camera = *citr;
|
||||||
|
|
||||||
|
camera->setStats(new osg::Stats("Camera"));
|
||||||
|
|
||||||
|
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
|
||||||
|
_cameraSceneViewMap[camera] = sceneView;
|
||||||
|
|
||||||
|
sceneView->setGlobalStateSet(_camera->getStateSet());
|
||||||
|
sceneView->setDefaults();
|
||||||
|
sceneView->setDisplaySettings(ds);
|
||||||
|
sceneView->setCamera(camera);
|
||||||
|
sceneView->setState(state);
|
||||||
|
sceneView->setFrameStamp(frameStamp);
|
||||||
|
|
||||||
|
if (dp) dp->setCompileGLObjectsForContextID(state->getContextID(), true);
|
||||||
|
|
||||||
|
gc->add(new ViewerRenderingOperation(sceneView, dp));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
_cameraSceneViewMap.clear();
|
||||||
|
|
||||||
|
Contexts contexts;
|
||||||
|
getContexts(contexts);
|
||||||
|
|
||||||
|
osg::FrameStamp* frameStamp = getFrameStamp();
|
||||||
|
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
||||||
|
osgDB::DatabasePager* dp = _scene.valid() ? _scene->getDatabasePager() : 0;
|
||||||
|
|
||||||
|
// clear out all the previously assigned operations
|
||||||
|
for(Contexts::iterator gcitr = contexts.begin();
|
||||||
|
gcitr != contexts.end();
|
||||||
|
++gcitr)
|
||||||
|
{
|
||||||
|
(*gcitr)->removeAllOperations();
|
||||||
|
}
|
||||||
|
|
||||||
if (_camera.valid() && _camera->getGraphicsContext())
|
if (_camera.valid() && _camera->getGraphicsContext())
|
||||||
{
|
{
|
||||||
_camera->setStats(new osg::Stats("Viewer"));
|
_camera->setStats(new osg::Stats("Camera"));
|
||||||
|
|
||||||
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
|
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
|
||||||
_cameraSceneViewMap[_camera] = sceneView;
|
_cameraSceneViewMap[_camera] = sceneView;
|
||||||
@ -595,6 +639,7 @@ void Viewer::setUpRenderingSupport()
|
|||||||
slave._camera->getGraphicsContext()->add(new ViewerRenderingOperation(sceneView, dp));
|
slave._camera->getGraphicsContext()->add(new ViewerRenderingOperation(sceneView, dp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user