Fixes to osgprerender and osgshadow scene for new cull and draw implemention

without use of ref counting.

New StatsEventHandler for osgprerender demo to add keyboard control of stats
output.
This commit is contained in:
Robert Osfield
2003-01-30 00:34:35 +00:00
parent 6439a719aa
commit 8422040e97
8 changed files with 73 additions and 22 deletions

View File

@@ -28,8 +28,8 @@ osgvertexprogram
echo sgv Town.osg
sgv Town.osg
echo sgv afterescher.geo
sgv afterescher.geo
#echo sgv afterescher.geo
#sgv afterescher.geo
echo osgshape
osgshape

View File

@@ -129,7 +129,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio)
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("land_shallow_topo_2048.jpg");
osg::Image* image = osgDB::readImageFile("Images/land_shallow_topo_2048.jpg");
if (image)
{
osg::Texture2D* texture = new osg::Texture2D;

View File

@@ -49,11 +49,13 @@ class MyCullCallback : public osg::NodeCallback
MyCullCallback(osg::Node* subgraph,osg::Texture2D* texture):
_subgraph(subgraph),
_texture(texture) {}
_texture(texture),
_localState(new osg::StateSet) {}
MyCullCallback(osg::Node* subgraph,osg::Image* image):
_subgraph(subgraph),
_image(image) {}
_image(image),
_localState(new osg::StateSet) {}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
@@ -79,7 +81,7 @@ class MyCullCallback : public osg::NodeCallback
osg::ref_ptr<osg::Node> _subgraph;
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osg::Image> _image;
osg::ref_ptr<osg::StateSet> _localState;
};
@@ -138,9 +140,7 @@ void MyCullCallback::doPreRender(osg::Node&, osgUtil::CullVisitor& cv)
cv.pushModelViewMatrix(matrix);
osg::ref_ptr<osg::StateSet> dummyState = new osg::StateSet;
cv.pushStateSet(dummyState.get());
cv.pushStateSet(_localState.get());
{
@@ -185,7 +185,7 @@ void MyCullCallback::doPreRender(osg::Node&, osgUtil::CullVisitor& cv)
new_viewport->setViewport(center_x-width/2,center_y-height/2,width,height);
rtts->setViewport(new_viewport);
dummyState->setAttribute(new_viewport);
_localState->setAttribute(new_viewport);
// and the render to texture stage to the current stages
// dependancy list.

View File

@@ -22,8 +22,10 @@ class FrameStatsHandler : public CameraGroup::StatsHandler, public Camera::Callb
_fs[_index] = cg.getFrameStats();
}
void operator() (const Camera &)
void operator() (const Camera &camera)
{
if (!camera.getInstrumentationMode()) return;
glViewport( 0, 0, 1280, 1024 );
// Set up the Orthographic view
glMatrixMode( GL_PROJECTION );

View File

@@ -0,0 +1,46 @@
#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

@@ -12,6 +12,7 @@
#include <osgProducer/Viewer>
#include "FrameStatsHandler"
#include "StatsEventHandler"
int main( int argc, char **argv )
@@ -65,8 +66,6 @@ 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);
@@ -87,6 +86,10 @@ int main( int argc, char **argv )
// 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

@@ -6,7 +6,7 @@ Camera "Camera 1"
{
RenderSurface "Window 1"
{
Visual { SetSimple };
Visual { VisualID 0x172 };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 0 0 426 512;
@@ -33,7 +33,7 @@ Camera "Camera 2"
{
RenderSurface "Window 2"
{
Visual { SetSimple };
Visual { VisualID 0x74 };
Screen 0;
#ifdef SINGLE_PIPE
WindowRectangle 426 0 426 512;
@@ -49,7 +49,7 @@ Camera "Camera 3"
{
RenderSurface "Window 3"
{
Visual { SetSimple };
Visual { VisualID 0xF3 };
#ifdef SINGLE_PIPE
Screen 0;
WindowRectangle 852 0 426 512;

View File

@@ -20,7 +20,8 @@ class CreateShadowTextureCullCallback : public osg::NodeCallback
_shadower(shadower),
_position(position),
_ambientLightColor(ambientLightColor),
_unit(textureUnit)
_unit(textureUnit),
_shadowState(new osg::StateSet)
{
_texture = new osg::Texture2D;
_texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
@@ -52,6 +53,7 @@ class CreateShadowTextureCullCallback : public osg::NodeCallback
osg::Vec3 _position;
osg::Vec4 _ambientLightColor;
unsigned int _unit;
osg::ref_ptr<osg::StateSet> _shadowState;
// we need this to get round the order dependance
// of eye linear tex gen...
@@ -146,17 +148,15 @@ void CreateShadowTextureCullCallback::doPreRender(osg::Node& node, osgUtil::Cull
cv.pushModelViewMatrix(matrix);
osg::ref_ptr<osg::StateSet> shadowState = new osg::StateSet;
// make the material black for a shadow.
osg::Material* material = new osg::Material;
material->setAmbient(osg::Material::FRONT_AND_BACK,_ambientLightColor);
material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,0.0f,1.0f));
material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,0.0f,1.0f));
material->setShininess(osg::Material::FRONT_AND_BACK,0.0f);
shadowState->setAttribute(material,osg::StateAttribute::OVERRIDE);
_shadowState->setAttribute(material,osg::StateAttribute::OVERRIDE);
cv.pushStateSet(shadowState.get());
cv.pushStateSet(_shadowState.get());
{
@@ -202,7 +202,7 @@ void CreateShadowTextureCullCallback::doPreRender(osg::Node& node, osgUtil::Cull
new_viewport->setViewport(center_x-width/2,center_y-height/2,width,height);
rtts->setViewport(new_viewport);
shadowState->setAttribute(new_viewport);
_shadowState->setAttribute(new_viewport);
// and the render to texture stage to the current stages
// dependancy list.