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:
@@ -40,7 +40,7 @@ osg::Camera* createHUD(const std::string& label)
|
||||
// set the projection matrix
|
||||
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||
|
||||
// set the view matrix
|
||||
// set the view matrix
|
||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
camera->setViewMatrix(osg::Matrix::identity());
|
||||
|
||||
@@ -80,14 +80,14 @@ osg::Camera* createHUD(const std::string& label)
|
||||
return camera;
|
||||
}
|
||||
|
||||
osg::Node* creatQuad(const std::string& name,
|
||||
osg::Image* image,
|
||||
osg::Node* creatQuad(const std::string& name,
|
||||
osg::Image* image,
|
||||
osg::Texture::InternalFormatMode formatMode,
|
||||
osg::Texture::FilterMode minFilter)
|
||||
{
|
||||
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
|
||||
@@ -104,14 +104,14 @@ osg::Node* creatQuad(const std::string& name,
|
||||
texture->setInternalFormatMode(formatMode);
|
||||
texture->setFilter(osg::Texture::MIN_FILTER, minFilter);
|
||||
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
group->addChild(geode);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
group->addChild(createHUD(name));
|
||||
}
|
||||
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -121,16 +121,16 @@ int main(int argc, char** argv)
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::CompositeViewer viewer(arguments);
|
||||
|
||||
|
||||
if (arguments.argc()<=1)
|
||||
{
|
||||
std::cout<<"Please supply an image filename on the commnand line."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
std::string filename = arguments[1];
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
|
||||
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
|
||||
if (!image)
|
||||
{
|
||||
std::cout<<"Error: unable able to read image from "<<filename<<std::endl;
|
||||
@@ -138,7 +138,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
if (!wsi)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return 1;
|
||||
@@ -155,7 +155,7 @@ int main(int argc, char** argv)
|
||||
traits->height = height;
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
if (!gc)
|
||||
{
|
||||
@@ -166,16 +166,16 @@ int main(int argc, char** argv)
|
||||
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator;
|
||||
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Node> > Models;
|
||||
|
||||
|
||||
Models models;
|
||||
models.push_back(creatQuad("no compression", image.get(), osg::Texture::USE_IMAGE_DATA_FORMAT, osg::Texture::LINEAR));
|
||||
models.push_back(creatQuad("ARB compression", image.get(), osg::Texture::USE_ARB_COMPRESSION, osg::Texture::LINEAR));
|
||||
models.push_back(creatQuad("DXT1 compression", image.get(), osg::Texture::USE_S3TC_DXT1_COMPRESSION, osg::Texture::LINEAR));
|
||||
models.push_back(creatQuad("DXT3 compression", image.get(), osg::Texture::USE_S3TC_DXT3_COMPRESSION, osg::Texture::LINEAR));
|
||||
models.push_back(creatQuad("DXT5 compression", image.get(), osg::Texture::USE_S3TC_DXT5_COMPRESSION, osg::Texture::LINEAR));
|
||||
|
||||
|
||||
int numX = 1;
|
||||
int numY = 1;
|
||||
|
||||
@@ -203,10 +203,10 @@ int main(int argc, char** argv)
|
||||
for(unsigned int i=0; i<models.size(); ++i)
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
|
||||
|
||||
int xCell = i % numX;
|
||||
int yCell = i / numX;
|
||||
|
||||
|
||||
int vx = int((float(xCell)/float(numX)) * float(width));
|
||||
int vy = int((float(yCell)/float(numY)) * float(height));
|
||||
int vw = int(float(width) / float(numX));
|
||||
@@ -214,7 +214,7 @@ int main(int argc, char** argv)
|
||||
|
||||
view->setSceneData(models[i].get());
|
||||
view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(vw) / double(vh), 1.0, 1000.0);
|
||||
view->getCamera()->setViewport(new osg::Viewport(vx, vy, vw, vh));
|
||||
view->getCamera()->setViewport(new osg::Viewport(vx, vy, vw, vh));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
view->getCamera()->setClearMask(0);
|
||||
view->setCameraManipulator(trackball.get());
|
||||
|
||||
Reference in New Issue
Block a user