Added FrameStats support into osgProducer lib, and removed them from the

osgproducer demo.

Removed the producer config files osgproducer demo.

Added a search the osgDB::DataFilePath for the producer config file.
This commit is contained in:
Robert Osfield
2003-01-30 23:02:32 +00:00
parent f485304665
commit 4c4735a586
9 changed files with 27 additions and 200 deletions

View File

@@ -1,143 +0,0 @@
#ifndef FRAME_STATS_HANDLER
#include <stdio.h>
#include <GL/gl.h>
namespace Producer {
class FrameStatsHandler : public CameraGroup::StatsHandler, public Camera::Callback
{
public:
FrameStatsHandler()
{
_fs.resize(6);
_index = 0;
}
void setArraySize(unsigned int size) { _fs.resize(size); }
unsigned int getArraySize() { return _fs.size(); }
void operator() (const CameraGroup &cg )
{
_index = (_index + 1) % _fs.size();
_fs[_index] = cg.getFrameStats();
}
void operator() (const Camera &camera)
{
if (!camera.getInstrumentationMode()) return;
glViewport( 0, 0, 1280, 1024 );
// Set up the Orthographic view
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho( -.01, .128, 600.0, -10.0, -1.0, 1.0 );
glPushAttrib( GL_ENABLE_BIT );
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
glEnable( GL_BLEND );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
unsigned int lindex = (_index + 1) % _fs.size();
Camera::TimeStamp zero = _fs[lindex]._startOfFrame;
int i;
double x1, x2, y1, y2;
for( int frame = 0; frame < _fs.size(); frame++ )
{
CameraGroup::FrameStats fs = _fs[(lindex + frame) % _fs.size()];
y1 = 0.0;
y2 = y1 + 10;
x1 = fs._startOfUpdate - zero;
x2 = fs._endOfUpdate - zero;
glBegin( GL_QUADS );
// Draw Update length
glColor4f( 0.0, 1.0, 0.0, 0.5 );
glVertex2d( x1, y1);
glVertex2d( x2, y1);
glVertex2d( x2, y2);
glVertex2d( x1, y2);
for( i = 0; i < fs.getNumFrameTimeStampSets(); i++ )
{
Camera::FrameTimeStampSet fts = fs.getFrameTimeStampSet(i);
y1 += 13.0;
y2 = y1 + 10.0;
x1 = fts[Camera::BeginCull] - zero;
x2 = fts[Camera::EndCull] - zero;
glColor4f( 0.0, 0.0, 1.0, 0.5 );
glVertex2d( x1, y1);
glVertex2d( x2, y1);
glVertex2d( x2, y2);
glVertex2d( x1, y2);
x1 = fts[Camera::BeginDraw] - zero;
x2 = fts[Camera::EndDraw] - zero;
glColor4f( 1.0, 0.0, 0.0, 0.5 );
glVertex2d( x1, y1);
glVertex2d( x2, y1);
glVertex2d( x2, y2);
glVertex2d( x1, y2);
}
glEnd();
glBegin( GL_LINES );
glColor4f( 1, 1, 1, 0.5 );
glVertex2d( fs._startOfFrame - zero , 0.0 );
y1 = fs.getNumFrameTimeStampSets() * 13.0 + 10.0;
glVertex2d( fs._startOfFrame - zero, y1 );
y1 = 12.5;
for( i = 0; i < fs.getNumFrameTimeStampSets(); i++ )
{
y2 = y1 + 11;
Camera::FrameTimeStampSet fts = fs.getFrameTimeStampSet(i);
Camera::TimeStamp vsync = fts[Camera::Vsync];
double x1 = vsync - zero;
glColor4f( 1.0, 1.0, 0.0, 0.5 );
glVertex2d( x1, y1 );
glVertex2d( x1, y2 );
y1 += 13.0;
}
glEnd();
}
glBegin( GL_LINES );
glColor4f( 1, 1, 1, 0.5 );
for( i = 0; i < 128; i++ )
{
glVertex2d((GLdouble)i*.001, y1);
if( !(i%10) )
glVertex2d((GLdouble)i*.001, y1 - 5.0);
else if( !(i%5) )
glVertex2d((GLdouble)i*.001, y1 - 3.0);
else
glVertex2d((GLdouble)i*.001, y1 - 1.0);
}
glEnd();
glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopAttrib();
}
private:
std::vector <CameraGroup::FrameStats> _fs;
unsigned int _index;
};
}
#endif

View File

@@ -1,46 +0,0 @@
#include <osgGA/GUIEventHandler>
#include <osgProducer/CameraGroup>
class StatsEventHandler : public osgGA::GUIEventHandler
{
public:
StatsEventHandler(osgProducer::Viewer* cg):_cg(cg) {}
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
if(!_cg) return false;
if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN)
{
switch( ea.getKey() )
{
case 's' :
_cg->setInstrumentationMode(!_cg->getInstrumentationMode());
return true;
case 'v' :
_cg->setBlockOnVsync(!_cg->getBlockOnVsync());
//std::cout<<"_cg->getBlockOnVsync()="<<_cg->getBlockOnVsync()<<std::endl;
return true;
default:
break;
}
}
return false;
}
virtual void accept(osgGA::GUIEventHandlerVisitor& gehv)
{
gehv.visit(*this);
}
protected:
osgProducer::Viewer* _cg;
};

View File

@@ -11,9 +11,6 @@
#include <osgProducer/Viewer>
#include "FrameStatsHandler"
#include "StatsEventHandler"
int main( int argc, char **argv )
{
@@ -66,11 +63,6 @@ int main( int argc, char **argv )
// set up the value with sensible defaults.
viewer->setUpViewer();
Producer::FrameStatsHandler* fsh = new Producer::FrameStatsHandler;
viewer->setStatsHandler(fsh);
viewer->getCamera(0)->addPostDrawCallback(fsh);
if( !pathfile.empty() ) {
osg::ref_ptr<osgGA::AnimationPathManipulator> apm = new osgGA::AnimationPathManipulator(pathfile);
if( apm.valid() && apm->valid() )
@@ -83,13 +75,6 @@ int main( int argc, char **argv )
// set the scene to render
viewer->setSceneData(loadedModel.get());
// set up the pthread stack size to large enough to run into problems.
viewer->setStackSize( 20*1024*1024);
// add the stats event handler to handler keyboard events for
// setting set block on vsync, instrumentation etc.
viewer->getEventHandlerList().push_back(new StatsEventHandler(viewer));
// create the windows and run the threads.
viewer->realize(Producer::CameraGroup::ThreadPerCamera);

View File

@@ -1,83 +0,0 @@
//#define SINGLE_PIPE
#define ASSYMETRICAL_FRUSTUM
Camera "Camera 1"
{
RenderSurface "Window 1"
{
Visual { VisualID 0x172 };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 0 0 426 512;
#else
Screen 2;
#endif
Border off;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
#ifdef ASSYMETRICAL_FRUSTUM
Shear 1.5 0.0;
#else
Rotate -90.0 1 0 0;
Rotate -45.0 0 0 1;
Rotate 90.0 1 0 0;
#endif
};
}
Camera "Camera 2"
{
RenderSurface "Window 2"
{
Visual { VisualID 0x74 };
Screen 0;
#ifdef SINGLE_PIPE
WindowRectangle 426 0 426 512;
#endif
Border off;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
}
Camera "Camera 3"
{
RenderSurface "Window 3"
{
Visual { VisualID 0xF3 };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 852 0 426 512;
#else
Screen 1;
#endif
Border off;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
#ifdef ASSYMETRICAL_FRUSTUM
Shear -1.5 0.0;
#else
Rotate -90.0 1 0 0;
Rotate 45.0 0 0 1;
Rotate 90.0 1 0 0;
#endif
};
}
InputArea
{
RenderSurface "Window 1" : -2.5 -0.5 -1.0 1.0;
RenderSurface "Window 2" : -1.0 1.0 -1.0 1.0;
RenderSurface "Window 3" : 0.5 2.5 -1.0 1.0;
}

View File

@@ -1,64 +0,0 @@
/*#define SINGLE_PIPE */
#define ASSYMETRICAL_FRUSTUM
Camera "Camera 1"
{
RenderSurface "Window 1"
{
Visual { SetSimple };
Screen 0;
#ifdef SINGLE_PIPE
WindowRectangle 0 0 426 512;
#else
#endif
Border off;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
#ifdef ASSYMETRICAL_FRUSTUM
Shear 1.0 0.0;
#else
Rotate -90.0 1 0 0;
Rotate -22.5 0 0 1;
Rotate 90.0 1 0 0;
#endif
};
}
Camera "Camera 2"
{
RenderSurface "Window 2"
{
Visual { SetSimple };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 426 0 426 512;
#else
Screen 1;
#endif
Border off;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
#ifdef ASSYMETRICAL_FRUSTUM
Shear -1.0 0.0;
#else
Rotate -90.0 1 0 0;
Rotate 22.5 0 0 1;
Rotate 90.0 1 0 0;
#endif
};
}
InputArea
{
RenderSurface "Window 1" : -1.0 0.0 0.0 1.0;
RenderSurface "Window 2" : 0.0 1.0 0.0 1.0;
}

View File

@@ -1,36 +0,0 @@
Camera "Camera 1"
{
RenderSurface "Pipe 0"
{
Visual { SetSimple };
Screen 0;
Border off;
WindowRect 0 0 640 480;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
Shear 0.8 0.0;
};
}
Camera "Camera 2"
{
RenderSurface "Pipe 1"
{
Visual { SetSimple };
Screen 0;
Border off;
WindowRect 640 0 640 480;
};
Lens {
Frustum -0.55228475 0.55228475 -0.41421356 0.41421356 1 1000.0;
};
Offset {
Shear -0.8 0.0;
};
}

View File

@@ -3,9 +3,18 @@
//as published by the Free Software Foundation.
#include <osgProducer/CameraGroup>
#include <osgDB/FileUtils>
using namespace osgProducer;
std::string findCameraConfigFile(const std::string& configFile)
{
std::string foundFile = osgDB::findDataFile(configFile);
if (foundFile.empty()) return "";
else return foundFile;
}
CameraGroup::CameraGroup() : Producer::CameraGroup()
{
_init();
@@ -16,7 +25,7 @@ CameraGroup::CameraGroup(Producer::CameraConfig *cfg): Producer::CameraGroup(cfg
_init();
}
CameraGroup::CameraGroup(const std::string& configFile) : Producer::CameraGroup(configFile)
CameraGroup::CameraGroup(const std::string& configFile) : Producer::CameraGroup(findCameraConfigFile(configFile))
{
_init();
}

View File

@@ -1,4 +1,6 @@
#include <osgProducer/Viewer>
#include <osgProducer/FrameStatsHandler>
#include <osgProducer/StatsEventHandler>
#include <osg/LightSource>
@@ -103,6 +105,18 @@ void Viewer::setUpViewer(unsigned int options)
_eventHandlerList.push_back(statesetManipulator.get());
}
if (options&STATS_MANIPULATOR)
{
// register the drawing of stats to pipe 0.
Producer::FrameStatsHandler* fsh = new Producer::FrameStatsHandler;
setStatsHandler(fsh);
getCamera(0)->addPostDrawCallback(fsh);
// register the event handler for stats.
getEventHandlerList().push_back(new StatsEventHandler(this));
}
}
unsigned int Viewer::addCameraManipulator(osgGA::CameraManipulator* cm)