Fixes for multipipe support.

Addition of FrameStatsHandler to osgproducer demo to add frame stats.
This commit is contained in:
Robert Osfield
2003-01-29 17:16:26 +00:00
parent cf1ff34d38
commit 6c4f2f5207
13 changed files with 222 additions and 61 deletions

View File

@@ -106,11 +106,15 @@ class DeleteHandler
inline void Referenced::unref() const
{
--_refCount;
if (_refCount<=0)
if (_refCount==0)
{
if (getDeleteHandler()) getDeleteHandler()->requestDelete(this);
else delete this;
}
else if (_refCount<0)
{
throw 2325;
}
}
}

View File

@@ -682,7 +682,7 @@ class SG_EXPORT State : public Referenced
typedef std::map<StateAttribute::Type,AttributeStack> AttributeMap;
typedef std::vector<AttributeMap> TextureAttributeMapList;
typedef std::vector<ref_ptr<const StateSet> > StateSetStack;
typedef std::vector<const StateSet*> StateSetStack;
typedef std::vector<ref_ptr<const Matrix> > MatrixStack;
ModeMap _modeMap;

View File

@@ -45,7 +45,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
typedef std::vector< osg::ref_ptr<RenderLeaf> > LeafList;
RenderGraph* _parent;
osg::ref_ptr<const osg::StateSet> _stateset;
const osg::StateSet* _stateset;
int _depth;
ChildList _children;
@@ -197,7 +197,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
++itr)
{
RenderGraph* rg = (*itr);
if (rg->_stateset.valid()) state.pushStateSet(rg->_stateset.get());
if (rg->_stateset) state.pushStateSet(rg->_stateset);
}
return;
}
@@ -209,9 +209,9 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
{
// state has changed so need to pop old state.
if (sg_curr->_stateset.valid()) state.popStateSet();
if (sg_curr->_stateset) state.popStateSet();
// and push new state.
if (sg_new->_stateset.valid()) state.pushStateSet(sg_new->_stateset.get());
if (sg_new->_stateset) state.pushStateSet(sg_new->_stateset);
return;
}
@@ -219,7 +219,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
// need to pop back up to the same depth as the new state group.
while (sg_curr->_depth>sg_new->_depth)
{
if (sg_curr->_stateset.valid()) state.popStateSet();
if (sg_curr->_stateset) state.popStateSet();
sg_curr = sg_curr->_parent;
}
@@ -240,7 +240,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
// nodes have the same parent
while (sg_curr != sg_new)
{
if (sg_curr->_stateset.valid()) state.popStateSet();
if (sg_curr->_stateset) state.popStateSet();
sg_curr = sg_curr->_parent;
return_path.push_back(sg_new);
@@ -252,7 +252,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
++itr)
{
RenderGraph* rg = (*itr);
if (rg->_stateset.valid()) state.pushStateSet(rg->_stateset.get());
if (rg->_stateset) state.pushStateSet(rg->_stateset);
}
}
@@ -262,7 +262,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
// need to pop back all statesets and matrices.
while (sg_curr)
{
if (sg_curr->_stateset.valid()) state.popStateSet();
if (sg_curr->_stateset) state.popStateSet();
sg_curr = sg_curr->_parent;
}

View File

@@ -103,9 +103,13 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
/** Get the background color.*/
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
void setGlobalStateSet(osg::StateSet* state) { _globalState = state; }
osg::StateSet* getGlobalStateSet() { return _globalState.get(); }
const osg::StateSet* getGlobalStateSet() const { return _globalState.get(); }
void setGlobalStateSet(osg::StateSet* state) { _globalStateSet = state; }
osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); }
const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); }
void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; }
osg::StateSet* getLocalStateSet() { return _localStateSet.get(); }
const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); }
enum LightingMode {
HEADLIGHT, // default
@@ -299,7 +303,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
void clearArea(int x,int y,int width,int height,const osg::Vec4& color);
osg::ref_ptr<osg::Node> _sceneData;
osg::ref_ptr<osg::StateSet> _globalState;
osg::ref_ptr<osg::StateSet> _globalStateSet;
osg::ref_ptr<osg::StateSet> _localStateSet;
osg::ref_ptr<osg::Light> _light;
osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::RefMatrix> _projectionMatrix;

View File

@@ -0,0 +1,141 @@
#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 &)
{
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

@@ -3,7 +3,6 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgproducer_viewer.cpp\
# osgproducer_cameragroup.cpp\
LIBS += -losgProducer -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
@@ -13,8 +12,8 @@ INSTFILES = \
EXEC = osgproducer
CXXFLAGS += $(OSG_INCLUDE_DIR)
LDFLAGS += $(OSG_LIB_DIR)
CXXFLAGS += $(PRODUCER_INCLUDE_DIR)
LDFLAGS += $(PRODUCER_LIB_DIR)
include $(TOPDIR)/Make/makerules

View File

@@ -2,12 +2,14 @@ TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
ProducerEventAdapter.cpp\
osgproducer.cpp\
osgproducer_viewer.cpp\
LIBS += -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgProducer -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgproducer
CXXFLAGS += $(PRODUCER_INCLUDE_DIR)
LDFLAGS += $(PRODUCER_LIB_DIR)
include $(TOPDIR)/Make/makerules

View File

@@ -11,6 +11,9 @@
#include <osgProducer/Viewer>
#include "FrameStatsHandler"
int main( int argc, char **argv )
{
@@ -62,6 +65,13 @@ int main( int argc, char **argv )
// set up the value with sensible defaults.
viewer->setUpViewer();
viewer->enableInstrumentation();
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() )

View File

@@ -1,11 +1,12 @@
//#define SINGLE_PIPE
#define ASSYMETRICAL_FRUSTUM
Camera "Camera 1"
{
RenderSurface "Window 1"
{
Visual { SetSimple };
Visual { SetSimple };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 0 0 426 512;
@@ -32,7 +33,7 @@ Camera "Camera 2"
{
RenderSurface "Window 2"
{
Visual { SetSimple };
Visual { SetSimple };
Screen 0;
#ifdef SINGLE_PIPE
WindowRectangle 426 0 426 512;
@@ -48,7 +49,7 @@ Camera "Camera 3"
{
RenderSurface "Window 3"
{
Visual { SetSimple };
Visual { SetSimple };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 852 0 426 512;

View File

@@ -139,7 +139,7 @@ void State::popStateSet()
{
if (_drawStateStack.empty()) return;
const StateSet* dstate = _drawStateStack.back().get();
const StateSet* dstate = _drawStateStack.back();
if (dstate)
{

View File

@@ -13,7 +13,7 @@ DEF += -DOSGPRODUCER_LIBRARY
TARGET_BASENAME = osgProducer
LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)
CXXFLAGS += $(OSG_INCLUDE_DIR)
LDFLAGS += $(OSG_LIB_DIR)
CXXFLAGS += $(PRODUCER_INCLUDE_DIR)
LDFLAGS += $(PRODUCER_LIB_DIR)
include $(TOPDIR)/Make/makerules

View File

@@ -41,14 +41,14 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
RenderGraph::moveRenderGraph(state,prev_rg_parent,rg->_parent);
// send state changes and matrix changes to OpenGL.
state.apply(rg->_stateset.get());
state.apply(rg->_stateset);
}
else if (rg!=prev_rg)
{
// send state changes and matrix changes to OpenGL.
state.apply(rg->_stateset.get());
state.apply(rg->_stateset);
}
@@ -72,7 +72,7 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
// apply state if required.
RenderGraph::moveRenderGraph(state,NULL,_parent->_parent);
state.apply(_parent->_stateset.get());
state.apply(_parent->_stateset);
#ifndef APPLY_MATRICES_BEFORE_STATE
// apply matrices if required.

View File

@@ -64,7 +64,7 @@ SceneView::~SceneView()
void SceneView::setDefaults()
{
_globalState = new osg::StateSet;
_globalStateSet = new osg::StateSet;
_lightingMode=HEADLIGHT;
_light = new osg::Light;
@@ -99,28 +99,28 @@ void SceneView::setDefaults()
_cullVisitor->setRenderGraph(_rendergraph.get());
_cullVisitor->setRenderStage(_renderStage.get());
_globalState->setGlobalDefaults();
_globalStateSet->setGlobalDefaults();
// enable lighting by default.
_globalState->setMode(GL_LIGHTING, osg::StateAttribute::ON);
_globalState->setAssociatedModes(_light.get(),osg::StateAttribute::ON);
_globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
_globalStateSet->setAssociatedModes(_light.get(),osg::StateAttribute::ON);
// enable depth testing by default.
_globalState->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
_globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
// set up an alphafunc by default to speed up blending operations.
osg::AlphaFunc* alphafunc = new osg::AlphaFunc;
alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f);
_globalState->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);
_globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);
// set up an texture environment by default to speed up blending operations.
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
_globalState->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
_globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
osg::LightModel* lightmodel = new osg::LightModel;
lightmodel->setAmbientIntensity(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
_globalState->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
_globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
_backgroundColor.set(0.2f, 0.2f, 0.4f, 1.0f);
@@ -190,12 +190,9 @@ void SceneView::cull()
_state = new osg::State;
}
if (!_globalState)
if (!_localStateSet)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView::_globalState attached, creating a default global stateset automatically."<< std::endl;
_globalState = new osg::StateSet;
_globalState->setGlobalDefaults();
_localStateSet = new osg::StateSet;
}
// we in theory should be able to be able to bypass reset, but we'll call it just incase.
@@ -503,7 +500,8 @@ void SceneView::cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,o
break;
}
if (_globalState.valid()) cullVisitor->pushStateSet(_globalState.get());
if (_globalStateSet.valid()) cullVisitor->pushStateSet(_globalStateSet.get());
if (_localStateSet.valid()) cullVisitor->pushStateSet(_localStateSet.get());
cullVisitor->pushViewport(_viewport.get());
@@ -518,7 +516,8 @@ void SceneView::cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,o
cullVisitor->popProjectionMatrix();
cullVisitor->popViewport();
if (_globalState.valid()) cullVisitor->popStateSet();
if (_localStateSet.valid()) cullVisitor->popStateSet();
if (_globalStateSet.valid()) cullVisitor->popStateSet();
const osg::ClearNode* clearNode = cullVisitor->getClearNode();
@@ -571,7 +570,7 @@ void SceneView::draw()
case(osg::DisplaySettings::QUAD_BUFFER):
{
_globalState->setAttribute(_viewport.get());
_localStateSet->setAttribute(_viewport.get());
_renderStageLeft->drawPreRenderStages(*_state,previous);
_renderStageRight->drawPreRenderStages(*_state,previous);
@@ -587,7 +586,7 @@ void SceneView::draw()
case(osg::DisplaySettings::ANAGLYPHIC):
{
_globalState->setAttribute(_viewport.get());
_localStateSet->setAttribute(_viewport.get());
_renderStageLeft->drawPreRenderStages(*_state,previous);
_renderStageRight->drawPreRenderStages(*_state,previous);
@@ -595,14 +594,14 @@ void SceneView::draw()
// draw left eye.
osg::ref_ptr<osg::ColorMask> red = new osg::ColorMask;
red->setMask(true,false,false,true);
_globalState->setAttribute(red.get());
_localStateSet->setAttribute(red.get());
_renderStageLeft->setColorMask(red.get());
_renderStageLeft->draw(*_state,previous);
// draw right eye.
osg::ref_ptr<osg::ColorMask> green = new osg::ColorMask;
green->setMask(false,true,true,true);
_globalState->setAttribute(green.get());
_localStateSet->setAttribute(green.get());
_renderStageRight->setColorMask(green.get());
_renderStageRight->draw(*_state,previous);
@@ -630,21 +629,21 @@ void SceneView::draw()
if (_displaySettings->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT)
{
_globalState->setAttribute(viewportLeft.get());
_localStateSet->setAttribute(viewportLeft.get());
_renderStageLeft->setViewport(viewportLeft.get());
_renderStageLeft->draw(*_state,previous);
_globalState->setAttribute(viewportRight.get());
_localStateSet->setAttribute(viewportRight.get());
_renderStageRight->setViewport(viewportRight.get());
_renderStageRight->draw(*_state,previous);
}
else
{
_globalState->setAttribute(viewportRight.get());
_localStateSet->setAttribute(viewportRight.get());
_renderStageLeft->setViewport(viewportRight.get());
_renderStageLeft->draw(*_state,previous);
_globalState->setAttribute(viewportLeft.get());
_localStateSet->setAttribute(viewportLeft.get());
_renderStageRight->setViewport(viewportLeft.get());
_renderStageRight->draw(*_state,previous);
}
@@ -673,21 +672,21 @@ void SceneView::draw()
if (_displaySettings->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_TOP_VIEWPORT)
{
_globalState->setAttribute(viewportTop.get());
_localStateSet->setAttribute(viewportTop.get());
_renderStageLeft->setViewport(viewportTop.get());
_renderStageLeft->draw(*_state,previous);
_globalState->setAttribute(viewportBottom.get());
_localStateSet->setAttribute(viewportBottom.get());
_renderStageRight->setViewport(viewportBottom.get());
_renderStageRight->draw(*_state,previous);
}
else
{
_globalState->setAttribute(viewportBottom.get());
_localStateSet->setAttribute(viewportBottom.get());
_renderStageLeft->setViewport(viewportBottom.get());
_renderStageLeft->draw(*_state,previous);
_globalState->setAttribute(viewportTop.get());
_localStateSet->setAttribute(viewportTop.get());
_renderStageRight->setViewport(viewportTop.get());
_renderStageRight->draw(*_state,previous);
}
@@ -696,7 +695,7 @@ void SceneView::draw()
case(osg::DisplaySettings::RIGHT_EYE):
case(osg::DisplaySettings::LEFT_EYE):
{
_globalState->setAttribute(_viewport.get());
_localStateSet->setAttribute(_viewport.get());
_renderStage->drawPreRenderStages(*_state,previous);
_renderStage->draw(*_state,previous);
}
@@ -710,10 +709,10 @@ void SceneView::draw()
}
else
{
_globalState->setAttribute(_viewport.get());
osg::ref_ptr<osg::ColorMask> cmask = new osg::ColorMask;
cmask->setMask(true,true,true,true);
_globalState->setAttribute(cmask.get());
_localStateSet->setAttribute(_viewport.get());
osg::ref_ptr<osg::ColorMask> cmask = new osg::ColorMask;
cmask->setMask(true,true,true,true);
_localStateSet->setAttribute(cmask.get());
// bog standard draw.
_renderStage->drawPreRenderStages(*_state,previous);