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/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -35,11 +35,11 @@ osg::StateSet* create1DTextureStateToDecorate(osg::Node* loadedModel)
|
||||
osg::Image* image = new osg::Image;
|
||||
|
||||
int noPixels = 1024;
|
||||
|
||||
|
||||
// allocate the image data, noPixels x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
|
||||
image->allocateImage(noPixels,1,1,GL_RGBA,GL_FLOAT);
|
||||
image->setInternalTextureFormat(GL_RGBA);
|
||||
|
||||
|
||||
typedef std::vector<osg::Vec4> ColorBands;
|
||||
ColorBands colorbands;
|
||||
colorbands.push_back(osg::Vec4(0.0f,0.0,0.0,1.0f));
|
||||
@@ -55,7 +55,7 @@ osg::StateSet* create1DTextureStateToDecorate(osg::Node* loadedModel)
|
||||
float delta = nobands/(float)noPixels;
|
||||
float pos = 0.0f;
|
||||
|
||||
// fill in the image data.
|
||||
// fill in the image data.
|
||||
osg::Vec4* dataPtr = (osg::Vec4*)image->data();
|
||||
for(int i=0;i<noPixels;++i,pos+=delta)
|
||||
{
|
||||
@@ -66,25 +66,25 @@ osg::StateSet* create1DTextureStateToDecorate(osg::Node* loadedModel)
|
||||
osg::Vec4 color = colorbands[(int)pos];
|
||||
*dataPtr++ = color;
|
||||
}
|
||||
|
||||
|
||||
osg::Texture1D* texture = new osg::Texture1D;
|
||||
texture->setWrap(osg::Texture1D::WRAP_S,osg::Texture1D::MIRROR);
|
||||
texture->setFilter(osg::Texture1D::MIN_FILTER,osg::Texture1D::LINEAR);
|
||||
texture->setImage(image);
|
||||
|
||||
|
||||
osg::Material* material = new osg::Material;
|
||||
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
|
||||
|
||||
stateset->setTextureAttribute(0,texture,osg::StateAttribute::OVERRIDE);
|
||||
stateset->setTextureMode(0,GL_TEXTURE_1D,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
||||
stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
||||
stateset->setTextureMode(0,GL_TEXTURE_3D,osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
||||
|
||||
stateset->setTextureMode(0,GL_TEXTURE_GEN_S,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
||||
|
||||
|
||||
stateset->setAttribute(material,osg::StateAttribute::OVERRIDE);
|
||||
|
||||
|
||||
return stateset;
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ class AnimateTexGenCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
AnimateTexGenCallback() {}
|
||||
|
||||
|
||||
void animateTexGen(osg::TexGenNode* texgenNode,double time)
|
||||
{
|
||||
// here we simply get any existing texgen, and then increment its
|
||||
// plane, pushing the R coordinate through the texture.
|
||||
const double timeInterval = 2.0f;
|
||||
|
||||
|
||||
static double previousTime = time;
|
||||
static bool state = false;
|
||||
while (time>previousTime+timeInterval)
|
||||
@@ -108,7 +108,7 @@ class AnimateTexGenCallback : public osg::NodeCallback
|
||||
previousTime+=timeInterval;
|
||||
state = !state;
|
||||
}
|
||||
|
||||
|
||||
if (state)
|
||||
{
|
||||
texgenNode->getTexGen()->setMode(osg::TexGen::OBJECT_LINEAR);
|
||||
@@ -117,11 +117,11 @@ class AnimateTexGenCallback : public osg::NodeCallback
|
||||
{
|
||||
texgenNode->getTexGen()->setMode(osg::TexGen::EYE_LINEAR);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
{
|
||||
osg::TexGenNode* texgenNode = dynamic_cast<osg::TexGenNode*>(node);
|
||||
|
||||
if (texgenNode && nv->getFrameStamp())
|
||||
@@ -131,10 +131,10 @@ class AnimateTexGenCallback : public osg::NodeCallback
|
||||
}
|
||||
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// should always include call the traverse(node,nv) to ensure
|
||||
// should always include call the traverse(node,nv) to ensure
|
||||
// that the rest of callbacks and the scene graph are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -143,23 +143,23 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the images specified on command line
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::StateSet* stateset = create1DTextureStateToDecorate(loadedModel);
|
||||
osg::ref_ptr<osg::StateSet> stateset = create1DTextureStateToDecorate(loadedModel.get());
|
||||
if (!stateset)
|
||||
{
|
||||
std::cout<<"Error: failed to create 1D texture state."<<std::endl;
|
||||
@@ -169,7 +169,7 @@ int main( int argc, char **argv )
|
||||
|
||||
loadedModel->setStateSet(stateset);
|
||||
|
||||
osg:: Group *root = new osg:: Group;
|
||||
osg::ref_ptr<osg::Group> root = new osg:: Group;
|
||||
root -> addChild( loadedModel );
|
||||
|
||||
// The contour banded color texture is used in conjunction with TexGenNode
|
||||
|
||||
Reference in New Issue
Block a user