Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods,
forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction
with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only
a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another
thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is
passed back and the referenceCount never goes to zero.
To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File()
usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of
templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group:
bool addChild(Node* child); // old method which can only be used with a Node*
tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method
These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache
and multi-threaded loaded more robust.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.4@15165 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "DePee.h"
|
||||
#include "DePee.h"
|
||||
|
||||
/*!
|
||||
Handles keyboard events.
|
||||
@@ -28,7 +28,7 @@
|
||||
class KeyboardEventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
KeyboardEventHandler(DePee* dePee)
|
||||
{
|
||||
_apc = 0;
|
||||
@@ -41,12 +41,12 @@ public:
|
||||
_dePee->setSketchy(_sketchy);
|
||||
_dePee->setColored(_colored);
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
|
||||
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Space)
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
_dePee->setSketchy(_sketchy);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
else if (ea.getKey() == 'e')
|
||||
{
|
||||
_edgy = !_edgy;
|
||||
@@ -106,13 +106,13 @@ public:
|
||||
_crayon = !_crayon;
|
||||
_dePee->setCrayon(_crayon);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -139,12 +139,12 @@ private:
|
||||
class MouseEventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
MouseEventHandler(DePee* dePee)
|
||||
{
|
||||
_dePee = dePee;
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
@@ -152,17 +152,17 @@ public:
|
||||
//mouse
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
{
|
||||
rotate(ea.getXnormalized(), ea.getYnormalized());
|
||||
rotate(ea.getXnormalized(), ea.getYnormalized());
|
||||
break;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::MOVE):
|
||||
_prevX = ea.getXnormalized();
|
||||
_prevX = ea.getXnormalized();
|
||||
_prevY = ea.getYnormalized();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -175,25 +175,25 @@ private:
|
||||
void rotate(float x, float y)
|
||||
{
|
||||
osg::Matrix baseMatrix = _modelGroupTransform->getMatrix();
|
||||
|
||||
|
||||
baseMatrix.preMultTranslate(_rotCenter);
|
||||
baseMatrix.preMultRotate(osg::Quat((x - _prevX) * 3, osg::Vec3d(0.0, 0.0, 1.0)));
|
||||
baseMatrix.preMultRotate(osg::Quat(-(y - _prevY) * 3, (baseMatrix * osg::Vec3d(1.0, 0.0, 0.0))));
|
||||
baseMatrix.preMultTranslate(-_rotCenter);
|
||||
|
||||
|
||||
_modelGroupTransform->setMatrix(baseMatrix);
|
||||
|
||||
_prevX = x;
|
||||
_prevX = x;
|
||||
_prevY = y;
|
||||
};
|
||||
|
||||
|
||||
DePee* _dePee;
|
||||
|
||||
float _prevX;
|
||||
|
||||
float _prevX;
|
||||
float _prevY;
|
||||
|
||||
|
||||
osg::Vec3 _rotCenter;
|
||||
osg::MatrixTransform* _modelGroupTransform;
|
||||
osg::MatrixTransform* _modelGroupTransform;
|
||||
};
|
||||
|
||||
|
||||
@@ -202,25 +202,25 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates Depth Peeling");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" filename");
|
||||
|
||||
|
||||
|
||||
|
||||
// construct the viewer
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
// 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);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (arguments.argc()<=1 || arguments.argc() > 3)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
@@ -232,29 +232,29 @@ int main( int argc, char **argv )
|
||||
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
|
||||
// read the model to do depth peeling with
|
||||
osg::Node* loadedModel = osgDB::readNodeFile(arguments.argv()[1]);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(arguments.argv()[1]);
|
||||
|
||||
if (!loadedModel)
|
||||
return 1;
|
||||
|
||||
|
||||
// create a transform to spin the model.
|
||||
osg::MatrixTransform* modelGroupTransform = new osg::MatrixTransform;
|
||||
osg::Group* modelGroup = new osg::Group;
|
||||
modelGroupTransform->addChild(modelGroup);
|
||||
modelGroup->addChild(loadedModel);
|
||||
|
||||
|
||||
osg::Group* rootNode = new osg::Group();
|
||||
|
||||
|
||||
// add model to the viewer.
|
||||
viewer.setSceneData(rootNode);
|
||||
|
||||
|
||||
// Depth peel example only works on a single graphics context right now
|
||||
// so open up viewer on single screen to prevent problems
|
||||
viewer.setUpViewOnSingleScreen(0);
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
|
||||
unsigned int width = 1280;
|
||||
unsigned int height = 1280;
|
||||
osgViewer::Viewer::Windows windows;
|
||||
@@ -266,11 +266,11 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<DePee> dePee = new DePee(rootNode,
|
||||
modelGroupTransform,
|
||||
osg::ref_ptr<DePee> dePee = new DePee(rootNode,
|
||||
modelGroupTransform,
|
||||
width,
|
||||
height);
|
||||
|
||||
|
||||
//create event handlers
|
||||
KeyboardEventHandler* keyboardEventHandler = new KeyboardEventHandler(dePee.get());
|
||||
MouseEventHandler* mouseEventHandler = new MouseEventHandler(dePee.get());
|
||||
@@ -278,7 +278,7 @@ int main( int argc, char **argv )
|
||||
viewer.addEventHandler(mouseEventHandler);
|
||||
|
||||
//viewer.setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
|
||||
|
||||
osg::StateSet* stateset = modelGroupTransform->getOrCreateStateSet();
|
||||
|
||||
stateset->setMode(GL_BLEND, osg::StateAttribute::OFF);
|
||||
@@ -287,15 +287,15 @@ int main( int argc, char **argv )
|
||||
osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(modelGroupTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
apc->setPause(true);
|
||||
modelGroupTransform->setUpdateCallback(apc);
|
||||
|
||||
|
||||
keyboardEventHandler->registerAnimationPathCallback(apc);
|
||||
mouseEventHandler->registerModelGroupTransform(modelGroupTransform);
|
||||
|
||||
|
||||
//setup stuff that is necessary for measuring fps
|
||||
osg::Timer_t current_tick, previous_tick = 1;
|
||||
double* fps = new double;
|
||||
dePee->setFPS(fps);
|
||||
|
||||
|
||||
while(!viewer.done())
|
||||
{
|
||||
current_tick = osg::Timer::instance()->tick();
|
||||
|
||||
Reference in New Issue
Block a user