diff --git a/CMakeLists.txt b/CMakeLists.txt index b44ef8bd9..551969961 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,7 @@ ENDIF() OPTION(OSG_DISABLE_MSVC_WARNINGS "Set to OFF to not disable MSVC warnings generated by OSG headers." ON) MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS) +OPTION(OSG_PROVIDE_READFILE "Set to ON for include/osgDB/ReadFile to provide the osgDB::read*File(() methods. " ON) OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON) diff --git a/applications/osgarchive/osgarchive.cpp b/applications/osgarchive/osgarchive.cpp index f3388524e..8be99851d 100644 --- a/applications/osgarchive/osgarchive.cpp +++ b/applications/osgarchive/osgarchive.cpp @@ -1,9 +1,9 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This application is open source and may be redistributed and/or modified + * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial applications, * as long as this copyright notice is maintained. - * + * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -26,12 +26,12 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an application for collecting a set of separate files into a single archive file that can be later read in OSG applications.."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); - + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { @@ -49,14 +49,14 @@ int main( int argc, char **argv ) { insert = true; } - + bool extract = false; while (arguments.read("-e") || arguments.read("--extract")) { extract = true; } - - bool list = false; + + bool list = false; while (arguments.read("-l") || arguments.read("--list")) { list = true; @@ -93,7 +93,7 @@ int main( int argc, char **argv ) } } } - + // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); @@ -103,7 +103,7 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - + if (archiveFilename.empty()) { std::cout<<"Please specify an archive name using --archive filename"< obj = osgDB::readObjectFile(*itr); + osg::ref_ptr obj = osgDB::readRefObjectFile(*itr); if (obj.valid()) { std::cout<<" write to archive "<<*itr<getFileNames(fileNames)) @@ -187,11 +187,11 @@ int main( int argc, char **argv ) std::cout<<" "<<*itr<getMasterFileName()<tick(); - osg::ref_ptr root = osgDB::readNodeFiles(fileNames); + osg::ref_ptr root = osgDB::readRefNodeFiles(fileNames); if (root.valid()) { diff --git a/applications/osgfilecache/osgfilecache.cpp b/applications/osgfilecache/osgfilecache.cpp index d23b91436..ceadad4fa 100644 --- a/applications/osgfilecache/osgfilecache.cpp +++ b/applications/osgfilecache/osgfilecache.cpp @@ -1,9 +1,9 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This application is open source and may be redistributed and/or modified + * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial applications, * as long as this copyright notice is maintained. - * + * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -46,20 +46,20 @@ struct Extents _maxLevel(maxLevel), _min(minX, minY), _max(maxX, maxY) {} - + Extents(const Extents& extents): _maxLevel(extents._maxLevel), _min(extents._min), _max(extents._max) {} - + Extents& operator = (const Extents& rhs) { if (&rhs == this) return *this; - + _maxLevel = rhs._maxLevel; _min = rhs._min; _max = rhs._max; - + return *this; } @@ -69,10 +69,10 @@ struct Extents osg::notify(osg::INFO)<<" _maxLevel="<<_maxLevel<<", _min="<<_min<<" _max="<<_max<_maxLevel) return false; - + osg::Vec2d union_min, union_max; - // handle mins + // handle mins if (_min.x()!=DBL_MAX && in_min.x()!=DBL_MAX) { // both _min.x() and in_min.x() are defined so use max of two @@ -95,7 +95,7 @@ struct Extents union_min.y() = _min.y()convertXYZToLatLongHeight(v.x(), v.y(), v.z(), v.y(), v.x(), v.z()); - + v.x() = osg::RadiansToDegrees(v.x()); v.y() = osg::RadiansToDegrees(v.y()); } - + void initBound() { _min.set(DBL_MAX, DBL_MAX); @@ -332,16 +332,16 @@ protected: if (v.x() > _max.x()) _max.x() = v.x(); if (v.y() > _max.y()) _max.y() = v.y(); } - + void updateBound(osg::Vec3Array& vertices) { // set up matrix osg::Matrix matrix; if (!_matrixStack.empty()) matrix = _matrixStack.back(); - + // set up ellipsoid model osg::EllipsoidModel* em = !_csnStack.empty() ? _csnStack.back()->getEllipsoidModel() : 0; - + for(osg::Vec3Array::iterator itr = vertices.begin(); itr != vertices.end(); ++itr) @@ -352,7 +352,7 @@ protected: updateBound(v); } } - + bool intersects() { osg::notify(osg::INFO)<<"intersects() _min = "<<_min<<" _max = "<<_max<intersects(_currentLevel, _min, _max)) return true; } - + return false; } @@ -376,7 +376,7 @@ protected: unsigned int _currentLevel; MatrixStack _matrixStack; CSNStack _csnStack; - + osg::Vec2d _min; osg::Vec2d _max; }; @@ -403,7 +403,7 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an application for collecting a set of separate files into a single archive file that can be later read in OSG applications.."); @@ -412,21 +412,21 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("-e level minX minY maxX maxY","Read down to across the extents minX, minY to maxY, maxY. Note, for geocentric datase X and Y are longitude and latitude respectively."); arguments.getApplicationUsage()->addCommandLineOption("-c directory","Shorthand for --file-cache directory."); arguments.getApplicationUsage()->addCommandLineOption("--file-cache directory","Set directory as to place cache download files."); - + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout); return 1; } - + LoadDataVisitor ldv; std::string fileCachePath; while(arguments.read("--file-cache",fileCachePath) || arguments.read("-c",fileCachePath)) {} - + if (fileCachePath.empty()) - { + { const char* env_fileCachePath = getenv("OSG_FILE_CACHE"); if (env_fileCachePath) { @@ -439,7 +439,7 @@ int main( int argc, char **argv ) std::cout<<"No path to the file cache defined, please set OSG_FILE_PATH env var, or use --file-cache to set a suitable directory for the file cache."< loadedModel = ldv.readNodeFileAndWriteToCache(filename); if (!loadedModel) { std::cout<<"No data loaded, please specify a database to load"<accept(ldv); if (s_ExitApplication) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index d63726a0d..d790d3873 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -87,10 +87,10 @@ int main(int argc, char** argv) std::string device; while(arguments.read("--device", device)) { - osg::ref_ptr dev = osgDB::readFile(device); + osg::ref_ptr dev = osgDB::readRefFile(device); if (dev.valid()) { - viewer.addDevice(dev.get()); + viewer.addDevice(dev); } } @@ -152,7 +152,7 @@ int main(int argc, char** argv) viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; @@ -172,9 +172,9 @@ int main(int argc, char** argv) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); - viewer.setSceneData( loadedModel.get() ); + viewer.setSceneData(loadedModel); viewer.realize(); diff --git a/applications/present3D/ReadShowFile.cpp b/applications/present3D/ReadShowFile.cpp index 09115f0e7..4e00bc756 100644 --- a/applications/present3D/ReadShowFile.cpp +++ b/applications/present3D/ReadShowFile.cpp @@ -215,24 +215,24 @@ osg::ref_ptr p3d::readShowFiles(osg::ArgumentParser& arguments,const std::string filename; while (arguments.read("--image",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); - if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image.get())); + osg::ref_ptr image = readRefImageFile(filename.c_str(), local_options.get()); + if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image)); } while (arguments.read("--movie",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); + osg::ref_ptr image = readRefImageFile(filename.c_str(), local_options.get()); osg::ref_ptr imageStream = dynamic_cast(image.get()); if (image.valid()) { imageStream->play(); - nodeList.push_back(osg::createGeodeForImage(imageStream.get())); + nodeList.push_back(osg::createGeodeForImage(imageStream)); } } while (arguments.read("--dem",filename)) { - osg::HeightField* hf = readHeightFieldFile(filename.c_str(), local_options.get()); + osg::ref_ptr hf = readRefHeightFieldFile(filename.c_str(), local_options.get()); if (hf) { osg::Geode* geode = new osg::Geode; @@ -247,7 +247,7 @@ osg::ref_ptr p3d::readShowFiles(osg::ArgumentParser& arguments,const if (!arguments.isOption(pos)) { // not an option so assume string is a filename. - osg::Node *node = osgDB::readNodeFile( arguments[pos], local_options.get()); + osg::ref_ptr node = osgDB::readRefNodeFile( arguments[pos], local_options.get()); if(node) { diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index d7c8de735..9d00000d3 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -266,7 +266,7 @@ void processLoadedModel(osg::ref_ptr& loadedModel, int optimizer_opti void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name, bool forward_mouse_events) { - osg::ref_ptr dev = osgDB::readFile(device_name); + osg::ref_ptr dev = osgDB::readRefFile(device_name); if (dev.valid()) { OSG_INFO << "Adding Device : " << device_name << std::endl; @@ -317,7 +317,7 @@ int main( int argc, char **argv ) if (arguments.read("-devices") || arguments.read("--devices")) { // Force load QuickTime plugin, probe video capability, exit - osgDB::readImageFile("devices.live"); + osgDB::readRefImageFile("devices.live"); return 1; } @@ -451,7 +451,7 @@ int main( int argc, char **argv ) osg::ref_ptr device_options = new osgDB::Options("documentRegisteredHandlers"); - osg::ref_ptr rest_http_device = osgDB::readFile(server_address+":"+server_port+"/"+document_root+".resthttp", device_options.get()); + osg::ref_ptr rest_http_device = osgDB::readRefFile(server_address+":"+server_port+"/"+document_root+".resthttp", device_options.get()); if (rest_http_device.valid()) { viewer.addDevice(rest_http_device.get()); diff --git a/examples/osg2cpp/osg2cpp.cpp b/examples/osg2cpp/osg2cpp.cpp index 857843c65..c10d16b64 100644 --- a/examples/osg2cpp/osg2cpp.cpp +++ b/examples/osg2cpp/osg2cpp.cpp @@ -85,7 +85,7 @@ int main( int argc, char **argv ) std::string filename; if (arguments.read("--shader",filename)) { - osg::ref_ptr shader = osgDB::readShaderFile(filename); + osg::ref_ptr shader = osgDB::readRefShaderFile(filename); if (shader.valid()) { std::string name = osgDB::getStrippedName(filename); diff --git a/examples/osgSSBO/osgSSBO.cpp b/examples/osgSSBO/osgSSBO.cpp index 8ece62447..c08b5ea74 100644 --- a/examples/osgSSBO/osgSSBO.cpp +++ b/examples/osgSSBO/osgSSBO.cpp @@ -311,7 +311,7 @@ public: //set OSG_FILE_PATH for loading axes.osgt void ComputeNode::addHelperGeometry() { - _helperNode = osgDB::readNodeFile("axes.osgt"); + _helperNode = osgDB::readRefNodeFile("axes.osgt"); if (_helperNode.valid()) { @@ -464,8 +464,8 @@ void ComputeNode::addDataMonitor(osg::Vec3 placement, osg::Vec3 relativePlacemen ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //add a label - osgText::Text* text = new osgText::Text; - osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); + osg::ref_ptr text = new osgText::Text; + osg::ref_ptr font = osgText::readRefFontFile("fonts/arial.ttf"); text->setFont(font); text->setColor(osg::Vec4(1, 1, 1, 1)); text->setCharacterSize(0.1*scale); diff --git a/examples/osganalysis/osganalysis.cpp b/examples/osganalysis/osganalysis.cpp index a420c8297..24b8bfa15 100644 --- a/examples/osganalysis/osganalysis.cpp +++ b/examples/osganalysis/osganalysis.cpp @@ -504,7 +504,7 @@ protected: optimizeVertexOrder = false; reallocateMemory = false; - + modifyTextureSettings = false; buildImageMipmaps = false; compressImages = false; @@ -524,21 +524,21 @@ protected: bool optimizeVertexOrder; bool reallocateMemory; - + bool modifyTextureSettings; bool buildImageMipmaps; bool compressImages; bool disableMipmaps; }; -// +// class DatabasePagingOperation : public osg::Operation, public osgUtil::IncrementalCompileOperation::CompileCompletedCallback { public: DatabasePagingOperation(const std::string& filename, const std::string& outputFilename, - SceneGraphProcessor* sceneGraphProcessor, + SceneGraphProcessor* sceneGraphProcessor, osgUtil::IncrementalCompileOperation* ico): osg::Referenced(true), Operation("DatabasePaging Operation", false), @@ -555,7 +555,7 @@ public: osg::notify(osg::NOTICE)<<"LoadAndCompileOperation "<<_filename<setTimeScale(animationSpeed); apm->setAnimationCompletedCallback(new ReportStatsAnimationCompletedCallback()); - + unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); keyswitchManipulator->selectMatrixManipulator(num); @@ -675,7 +675,7 @@ int main(int argc, char** argv) viewer.setCameraManipulator( keyswitchManipulator.get() ); } - // set up event handlers + // set up event handlers { viewer.addEventHandler( new osgViewer::StatsHandler()); viewer.addEventHandler( new osgViewer::WindowSizeHandler() ); @@ -797,7 +797,7 @@ int main(int argc, char** argv) if (databasePagingOperation.get() && databasePagingOperation->_modelReadyToMerge) { OSG_NOTICE<<"Merging subgraph"<removeChildren(0,group->getNumChildren()); diff --git a/examples/osganimate/osganimate.cpp b/examples/osganimate/osganimate.cpp index b6cf5eb86..f8db214b7 100644 --- a/examples/osganimate/osganimate.cpp +++ b/examples/osganimate/osganimate.cpp @@ -136,9 +136,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength); - osg::Group* model = new osg::Group; + osg::ref_ptr model = new osg::Group; - osg::Node* glider = osgDB::readNodeFile("glider.osgt"); + osg::ref_ptr glider = osgDB::readRefNodeFile("glider.osgt"); if (glider) { const osg::BoundingSphere& bs = glider->getBound(); @@ -159,7 +159,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) model->addChild(xform); } - osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { const osg::BoundingSphere& bs = cessna->getBound(); @@ -173,26 +173,26 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) positioned->addChild(cessna); - osg::MatrixTransform* xform = new osg::MatrixTransform; + osg::ref_ptr xform = new osg::MatrixTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0)); xform->addChild(positioned); model->addChild(xform); } - return model; + return model.release(); } -osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique technique) +osg::ref_ptr createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique technique) { osg::Vec3 center(0.0f,0.0f,0.0f); float radius = 100.0f; - osg::Group* root = new osg::Group; + osg::ref_ptr root = new osg::Group; float baseHeight = center.z()-radius*0.5; - osg::Node* baseModel = createBase(osg::Vec3(center.x(), center.y(), baseHeight),radius); - osg::Node* movingModel = createMovingModel(center,radius*0.8f); + osg::ref_ptr baseModel = createBase(osg::Vec3(center.x(), center.y(), baseHeight),radius); + osg::ref_ptr movingModel = createMovingModel(center,radius*0.8f); if (overlay) { @@ -232,14 +232,14 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* model = createModel(overlay, technique); + osg::ref_ptr model = createModel(overlay, technique); if (!model) { return 1; } // tilt the scene so the default eye position is looking down on the model. - osg::MatrixTransform* rootnode = new osg::MatrixTransform; + osg::ref_ptr rootnode = new osg::MatrixTransform; rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(30.0f),1.0f,0.0f,0.0f)); rootnode->addChild(model); diff --git a/examples/osganimationhardware/osganimationhardware.cpp b/examples/osganimationhardware/osganimationhardware.cpp index d7f1fa701..afd56015c 100644 --- a/examples/osganimationhardware/osganimationhardware.cpp +++ b/examples/osganimationhardware/osganimationhardware.cpp @@ -1,14 +1,14 @@ -/* -*-c++-*- +/* -*-c++-*- * Copyright (C) 2009 Cedric Pinson * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -110,7 +110,7 @@ struct MyRigTransformHardware : public osgAnimation::RigTransformHardware osg::notify(osg::INFO) << "set vertex attrib " << ss.str() << std::endl; } - } + } for (int i = 0; i < nbAttribs; i++) { std::stringstream ss; @@ -134,7 +134,7 @@ struct SetupRigGeometry : public osg::NodeVisitor { bool _hardware; SetupRigGeometry( bool hardware = true) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _hardware(hardware) {} - + void apply(osg::Geode& geode) { for (unsigned int i = 0; i < geode.getNumDrawables(); i++) @@ -173,7 +173,7 @@ osg::Group* createCharacterInstance(osg::Group* character, bool hardware) anim->playAnimation(list[v].get()); v = (v + 1)%list.size(); } - + anim->playAnimation(list[v].get()); SetupRigGeometry switcher(hardware); @@ -196,9 +196,9 @@ int main (int argc, char* argv[]) while (psr.read("--software")) { hardware = false; } while (psr.read("--number", maxChar)) {} - - osg::ref_ptr root = dynamic_cast(osgDB::readNodeFiles(psr)); - if (!root) + osg::ref_ptr node = osgDB::readRefNodeFiles(psr); + osg::ref_ptr root = dynamic_cast(node.get()); + if (!root) { std::cout << psr.getApplicationName() <<": No data loaded" << std::endl; return 1; @@ -206,7 +206,7 @@ int main (int argc, char* argv[]) { osgAnimation::AnimationManagerBase* animationManager = dynamic_cast(root->getUpdateCallback()); - if(!animationManager) + if(!animationManager) { osg::notify(osg::FATAL) << "no AnimationManagerBase found, updateCallback need to animate elements" << std::endl; return 1; @@ -218,13 +218,13 @@ int main (int argc, char* argv[]) // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); diff --git a/examples/osganimationmorph/osganimationmorph.cpp b/examples/osganimationmorph/osganimationmorph.cpp index 75dcbc8d6..8506bb49f 100644 --- a/examples/osganimationmorph/osganimationmorph.cpp +++ b/examples/osganimationmorph/osganimationmorph.cpp @@ -1,14 +1,14 @@ -/* -*-c++-*- +/* -*-c++-*- * Copyright (C) 2008 Cedric Pinson * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -33,11 +33,11 @@ struct GeometryFinder : public osg::NodeVisitor { osg::ref_ptr _geom; GeometryFinder() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - void apply(osg::Geode& geode) + void apply(osg::Geode& geode) { if (_geom.valid()) return; - for (unsigned int i = 0; i < geode.getNumDrawables(); i++) + for (unsigned int i = 0; i < geode.getNumDrawables(); i++) { osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); if (geom) { @@ -50,7 +50,7 @@ struct GeometryFinder : public osg::NodeVisitor osg::ref_ptr getShape(const std::string& name) { - osg::ref_ptr shape0 = osgDB::readNodeFile(name); + osg::ref_ptr shape0 = osgDB::readRefNodeFile(name); if (shape0) { GeometryFinder finder; @@ -104,7 +104,7 @@ int main (int argc, char* argv[]) osg::Group* scene = new osg::Group; scene->addUpdateCallback(bam); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(morph); geode->addUpdateCallback(new osgAnimation::UpdateMorph("MorphNodeCallback")); diff --git a/examples/osganimationtimeline/osganimationtimeline.cpp b/examples/osganimationtimeline/osganimationtimeline.cpp index 9efedbe0e..677d682c7 100644 --- a/examples/osganimationtimeline/osganimationtimeline.cpp +++ b/examples/osganimationtimeline/osganimationtimeline.cpp @@ -163,7 +163,8 @@ int main (int argc, char* argv[]) file = psr[1]; // replace the manager - osg::Group* root = dynamic_cast(osgDB::readNodeFile(file)); + osg::ref_ptr loadedmodel = osgDB::readRefNodeFile(file); + osg::Group* root = dynamic_cast(loadedmodel.get()); if (!root) { osg::notify(osg::FATAL) << "can't read file " << file << std::endl; return 1; diff --git a/examples/osganimationviewer/AnimtkViewer.cpp b/examples/osganimationviewer/AnimtkViewer.cpp index a9a22a121..d4a59f423 100644 --- a/examples/osganimationviewer/AnimtkViewer.cpp +++ b/examples/osganimationviewer/AnimtkViewer.cpp @@ -127,7 +127,8 @@ int main(int argc, char** argv) osgViewer::Viewer viewer(arguments); osg::ref_ptr group = new osg::Group(); - osg::Group* node = dynamic_cast(osgDB::readNodeFiles(arguments)); //dynamic_cast(osgDB::readNodeFile(psr[1])); + osg::ref_ptr loadedmodel = osgDB::readRefNodeFiles(arguments); + osg::Group* node = dynamic_cast(loadedmodel.get()); if(!node) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; diff --git a/examples/osgatomiccounter/osgatomiccounter.cpp b/examples/osgatomiccounter/osgatomiccounter.cpp index 9f58c8642..6364d988e 100644 --- a/examples/osgatomiccounter/osgatomiccounter.cpp +++ b/examples/osgatomiccounter/osgatomiccounter.cpp @@ -165,7 +165,7 @@ int main(int argc, char** argv) viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { osg::Geometry * quad = osg::createTexturedQuadGeometry(osg::Vec3f(-2.0f, 0.0f, -2.0f), diff --git a/examples/osgautocapture/osgautocapture.cpp b/examples/osgautocapture/osgautocapture.cpp index 48e56459b..be19ef22a 100644 --- a/examples/osgautocapture/osgautocapture.cpp +++ b/examples/osgautocapture/osgautocapture.cpp @@ -28,7 +28,7 @@ #include #include #include - + #include #include @@ -41,7 +41,7 @@ public: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _foundNode(0) {} - + void apply(osg::Node& node) { T* result = dynamic_cast(&node); @@ -50,7 +50,7 @@ public: else traverse(node); } - + T* _foundNode; }; @@ -62,21 +62,21 @@ T* findTopMostNodeOfType(osg::Node* node) FindTopMostNodeOfTypeVisitor fnotv; node->accept(fnotv); - + return fnotv._foundNode; } /** Capture the frame buffer and write image to disk*/ class WindowCaptureCallback : public osg::Camera::DrawCallback { -public: +public: WindowCaptureCallback(GLenum readBuffer, const std::string& name): _readBuffer(readBuffer), _fileName(name) { _image = new osg::Image; } - + virtual void operator () (osg::RenderInfo& renderInfo) const { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) @@ -93,9 +93,9 @@ public: if (gc->getTraits()->alpha) pixelFormat = GL_RGBA; - else + else pixelFormat = GL_RGB; - + #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) if (pixelFormat == GL_RGB) { @@ -118,7 +118,7 @@ public: _image->readPixels(0, 0, width, height, pixelFormat, GL_UNSIGNED_BYTE); } - + if (!_fileName.empty()) { std::cout << "Writing to: " << _fileName << std::endl; @@ -126,7 +126,7 @@ public: } } -protected: +protected: GLenum _readBuffer; std::string _fileName; osg::ref_ptr _image; @@ -138,7 +138,7 @@ protected: class CustomRenderer : public osgViewer::Renderer { public: - CustomRenderer(osg::Camera* camera) + CustomRenderer(osg::Camera* camera) : osgViewer::Renderer(camera), _cullOnly(true) { @@ -162,19 +162,19 @@ public: { osgUtil::SceneView* sceneView = _sceneView[0].get(); if (!sceneView || _done ) return; - + updateSceneView(sceneView); - + osgViewer::View* view = dynamic_cast(_camera->getView()); if (view) sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue()); sceneView->inheritCullSettings(*(sceneView->getCamera())); sceneView->cull(); } - + bool _cullOnly; }; - + //=============================================================== // MAIN @@ -287,8 +287,8 @@ int main( int argc, char **argv ) } // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - if (!loadedModel) + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; @@ -309,7 +309,7 @@ int main( int argc, char **argv ) { osg::CoordinateSystemNode* csn = findTopMostNodeOfType(loadedModel.get()); if(!csn) return 1; - + // Compute eye point in world coordiantes osg::Vec3d eye; csn->getEllipsoidModel()->convertLatLongHeightToXYZ(lat, lon, alt, eye.x(), eye.y(), eye.z()); @@ -331,11 +331,11 @@ int main( int argc, char **argv ) osg::Vec3d up_cross_tangent = up ^ tangent; osg::Matrixd incline_matrix = osg::Matrixd::rotate(incline, up_cross_tangent); osg::Vec3d target = incline_matrix.preMult(tangent); - + // Roll by rotating the up vector around the target vector ... osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate(roll, target); up = roll_matrix.preMult(up); - + viewer.getCamera()->setViewMatrixAsLookAt(eye, eye+target, up); } else @@ -349,10 +349,10 @@ int main( int argc, char **argv ) keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); - viewer.setCameraManipulator( keyswitchManipulator.get() ); + viewer.setCameraManipulator( keyswitchManipulator.get() ); } - + // Optimize DatabasePager for auto-capture osgDB::DatabasePager* pager = viewer.getDatabasePager(); pager->setDoPreCompile(false); @@ -374,9 +374,9 @@ int main( int argc, char **argv ) // Initiate the first PagedLOD request viewer.frame(); - + osg::Timer_t beforeLoadTick = osg::Timer::instance()->tick(); - + // Keep updating and culling until full level of detail is reached while(!viewer.done() && pager->getRequestsInProgress()) { @@ -385,14 +385,14 @@ int main( int argc, char **argv ) viewer.renderingTraversals(); } // std::cout<tick(); std::cout<<"Load and Compile time = "<delta_s(beforeLoadTick, afterLoadTick)<<" seconds"<setCullOnly(false); - - + + //--- Capture the image!!! --- if (!activeMode) { diff --git a/examples/osgbillboard/osgbillboard.cpp b/examples/osgbillboard/osgbillboard.cpp index a6243e873..8c0a7727f 100644 --- a/examples/osgbillboard/osgbillboard.cpp +++ b/examples/osgbillboard/osgbillboard.cpp @@ -42,10 +42,10 @@ typedef std::vector< osg::ref_ptr > ImageList; /** create quad at specified position. */ -osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image=NULL) +osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::ref_ptr image) { // set up the Geometry. - osg::Geometry* geom = new osg::Geometry; + osg::ref_ptr geom = new osg::Geometry; osg::Vec3Array* coords = new osg::Vec3Array(4); (*coords)[0] = corner; @@ -80,13 +80,13 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const geom->setStateSet(stateset); } - return geom; + return geom.release(); } osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const osg::Vec3& ydir,const osg::Vec3& zdir) { // set up the Geometry. - osg::Geometry* geom = new osg::Geometry; + osg::ref_ptr geom = new osg::Geometry; osg::Vec3Array* coords = new osg::Vec3Array(6); (*coords)[0] = corner; @@ -121,20 +121,20 @@ osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const os stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); geom->setStateSet(stateset); - return geom; + return geom.release(); } -osg::Node* createModel() +osg::ref_ptr createModel() { // create the root node which will hold the model. - osg::Group* root = new osg::Group(); + osg::ref_ptr root = new osg::Group(); // add the drawable into a single geode to be shared... osg::Billboard* center = new osg::Billboard(); center->setMode(osg::Billboard::POINT_ROT_EYE); center->addDrawable( - createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Images/reflect.rgb")), + createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Images/reflect.rgb")), osg::Vec3(0.0f,0.0f,0.0f)); osg::Billboard* x_arrow = new osg::Billboard(); @@ -142,7 +142,7 @@ osg::Node* createModel() x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f)); x_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f)); x_arrow->addDrawable( - createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posx.png")), + createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posx.png")), osg::Vec3(5.0f,0.0f,0.0f)); osg::Billboard* y_arrow = new osg::Billboard(); @@ -150,7 +150,7 @@ osg::Node* createModel() y_arrow->setAxis(osg::Vec3(0.0f,1.0f,0.0f)); y_arrow->setNormal(osg::Vec3(1.0f,0.0f,0.0f)); y_arrow->addDrawable( - createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posy.png")), + createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posy.png")), osg::Vec3(0.0f,5.0f,0.0f)); osg::Billboard* z_arrow = new osg::Billboard(); @@ -158,7 +158,7 @@ osg::Node* createModel() z_arrow->setAxis(osg::Vec3(0.0f,0.0f,1.0f)); z_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f)); z_arrow->addDrawable( - createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posz.png")), + createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posz.png")), osg::Vec3(0.0f,0.0f,5.0f)); diff --git a/examples/osgblenddrawbuffers/osgblenddrawbuffers.cpp b/examples/osgblenddrawbuffers/osgblenddrawbuffers.cpp index 91ef96dc8..c8b203284 100644 --- a/examples/osgblenddrawbuffers/osgblenddrawbuffers.cpp +++ b/examples/osgblenddrawbuffers/osgblenddrawbuffers.cpp @@ -71,9 +71,17 @@ int main( int argc, char **argv ) bool useGlobalBlending = false; if ( arguments.read("--no-draw-buffers") ) useGlobalBlending = true; + + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); + if (!cessna) + { + OSG_NOTICE<<"Cannot not find model 'cessna.osg' to render"<addChild( osgDB::readNodeFile("cessna.osgt") ); + osg::ref_ptr mrtCam = createMRTCamera( textures ); + mrtCam->addChild( cessna ); // Create shader program to be used const char* mrtFragmentCode = { @@ -87,8 +95,8 @@ int main( int argc, char **argv ) osg::ref_ptr program = new osg::Program; program->addShader( new osg::Shader(osg::Shader::FRAGMENT, mrtFragmentCode) ); - osg::StateSet* ss = mrtCam->getOrCreateStateSet(); - ss->setAttributeAndModes( program.get() ); + osg::ref_ptr ss = mrtCam->getOrCreateStateSet(); + ss->setAttributeAndModes( program ); // Apply blending to the original scene in MRT if ( !useGlobalBlending ) @@ -103,8 +111,8 @@ int main( int argc, char **argv ) // Accept different blend/colormask attributes on multiple render targets osg::ref_ptr blend0 = new osg::BlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); osg::ref_ptr colormask3 = new osg::ColorMaski(3, false, true, false, true); - ss->setAttribute( blend0.get() ); - ss->setAttributeAndModes( colormask3.get() ); + ss->setAttribute( blend0 ); + ss->setAttributeAndModes( colormask3 ); } else { diff --git a/examples/osgblendequation/osgblendequation.cpp b/examples/osgblendequation/osgblendequation.cpp index c1a5e4558..2c0d993d7 100644 --- a/examples/osgblendequation/osgblendequation.cpp +++ b/examples/osgblendequation/osgblendequation.cpp @@ -139,10 +139,10 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cessnafire.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessnafire.osgt"); if (!loadedModel) { @@ -150,11 +150,11 @@ int main( int argc, char **argv ) return 1; } - osg::Group* root = new osg::Group; + osg::ref_ptr root = new osg::Group; root->addChild(loadedModel); - osg::StateSet* stateset = new osg::StateSet; + osg::ref_ptr stateset = new osg::StateSet; stateset->setDataVariance(osg::Object::DYNAMIC); osg::BlendEquation* blendEquation = new osg::BlendEquation(osg::BlendEquation::FUNC_ADD); diff --git a/examples/osgcallback/osgcallback.cpp b/examples/osgcallback/osgcallback.cpp index ea04bd6a2..499d65c10 100644 --- a/examples/osgcallback/osgcallback.cpp +++ b/examples/osgcallback/osgcallback.cpp @@ -239,10 +239,10 @@ int main( int argc, char **argv ) } else { - rootnode = osgDB::readNodeFiles(arguments); + rootnode = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!rootnode) rootnode = osgDB::readNodeFile("cow.osgt"); + if (!rootnode) rootnode = osgDB::readRefNodeFile("cow.osgt"); if (!rootnode) { diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index ec4fce8b2..af585549e 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -25,50 +25,50 @@ #include #include -class ModelHandler : public osgGA::GUIEventHandler +class ModelHandler : public osgGA::GUIEventHandler { -public: +public: ModelHandler(): _position(0) {} - + typedef std::vector Filenames; Filenames _filenames; unsigned int _position; - + void add(const std::string& filename) { _filenames.push_back(filename); } - + bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { osgViewer::Viewer* viewer = dynamic_cast(&aa); if (!viewer) return false; - + if (_filenames.empty()) return false; - + switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey()=='l') - { - osg::ref_ptr model = osgDB::readNodeFile( _filenames[_position] ); + { + osg::ref_ptr model = osgDB::readRefNodeFile( _filenames[_position] ); ++_position; if (_position>=_filenames.size()) _position = 0; - + if (model.valid()) { viewer->setSceneData(model.get()); } - + return true; } } default: break; } - + return false; } - + bool _done; }; @@ -76,12 +76,12 @@ public: void singleWindowMultipleCameras(osgViewer::Viewer& viewer) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) + if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); @@ -127,12 +127,12 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer) void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScreens) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) + if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); @@ -198,7 +198,7 @@ int main( int argc, char **argv ) // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - if (argc<2) + if (argc<2) { std::cout << argv[0] <<": requires filename argument." << std::endl; return 1; @@ -214,7 +214,7 @@ int main( int argc, char **argv ) osg::ref_ptr model; if (sharedModel) { - model = osgDB::readNodeFiles(arguments); + model = osgDB::readRefNodeFiles(arguments); if (!model) return 0; if (enableVBO) @@ -242,7 +242,7 @@ int main( int argc, char **argv ) if (sharedModel) viewer.setSceneData(model.get()); else { - osg::ref_ptr node = osgDB::readNodeFiles(arguments); + osg::ref_ptr node = osgDB::readRefNodeFiles(arguments); if (!node) return 0; if (enableVBO) @@ -268,19 +268,19 @@ int main( int argc, char **argv ) while (arguments.read("-p",pathfile)) { apm = new osgGA::AnimationPathManipulator(pathfile); - if (!apm.valid() || !(apm->valid()) ) + if (!apm.valid() || !(apm->valid()) ) { apm = 0; } } osgViewer::Viewer viewer(arguments); - + while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); } while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); } while (arguments.read("-d")) { viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); } while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); } - + bool limitNumberOfFrames = false; unsigned int maxFrames = 10; while (arguments.read("--run-till-frame-number",maxFrames)) { limitNumberOfFrames = true; } @@ -292,7 +292,7 @@ int main( int argc, char **argv ) if (apm.valid()) viewer.setCameraManipulator(apm.get()); else viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); - + viewer.addEventHandler(new osgViewer::StatsHandler); viewer.addEventHandler(new osgViewer::ThreadingHandler); @@ -300,7 +300,7 @@ int main( int argc, char **argv ) while (arguments.read("--config", configfile)) { osg::notify(osg::NOTICE)<<"Trying to read config file "< object = osgDB::readObjectFile(configfile); + osg::ref_ptr object = osgDB::readRefObjectFile(configfile); osgViewer::View* view = dynamic_cast(object.get()); if (view) { @@ -329,19 +329,19 @@ int main( int argc, char **argv ) else { // load the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); - if (!loadedModel) + if (!loadedModel) { std::cout << argv[0] <<": No data loaded." << std::endl; return 1; } - viewer.setSceneData(loadedModel.get()); + viewer.setSceneData(loadedModel); } - + viewer.realize(); unsigned int numFrames = 0; diff --git a/examples/osgcatch/osgcatch.cpp b/examples/osgcatch/osgcatch.cpp index 44b34c199..09cbb25e6 100644 --- a/examples/osgcatch/osgcatch.cpp +++ b/examples/osgcatch/osgcatch.cpp @@ -55,11 +55,11 @@ class Character : public osg::Referenced { public: Character(); - + void setCharacter(const std::string& filename, const std::string& name, const osg::Vec3& orgin, const osg::Vec3& width, const osg::Vec3& catchPos, float positionRatio); - + void setLives(const std::string& filename, const osg::Vec3& orgin, const osg::Vec3& delta, unsigned int numLives); - + void setCatches(const std::string& filename, const osg::Vec3& orgin, const osg::Vec3& delta, unsigned int numLives); void moveLeft(); @@ -71,7 +71,7 @@ public: void resetCatches(); bool addCatch(); - + bool looseLife(); osg::Vec3 getCurrentCenterOfBasket() const { return _character->getPosition()+_centerBasket; } @@ -91,12 +91,12 @@ public: unsigned int _numCatches; osg::ref_ptr _catchSwitch; - + osg::ref_ptr _objectsGroup; - + osg::Vec3 _centerBasket; float _radiusBasket; - + }; Character::Character(): @@ -117,7 +117,7 @@ void Character::setCharacter(const std::string& filename, const std::string& nam float _characterSize = _width.length()*0.2f; - osg::Image* image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image) { osg::Vec3 pos(-0.5f*_characterSize,0.0f,0.0f); @@ -136,14 +136,14 @@ void Character::setCharacter(const std::string& filename, const std::string& nam _character = new osg::PositionAttitudeTransform; _character->setName(name); _character->addChild(geode); - + moveTo(positionRatio); _centerBasket = width*catchPos.x() + height*catchPos.y() + pos; _radiusBasket = width.length()*catchPos.z(); } - + } void Character::setLives(const std::string& filename, const osg::Vec3& origin, const osg::Vec3& delta, unsigned int numLives) @@ -153,7 +153,7 @@ void Character::setLives(const std::string& filename, const osg::Vec3& origin, c _numLives = numLives; _livesSwitch = new osg::Switch; - osg::Image* image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image) { osg::StateSet* stateset = _livesSwitch->getOrCreateStateSet(); @@ -186,7 +186,7 @@ void Character::setCatches(const std::string& filename, const osg::Vec3& origin, _numCatches = 0; _catchSwitch = new osg::Switch; - osg::Image* image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image) { osg::StateSet* stateset = _catchSwitch->getOrCreateStateSet(); @@ -249,20 +249,20 @@ void Character::resetCatches() bool Character::addCatch() { if (!_catchSwitch || _numCatches>=_catchSwitch->getNumChildren()) return false; - + _catchSwitch->setValue(_numCatches,true); ++_numCatches; - + return true; } bool Character::looseLife() { if (!_livesSwitch || _numLives==0) return false; - + --_numLives; _livesSwitch->setValue(_numLives,false); - + return (_numLives!=0); } @@ -279,21 +279,21 @@ class CatchableObject : public osg::Referenced bool anyInside(const osg::Vec3& lower_left, const osg::Vec3& top_right); bool centerInside(const osg::Vec3& center, float radius); - + void explode(); - + bool dangerous() { return _dangerous; } void stop() { _stopped = true; } - + bool stopped() { return _stopped; } - + void setTimeToRemove(double time) { _timeToRemove=time; } - + double getTimeToRemove() { return _timeToRemove; } - + bool needToRemove(double time) { return _timeToRemove>=0.0 && time>_timeToRemove; } - + osg::ref_ptr _object; osg::Vec3 _velocity; float _mass; @@ -307,7 +307,7 @@ class CatchableObject : public osg::Referenced static void setUpCatchablesMap(const FileList& fileList); public: - + // update position and velocity void update(double dt); @@ -317,7 +317,7 @@ class CatchableObject : public osg::Referenced _viscosity = v; _viscosityCoefficient = 6 * osg::PI * _viscosity; } - + /// Get the viscosity of the fluid. inline float getFluidViscosity() const { return _viscosity; } @@ -330,17 +330,17 @@ class CatchableObject : public osg::Referenced /// Get the density of the fluid. inline float getFluidDensity() const { return _density; } - - + + /// Set the wind vector. inline void setWind(const osg::Vec3& wind) { _wind = wind; } - + /// Get the wind vector. inline const osg::Vec3& getWind() const { return _wind; } - + /// Set the acceleration vector. inline void setAcceleration(const osg::Vec3& v) { _acceleration = v; } - + /// Get the acceleration vector. inline const osg::Vec3& getAcceleration() const { return _acceleration; } @@ -349,22 +349,22 @@ class CatchableObject : public osg::Referenced */ inline void setToGravity(float scale = 1.0f) { _acceleration.set(0, 0, -9.81f*scale); } - /// Set the fluid parameters as for air (20°C temperature). + /// Set the fluid parameters as for air (20C temperature). inline void setFluidToAir() { setToGravity(1.0f); setFluidDensity(1.2929f); setFluidViscosity(1.8e-5f); } - - /// Set the fluid parameters as for pure water (20°C temperature). + + /// Set the fluid parameters as for pure water (20C temperature). inline void setFluidToWater() { setToGravity(1.0f); setFluidDensity(1.0f); setFluidViscosity(1.002e-3f); } - + protected: @@ -375,15 +375,15 @@ class CatchableObject : public osg::Referenced float _viscosityCoefficient; float _densityCoefficeint; - - + + }; CatchableObject::CatchableObject() { _stopped = false; _dangerous = false; - + _timeToRemove = -1.0; // do not remove. setFluidToAir(); } @@ -395,14 +395,14 @@ void CatchableObject::setUpCatchablesMap(const FileList& fileList) ++itr) { const std::string& filename = *itr; - osg::Image* image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image) { osg::ref_ptr stateset = new osg::StateSet(); stateset->setTextureAttributeAndModes(0,new osg::Texture2D(image),osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - + osg::Vec3 width((float)(image->s())/(float)(image->t()),0.0f,0.0); osg::Vec3 height(0.0f,0.0f,1.0f); osg::Vec3 pos = (width+height)*-0.5f; @@ -455,8 +455,8 @@ void CatchableObject::update(double dt) osg::Vec3 force = _acceleration * (_mass - _density*Volume); // compute force due to friction - osg::Vec3 relative_wind = _velocity-_wind; - force -= relative_wind * Area * (_viscosityCoefficient + _densityCoefficeint*relative_wind.length()); + osg::Vec3 relative_wind = _velocity-_wind; + force -= relative_wind * Area * (_viscosityCoefficient + _densityCoefficeint*relative_wind.length()); // divide force by mass to get acceleration. _velocity += force*(dt/_mass); @@ -466,7 +466,7 @@ void CatchableObject::update(double dt) bool CatchableObject::anyInside(const osg::Vec3& lower_left, const osg::Vec3& upper_right) { osg::Vec3 pos = _object->getPosition(); - + if (pos.x()+_radius < lower_left.x()) return false; if (pos.x()-_radius > upper_right.x()) return false; if (pos.z()+_radius < lower_left.z()) return false; @@ -513,20 +513,20 @@ class GameEventHandler : public osgGA::GUIEventHandler public: GameEventHandler(); - + META_Object(osgStereImageApp,GameEventHandler); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); - + virtual void getUsage(osg::ApplicationUsage& usage) const; - + osg::Matrix getCameraPosition(); - + void compileGLObjects(osg::State& state) { osgUtil::GLObjectsVisitor compile; compile.setState(&state); - + for(ObjectMap::iterator itr = s_objectMap.begin(); itr != s_objectMap.end(); ++itr) @@ -534,14 +534,14 @@ public: itr->second->accept(compile); } } - + osg::Node* createScene(); - + void setFOVY(float fovy) { _fovy = fovy; } float getFOVY() const { return _fovy; } - + void createNewCatchable(); - + void clearCatchables() { for(CatchableObjectList::iterator itr=_catchableObjects.begin(); @@ -562,7 +562,7 @@ public: _catchableObjects.clear(); } - + void resetLevel() { _level = 0; @@ -573,7 +573,7 @@ public: _levelStartTick = osg::Timer::instance()->tick(); } - + void nextLevel() { ++_level; @@ -596,12 +596,12 @@ public: void resetGame() { _currentScore = 0; - + updateTextWithScore(); clearCatchables(); resetLevel(); - + for(unsigned int i=0;i<_numberOfPlayers;++i) { _players[i].reset(); @@ -629,12 +629,12 @@ public: livesPosition = _originBaseLine+osg::Vec3(1000.0f,-0.5f,000.0f); catchesPosition = _originBaseLine+osg::Vec3(1100.0f,-0.5f,0.0f); } - + switch(player) { case PLAYER_GIRL: { - std::string player_one = "Catch/girl.png"; + std::string player_one = "Catch/girl.png"; osg::Vec3 catchPos(0.2, 0.57, 0.34); _players[_numberOfPlayers].setCharacter(player_one,"girl", _originBaseLine + osg::Vec3(0.0f,-1.0f,0.0f), _widthBaseLine, catchPos, 0.5f); @@ -646,7 +646,7 @@ public: } case PLAYER_BOY: { - std::string player_two = "Catch/boy.png"; + std::string player_two = "Catch/boy.png"; osg::Vec3 catchPos(0.8, 0.57, 0.34); _players[_numberOfPlayers].setCharacter(player_two,"boy", _originBaseLine + osg::Vec3(0.0f,-2.0f,0.0f), _widthBaseLine, catchPos, 0.5f); @@ -656,10 +656,10 @@ public: ++_numberOfPlayers; break; } - } + } } - - + + typedef std::vector< osg::ref_ptr > TextList; void updateScoreWithCatch() @@ -673,8 +673,8 @@ public: osg::Timer_t newTick = osg::Timer::instance()->tick(); double timeForLevel = osg::Timer::instance()->delta_s(_levelStartTick, newTick); - // a ten second level gets you 10 points, - // a twenty second levels gets you 5 points. + // a ten second level gets you 10 points, + // a twenty second levels gets you 5 points. _currentScore += static_cast(10000.0f/(timeForLevel*timeForLevel)); updateTextWithScore(); @@ -685,24 +685,24 @@ public: { std::ostringstream os; os<<"Score: "<<_currentScore; - + std::string textString = os.str(); - + for(TextList::iterator itr = _scoreTextList.begin(); itr != _scoreTextList.end(); ++itr) { (*itr)->setText(textString); } - } - + } + void updateLevelText() { std::ostringstream os; os<<"Level: "<<_level+1; _levelText->setText(os.str()); } - + protected: @@ -715,45 +715,45 @@ protected: osg::Vec3 _originBaseLine; osg::Vec3 _widthBaseLine; float _characterSize; - + float _fovy; unsigned _level; - + float _chanceOfExplodingAtStart; float _initialNumDropsPerSecond; - + osg::ref_ptr _gameSwitch; osg::ref_ptr _gameGroup; osg::ref_ptr _levelSwitch; - + unsigned int _currentIndex; unsigned int _welcomeIndex; unsigned int _lostIndex; unsigned int _wonIndex; unsigned int _gameIndex; - + osg::Timer_t _levelStartTick; unsigned int _currentScore; - + osg::ref_ptr _levelText; TextList _scoreTextList; - + unsigned int _numberOfPlayers; Character _players[2]; typedef std::list< osg::ref_ptr > CatchableObjectList; CatchableObjectList _catchableObjects; - + FileList _backgroundFiles; FileList _benignCatachables; bool _leftKeyPressed; bool _rightKeyPressed; - + osg::ref_ptr _dummyCatchable; - - + + }; @@ -791,11 +791,11 @@ GameEventHandler::GameEventHandler() _benignCatachables.push_back("Catch/t.png"); _benignCatachables.push_back("Catch/u.png"); _benignCatachables.push_back("Catch/ball.png"); - + CatchableObject::setUpCatchablesMap(_benignCatachables); - + _currentScore = 0; - + setFOVY(osg::DegreesToRadians(60.0)); } @@ -817,7 +817,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA default: return false; } - + } else if (_currentIndex==_lostIndex) { @@ -834,7 +834,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA default: return false; } - + } else if (_currentIndex==_wonIndex) { @@ -851,7 +851,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA default: return false; } - + } else if (_currentIndex==_gameIndex) { @@ -888,7 +888,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA for(unsigned int i=0;i<_numberOfPlayers;++i) { bool inBasket = ((*itr)->centerInside(_players[i].getCurrentCenterOfBasket(),_players[i].getCurrentRadiusOfBasket())); - + if ((*itr)->dangerous()) { if ((*itr)->anyInside(_players[i].getLowerLeft(),_players[i].getUpperRight()) || inBasket) @@ -912,7 +912,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA { // player has caught a safe object. updateScoreWithCatch(); - + if (!_players[i].addCatch()) { _players[i].resetCatches(); @@ -930,7 +930,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA } } - if (!(*itr)->anyInside(_origin, _origin+_width+_height) || + if (!(*itr)->anyInside(_origin, _origin+_width+_height) || (*itr)->needToRemove(ea.getTime()) || removeEntry) { @@ -968,7 +968,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA float numDropsPerSecond = _initialNumDropsPerSecond * (_level+1); float r = (float)rand()/(float)RAND_MAX; if (r < deltaTime*numDropsPerSecond) - { + { createNewCatchable(); } @@ -1015,7 +1015,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA return false; } } - return false; + return false; } void GameEventHandler::getUsage(osg::ApplicationUsage&) const @@ -1026,9 +1026,9 @@ osg::Matrix GameEventHandler::getCameraPosition() { osg::Matrix cameraPosition; osg::Vec3 center = _origin+(_width+_height)*0.5f; - + float distance = _height.length()/(2.0f*tanf(_fovy*0.5f)); - + cameraPosition.makeLookAt(center-osg::Vec3(0.0f,distance,0.0f),center,osg::Vec3(0.0f,0.0f,1.0f)); return cameraPosition; } @@ -1036,8 +1036,8 @@ osg::Matrix GameEventHandler::getCameraPosition() osg::Node* GameEventHandler::createScene() { _gameSwitch = new osg::Switch; - - // create a dummy catchable to load all the particule textures to reduce + + // create a dummy catchable to load all the particule textures to reduce // latency later on.. _dummyCatchable = new CatchableObject; _dummyCatchable->setObject("Catch/a.png","a",osg::Vec3(0.0f,0.0,0.0f),1.0f,osg::Vec3(0.0f,0.0,0.0f)); @@ -1045,10 +1045,10 @@ osg::Node* GameEventHandler::createScene() // set up welcome subgraph { - osg::Geode* geode = new osg::Geode; + osg::ref_ptr geode = new osg::Geode; // set up the background - osg::Image* image = osgDB::readImageFile("Catch/Welcome.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Catch/Welcome.jpg"); if (image) { osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height); @@ -1057,7 +1057,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(geometry); } - + // set up the text osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.8f -osg::Vec3(0.0f,0.1f,0.0f); { @@ -1072,7 +1072,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(text); } - + { textPosition -= _height*0.25f; osgText::Text* text = new osgText::Text; @@ -1121,9 +1121,9 @@ osg::Node* GameEventHandler::createScene() // set up you've lost subgraph { - osg::Geode* geode = new osg::Geode; + osg::ref_ptr geode = new osg::Geode; - osg::Image* image = osgDB::readImageFile("Catch/YouLost.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Catch/YouLost.jpg"); if (image) { osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height); @@ -1132,7 +1132,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(geometry); } - + // set up the text osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.75f -osg::Vec3(0.0f,0.1f,0.0f); { @@ -1147,7 +1147,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(text); } - + { textPosition -= _height*0.25f; osgText::Text* text = new osgText::Text; @@ -1184,9 +1184,9 @@ osg::Node* GameEventHandler::createScene() // set up you've won subgraph { - osg::Geode* geode = new osg::Geode; + osg::ref_ptr geode = new osg::Geode; - osg::Image* image = osgDB::readImageFile("Catch/YouWon.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Catch/YouWon.jpg"); if (image) { osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height); @@ -1195,7 +1195,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(geometry); } - + // set up the text osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.75f -osg::Vec3(0.0f,0.1f,0.0f); { @@ -1210,7 +1210,7 @@ osg::Node* GameEventHandler::createScene() geode->addDrawable(text); } - + { textPosition -= _height*0.25f; osgText::Text* text = new osgText::Text; @@ -1258,7 +1258,7 @@ osg::Node* GameEventHandler::createScene() _gameGroup->addChild(_players[i]._character.get()); _gameGroup->addChild(_players[i]._livesSwitch.get()); _gameGroup->addChild(_players[i]._catchSwitch.get()); - } + } // background { @@ -1269,7 +1269,7 @@ osg::Node* GameEventHandler::createScene() ++itr) { - osg::Image* image = osgDB::readImageFile(*itr); + osg::ref_ptr image = osgDB::readRefImageFile(*itr); if (image) { osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height); @@ -1305,7 +1305,7 @@ osg::Node* GameEventHandler::createScene() osg::Geode* geode = new osg::Geode; geode->addDrawable(text); _scoreTextList.push_back(text); - + textPosition -= _height*0.05f; _levelText = new osgText::Text; _levelText->setText("Level : 0"); @@ -1317,7 +1317,7 @@ osg::Node* GameEventHandler::createScene() _levelText->setAxisAlignment(osgText::Text::XZ_PLANE); geode->addDrawable(_levelText.get()); - + _gameGroup->addChild(geode); @@ -1325,7 +1325,7 @@ osg::Node* GameEventHandler::createScene() } - + _currentIndex = _welcomeIndex; _gameSwitch->setSingleChildOn(_currentIndex); @@ -1338,7 +1338,7 @@ void GameEventHandler::createNewCatchable() unsigned int catachableIndex = (unsigned int)((float)_benignCatachables.size()*(float)rand()/(float)RAND_MAX); if (catachableIndex>=_benignCatachables.size()) catachableIndex = _benignCatachables.size()-1; - + const std::string& filename = _benignCatachables[catachableIndex]; float ratio = ((float)rand() / (float)RAND_MAX); @@ -1356,7 +1356,7 @@ void GameEventHandler::createNewCatchable() float r = (float)rand() / (float)RAND_MAX; if (r < _chanceOfExplodingAtStart) { - catchableObject->explode(); + catchableObject->explode(); } _gameGroup->addChild(catchableObject->_object.get()); @@ -1369,7 +1369,7 @@ class CompileStateCallback : public osg::Operation osg::Referenced(true), osg::Operation("CompileStateCallback", false), _gameEventHandler(eh) {} - + virtual void operator () (osg::Object* object) { osg::GraphicsContext* context = dynamic_cast(object); @@ -1380,7 +1380,7 @@ class CompileStateCallback : public osg::Operation _gameEventHandler->compileGLObjects(*(context->getState())); } } - + OpenThreads::Mutex _mutex; GameEventHandler* _gameEventHandler; }; @@ -1390,7 +1390,7 @@ 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 use node masks to create stereo images."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); @@ -1410,8 +1410,8 @@ int main( int argc, char **argv ) while (arguments.read("--boy")) seh->addPlayer(GameEventHandler::PLAYER_BOY); while (arguments.read("--girl")) seh->addPlayer(GameEventHandler::PLAYER_GIRL); - - + + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { @@ -1428,8 +1428,8 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - - + + // enable the image cache so we don't need to keep loading the particle files osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options; options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_IMAGES); @@ -1454,7 +1454,7 @@ int main( int argc, char **argv ) double fovy, aspectRatio, zNear, zFar; viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - seh->setFOVY(osg::DegreesToRadians(fovy)); + seh->setFOVY(osg::DegreesToRadians(fovy)); // todo for osgViewer - create default set up. viewer.setUpViewAcrossAllScreens(); @@ -1472,7 +1472,7 @@ int main( int argc, char **argv ) } // todo for osgViewer - implement warp pointer that can be done relative to different coordinate frames - // viewer.requestWarpPointer(0.5f,0.5f); + // viewer.requestWarpPointer(0.5f,0.5f); while( !viewer.done() ) { @@ -1480,8 +1480,8 @@ int main( int argc, char **argv ) // fire off the cull and draw traversals of the scene. viewer.frame(); - + } - + return 0; } diff --git a/examples/osgclip/osgclip.cpp b/examples/osgclip/osgclip.cpp index 3b74bd27b..b6f8e5cb1 100644 --- a/examples/osgclip/osgclip.cpp +++ b/examples/osgclip/osgclip.cpp @@ -40,10 +40,9 @@ #include -osg::Node* decorate_with_clip_node(osg::Node* subgraph) +osg::ref_ptr decorate_with_clip_node(const osg::ref_ptr& subgraph) { - osg::Group* rootnode = new osg::Group; - + osg::ref_ptr rootnode = new osg::Group; // create wireframe view of the model so the user can see // what parts are being culled away. @@ -52,7 +51,7 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph) osg::PolygonMode* polymode = new osg::PolygonMode; polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); - + osg::Group* wireframe_subgraph = new osg::Group; wireframe_subgraph->setStateSet(stateset); wireframe_subgraph->addChild(subgraph); @@ -80,7 +79,7 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph) // more complex approach to managing ClipNode, allowing // ClipNode node to be transformed independently from the subgraph // that it is clipping. - + osg::MatrixTransform* transform= new osg::MatrixTransform; osg::NodeCallback* nc = new osg::AnimationPathCallback(subgraph->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); @@ -117,11 +116,11 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); if (!loadedModel) @@ -129,16 +128,16 @@ int main( int argc, char **argv ) osg::notify(osg::NOTICE)<<"Please specify a filename on the command line"< rootnode = decorate_with_clip_node(loadedModel); + // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + osgViewer::Viewer viewer; - + // set the scene to render viewer.setSceneData(rootnode); diff --git a/examples/osgcluster/osgcluster.cpp b/examples/osgcluster/osgcluster.cpp index b8994cfc7..d895c6c93 100644 --- a/examples/osgcluster/osgcluster.cpp +++ b/examples/osgcluster/osgcluster.cpp @@ -505,7 +505,7 @@ int main( int argc, char **argv ) } // load model. - osg::ref_ptr rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); // set the scene to render viewer.setSceneData(rootnode.get()); diff --git a/examples/osgcompositeviewer/osgcompositeviewer.cpp b/examples/osgcompositeviewer/osgcompositeviewer.cpp index 6cc732653..3e664d325 100644 --- a/examples/osgcompositeviewer/osgcompositeviewer.cpp +++ b/examples/osgcompositeviewer/osgcompositeviewer.cpp @@ -133,7 +133,7 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); if (!scene) { @@ -149,7 +149,7 @@ int main( int argc, char **argv ) { osgViewer::View* view = new osgViewer::View; view->setName("Single view"); - view->setSceneData(osgDB::readNodeFile("fountain.osgt")); + view->setSceneData(osgDB::readRefNodeFile("fountain.osgt")); view->addEventHandler( new osgViewer::StatsHandler ); @@ -283,7 +283,7 @@ int main( int argc, char **argv ) view->setName("View three"); viewer.addView(view); - view->setSceneData(osgDB::readNodeFile("cessnafire.osgt")); + view->setSceneData(osgDB::readRefNodeFile("cessnafire.osgt")); view->getCamera()->setName("Cam three"); view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0); diff --git a/examples/osgcomputeshaders/osgcomputeshaders.cpp b/examples/osgcomputeshaders/osgcomputeshaders.cpp index ef1cb2e48..87073cfe5 100644 --- a/examples/osgcomputeshaders/osgcomputeshaders.cpp +++ b/examples/osgcomputeshaders/osgcomputeshaders.cpp @@ -43,7 +43,7 @@ static const char* computeSrc = { int main( int argc, char** argv ) { osg::ArgumentParser arguments( &argc, argv ); - + // Create the texture as both the output of compute shader and the input of a normal quad osg::ref_ptr tex2D = new osg::Texture2D; tex2D->setTextureSize( 512, 512 ); @@ -53,23 +53,23 @@ int main( int argc, char** argv ) tex2D->setSourceFormat( GL_RED ); tex2D->setSourceType( GL_FLOAT ); tex2D->bindToImageUnit( 0, osg::Texture::WRITE_ONLY ); // So we can use 'image2D' in the compute shader - + // The compute shader can't work with other kinds of shaders // It also requires the work group numbers. Setting them to 0 will disable the compute shader osg::ref_ptr computeProg = new osg::Program; computeProg->setComputeGroups( 512/16, 512/16, 1 ); computeProg->addShader( new osg::Shader(osg::Shader::COMPUTE, computeSrc) ); - + // Create a node for outputting to the texture. // It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then. // TODO: maybe we can have a custom drawable which also will implement glMemoryBarrier? - osg::Node* sourceNode = osgDB::readNodeFile("axes.osgt"); + osg::ref_ptr sourceNode = osgDB::readRefNodeFile("axes.osgt"); if ( !sourceNode ) sourceNode = new osg::Node; sourceNode->setDataVariance( osg::Object::DYNAMIC ); sourceNode->getOrCreateStateSet()->setAttributeAndModes( computeProg.get() ); sourceNode->getOrCreateStateSet()->addUniform( new osg::Uniform("targetTex", (int)0) ); sourceNode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2D.get() ); - + // Display the texture on a quad. We will also be able to operate on the data if reading back to CPU side osg::Geometry* geom = osg::createTexturedQuadGeometry( osg::Vec3(), osg::Vec3(1.0f,0.0f,0.0f), osg::Vec3(0.0f,0.0f,1.0f) ); @@ -77,12 +77,12 @@ int main( int argc, char** argv ) quad->addDrawable( geom ); quad->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2D.get() ); - + // Create the scene graph and start the viewer osg::ref_ptr scene = new osg::Group; scene->addChild( sourceNode ); scene->addChild( quad.get() ); - + osgViewer::Viewer viewer; viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler ); diff --git a/examples/osgcopy/osgcopy.cpp b/examples/osgcopy/osgcopy.cpp index 79c614f71..6e9087c6a 100644 --- a/examples/osgcopy/osgcopy.cpp +++ b/examples/osgcopy/osgcopy.cpp @@ -33,12 +33,12 @@ #include -// Customize the CopyOp so that we add our own verbose +// Customize the CopyOp so that we add our own verbose // output of what's being copied. class MyCopyOp : public osg::CopyOp { public: - + inline MyCopyOp(CopyFlags flags=SHALLOW_COPY): osg::CopyOp(flags), _indent(0), @@ -46,11 +46,11 @@ class MyCopyOp : public osg::CopyOp inline void moveIn() const { _indent += _step; } inline void moveOut() const { _indent -= _step; } - inline void writeIndent() const + inline void writeIndent() const { for(int i=0;i<_indent;++i) std::cout << " "; } - + virtual osg::Referenced* operator() (const osg::Referenced* ref) const { writeIndent(); std::cout << "copying Referenced "<(node); } - + protected: - + // must be mutable since CopyOp is passed around as const to // the various clone/copy constructors. mutable std::map _nodeCopyMap; @@ -198,19 +198,19 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); if (!rootnode) { osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."< mycopy = dynamic_cast(rootnode->clone(osg::CopyOp::DEEP_COPY_ALL)); @@ -219,7 +219,7 @@ int main( int argc, char **argv ) // note, we need the dyanmic_cast because MS Visual Studio can't handle covarient // return types, so that clone has return just Object*. bahh hum bug osg::ref_ptr deep_copy = dynamic_cast(rootnode->clone(MyCopyOp(osg::CopyOp::DEEP_COPY_ALL))); - + std::cout << "----------------------------------------------------------------"<(rootnode->clone(osg::CopyOp::DEEP_COPY_NODES | DEEP_COPY_DRAWABLES)); // Which shares state but creates copies of all nodes and drawables (which contain the geometry). - // + // // You may also want to subclass from CopyOp to provide finer grained control of what gets shared (shallow copy) vs // cloned (deep copy). - + // ------------- End of copy specific code ------------------------------------------------------- - + // set the scene to render viewer.setSceneData(rootnode); diff --git a/examples/osgcubemap/osgcubemap.cpp b/examples/osgcubemap/osgcubemap.cpp index 47c3dd3cb..843186485 100644 --- a/examples/osgcubemap/osgcubemap.cpp +++ b/examples/osgcubemap/osgcubemap.cpp @@ -95,10 +95,10 @@ int main(int argc, char *argv[]) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!rootnode) rootnode = osgDB::readNodeFile("cessna.osgt"); + if (!rootnode) rootnode = osgDB::readRefNodeFile("cessna.osgt"); if (!rootnode) { @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) } // create specular highlights - create_specular_highlights(rootnode); + create_specular_highlights(rootnode.get()); // run optimization over the scene graph osgUtil::Optimizer optimzer; diff --git a/examples/osgdatabaserevisions/osgdatabaserevisions.cpp b/examples/osgdatabaserevisions/osgdatabaserevisions.cpp index f3b80ccdf..37cf623d2 100644 --- a/examples/osgdatabaserevisions/osgdatabaserevisions.cpp +++ b/examples/osgdatabaserevisions/osgdatabaserevisions.cpp @@ -1,9 +1,9 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This application is open source and may be redistributed and/or modified + * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial applications, * as long as this copyright notice is maintained. - * + * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -50,7 +50,7 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->write(std::cout, helpType); return 1; } - + // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { @@ -81,7 +81,7 @@ int main(int argc, char** argv) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -95,13 +95,13 @@ int main(int argc, char** argv) // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); @@ -129,8 +129,8 @@ int main(int argc, char** argv) // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFile(file); - if (!loadedModel) + osg::ref_ptr loadedModel = osgDB::readRefNodeFile(file); + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; diff --git a/examples/osgdelaunay/osgdelaunay.cpp b/examples/osgdelaunay/osgdelaunay.cpp index 72a8ff466..10a444e12 100644 --- a/examples/osgdelaunay/osgdelaunay.cpp +++ b/examples/osgdelaunay/osgdelaunay.cpp @@ -224,7 +224,7 @@ public: osg::StateSet *dstate= gm->getOrCreateStateSet( ); dstate->setMode( GL_LIGHTING, osg::StateAttribute::ON ); - osg::Image* image = osgDB::readImageFile("Images/Brick-Std-Orange.TGA"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/Brick-Std-Orange.TGA"); if (image) { osg::Texture2D* txt = new osg::Texture2D; @@ -354,7 +354,7 @@ osg::Group *makedelaunay(const int ndcs) osg::Vec3Array *points=new osg::Vec3Array; - osg::Image* image = osgDB::readImageFile("Images/blueFlowers.png"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/blueFlowers.png"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -817,7 +817,7 @@ osg::Geometry *WallConstraint::makeWallGeometry() const { osg::ref_ptr gm=new osg::Geometry; // the wall if (texture!="") { - osg::Image* image = osgDB::readImageFile(texture.c_str()); + osg::ref_ptr image = osgDB::readRefImageFile(texture.c_str()); if (image) { osg::Texture2D* txt = new osg::Texture2D; @@ -1005,7 +1005,7 @@ deprecated_osg::Geometry *ArealConstraint::makeWallGeometry( osg::Vec3Array *pt) tscx->retessellatePolygons(*(edges)); // find all edges if (walltexture!="") { - osg::Image* image = osgDB::readImageFile(walltexture.c_str()); + osg::ref_ptr image = osgDB::readRefImageFile(walltexture.c_str()); if (image) { osg::Texture2D* txt = new osg::Texture2D; @@ -1062,7 +1062,7 @@ deprecated_osg::Geometry * ArealConstraint::makeAreal( osg::Vec3Array *points) gm->setNormalArray(getCanopyNormals(points)); gm->setNormalBinding(deprecated_osg::Geometry::BIND_PER_PRIMITIVE); gm->setTexCoordArray(0,getCanopyTexcoords(points)); - osg::Image* image = osgDB::readImageFile(texture); + osg::ref_ptr image = osgDB::readRefImageFile(texture); if (image) { osg::Texture2D* txt = new osg::Texture2D; @@ -1238,7 +1238,7 @@ deprecated_osg::Geometry * LinearConstraint::makeGeometry(const osg::Vec3Array * if (_midline->size()>0) { osg::ref_ptr locpts=getPoints(points); if (texture!="") { - osg::Image* image = osgDB::readImageFile(texture.c_str()); + osg::ref_ptr image = osgDB::readRefImageFile(texture.c_str()); if (image) { osg::Texture2D* txt = new osg::Texture2D; diff --git a/examples/osgdepthpartition/osgdepthpartition.cpp b/examples/osgdepthpartition/osgdepthpartition.cpp index 14f1da2cc..1a7d5a6d1 100644 --- a/examples/osgdepthpartition/osgdepthpartition.cpp +++ b/examples/osgdepthpartition/osgdepthpartition.cpp @@ -139,7 +139,7 @@ int main( int argc, char **argv ) bool needToSetHomePosition = false; // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); // if one hasn't been loaded create an earth and sun test model. if (!scene) diff --git a/examples/osgdepthpeeling/osgdepthpeeling.cpp b/examples/osgdepthpeeling/osgdepthpeeling.cpp index f8b887db6..43e53f05e 100644 --- a/examples/osgdepthpeeling/osgdepthpeeling.cpp +++ b/examples/osgdepthpeeling/osgdepthpeeling.cpp @@ -18,7 +18,7 @@ #include -#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 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 = new DePee(rootNode, - modelGroupTransform, + osg::ref_ptr 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(); diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index a27cb0fbd..40da27ed0 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -703,10 +703,10 @@ int main(int argc, char** argv) osgViewer::Viewer viewer(arguments); // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); if (!loadedModel) { @@ -731,7 +731,7 @@ int main(int argc, char** argv) } else { - osg::Node* distortionNode = createDistortionSubgraph( options, loadedModel, viewer.getCamera()->getClearColor()); + osg::Node* distortionNode = createDistortionSubgraph( options, loadedModel.get(), viewer.getCamera()->getClearColor()); viewer.setSceneData( distortionNode ); } diff --git a/examples/osgdrawinstanced/osgdrawinstanced.cpp b/examples/osgdrawinstanced/osgdrawinstanced.cpp index 65b12aa5e..87d856e7d 100644 --- a/examples/osgdrawinstanced/osgdrawinstanced.cpp +++ b/examples/osgdrawinstanced/osgdrawinstanced.cpp @@ -97,7 +97,7 @@ createStateSet() ss->setAttribute( program.get(), osg::StateAttribute::ON | osg::StateAttribute::PROTECTED ); - osg::ref_ptr< osg::Image> iLogo = osgDB::readImageFile( "Images/osg128.png" ); + osg::ref_ptr< osg::Image> iLogo = osgDB::readRefImageFile( "Images/osg128.png" ); if( !iLogo.valid() ) { osg::notify( osg::ALWAYS ) << "Can't open image file osg128.png" << std::endl; diff --git a/examples/osgfadetext/osgfadetext.cpp b/examples/osgfadetext/osgfadetext.cpp index ba329529a..37b0eafe2 100644 --- a/examples/osgfadetext/osgfadetext.cpp +++ b/examples/osgfadetext/osgfadetext.cpp @@ -44,21 +44,21 @@ osg::Node* createEarth() osg::TessellationHints* hints = new osg::TessellationHints; hints->setDetailRatio(5.0f); - + osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0,0.0,0.0), osg::WGS_84_RADIUS_POLAR), hints); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(sd); - + std::string filename = osgDB::findDataFile("Images/land_shallow_topo_2048.jpg"); - geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile(filename))); - + geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readRefImageFile(filename))); + osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode; csn->setEllipsoidModel(new osg::EllipsoidModel()); csn->addChild(geode); - + return csn; - + } osgText::Text* createText(osg::EllipsoidModel* ellipsoid, double latitude, double longitude, double height, const std::string& str) @@ -78,7 +78,7 @@ osgText::Text* createText(osg::EllipsoidModel* ellipsoid, double latitude, doubl text->setCharacterSize(300000.0f); text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); text->setAutoRotateToScreen(true); - + return text; } @@ -87,10 +87,10 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid) osg::Group* group = new osg::Group; group->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); - + osg::Geode* geode = new osg::Geode; group->addChild(geode); - + std::vector textList; textList.push_back("Town"); textList.push_back("City"); @@ -99,7 +99,7 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid) textList.push_back("Mountain"); textList.push_back("Road"); textList.push_back("Lake"); - + unsigned int numLat = 15; unsigned int numLong = 20; double latitude = 0.0; @@ -118,7 +118,7 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid) } return group; -} +} int main(int, char**) @@ -128,10 +128,10 @@ int main(int, char**) viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); viewer.getCamera()->setNearFarRatio(0.00001f); - + // read the scene from the list of file specified commandline args. osg::ref_ptr root = createEarth(); - + if (!root) return 0; // add a viewport to the viewer and attach the scene graph. @@ -142,7 +142,7 @@ int main(int, char**) { // add fade text around the globe csn->addChild(createFadeText(csn->getEllipsoidModel())); - } + } viewer.setCameraManipulator(new osgGA::TerrainManipulator); diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index 976c1e28d..77617a87a 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -62,7 +62,7 @@ osgText::Text* createLabel(const std::string& l, const char* f, unsigned int siz static osg::Vec3 pos(10.0f, 10.0f, 0.0f); osgText::Text* label = new osgText::Text(); - osgText::Font* font = osgText::readFontFile(f); + osg::ref_ptr font = osgText::readRefFontFile(f); label->setFont(font); label->setCharacterSize(size); diff --git a/examples/osgforest/osgforest.cpp b/examples/osgforest/osgforest.cpp index e37e9608f..5acada741 100644 --- a/examples/osgforest/osgforest.cpp +++ b/examples/osgforest/osgforest.cpp @@ -388,7 +388,7 @@ osg::Geode* ForestTechniqueManager::createTerrain(const osg::Vec3& origin, const // --------------------------------------- osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -1182,7 +1182,7 @@ osg::Node* ForestTechniqueManager::createScene(unsigned int numTreesToCreates, u osg::Texture2D *tex = new osg::Texture2D; tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP ); tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP ); - tex->setImage(osgDB::readImageFile("Images/tree0.rgba")); + tex->setImage(osgDB::readRefImageFile("Images/tree0.rgba")); osg::StateSet *dstate = new osg::StateSet; { diff --git a/examples/osgfpdepth/osgfpdepth.cpp b/examples/osgfpdepth/osgfpdepth.cpp index 86541bc30..db8611db5 100644 --- a/examples/osgfpdepth/osgfpdepth.cpp +++ b/examples/osgfpdepth/osgfpdepth.cpp @@ -963,7 +963,7 @@ int main(int argc, char **argv) arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } - ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { cerr << "couldn't load " << argv[1] << "\n"; return 1; diff --git a/examples/osgfxbrowser/osgfxbrowser.cpp b/examples/osgfxbrowser/osgfxbrowser.cpp index c33f9c924..ec1f027ee 100644 --- a/examples/osgfxbrowser/osgfxbrowser.cpp +++ b/examples/osgfxbrowser/osgfxbrowser.cpp @@ -127,7 +127,7 @@ public: for (osgFX::Registry::EffectMap::const_iterator i=emap.begin(); i!=emap.end(); ++i) { std::cout << "INFO: \t" << i->first << "\n"; osg::ref_ptr effect = static_cast(i->second->cloneType()); - _effects.push_back(effect.get()); + _effects.push_back(effect.get()); } std::cout << "INFO: " << emap.size() << " effect(s) ready.\n"; @@ -144,9 +144,9 @@ public: inline void setScene(osg::Node* node) { _scene = node; } inline bool getEffectsEnabled() const { return _fxen; } - inline void setEffectsEnabled(bool v) - { - _fxen = v; + inline void setEffectsEnabled(bool v) + { + _fxen = v; if (getSelectedEffect()) { getSelectedEffect()->setEnabled(_fxen); } @@ -156,7 +156,7 @@ public: inline void setEffectIndex(int i) { if (i >= static_cast(_effects.size())) i = 0; - if (i < 0) i = static_cast(_effects.size()-1); + if (i < 0) i = static_cast(_effects.size()-1); _selected_fx = i; rebuild(); } @@ -174,11 +174,11 @@ protected: { float zPos = -0.1; // note from Robert, was 0.1f, but now must be -0.1f to keep text visible??#!? due // to some other change in the OSG not tracked down yet... - - osg::ref_ptr arial = osgText::readFontFile("fonts/arial.ttf"); + + osg::ref_ptr arial = osgText::readRefFontFile("fonts/arial.ttf"); osg::ref_ptr hints = new osgText::Text; - hints->setFont(arial.get()); + hints->setFont(arial); hints->setColor(_hints_color); hints->setAlignment(osgText::Text::CENTER_BOTTOM); hints->setCharacterSize(13); @@ -195,7 +195,7 @@ protected: if (!author_name.empty()) { effect_description = author_name = "AUTHOR: " + std::string(_effects[_selected_fx]->effectAuthor()) + std::string("\n\n"); } - effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription()); + effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription()); if (_scene.valid() && _root.valid()) { _root->removeChildren(0, _root->getNumChildren()); @@ -268,7 +268,7 @@ EffectPanel* build_gui(osg::Group* root) osg::ref_ptr effect_panel = new EffectPanel; effect_panel->setCaption("osgFX Effect Browser"); - effect_panel->setRect(osgfxbrowser::Rect(20, 20, 1000, 280)); + effect_panel->setRect(osgfxbrowser::Rect(20, 20, 1000, 280)); hud->addChild(effect_panel.get()); @@ -325,7 +325,7 @@ int main(int argc, char *argv[]) unsigned int clearMask = viewer.getCamera()->getClearMask(); viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT); viewer.getCamera()->setClearStencil(0); - + // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); @@ -336,11 +336,11 @@ int main(int argc, char *argv[]) } // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr 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) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; diff --git a/examples/osggameoflife/osggameoflife.cpp b/examples/osggameoflife/osggameoflife.cpp index 097f8c921..a75ee2cfd 100644 --- a/examples/osggameoflife/osggameoflife.cpp +++ b/examples/osggameoflife/osggameoflife.cpp @@ -117,14 +117,14 @@ int main(int argc, char *argv[]) } // load the image - osg::ref_ptr startIm = osgDB::readImageFile(startName); + osg::ref_ptr startIm = osgDB::readRefImageFile(startName); if (!startIm) { std::cout << "Could not load start image.\n"; return(1); } - osg::Node* scene = createScene(startIm.get()); + osg::ref_ptr scene = createScene(startIm.get()); // construct the viewer. osgViewer::Viewer viewer; diff --git a/examples/osggeometry/osggeometry.cpp b/examples/osggeometry/osggeometry.cpp index c37a1acf3..27b4eec1f 100644 --- a/examples/osggeometry/osggeometry.cpp +++ b/examples/osggeometry/osggeometry.cpp @@ -550,7 +550,7 @@ osg::Node* createBackground() { // we'll create a texture mapped quad to sit behind the Geometry - osg::Image* image = osgDB::readImageFile("Images/primitives.gif"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/primitives.gif"); if (!image) return NULL; diff --git a/examples/osggpx/osggpx.cpp b/examples/osggpx/osggpx.cpp index d8834444a..5d484cee1 100644 --- a/examples/osggpx/osggpx.cpp +++ b/examples/osggpx/osggpx.cpp @@ -434,8 +434,8 @@ int main(int argv, char **argc) osg::ref_ptr group = new osg::Group; - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - if (loadedModel.valid()) group->addChild(loadedModel.get()); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + if (loadedModel.valid()) group->addChild(loadedModel); for(Tracks::iterator itr = tracks.begin(); itr != tracks.end(); diff --git a/examples/osggraphicscost/osggraphicscost.cpp b/examples/osggraphicscost/osggraphicscost.cpp index 4745de9c2..7f269de11 100644 --- a/examples/osggraphicscost/osggraphicscost.cpp +++ b/examples/osggraphicscost/osggraphicscost.cpp @@ -52,12 +52,12 @@ int main(int argc, char** argv) osgViewer::Viewer viewer(arguments); - osg::ref_ptr node = osgDB::readNodeFiles(arguments); + osg::ref_ptr node = osgDB::readRefNodeFiles(arguments); if (!node) return 0; osg::ref_ptr gce = new osg::GraphicsCostEstimator; - viewer.setSceneData(node.get()); + viewer.setSceneData(node); viewer.realize(); diff --git a/examples/osghangglide/base.cpp b/examples/osghangglide/base.cpp index c8cd5119a..9061b2980 100644 --- a/examples/osghangglide/base.cpp +++ b/examples/osghangglide/base.cpp @@ -67,7 +67,7 @@ Node *makeBase( void ) Texture2D *tex = new Texture2D; - tex->setImage(osgDB::readImageFile("Images/water.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/water.rgb")); tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT ); tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT ); diff --git a/examples/osghangglide/sky.cpp b/examples/osghangglide/sky.cpp index 3a23f53a4..d1d0a23bd 100644 --- a/examples/osghangglide/sky.cpp +++ b/examples/osghangglide/sky.cpp @@ -112,7 +112,7 @@ Node *makeSky( void ) Texture2D *tex = new Texture2D; - tex->setImage(osgDB::readImageFile("Images/white.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/white.rgb")); StateSet *dstate = new StateSet; diff --git a/examples/osghangglide/tank.cpp b/examples/osghangglide/tank.cpp index 83a1fd223..5f1e1f4a5 100644 --- a/examples/osghangglide/tank.cpp +++ b/examples/osghangglide/tank.cpp @@ -161,7 +161,7 @@ Node *makeTank( void ) for( i = 0; i < c; i++ ) conv( vc[i], mat, vc[i] ); - + gset->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c)); @@ -171,7 +171,7 @@ Node *makeTank( void ) tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT ); tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT ); - tex->setImage(osgDB::readImageFile("Images/tank.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/tank.rgb")); StateSet *dstate = new StateSet; dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON ); diff --git a/examples/osghangglide/terrain.cpp b/examples/osghangglide/terrain.cpp index 52e1e4118..ffc0f7917 100644 --- a/examples/osghangglide/terrain.cpp +++ b/examples/osghangglide/terrain.cpp @@ -131,7 +131,7 @@ Node *makeTerrain( void ) Texture2D *tex = new Texture2D; - tex->setImage(osgDB::readImageFile("Images/lz.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/lz.rgb")); StateSet *dstate = new StateSet; dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); diff --git a/examples/osghangglide/trees.cpp b/examples/osghangglide/trees.cpp index 600b38251..205e6295d 100644 --- a/examples/osghangglide/trees.cpp +++ b/examples/osghangglide/trees.cpp @@ -234,7 +234,7 @@ Node *makeTrees( void ) struct _tree *t; Texture2D *tex = new Texture2D; - tex->setImage(osgDB::readImageFile("Images/tree0.rgba")); + tex->setImage(osgDB::readRefImageFile("Images/tree0.rgba")); StateSet *dstate = new StateSet; diff --git a/examples/osghud/osghud.cpp b/examples/osghud/osghud.cpp index 46535d21e..c72eef6c7 100644 --- a/examples/osghud/osghud.cpp +++ b/examples/osghud/osghud.cpp @@ -248,7 +248,7 @@ struct SnapeImageHandler : public osgGA::GUIEventHandler { osgViewer::View* view = dynamic_cast(&aa); osg::Node* node = view ? view->getSceneData() : 0; - if (node) + if (node) { osgDB::writeNodeFile(*node, "hud.osgt"); osgDB::writeNodeFile(*node, "hud.osgb"); @@ -284,10 +284,10 @@ int main( int argc, char **argv ) // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default model instead. - if (!scene) scene = osgDB::readNodeFile("dumptruck.osgt"); + if (!scene) scene = osgDB::readRefNodeFile("dumptruck.osgt"); if (!scene) @@ -320,7 +320,7 @@ int main( int argc, char **argv ) viewer.addSlave(hudCamera, false); // set the scene to render - viewer.setSceneData(scene.get()); + viewer.setSceneData(scene); return viewer.run(); @@ -334,7 +334,7 @@ int main( int argc, char **argv ) osgViewer::View* view = new osgViewer::View; viewer.addView(view); - view->setSceneData(scene.get()); + view->setSceneData(scene); view->setUpViewAcrossAllScreens();; view->setCameraManipulator(new osgGA::TrackballManipulator); @@ -375,11 +375,11 @@ int main( int argc, char **argv ) osg::ref_ptr group = new osg::Group; // add the HUD subgraph. - if (scene.valid()) group->addChild(scene.get()); + if (scene.valid()) group->addChild(scene); group->addChild(createHUD()); // set the scene to render - viewer.setSceneData(group.get()); + viewer.setSceneData(group); return viewer.run(); } diff --git a/examples/osgimagesequence/osgimagesequence.cpp b/examples/osgimagesequence/osgimagesequence.cpp index 7246d6d73..cc64ae49b 100644 --- a/examples/osgimagesequence/osgimagesequence.cpp +++ b/examples/osgimagesequence/osgimagesequence.cpp @@ -48,7 +48,7 @@ static osgDB::DirectoryContents getSuitableFiles(osg::ArgumentParser& arguments) { const std::string& directory = arguments[i]; osgDB::DirectoryContents dc = osgDB::getSortedDirectoryContents(directory); - + for(osgDB::DirectoryContents::iterator itr = dc.begin(); itr != dc.end(); ++itr) { std::string full_file_name = directory + "/" + (*itr); @@ -76,28 +76,28 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) osg::ref_ptr imageSequence = new osg::ImageSequence; bool preLoad = true; - + while (arguments.read("--page-and-discard")) { imageSequence->setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES); preLoad = false; } - + while (arguments.read("--page-and-retain")) { imageSequence->setMode(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES); preLoad = false; } - + while (arguments.read("--preload")) { imageSequence->setMode(osg::ImageSequence::PRE_LOAD_ALL_IMAGES); preLoad = true; } - + double length = -1.0; while (arguments.read("--length",length)) {} - + double fps = 30.0; while (arguments.read("--fps",fps)) {} @@ -111,7 +111,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) const std::string& filename = *itr; if (preLoad) { - osg::ref_ptr image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image.valid()) { imageSequence->addImage(image.get()); @@ -123,7 +123,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) } } - + if (length>0.0) { imageSequence->setLength(length); @@ -144,14 +144,14 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) { imageSequence->setLength(4.0); } - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png")); - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png")); - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png")); - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png")); - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png")); - imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posx.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negx.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posy.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negy.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posz.png")); + imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negz.png")); } - + // start the image sequence playing imageSequence->play(); @@ -163,7 +163,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) texture->setResizeNonPowerOfTwoHint(false); texture->setImage(imageSequence.get()); //texture->setTextureSize(512,512); -#else +#else osg::TextureRectangle* texture = new osg::TextureRectangle; texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); @@ -183,12 +183,12 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) osg::Node* createModel(osg::ArgumentParser& arguments) { - // create the geometry of the model, just a simple 2d quad right now. + // create the geometry of the model, just a simple 2d quad right now. osg::Geode* geode = new osg::Geode; geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f))); geode->setStateSet(createState(arguments)); - + return geode; } @@ -200,10 +200,10 @@ class MovieEventHandler : public osgGA::GUIEventHandler public: MovieEventHandler():_playToggle(true),_trackMouse(false) {} - + void setMouseTracking(bool track) { _trackMouse = track; } bool getMouseTracking() const { return _trackMouse; } - + void set(osg::Node* node); void setTrackMouse(bool tm) @@ -233,20 +233,20 @@ public: bool getTrackMouse() const { return _trackMouse; } virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv); - + virtual void getUsage(osg::ApplicationUsage& usage) const; typedef std::vector< osg::observer_ptr > ImageStreamList; - + struct ImageStreamPlaybackSpeedData { double fps; unsigned char* lastData; double timeStamp, lastOutput; - + ImageStreamPlaybackSpeedData() : fps(0), lastData(NULL), timeStamp(0), lastOutput(0) {} - + }; - + typedef std::vector< ImageStreamPlaybackSpeedData > ImageStreamPlayBackSpeedList; protected: @@ -258,7 +258,7 @@ protected: public: FindImageStreamsVisitor(ImageStreamList& imageStreamList): _imageStreamList(imageStreamList) {} - + virtual void apply(osg::Geode& geode) { apply(geode.getStateSet()); @@ -267,7 +267,7 @@ protected: { apply(geode.getDrawable(i)->getStateSet()); } - + traverse(geode); } @@ -276,11 +276,11 @@ protected: apply(node.getStateSet()); traverse(node); } - + inline void apply(osg::StateSet* stateset) { if (!stateset) return; - + osg::StateAttribute* attr = stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE); if (attr) { @@ -291,20 +291,20 @@ protected: if (textureRec) apply(dynamic_cast(textureRec->getImage())); } } - + inline void apply(osg::ImageStream* imagestream) { if (imagestream) { - _imageStreamList.push_back(imagestream); + _imageStreamList.push_back(imagestream); s_imageStream = imagestream; } } - + ImageStreamList& _imageStreamList; - + protected: - + FindImageStreamsVisitor& operator = (const FindImageStreamsVisitor&) { return *this; } }; @@ -313,7 +313,7 @@ protected: bool _trackMouse; ImageStreamList _imageStreamList; ImageStreamPlayBackSpeedList _imageStreamPlayBackSpeedList; - + }; @@ -338,7 +338,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { double t = ea.getTime(); bool printed(false); - + ImageStreamPlayBackSpeedList::iterator fps_itr = _imageStreamPlayBackSpeedList.begin(); for(ImageStreamList::iterator itr=_imageStreamList.begin(); itr!=_imageStreamList.end(); @@ -351,17 +351,17 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction data.lastData = (*itr)->data(); data.fps = (*fps_itr).fps * 0.8 + 0.2 * (1/dt); data.timeStamp = t; - + if (t-data.lastOutput > 1) { std::cout << data.fps << " "; data.lastOutput = t; printed = true; } - + } } - if (printed) + if (printed) std::cout << std::endl; } break; @@ -380,7 +380,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction } return false; } - + case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='p') @@ -434,11 +434,11 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction } return true; } - else if (ea.getKey() == 'i') + else if (ea.getKey() == 'i') { setTrackMouse(!_trackMouse); - - + + } return false; } @@ -479,7 +479,7 @@ int main(int argc, char **argv) meh->set( viewer.getSceneData() ); if (arguments.read("--track-mouse")) meh->setTrackMouse(true); - + viewer.addEventHandler( meh ); viewer.addEventHandler( new osgViewer::StatsHandler()); diff --git a/examples/osgimpostor/osgimpostor.cpp b/examples/osgimpostor/osgimpostor.cpp index fe98f1206..ce3fe9ece 100644 --- a/examples/osgimpostor/osgimpostor.cpp +++ b/examples/osgimpostor/osgimpostor.cpp @@ -244,7 +244,7 @@ int main( int argc, char **argv ) // load the nodes from the commandline arguments. - osg::ref_ptr model = osgDB::readNodeFiles(arguments); + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); if (model) { // the osgSim::InsertImpostorsVisitor used lower down to insert impostors @@ -280,7 +280,7 @@ int main( int argc, char **argv ) // on it right now as it requires a getRoots() method to be added to // osg::Node, and we're about to make a release so no new features! osg::ref_ptr rootnode = new osg::Group; - rootnode->addChild(model.get()); + rootnode->addChild(model); // now insert impostors in the model using the InsertImpostorsVisitor. @@ -304,7 +304,7 @@ int main( int argc, char **argv ) } // add model to viewer. - viewer.setSceneData(model.get()); + viewer.setSceneData(model); return viewer.run(); } diff --git a/examples/osgintersection/osgintersection.cpp b/examples/osgintersection/osgintersection.cpp index 005c2dded..78b147881 100644 --- a/examples/osgintersection/osgintersection.cpp +++ b/examples/osgintersection/osgintersection.cpp @@ -38,7 +38,7 @@ struct MyReadCallback : public osgUtil::IntersectionVisitor::ReadCallback { virtual osg::Node* readNodeFile(const std::string& filename) { - return osgDB::readNodeFile(filename); + return osgDB::readRefNodeFile(filename).release(); } }; @@ -47,37 +47,37 @@ int main(int argc, char **argv) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); - - if (!scene) + + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); + + if (!scene) { std::cout<<"No model loaded, please specify a valid model on the command line."<getBound(); bool useIntersectorGroup = true; bool useLineOfSight = true; - + //osg::CoordinateSystemNode* csn = dynamic_cast(scene.get()); //osg::EllipsoidModel* em = csn ? csn->getEllipsoidModel() : 0; if (useLineOfSight) { - + osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); osg::Vec3d end = bs.center() - osg::Vec3d(0.0, bs.radius(),0.0); osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01); osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0); osgSim::LineOfSight los; - + #if 1 unsigned int numRows = 20; unsigned int numColumns = 20; @@ -118,7 +118,7 @@ int main(int argc, char **argv) } } } - + { // now do a second traversal to test performance of cache. osg::Timer_t startTick = osg::Timer::instance()->tick(); @@ -173,7 +173,7 @@ int main(int argc, char **argv) else if (useIntersectorGroup) { osg::Timer_t startTick = osg::Timer::instance()->tick(); - + osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0); osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01); @@ -194,7 +194,7 @@ int main(int argc, char **argv) } } - + osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), new MyReadCallback ); scene->accept(intersectVisitor); @@ -229,7 +229,7 @@ int main(int argc, char **argv) } } } - + } } @@ -272,6 +272,6 @@ int main(int argc, char **argv) } } } - + return 0; } diff --git a/examples/osgkdtree/osgkdtree.cpp b/examples/osgkdtree/osgkdtree.cpp index 3aa9f28d1..0bbe61eb7 100644 --- a/examples/osgkdtree/osgkdtree.cpp +++ b/examples/osgkdtree/osgkdtree.cpp @@ -16,7 +16,7 @@ * THE SOFTWARE. */ - + #include #include @@ -47,24 +47,24 @@ int main(int argc, char **argv) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + int maxNumLevels = 16; int targetNumIndicesPerLeaf = 16; while (arguments.read("--max", maxNumLevels)) {} while (arguments.read("--leaf", targetNumIndicesPerLeaf)) {} - + osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES); - - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); - - if (!scene) + + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); + + if (!scene) { std::cout<<"No model loaded, please specify a valid model on the command line."< loadedModel; // load the scene. - if (argc>1) loadedModel = osgDB::readNodeFile(argv[1]); + if (argc>1) loadedModel = osgDB::readRefNodeFile(argv[1]); // 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) { @@ -374,7 +374,7 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; viewer.getCamera()->setGraphicsContext(gc.get()); viewer.getCamera()->setViewport(0,0,800,600); - viewer.setSceneData(loadedModel.get()); + viewer.setSceneData(loadedModel); // create a tracball manipulator to move the camera around in response to keyboard/mouse events viewer.setCameraManipulator( new osgGA::TrackballManipulator ); diff --git a/examples/osgkeystone/osgkeystone.cpp b/examples/osgkeystone/osgkeystone.cpp index 9d24871ae..68e7476cd 100644 --- a/examples/osgkeystone/osgkeystone.cpp +++ b/examples/osgkeystone/osgkeystone.cpp @@ -38,14 +38,14 @@ int main( int argc, char **argv ) { osg::ArgumentParser arguments(&argc,argv); - + // initialize the viewer. osgViewer::Viewer viewer(arguments); - + osg::DisplaySettings* ds = viewer.getDisplaySettings() ? viewer.getDisplaySettings() : osg::DisplaySettings::instance().get(); ds->readCommandLine(arguments); - osg::ref_ptr model = osgDB::readNodeFiles(arguments); + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); if (!model) { @@ -57,8 +57,8 @@ int main( int argc, char **argv ) OSG_NOTICE<<"Stereo "<getStereo()<getStereoMode()<getOrCreateStateSet()) ); @@ -77,7 +77,7 @@ int main( int argc, char **argv ) } ds->setKeystoneHint(true); - + if (!ds->getKeystoneFileNames().empty()) { for(osg::DisplaySettings::Objects::iterator itr = ds->getKeystones().begin(); @@ -85,19 +85,19 @@ int main( int argc, char **argv ) ++itr) { osgViewer::Keystone* keystone = dynamic_cast(itr->get()); - if (keystone) + if (keystone) { std::string filename; keystone->getUserValue("filename",filename); OSG_NOTICE<<"Loaded keystone "<getKeystones().push_back(keystone); } } } - + viewer.apply(new osgViewer::SingleScreen(0)); - + viewer.realize(); while(!viewer.done()) diff --git a/examples/osglauncher/osglauncher.cpp b/examples/osglauncher/osglauncher.cpp index 095f94b20..00c98b42c 100644 --- a/examples/osglauncher/osglauncher.cpp +++ b/examples/osglauncher/osglauncher.cpp @@ -53,23 +53,23 @@ int runApp(std::string xapp); // class to handle events with a pick class PickHandler : public osgGA::GUIEventHandler { -public: +public: PickHandler(osgViewer::Viewer* viewer,osgText::Text* updateText): _viewer(viewer), _updateText(updateText) {} - + ~PickHandler() {} - + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); std::string pick(const osgGA::GUIEventAdapter& event); - + void highlight(const std::string& name) { if (_updateText.get()) _updateText->setText(name); } - + protected: osgViewer::Viewer* _viewer; @@ -133,14 +133,14 @@ osg::Node* createHUD(osgText::Text* updateText) osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF); modelview_abs->setMatrix(osg::Matrix::identity()); - + osg::Projection* projection = new osg::Projection; projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); projection->addChild(modelview_abs); - - + + std::string timesFont("fonts/times.ttf"); - + // turn lighting off for the text and disable depth test to ensure its always ontop. osg::Vec3 position(50.0f,510.0f,0.0f); osg::Vec3 delta(0.0f,-60.0f,0.0f); @@ -153,16 +153,16 @@ osg::Node* createHUD(osgText::Text* updateText) geode->setName("The text label"); geode->addDrawable( updateText ); modelview_abs->addChild(geode); - + updateText->setCharacterSize(20.0f); updateText->setFont(timesFont); updateText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); updateText->setText(""); updateText->setPosition(position); - + position += delta; - } - + } + return projection; } // end create HUDf @@ -179,13 +179,13 @@ class Xample std::string app; public: Xample(std::string image, std::string prog) - { + { texture = image; app = prog; osg::notify(osg::INFO) << "New Xample!" << std::endl; }; ~Xample() { }; - + std::string getTexture() { return texture; @@ -225,11 +225,11 @@ int runApp(std::string xapp) if(!xapp.compare(x.getApp())) { osg::notify(osg::INFO) << "app found!" << std::endl; - + const char* cxapp = xapp.c_str(); - + osg::notify(osg::INFO) << "char* = " << cxapp <getOrCreateStateSet(); // load texture.jpg as an image - osg::Image* imgTexture = osgDB::readImageFile( texture ); - + osg::ref_ptr imgTexture = osgDB::readRefImageFile( texture ); + // if the image is successfully loaded if (imgTexture) { @@ -338,11 +338,11 @@ osg::PositionAttitudeTransform* getPATransformation(osg::Node* object, osg::Vec3 { osg::PositionAttitudeTransform* tmpTrans = new osg::PositionAttitudeTransform(); tmpTrans->addChild( object ); - + tmpTrans->setPosition( position ); tmpTrans->setScale( scale ); tmpTrans->setPivotPoint( pivot ); - + return tmpTrans; } @@ -352,7 +352,7 @@ void printBoundings(osg::Node* current, std::string name) osg::notify(osg::INFO) << name << std::endl; osg::notify(osg::INFO) << "center = " << currentBound.center() << std::endl; osg::notify(osg::INFO) << "radius = " << currentBound.radius() << std::endl; - + // return currentBound.radius(); } @@ -361,7 +361,7 @@ osg::Group* setupGraph() { osg::Group* xGroup = new osg::Group(); - + // positioning and sizes float defaultRadius = 0.8f; @@ -375,20 +375,20 @@ osg::Group* setupGraph() float xjump = (2*bs); float zjump = xjump; osg::Vec3 vScale( 0.5f, 0.5f, 0.5f ); - osg::Vec3 vPivot( 0.0f, 0.0f, 0.0f ); + osg::Vec3 vPivot( 0.0f, 0.0f, 0.0f ); // run through Xampleliste int z = 1; for (OP i = Xamplelist.begin() ; i != Xamplelist.end() ; ++i, ++z) { Xample& x = *i; - + osg::Node* tmpCube = createTexturedCube(defaultRadius, defaultPos, x.getTexture(), x.getApp()); printBoundings(tmpCube, x.getApp()); osg::Vec3 vPosition( xnext, 0.0f, znext ); osg::PositionAttitudeTransform* transX = getPATransformation(tmpCube, vPosition, vScale, vPivot); xGroup->addChild( transX ); - + // line feed if(z < itemsInLine) xnext += xjump; @@ -398,8 +398,8 @@ osg::Group* setupGraph() znext -= zjump; z = 0; } - } // end run through list - + } // end run through list + return xGroup; } // end setupGraph @@ -414,7 +414,7 @@ int main( int argc, char **argv ) { readConfFile(argv[1]); // read ConfigFile 1 } - + // construct the viewer. osgViewer::Viewer viewer; @@ -428,9 +428,9 @@ int main( int argc, char **argv ) root->addChild( setupGraph() ); - // add the HUD subgraph. + // add the HUD subgraph. root->addChild(createHUD(updateText.get())); - + // add model to viewer. viewer.setSceneData( root ); @@ -438,13 +438,13 @@ int main( int argc, char **argv ) lookAt.makeLookAt(osg::Vec3(0.0f, -4.0f, 0.0f), centerScope, osg::Vec3(0.0f, 0.0f, 1.0f)); viewer.getCamera()->setViewMatrix(lookAt); - + viewer.realize(); while( !viewer.done() ) { // fire off the cull and draw traversals of the scene. - viewer.frame(); + viewer.frame(); } return 0; diff --git a/examples/osglight/osglight.cpp b/examples/osglight/osglight.cpp index 593d095a0..394285e45 100644 --- a/examples/osglight/osglight.cpp +++ b/examples/osglight/osglight.cpp @@ -226,7 +226,7 @@ osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec } -osg::Node* createRoom(osg::Node* loadedModel) +osg::ref_ptr createRoom(const osg::ref_ptr& loadedModel) { // default scale for this model. osg::BoundingSphere bs(osg::Vec3(0.0f,0.0f,0.0f),1.0f); @@ -323,20 +323,20 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("glider.osgt"); // create a room made of foor walls, a floor, a roof, and swinging light fitting. - osg::Node* rootnode = createRoom(loadedModel); + osg::ref_ptr rootnode = createRoom(loadedModel); // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); // add a viewport to the viewer and attach the scene graph. - viewer.setSceneData( rootnode ); + viewer.setSceneData(rootnode); // create the windows and run the threads. diff --git a/examples/osglightpoint/osglightpoint.cpp b/examples/osglightpoint/osglightpoint.cpp index d2e77a3f2..c6c0fcf80 100644 --- a/examples/osglightpoint/osglightpoint.cpp +++ b/examples/osglightpoint/osglightpoint.cpp @@ -47,12 +47,12 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o lpn.addLightPoint(start); return; } - + float rend = 0.0f; float rdelta = 1.0f/((float)noSteps-1.0f); - + lpn.getLightPointList().reserve(noSteps); - + for(unsigned int i=0;isetDataVariance(osg::Object::STATIC); transform->setMatrix(osg::Matrix::scale(0.1,0.1,0.1)); @@ -100,7 +100,7 @@ osg::Node* createLightPointsDatabase() // bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off // bs->addPulse(1.0,osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off - + // osgSim::Sector* sector = new osgSim::ConeSector(osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0),osg::inDegrees(45.0)); // osgSim::Sector* sector = new osgSim::ElevationSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(45.0)); @@ -113,7 +113,7 @@ osg::Node* createLightPointsDatabase() { // osgSim::BlinkSequence* local_bs = new osgSim::BlinkSequence(*bs); -// local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1)); +// local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1)); // start._blinkSequence = local_bs; // start._sector = sector; @@ -129,7 +129,7 @@ osg::Node* createLightPointsDatabase() // Set point sprite texture in LightPointNode StateSet. osg::Texture2D *tex = new osg::Texture2D(); - tex->setImage(osgDB::readImageFile("Images/particle.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/particle.rgb")); set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); } @@ -140,17 +140,17 @@ osg::Node* createLightPointsDatabase() // addToLightPointNode(*lpn,start,end,noStepsX); - + start._position += start_delta; end._position += end_delta; - - transform->addChild(lpn); + + transform->addChild(lpn); } - + osg::Group* group = new osg::Group; group->addChild(transform); - - + + return group; } @@ -232,16 +232,16 @@ int main( int argc, char **argv ) osg::Group* rootnode = new osg::Group; // load the nodes from the commandline arguments. - rootnode->addChild(osgDB::readNodeFiles(arguments)); + rootnode->addChild(osgDB::readRefNodeFiles(arguments)); rootnode->addChild(createLightPointsDatabase()); rootnode->addChild(CreateBlinkSequenceLightNode()); - + // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode ); - + return viewer.run(); } diff --git a/examples/osglogicop/osglogicop.cpp b/examples/osglogicop/osglogicop.cpp index acee4228d..109d91ec1 100644 --- a/examples/osglogicop/osglogicop.cpp +++ b/examples/osglogicop/osglogicop.cpp @@ -32,7 +32,7 @@ const int _ops_nb=16; const osg::LogicOp::Opcode _operations[_ops_nb]= -{ +{ osg::LogicOp::CLEAR, osg::LogicOp::SET, osg::LogicOp::COPY, @@ -52,7 +52,7 @@ const osg::LogicOp::Opcode _operations[_ops_nb]= }; const char* _ops_name[_ops_nb]= -{ +{ "osg::LogicOp::CLEAR", "osg::LogicOp::SET", "osg::LogicOp::COPY", @@ -142,22 +142,22 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); - + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt"); - + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("glider.osgt"); + if (!loadedModel) { osg::notify(osg::NOTICE)<<"Please specify model filename on the command line."< root = new osg::Group; root->addChild(loadedModel); - - osg::StateSet* stateset = new osg::StateSet; - osg::LogicOp* logicOp = new osg::LogicOp(osg::LogicOp::OR_INVERTED); + + osg::ref_ptr stateset = new osg::StateSet; + osg::ref_ptr logicOp = new osg::LogicOp(osg::LogicOp::OR_INVERTED); stateset->setAttributeAndModes(logicOp,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); @@ -170,14 +170,14 @@ int main( int argc, char **argv ) // construct the viewer. osgViewer::Viewer viewer; - viewer.addEventHandler(new TechniqueEventHandler(logicOp)); - + viewer.addEventHandler(new TechniqueEventHandler(logicOp.get())); + // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(root); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( root ); - + return viewer.run(); } diff --git a/examples/osglogo/osglogo.cpp b/examples/osglogo/osglogo.cpp index bc5e11cfe..c07ae3d40 100644 --- a/examples/osglogo/osglogo.cpp +++ b/examples/osglogo/osglogo.cpp @@ -234,7 +234,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin osg::MatrixTransform* xform = new osg::MatrixTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(10.0f))); - osg::Node* bluemarble = filename.empty() ? 0 : osgDB::readNodeFile(filename.c_str()); + osg::ref_ptr bluemarble = filename.empty() ? 0 : osgDB::readRefNodeFile(filename.c_str()); if (bluemarble) { const osg::BoundingSphere& bs = bluemarble->getBound(); @@ -252,7 +252,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin osg::StateSet* stateset = geode->getOrCreateStateSet(); - osg::Image* image = osgDB::readImageFile("Images/land_shallow_topo_2048.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/land_shallow_topo_2048.jpg"); if (image) { osg::Texture2D* texture = new osg::Texture2D; diff --git a/examples/osgmanipulator/osgmanipulator.cpp b/examples/osgmanipulator/osgmanipulator.cpp index 43352df48..499bf3884 100644 --- a/examples/osgmanipulator/osgmanipulator.cpp +++ b/examples/osgmanipulator/osgmanipulator.cpp @@ -453,7 +453,7 @@ int main( int argc, char **argv ) osg::Timer_t start_tick = osg::Timer::instance()->tick(); // read the scene from the list of file specified command line args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if no model has been successfully loaded report failure. bool tragger2Scene(true); @@ -481,14 +481,14 @@ int main( int argc, char **argv ) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); // pass the loaded scene graph to the viewer. if ( tragger2Scene ) { viewer.setSceneData(addDraggerToScene(loadedModel.get(), dragger_name, fixedSizeInScreen)); } else { - viewer.setSceneData(loadedModel.get()); + viewer.setSceneData(loadedModel); } diff --git a/examples/osgmotionblur/osgmotionblur.cpp b/examples/osgmotionblur/osgmotionblur.cpp index d5ace21f6..8e9953b66 100644 --- a/examples/osgmotionblur/osgmotionblur.cpp +++ b/examples/osgmotionblur/osgmotionblur.cpp @@ -37,7 +37,7 @@ public: { osg::GraphicsContext* gc = dynamic_cast(object); if (!gc) return; - + double t = gc->getState()->getFrameStamp()->getSimulationTime(); if (!cleared_) @@ -73,14 +73,14 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an OpenSceneGraph example that shows how to use the accumulation buffer to achieve a simple motion blur effect."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-P or --persistence","Set the motion blur persistence time"); - + // construct the viewer. osgViewer::Viewer viewer; @@ -96,13 +96,13 @@ int main( int argc, char **argv ) arguments.read("-P", persistence) || arguments.read("--persistence", persistence); // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); // if no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 706bc4760..7221e6f37 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -520,8 +520,8 @@ int main(int argc, char** argv) { if (arguments.isString(i)) { - osg::Image* image = osgDB::readImageFile(arguments[i]); - osg::ImageStream* imagestream = dynamic_cast(image); + osg::ref_ptr image = osgDB::readRefImageFile(arguments[i]); + osg::ImageStream* imagestream = dynamic_cast(image.get()); if (imagestream) { osg::ImageStream::AudioStreams& audioStreams = imagestream->getAudioStreams(); @@ -550,7 +550,7 @@ int main(int argc, char** argv) float width = image->s() * image->getPixelAspectRatio(); float height = image->t(); - osg::ref_ptr drawable = myCreateTexturedQuadGeometry(pos, width, height,image, useTextureRectangle, xyPlane, flip); + osg::ref_ptr drawable = myCreateTexturedQuadGeometry(pos, width, height, image.get(), useTextureRectangle, xyPlane, flip); if (image->isImageTranslucent()) { diff --git a/examples/osgmultiplemovies/osgmultiplemovies.cpp b/examples/osgmultiplemovies/osgmultiplemovies.cpp index c81ac68cd..adc77f8d5 100644 --- a/examples/osgmultiplemovies/osgmultiplemovies.cpp +++ b/examples/osgmultiplemovies/osgmultiplemovies.cpp @@ -362,7 +362,7 @@ private: static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, float desired_height, osgDB::Options* options) { - osg::ref_ptr obj = osgDB::readObjectFile(file_name, options); + osg::ref_ptr obj = osgDB::readRefObjectFile(file_name, options); osg::ref_ptr tex = dynamic_cast(obj.get()); osg::Geometry* geo(NULL); float w(0); @@ -374,7 +374,7 @@ static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, fl // try readImageFile if readObjectFile failed if (!img_stream) { - img_stream = dynamic_cast(osgDB::readImageFile(file_name, options)); + img_stream = osgDB::readRefFile(file_name, options); } if (img_stream) @@ -531,7 +531,9 @@ private: if (!tex) { osg::ref_ptr stream = dynamic_cast(obj.get()); if (!stream) - stream = dynamic_cast(osgDB::readImageFile(_files[_currentFile], _options.get())); + { + stream = osgDB::readRefFile(_files[_currentFile], _options.get()); + } if (stream) { diff --git a/examples/osgmultitexture/osgmultitexture.cpp b/examples/osgmultitexture/osgmultitexture.cpp index 2491124cb..7c026a807 100644 --- a/examples/osgmultitexture/osgmultitexture.cpp +++ b/examples/osgmultitexture/osgmultitexture.cpp @@ -44,10 +44,10 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!rootnode) rootnode = osgDB::readNodeFile("cessnafire.osgt"); + if (!rootnode) rootnode = osgDB::readRefNodeFile("cessnafire.osgt"); if (!rootnode) { @@ -55,7 +55,7 @@ int main( int argc, char **argv ) return 1; } - osg::Image* image = osgDB::readImageFile("Images/reflect.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/reflect.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; diff --git a/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp b/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp index ea9057b61..fd732e4f4 100644 --- a/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp +++ b/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp @@ -55,7 +55,7 @@ public: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _foundNode(0) {} - + void apply(osg::Node& node) { T* result = dynamic_cast(&node); @@ -68,18 +68,18 @@ public: traverse(node); } } - + T* _foundNode; }; -template -T* findTopMostNodeOfType(osg::Node* node) +template +T* findTopMostNodeOfType(R node) { if (!node) return 0; FindTopMostNodeOfTypeVisitor fnotv; node->accept(fnotv); - + return fnotv._foundNode; } @@ -87,7 +87,7 @@ T* findTopMostNodeOfType(osg::Node* node) class ElevationLayerBlendingCallback : public osg::NodeCallback { public: - + typedef std::vector Elevations; ElevationLayerBlendingCallback(osgFX::MultiTextureControl* mtc, const Elevations& elevations, float animationTime=4.0f): @@ -97,7 +97,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback _currentElevation(0.0), _mtc(mtc), _elevations(elevations) {} - + /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { @@ -118,7 +118,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback unsigned int index = _mtc->getNumTextureWeights()-1; for(unsigned int i=0; i<_elevations.size(); ++i) { - if (_currentElevation>_elevations[i]) + if (_currentElevation>_elevations[i]) { index = i; break; @@ -153,7 +153,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback _currentElevation = nv->getViewPoint().z(); osg::CoordinateSystemNode* csn = dynamic_cast(node); - if (csn) + if (csn) { osg::EllipsoidModel* em = csn->getEllipsoidModel(); if (em) @@ -175,7 +175,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback double _previousTime; float _animationTime; double _currentElevation; - + osg::observer_ptr _mtc; Elevations _elevations; }; @@ -183,17 +183,17 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback // class to handle events with a pick class TerrainHandler : public osgGA::GUIEventHandler { -public: +public: TerrainHandler(osgTerrain::Terrain* terrain): _terrain(terrain) {} - + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): - { + { if (ea.getKey()=='r') { _terrain->setSampleRatio(_terrain->getSampleRatio()*0.5); @@ -220,12 +220,12 @@ public: } return false; - } + } default: return false; } } - + protected: ~TerrainHandler() {} @@ -240,7 +240,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("-v","Set the terrain vertical scale."); arguments.getApplicationUsage()->addCommandLineOption("-r","Set the terrain sample ratio."); arguments.getApplicationUsage()->addCommandLineOption("--login ","Provide authentication information for http file access."); - + // construct the viewer. osgViewer::Viewer viewer(arguments); @@ -262,7 +262,7 @@ int main( int argc, char **argv ) // obtain the vertical scale float verticalScale = 1.0f; while(arguments.read("-v",verticalScale)) {} - + // obtain the sample ratio float sampleRatio = 1.0f; while(arguments.read("-r",sampleRatio)) {} @@ -322,7 +322,7 @@ int main( int argc, char **argv ) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -338,7 +338,7 @@ int main( int argc, char **argv ) // set up the scene graph { // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); if (!rootnode) { @@ -410,7 +410,7 @@ int main( int argc, char **argv ) // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode ); } - + // create the windows and run the threads. diff --git a/examples/osgmultitouch/osgmultitouch.cpp b/examples/osgmultitouch/osgmultitouch.cpp index 04ce3bd54..d57f2c7c0 100644 --- a/examples/osgmultitouch/osgmultitouch.cpp +++ b/examples/osgmultitouch/osgmultitouch.cpp @@ -52,7 +52,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h) // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h)); - // set the view matrix + // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); @@ -64,7 +64,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h) // we don't want the camera to grab event focus from the viewers main camera(s). camera->setAllowEventFocus(false); - + // add to this camera a subgraph to render @@ -87,7 +87,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h) text->setFont(timesFont); text->setPosition(position); text->setText("A simple multi-touch-example\n1 touch = rotate, \n2 touches = drag + scale, \n3 touches = home"); - } + } camera->addChild(geode); } @@ -106,49 +106,49 @@ public: { createTouchRepresentations(parent_group, 10); } - + private: - void createTouchRepresentations(osg::Group* parent_group, unsigned int num_objects) + void createTouchRepresentations(osg::Group* parent_group, unsigned int num_objects) { // create some geometry which is shown for every touch-point - for(unsigned int i = 0; i != num_objects; ++i) + for(unsigned int i = 0; i != num_objects; ++i) { std::ostringstream ss; - + osg::Geode* geode = new osg::Geode(); - + osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 100)); drawable->setColor(osg::Vec4(0.5, 0.5, 0.5,1)); geode->addDrawable(drawable); - + ss << "Touch " << i; - + osgText::Text* text = new osgText::Text; geode->addDrawable( text ); drawable->setDataVariance(osg::Object::DYNAMIC); _drawables.push_back(drawable); - - + + text->setFont("fonts/arial.ttf"); text->setPosition(osg::Vec3(110,0,0)); text->setText(ss.str()); _texts.push_back(text); text->setDataVariance(osg::Object::DYNAMIC); - - - + + + osg::MatrixTransform* mat = new osg::MatrixTransform(); mat->addChild(geode); mat->setNodeMask(0x0); - + _mats.push_back(mat); - + parent_group->addChild(mat); - } - + } + parent_group->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); } - + virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *) { if (ea.getEventType() != osgGA::GUIEventAdapter::FRAME) { @@ -162,7 +162,7 @@ private: } std::cout << std::endl; } - + switch(ea.getEventType()) { case osgGA::GUIEventAdapter::FRAME: @@ -171,7 +171,7 @@ private: _cleanupOnNextFrame = false; } break; - + case osgGA::GUIEventAdapter::PUSH: case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::RELEASE: @@ -179,74 +179,74 @@ private: // is this a multi-touch event? if (!ea.isMultiTouchEvent()) return false; - + unsigned int j(0); - + // iterate over all touch-points and update the geometry unsigned num_touch_ended(0); - + for(osgGA::GUIEventAdapter::TouchData::iterator i = ea.getTouchData()->begin(); i != ea.getTouchData()->end(); ++i, ++j) { const osgGA::GUIEventAdapter::TouchData::TouchPoint& tp = (*i); float x = ea.getTouchPointNormalizedX(j); float y = ea.getTouchPointNormalizedY(j); - + // std::cout << j << ": " << tp.x << "/" << tp.y <<" "<< x << " " << y << " " << _w << " " << _h << std::endl; - + _mats[j]->setMatrix(osg::Matrix::translate((1+x) * 0.5 * _w, (1+y) * 0.5 * _h, 0)); _mats[j]->setNodeMask(0xffff); - + std::ostringstream ss; ss << "Touch " << tp.id; _texts[j]->setText(ss.str()); - - switch (tp.phase) + + switch (tp.phase) { case osgGA::GUIEventAdapter::TOUCH_BEGAN: _drawables[j]->setColor(osg::Vec4(0,1,0,1)); break; - + case osgGA::GUIEventAdapter::TOUCH_MOVED: _drawables[j]->setColor(osg::Vec4(1,1,1,1)); break; - + case osgGA::GUIEventAdapter::TOUCH_ENDED: _drawables[j]->setColor(osg::Vec4(1,0,0,1)); ++num_touch_ended; break; - + case osgGA::GUIEventAdapter::TOUCH_STATIONERY: _drawables[j]->setColor(osg::Vec4(0.8,0.8,0.8,1)); break; - + default: break; } } - + // hide unused geometry cleanup(j); - + //check if all touches ended if ((ea.getTouchData()->getNumTouchPoints() > 0) && (ea.getTouchData()->getNumTouchPoints() == num_touch_ended)) { _cleanupOnNextFrame = true; } - + // reposition mouse-pointer aa.requestWarpPointer((ea.getWindowX() + ea.getWindowWidth()) / 2.0, (ea.getWindowY() + ea.getWindowHeight()) / 2.0); } break; - + default: break; } - + return false; } - - void cleanup(unsigned int j) + + void cleanup(unsigned int j) { for(unsigned k = j; k < _mats.size(); ++k) { _mats[k]->setNodeMask(0x0); @@ -257,7 +257,7 @@ private: std::vector _mats; std::vector _texts; bool _cleanupOnNextFrame; - + float _w, _h; }; @@ -267,7 +267,7 @@ int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + unsigned int helpType = 0; if ((helpType = arguments.readHelpType())) @@ -284,12 +284,12 @@ int main( int argc, char **argv ) } // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); - + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); + // if not loaded assume no arguments passed in, try use default model instead. - if (!scene) scene = osgDB::readNodeFile("dumptruck.osgt"); - - if (!scene) + if (!scene) scene = osgDB::readRefNodeFile("dumptruck.osgt"); + + if (!scene) { osg::Geode* geode = new osg::Geode(); osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 100)); @@ -301,43 +301,43 @@ int main( int argc, char **argv ) // construct the viewer. osgViewer::Viewer viewer(arguments); - - + + //opening devices std::string device; while(arguments.read("--device", device)) { - osg::ref_ptr dev = osgDB::readFile(device); + osg::ref_ptr dev = osgDB::readRefFile(device); if (dev.valid()) { - viewer.addDevice(dev.get()); + viewer.addDevice(dev); } } - - + + osg::ref_ptr group = new osg::Group; - // add the HUD subgraph. - if (scene.valid()) group->addChild(scene.get()); - + // add the HUD subgraph. + if (scene) group->addChild(scene); + viewer.setCameraManipulator(new osgGA::MultiTouchTrackballManipulator()); viewer.realize(); - + osg::GraphicsContext* gc = viewer.getCamera()->getGraphicsContext(); - + #ifdef __APPLE__ // as multitouch is disabled by default, enable it now osgViewer::GraphicsWindowCocoa* win = dynamic_cast(gc); if (win) win->setMultiTouchEnabled(true); #endif - + std::cout << "creating hud with " << gc->getTraits()->width << "x" << gc->getTraits()->height << std::endl; osg::Camera* hud_camera = createHUD(gc->getTraits()->width, gc->getTraits()->height); - - + + viewer.addEventHandler(new TestMultiTouchEventHandler(hud_camera, gc->getTraits()->width, gc->getTraits()->height)); - - + + group->addChild(hud_camera); // set the scene to render @@ -345,5 +345,5 @@ int main( int argc, char **argv ) return viewer.run(); - + } diff --git a/examples/osgmultiviewpaging/osgmultiviewpaging.cpp b/examples/osgmultiviewpaging/osgmultiviewpaging.cpp index 49c6666c4..73b5c3997 100644 --- a/examples/osgmultiviewpaging/osgmultiviewpaging.cpp +++ b/examples/osgmultiviewpaging/osgmultiviewpaging.cpp @@ -64,11 +64,11 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); if (!scene) { - scene = osgDB::readNodeFile("http://www.openscenegraph.org/data/earth_bayarea/earth.ive"); + scene = osgDB::readRefNodeFile("http://www.openscenegraph.org/data/earth_bayarea/earth.ive"); } if (!scene) @@ -123,7 +123,7 @@ int main( int argc, char **argv ) view->setName("View one"); viewer.addView(view); - view->setSceneData(scene.get()); + view->setSceneData(scene); view->getCamera()->setName("Cam one"); view->getCamera()->setViewport(new osg::Viewport(0,0, traits->width/2, traits->height/2)); view->getCamera()->setGraphicsContext(gc.get()); @@ -148,7 +148,7 @@ int main( int argc, char **argv ) view->setName("View two"); viewer.addView(view); - view->setSceneData(scene.get()); + view->setSceneData(scene); view->getCamera()->setName("Cam two"); view->getCamera()->setViewport(new osg::Viewport(traits->width/2,0, traits->width/2, traits->height/2)); view->getCamera()->setGraphicsContext(gc.get()); @@ -162,7 +162,7 @@ int main( int argc, char **argv ) view->setName("View three"); viewer.addView(view); - view->setSceneData(scene.get()); + view->setSceneData(scene); view->getCamera()->setName("Cam three"); view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0); diff --git a/examples/osgoccluder/osgoccluder.cpp b/examples/osgoccluder/osgoccluder.cpp index a754074cd..12f917b49 100644 --- a/examples/osgoccluder/osgoccluder.cpp +++ b/examples/osgoccluder/osgoccluder.cpp @@ -311,10 +311,10 @@ int main( int argc, char **argv ) } // load the nodes from the commandline arguments. - osg::Node* loadedmodel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedmodel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try using default mode instead. - if (!loadedmodel) loadedmodel = osgDB::readNodeFile("glider.osgt"); + if (!loadedmodel) loadedmodel = osgDB::readRefNodeFile("glider.osgt"); if (!loadedmodel) { @@ -336,12 +336,12 @@ int main( int argc, char **argv ) } else { - rootnode = createOccludersAroundModel(loadedmodel); + rootnode = createOccludersAroundModel(loadedmodel.get()); } // add a viewport to the viewer and attach the scene graph. - viewer.setSceneData( rootnode.get() ); + viewer.setSceneData( rootnode ); return viewer.run(); } diff --git a/examples/osgocclusionquery/osgocclusionquery.cpp b/examples/osgocclusionquery/osgocclusionquery.cpp index 569ba0331..9d2643d43 100644 --- a/examples/osgocclusionquery/osgocclusionquery.cpp +++ b/examples/osgocclusionquery/osgocclusionquery.cpp @@ -749,8 +749,8 @@ int main(int argc, char** argv) if (arguments.argc()>1) { - root = osgDB::readNodeFiles( arguments ); - if (root.valid()) + root = osgDB::readRefNodeFiles( arguments ); + if (root) { // Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph. OcclusionQueryVisitor oqv; @@ -787,10 +787,10 @@ int main(int argc, char** argv) if (optimize) { osgUtil::Optimizer optimizer; - optimizer.optimize( root.get() ); + optimizer.optimize( root ); } - viewer.setSceneData( root.get() ); + viewer.setSceneData( root ); KeyHandler* kh = new KeyHandler( *root ); viewer.addEventHandler( kh ); diff --git a/examples/osgoit/osgoit.cpp b/examples/osgoit/osgoit.cpp index cf9b19706..7fe63661d 100644 --- a/examples/osgoit/osgoit.cpp +++ b/examples/osgoit/osgoit.cpp @@ -55,23 +55,23 @@ int main(int argc, char** argv) osg::DisplaySettings* displaySettings = new osg::DisplaySettings; viewer.setDisplaySettings(displaySettings); - + // Add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); - + // add the help handler viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); - + // read the dump truck, we will need it twice - osg::ref_ptr dt = osgDB::readNodeFile("dumptruck.osg"); + osg::ref_ptr dt = osgDB::readRefNodeFile("dumptruck.osg"); // display a solid version of the dump truck osg::ref_ptr solidModel = new osg::PositionAttitudeTransform; solidModel->setPosition(osg::Vec3f(7.0f, -2.0f, 7.0f)); - solidModel->addChild(dt.get()); + solidModel->addChild(dt); // generate the 3D heatmap surface to display osg::ref_ptr hm = new Heatmap(30, 30, 10, 30, 30, 1.0, 0.25); diff --git a/examples/osgoscdevice/osgoscdevice.cpp b/examples/osgoscdevice/osgoscdevice.cpp index be66ca150..71ffcbb36 100644 --- a/examples/osgoscdevice/osgoscdevice.cpp +++ b/examples/osgoscdevice/osgoscdevice.cpp @@ -200,7 +200,7 @@ private: bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { - + OSG_ALWAYS << "handle user-event: " << event->getName() << std::endl; if (event->getName() == "/pick-result") @@ -215,7 +215,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod ss << "x: " << y << " y: " << y << std::endl; _text->setText(ss.str()); - + return true; } else if(event->getName() == "/osgga") @@ -231,7 +231,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod if (win) win->setWindowRectangle(rect[2] + 10 + rect[0], rect[1], rect[2], rect[3]); } - + return true; } else { @@ -251,7 +251,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod } return true; } - + return false; } @@ -377,8 +377,8 @@ public: std::ostringstream ss ; ss << host << ":" << port << ".sender.osc"; - _device = osgDB::readFile(ss.str()); - + _device = osgDB::readRefFile(ss.str()); + osgGA::EventVisitor* ev = dynamic_cast(nv); osgViewer::View* view = ev ? dynamic_cast(ev->getActionAdapter()) : NULL; if (view) @@ -403,14 +403,14 @@ int main( int argc, char **argv ) // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); if (!scene) { osg::Geode* geode = new osg::Geode(); osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box()); geode->addDrawable(drawable); - + scene = geode; } @@ -463,15 +463,15 @@ int main( int argc, char **argv ) view->addEventHandler( new osgViewer::StatsHandler ); view->addEventHandler( new UserEventHandler(text) ); - osg::ref_ptr device = osgDB::readFile("0.0.0.0:9000.receiver.osc"); + osg::ref_ptr device = osgDB::readRefFile("0.0.0.0:9000.receiver.osc"); if (device.valid() && (device->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)) { - view->addDevice(device.get()); + view->addDevice(device); // add a zeroconf device, advertising the osc-device if(use_zeroconf) { - osgGA::Device* zeroconf_device = osgDB::readFile("_osc._udp:9000.advertise.zeroconf"); + osg::ref_ptr zeroconf_device = osgDB::readRefFile("_osc._udp:9000.advertise.zeroconf"); if (zeroconf_device) { view->addDevice(zeroconf_device); @@ -496,8 +496,8 @@ int main( int argc, char **argv ) traits->windowName = "Sender / view one"; osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - + + #ifdef __APPLE__ // as multitouch is disabled by default, enable it now osgViewer::GraphicsWindowCocoa* win = dynamic_cast(gc.get()); @@ -527,7 +527,7 @@ int main( int argc, char **argv ) if (use_zeroconf) { - osgGA::Device* zeroconf_device = osgDB::readFile("_osc._udp.discover.zeroconf"); + osg::ref_ptr zeroconf_device = osgDB::readRefFile("_osc._udp.discover.zeroconf"); if(zeroconf_device) { view->addDevice(zeroconf_device); view->getEventHandlers().push_front(new OscServiceDiscoveredEventHandler()); @@ -536,7 +536,7 @@ int main( int argc, char **argv ) } else { - osg::ref_ptr device = osgDB::readFile("localhost:9000.sender.osc"); + osg::ref_ptr device = osgDB::readRefFile("localhost:9000.sender.osc"); if (device.valid() && (device->getCapabilities() & osgGA::Device::SEND_EVENTS)) { // add as first event handler, so it gets ALL events ... diff --git a/examples/osgoutline/osgoutline.cpp b/examples/osgoutline/osgoutline.cpp index eb26a8638..994ec857a 100644 --- a/examples/osgoutline/osgoutline.cpp +++ b/examples/osgoutline/osgoutline.cpp @@ -25,7 +25,7 @@ int main(int argc, char** argv) // load outlined object std::string modelFilename = arguments.argc() > 1 ? arguments[1] : "dumptruck.osgt"; - osg::ref_ptr outlineModel = osgDB::readNodeFile(modelFilename); + osg::ref_ptr outlineModel = osgDB::readRefNodeFile(modelFilename); if (!outlineModel) { osg::notify(osg::FATAL) << "Unable to load model '" << modelFilename << "'\n"; @@ -38,18 +38,18 @@ int main(int argc, char** argv) { // create outline effect osg::ref_ptr outline = new osgFX::Outline; - root->addChild(outline.get()); + root->addChild(outline); outline->setWidth(8); outline->setColor(osg::Vec4(1,1,0,1)); - outline->addChild(outlineModel.get()); + outline->addChild(outlineModel); } if (testOcclusion) { // load occluder std::string occludedModelFilename = "cow.osgt"; - osg::ref_ptr occludedModel = osgDB::readNodeFile(occludedModelFilename); + osg::ref_ptr occludedModel = osgDB::readRefNodeFile(occludedModelFilename); if (!occludedModel) { osg::notify(osg::FATAL) << "Unable to load model '" << occludedModelFilename << "'\n"; @@ -63,14 +63,14 @@ int main(int argc, char** argv) // occluder behind outlined model osg::ref_ptr modelTransform0 = new osg::PositionAttitudeTransform; modelTransform0->setPosition(bsphere.center() + occluderOffset); - modelTransform0->addChild(occludedModel.get()); - root->addChild(modelTransform0.get()); + modelTransform0->addChild(occludedModel); + root->addChild(modelTransform0); // occluder in front of outlined model osg::ref_ptr modelTransform1 = new osg::PositionAttitudeTransform; modelTransform1->setPosition(bsphere.center() - occluderOffset); - modelTransform1->addChild(occludedModel.get()); - root->addChild(modelTransform1.get()); + modelTransform1->addChild(occludedModel); + root->addChild(modelTransform1); } // must have stencil buffer... @@ -78,7 +78,7 @@ int main(int argc, char** argv) // construct the viewer osgViewer::Viewer viewer; - viewer.setSceneData(root.get()); + viewer.setSceneData(root); // must clear stencil buffer... unsigned int clearMask = viewer.getCamera()->getClearMask(); diff --git a/examples/osgpagedlod/osgpagedlod.cpp b/examples/osgpagedlod/osgpagedlod.cpp index 646ae73bb..d85886a84 100644 --- a/examples/osgpagedlod/osgpagedlod.cpp +++ b/examples/osgpagedlod/osgpagedlod.cpp @@ -43,17 +43,17 @@ public: _count(0) { } - + virtual void apply(osg::Node& node) { std::ostringstream os; os << node.className() << "_"<<_count++; node.setName(os.str()); - + traverse(node); - } - + } + unsigned int _count; }; @@ -64,7 +64,7 @@ public: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { } - + virtual void apply(osg::PagedLOD& plod) { std::cout<<"PagedLOD "< lod = const_cast(itr->get()); - + if (lod->getNumParents()==0) { osg::notify(osg::NOTICE)<<"Warning can't operator on root node."<getRangeList(); typedef std::multimap< osg::LOD::MinMaxPair , unsigned int > MinMaxPairMap; MinMaxPairMap rangeMap; @@ -166,7 +166,7 @@ public: { rangeMap.insert(std::multimap< osg::LOD::MinMaxPair , unsigned int >::value_type(*ritr, pos)); } - + pos = 0; for(MinMaxPairMap::reverse_iterator mitr = rangeMap.rbegin(); mitr != rangeMap.rend(); @@ -181,11 +181,11 @@ public: std::string filename = _basename; std::ostringstream os; os << _basename << "_"<addChild(lod->getChild(mitr->second), mitr->first.first, mitr->first.second, os.str()); } } - + osg::Node::ParentList parents = lod->getParents(); for(osg::Node::ParentList::iterator pitr=parents.begin(); pitr!=parents.end(); @@ -195,12 +195,12 @@ public: } plod->setCenter(plod->getBound().center()); - + } } - + typedef std::set< osg::ref_ptr > LODSet; LODSet _lodSet; std::string _basename; @@ -214,7 +214,7 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" creates a hierarchy of files for paging which can be later loaded by viewers."); @@ -232,8 +232,8 @@ int main( int argc, char **argv ) std::string outputfile("output.ive"); while (arguments.read("-o",outputfile)) {} - - + + bool makeAllChildrenPaged = false; while (arguments.read("--makeAllChildrenPaged")) { makeAllChildrenPaged = true; } @@ -246,7 +246,7 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - + // if (arguments.argc()<=1) // { // arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); @@ -254,21 +254,21 @@ int main( int argc, char **argv ) // } - osg::ref_ptr model = osgDB::readNodeFiles(arguments); - + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); + if (!model) { osg::notify(osg::NOTICE)<<"No model loaded."<accept(converter); converter.convert(); - + NameVistor nameNodes; model->accept(nameNodes); @@ -278,7 +278,7 @@ int main( int argc, char **argv ) if (model.valid()) { osgDB::writeNodeFile(*model,outputfile); - + WriteOutPagedLODSubgraphsVistor woplsv; model->accept(woplsv); } diff --git a/examples/osgparametric/osgparametric.cpp b/examples/osgparametric/osgparametric.cpp index c5cc74f8d..fb39b091c 100644 --- a/examples/osgparametric/osgparametric.cpp +++ b/examples/osgparametric/osgparametric.cpp @@ -40,7 +40,7 @@ /////////////////////////////////////////////////////////////////// // vertex shader using just Vec4 coefficients -char vertexShaderSource_simple[] = +char vertexShaderSource_simple[] = "uniform vec4 coeff; \n" "\n" "void main(void) \n" @@ -52,11 +52,11 @@ char vertexShaderSource_simple[] = " gl_Vertex.y*coeff[2] + gl_Vertex.y*gl_Vertex.y* coeff[3]; \n" " gl_Position = gl_ModelViewProjectionMatrix * vert;\n" "}\n"; - - + + ////////////////////////////////////////////////////////////////// // vertex shader using full Matrix4 coefficients -char vertexShaderSource_matrix[] = +char vertexShaderSource_matrix[] = "uniform vec4 origin; \n" "uniform mat4 coeffMatrix; \n" "\n" @@ -70,7 +70,7 @@ char vertexShaderSource_matrix[] = ////////////////////////////////////////////////////////////////// // vertex shader using texture read -char vertexShaderSource_texture[] = +char vertexShaderSource_texture[] = "uniform sampler2D vertexTexture; \n" "\n" "void main(void) \n" @@ -86,7 +86,7 @@ char vertexShaderSource_texture[] = ////////////////////////////////////////////////////////////////// // fragment shader // -char fragmentShaderSource[] = +char fragmentShaderSource[] = "uniform sampler2D baseTexture; \n" "\n" "void main(void) \n" @@ -109,17 +109,17 @@ class UniformVarying : public osg::UniformCallback osg::Node* createModel(const std::string& shader, const std::string& textureFileName, const std::string& terrainFileName, bool dynamic, bool useVBO) { osg::Geode* geode = new osg::Geode; - + osg::Geometry* geom = new osg::Geometry; geode->addDrawable(geom); - + // dimensions for ~one million triangles :-) unsigned int num_x = 708; unsigned int num_y = 708; // set up state { - + osg::StateSet* stateset = geom->getOrCreateStateSet(); osg::Program* program = new osg::Program; @@ -131,7 +131,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile program->addShader(vertex_shader); osg::Uniform* coeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f)); - + stateset->addUniform(coeff); if (dynamic) @@ -140,7 +140,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile coeff->setDataVariance(osg::Object::DYNAMIC); stateset->setDataVariance(osg::Object::DYNAMIC); } - + } else if (shader=="matrix") { @@ -163,7 +163,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource_texture); program->addShader(vertex_shader); - osg::Image* image = 0; + osg::ref_ptr image; if (terrainFileName.empty()) { @@ -184,7 +184,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile } else { - image = osgDB::readImageFile(terrainFileName); + image = osgDB::readRefImageFile(terrainFileName); num_x = image->s(); num_y = image->t(); @@ -206,7 +206,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource); program->addShader(fragment_shader); - osg::Texture2D* texture = new osg::Texture2D(osgDB::readImageFile(textureFileName)); + osg::Texture2D* texture = new osg::Texture2D(osgDB::readRefImageFile(textureFileName)); stateset->setTextureAttributeAndModes(0,texture); osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); @@ -218,11 +218,11 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile // set up geometry data. osg::Vec3Array* vertices = new osg::Vec3Array( num_x * num_y ); - + float dx = 1.0f/(float)(num_x-1); float dy = 1.0f/(float)(num_y-1); osg::Vec3 row(0.0f,0.0f,0.0); - + unsigned int vert_no = 0; unsigned int iy; for(iy=0; iysetVertexBufferObject(vbo); - + osg::ElementBufferObject* ebo = useVBO ? new osg::ElementBufferObject : 0; for(iy=0; iyaddPrimitiveSet(elements); - + geom->addPrimitiveSet(elements); + if (ebo) elements->setElementBufferObject(ebo); } - + geom->setUseVertexBufferObjects(useVBO); return geode; @@ -272,7 +272,7 @@ int main(int argc, char *argv[]) arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrate support for ARB_vertex_program."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); - + // construct the viewer. osgViewer::Viewer viewer; @@ -281,7 +281,7 @@ int main(int argc, char *argv[]) std::string shader("simple"); while(arguments.read("-s",shader)) {} - + std::string textureFileName("Images/lz.rgb"); while(arguments.read("-t",textureFileName)) {} @@ -300,14 +300,14 @@ int main(int argc, char *argv[]) arguments.getApplicationUsage()->write(std::cout); return 1; } - + // load the nodes from the commandline arguments. osg::Node* model = createModel(shader,textureFileName,terrainFileName, dynamic, vbo); if (!model) { return 1; } - + viewer.setSceneData(model); return viewer.run(); diff --git a/examples/osgparticleeffects/osgparticleeffects.cpp b/examples/osgparticleeffects/osgparticleeffects.cpp index 2399905c7..289914328 100644 --- a/examples/osgparticleeffects/osgparticleeffects.cpp +++ b/examples/osgparticleeffects/osgparticleeffects.cpp @@ -77,9 +77,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength); - osg::Group* model = new osg::Group; + osg::ref_ptr model = new osg::Group; - osg::Node* glider = osgDB::readNodeFile("glider.osgt"); + osg::ref_ptr glider = osgDB::readRefNodeFile("glider.osgt"); if (glider) { const osg::BoundingSphere& bs = glider->getBound(); @@ -102,7 +102,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) model->addChild(xform); } - osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { const osg::BoundingSphere& bs = cessna->getBound(); @@ -126,7 +126,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) model->addChild(xform); } - return model; + return model.release(); } @@ -162,8 +162,8 @@ void build_world(osg::Group *root) osg::Geode* terrainGeode = new osg::Geode; // create terrain { - osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr stateset = new osg::StateSet(); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; diff --git a/examples/osgphotoalbum/ImageReaderWriter.cpp b/examples/osgphotoalbum/ImageReaderWriter.cpp index ddfa8f63f..83e72a604 100644 --- a/examples/osgphotoalbum/ImageReaderWriter.cpp +++ b/examples/osgphotoalbum/ImageReaderWriter.cpp @@ -75,21 +75,20 @@ std::string ImageReaderWriter::local_insertReference(const std::string& fileName return myReference; } -osg::Image* ImageReaderWriter::readImage_Archive(DataReference& dr, float& s,float& t) +osg::ref_ptr ImageReaderWriter::readImage_Archive(DataReference& dr, float& s,float& t) { for(PhotoArchiveList::iterator itr=_photoArchiveList.begin(); itr!=_photoArchiveList.end(); ++itr) { - osg::Image* image = (*itr)->readImage(dr._fileName,dr._resolutionX,dr._resolutionY,s,t); + osg::ref_ptr image = (*itr)->readImage(dr._fileName,dr._resolutionX,dr._resolutionY,s,t); if (image) return image; } return 0; } -osg::Image* ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, float& s,float& t) +osg::ref_ptr ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, float& s,float& t) { - // record previous options. osg::ref_ptr previousOptions = osgDB::Registry::instance()->getOptions(); @@ -99,7 +98,7 @@ osg::Image* ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, floa osgDB::Registry::instance()->setOptions(options.get()); - osg::Image* image = osgDB::readImageFile(dr._fileName); + osg::ref_ptr image = osgDB::readRefImageFile(dr._fileName); // restore previous options. osgDB::Registry::instance()->setOptions(previousOptions.get()); @@ -119,7 +118,7 @@ osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::str DataReference& dr = itr->second; - osg::Image* image = 0; + osg::ref_ptr image; float s=1.0f,t=1.0f; // try to load photo from any loaded PhotoArchives diff --git a/examples/osgphotoalbum/ImageReaderWriter.h b/examples/osgphotoalbum/ImageReaderWriter.h index 751d3d73f..1e20736b3 100644 --- a/examples/osgphotoalbum/ImageReaderWriter.h +++ b/examples/osgphotoalbum/ImageReaderWriter.h @@ -1,4 +1,4 @@ -/* -*-c++-*- +/* -*-c++-*- * * OpenSceneGraph example, osgphotoalbum. * @@ -30,14 +30,14 @@ #include "PhotoArchive.h" -#define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex) +#define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex) class ImageReaderWriter : public osgDB::ReaderWriter { public: - + ImageReaderWriter(); - + virtual const char* className() const { return "ImageReader"; } void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); } @@ -54,7 +54,7 @@ class ImageReaderWriter : public osgDB::ReaderWriter return const_cast(this)->local_readNode(fileName, options); } - + protected: std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage); @@ -73,16 +73,16 @@ class ImageReaderWriter : public osgDB::ReaderWriter unsigned int _resolutionX; unsigned int _resolutionY; osg::Vec3 _center; - osg::Vec3 _maximumWidth; + osg::Vec3 _maximumWidth; osg::Vec3 _maximumHeight; - unsigned int _numPointsAcross; + unsigned int _numPointsAcross; unsigned int _numPointsUp; bool _backPage; }; - - osg::Image* readImage_Archive(DataReference& dr, float& s,float& t); - - osg::Image* readImage_DynamicSampling(DataReference& dr, float& s,float& t); + + osg::ref_ptr readImage_Archive(DataReference& dr, float& s,float& t); + + osg::ref_ptr readImage_DynamicSampling(DataReference& dr, float& s,float& t); typedef std::map< std::string,DataReference > DataReferenceMap; typedef std::vector< osg::ref_ptr > PhotoArchiveList; diff --git a/examples/osgphotoalbum/PhotoArchive.cpp b/examples/osgphotoalbum/PhotoArchive.cpp index 76db14477..b1319277e 100644 --- a/examples/osgphotoalbum/PhotoArchive.cpp +++ b/examples/osgphotoalbum/PhotoArchive.cpp @@ -38,7 +38,7 @@ PhotoArchive::PhotoArchive(const std::string& filename) bool PhotoArchive::readPhotoIndex(const std::string& filename) { osgDB::ifstream in(filename.c_str()); - + char* fileIndentifier = new char [FILE_IDENTIFER.size()]; in.read(fileIndentifier,FILE_IDENTIFER.size()); if (FILE_IDENTIFER!=fileIndentifier) @@ -47,17 +47,17 @@ bool PhotoArchive::readPhotoIndex(const std::string& filename) return false; } delete [] fileIndentifier; - + unsigned int numPhotos; in.read((char*)&numPhotos,sizeof(numPhotos)); _photoIndex.resize(numPhotos); in.read((char*)&_photoIndex.front(),sizeof(PhotoHeader)*numPhotos); - + // success record filename. _archiveFileName = filename; - + return true; } @@ -69,10 +69,10 @@ void PhotoArchive::getImageFileNameList(FileNameList& filenameList) { filenameList.push_back(std::string(itr->filename)); } - + } -osg::Image* PhotoArchive::readImage(const std::string& filename, +osg::ref_ptr PhotoArchive::readImage(const std::string& filename, unsigned int target_s, unsigned target_t, float& original_s, float& original_t) { @@ -83,56 +83,56 @@ osg::Image* PhotoArchive::readImage(const std::string& filename, if (filename==itr->filename) { const PhotoHeader& photoHeader = *itr; - + if (target_s <= photoHeader.thumbnail_s && target_t <= photoHeader.thumbnail_t && photoHeader.thumbnail_position != 0) { osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); - + // find image in.seekg(photoHeader.thumbnail_position); - + // read image header ImageHeader imageHeader; in.read((char*)&imageHeader,sizeof(ImageHeader)); unsigned char* data = new unsigned char[imageHeader.size]; in.read((char*)data,imageHeader.size); - - osg::Image* image = new osg::Image; + + osg::ref_ptr image = new osg::Image; image->setImage(photoHeader.thumbnail_s,photoHeader.thumbnail_t,1, imageHeader.pixelFormat,imageHeader.pixelFormat,imageHeader.type, data,osg::Image::USE_NEW_DELETE); - + original_s = photoHeader.original_s; original_t = photoHeader.original_t; - + return image; } - + if (photoHeader.fullsize_s && photoHeader.fullsize_t && photoHeader.fullsize_position != 0) { osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); - + // find image in.seekg(photoHeader.fullsize_position); - + // read image header ImageHeader imageHeader; in.read((char*)&imageHeader,sizeof(ImageHeader)); unsigned char* data = new unsigned char[imageHeader.size]; in.read((char*)data,imageHeader.size); - - osg::Image* image = new osg::Image; + + osg::ref_ptr image = new osg::Image; image->setImage(photoHeader.fullsize_s,photoHeader.fullsize_t,1, imageHeader.pixelFormat,imageHeader.pixelFormat,imageHeader.type, data,osg::Image::USE_NEW_DELETE); - + original_s = photoHeader.original_s; original_t = photoHeader.original_t; - + return image; } @@ -152,21 +152,21 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& ++fitr) { PhotoHeader header; - + // set name strncpy(header.filename,fitr->c_str(),255); header.filename[255]=0; - + header.thumbnail_s = thumbnailSize; header.thumbnail_t = thumbnailSize; header.thumbnail_position = 0; - + header.fullsize_s = thumbnailSize; header.fullsize_t = thumbnailSize; header.fullsize_position = 0; photoIndex.push_back(header); - + } std::cout<<"Building photo archive containing "< image = osgDB::readImageFile(photoHeader.filename); - + + osg::ref_ptr image = osgDB::readRefImageFile(photoHeader.filename); + std::cout<<"done."<< std::endl; - + photoHeader.original_s = image->s(); photoHeader.original_t = image->t(); @@ -207,7 +207,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& std::cout<<" creating thumbnail image..."; // first need to rescale image to the require thumbnail size - unsigned int newTotalSize = + unsigned int newTotalSize = image->computeRowWidthInBytes(thumbnailSize,image->getPixelFormat(),image->getDataType(),image->getPacking())* thumbnailSize; @@ -241,7 +241,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& osg::notify(osg::WARN) << "Error scaleImage() did not succeed : errorString = "<computeRowWidthInBytes(photoHeader.fullsize_s,image->getPixelFormat(),image->getDataType(),image->getPacking())* photoHeader.fullsize_t; @@ -326,7 +326,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& std::cout<<"done."<< std::endl; } - + } // rewrite photo index now it has the correct sizes set diff --git a/examples/osgphotoalbum/PhotoArchive.h b/examples/osgphotoalbum/PhotoArchive.h index b66abe26f..6a28af031 100644 --- a/examples/osgphotoalbum/PhotoArchive.h +++ b/examples/osgphotoalbum/PhotoArchive.h @@ -1,4 +1,4 @@ -/* -*-c++-*- +/* -*-c++-*- * * OpenSceneGraph example, osgphotoalbum. * @@ -35,19 +35,19 @@ public: } typedef std::vector FileNameList; - + bool empty() { return _photoIndex.empty(); } void getImageFileNameList(FileNameList& filenameList); - + static void buildArchive(const std::string& filename, const FileNameList& imageList, unsigned int thumbnailSize=256, unsigned int maximumSize=1024, bool compressed=true); - osg::Image* readImage(const std::string& filename, + osg::ref_ptr readImage(const std::string& filename, unsigned int target_s, unsigned target_t, float& original_s, float& original_t); - - - + + + protected: PhotoArchive(const std::string& filename); @@ -55,7 +55,7 @@ protected: virtual ~PhotoArchive() {} bool readPhotoIndex(const std::string& filename); - + struct PhotoHeader { PhotoHeader(): @@ -70,7 +70,7 @@ protected: { filename[0]='\0'; } - + char filename[256]; unsigned int original_s; unsigned int original_t; @@ -84,7 +84,7 @@ protected: unsigned int fullsize_position; }; - + struct ImageHeader { ImageHeader(): @@ -94,7 +94,7 @@ protected: pixelFormat(0), type(0), size(0) {} - + unsigned int s; unsigned int t; GLint internalTextureformat; @@ -107,7 +107,7 @@ protected: typedef std::vector PhotoIndexList; std::string _archiveFileName; - PhotoIndexList _photoIndex; + PhotoIndexList _photoIndex; }; diff --git a/examples/osgpick/osgpick.cpp b/examples/osgpick/osgpick.cpp index c6b99b9e4..0f21490a6 100644 --- a/examples/osgpick/osgpick.cpp +++ b/examples/osgpick/osgpick.cpp @@ -239,7 +239,7 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args. - osg::ref_ptr scene = osgDB::readNodeFiles(arguments); + osg::ref_ptr scene = osgDB::readRefNodeFiles(arguments); if (!scene && arguments.read("--relative-camera-scene")) { @@ -271,7 +271,7 @@ int main( int argc, char **argv ) } // if not loaded assume no arguments passed in, try use default mode instead. - if (!scene) scene = osgDB::readNodeFile("fountain.osgt"); + if (!scene) scene = osgDB::readRefNodeFile("fountain.osgt"); osg::ref_ptr group = dynamic_cast(scene.get()); if (!group) diff --git a/examples/osgplanets/osgplanets.cpp b/examples/osgplanets/osgplanets.cpp index c4b39f601..ffea3ef00 100644 --- a/examples/osgplanets/osgplanets.cpp +++ b/examples/osgplanets/osgplanets.cpp @@ -366,7 +366,7 @@ osg::Geode* SolarSystem::createSpace( const std::string& name, const std::string if( !textureName.empty() ) { - osg::Image* image = osgDB::readImageFile( textureName ); + osg::ref_ptr image = osgDB::readRefImageFile( textureName ); if ( image ) { sSpaceSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); @@ -467,7 +467,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c if( !textureName.empty() ) { - osg::Image* image = osgDB::readImageFile( textureName ); + osg::ref_ptr image = osgDB::readRefImageFile( textureName ); if ( image ) { osg::Texture2D* tex2d = new osg::Texture2D( image ); @@ -493,7 +493,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c if( !textureName2.empty() ) { - osg::Image* image = osgDB::readImageFile( textureName2 ); + osg::ref_ptr image = osgDB::readRefImageFile( textureName2 ); if ( image ) { osg::StateSet* stateset = geodePlanet->getOrCreateStateSet(); diff --git a/examples/osgpoints/osgpoints.cpp b/examples/osgpoints/osgpoints.cpp index 54590b574..ca2fb2a72 100644 --- a/examples/osgpoints/osgpoints.cpp +++ b/examples/osgpoints/osgpoints.cpp @@ -31,7 +31,7 @@ class KeyboardEventHandler : public osgGA::GUIEventHandler { public: - + KeyboardEventHandler(osg::StateSet* stateset): _stateset(stateset) { @@ -39,7 +39,7 @@ public: _point->setDistanceAttenuation(osg::Vec3(0.0,0.0000,0.05f)); _stateset->setAttribute(_point.get()); } - + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) @@ -73,13 +73,13 @@ public: } return false; } - - + + float getPointSize() const { return _point->getSize(); } - + void setPointSize(float psize) { if (psize>0.0) @@ -98,10 +98,10 @@ public: { _point->setDistanceAttenuation(_point->getDistanceAttenuation()*scale); } - + osg::ref_ptr _stateset; osg::ref_ptr _point; - + }; int main( int argc, char **argv ) @@ -109,7 +109,7 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds.."); @@ -131,7 +131,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->write(std::cout); return 1; } - + bool usePointSprites = false; while (arguments.read("--sprites")) { usePointSprites = true; }; @@ -145,10 +145,10 @@ int main( int argc, char **argv ) } // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; @@ -161,10 +161,10 @@ int main( int argc, char **argv ) // set the scene to render viewer.setSceneData(loadedModel.get()); - + osg::StateSet* stateset = loadedModel->getOrCreateStateSet(); - if (usePointSprites) + if (usePointSprites) { /// Setup cool blending osg::BlendFunc *fn = new osg::BlendFunc(); @@ -176,7 +176,7 @@ int main( int argc, char **argv ) /// The texture for the sprites osg::Texture2D *tex = new osg::Texture2D(); - tex->setImage(osgDB::readImageFile("Images/particle.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/particle.rgb")); stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); } @@ -187,7 +187,7 @@ int main( int argc, char **argv ) osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::POINT ); stateset->setAttributeAndModes( pm, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); } - + // register the handler for modifying the point size viewer.addEventHandler(new KeyboardEventHandler(viewer.getCamera()->getOrCreateStateSet())); @@ -196,10 +196,10 @@ int main( int argc, char **argv ) if (shader) { osg::StateSet* stateset = loadedModel->getOrCreateStateSet(); - + /////////////////////////////////////////////////////////////////// // vertex shader using just Vec4 coefficients - char vertexShaderSource[] = + char vertexShaderSource[] = "void main(void) \n" "{ \n" "\n" @@ -218,7 +218,7 @@ int main( int argc, char **argv ) ////////////////////////////////////////////////////////////////// // fragment shader // - char fragmentShaderSource[] = + char fragmentShaderSource[] = "void main(void) \n" "{ \n" " gl_FragColor = gl_Color; \n" diff --git a/examples/osgpointsprite/osgpointsprite.cpp b/examples/osgpointsprite/osgpointsprite.cpp index 1bbef0df2..dc134ab04 100644 --- a/examples/osgpointsprite/osgpointsprite.cpp +++ b/examples/osgpointsprite/osgpointsprite.cpp @@ -86,7 +86,7 @@ osg::StateSet* makeStateSet(float size) /// The texture for the sprites osg::Texture2D *tex = new osg::Texture2D(); - tex->setImage(osgDB::readImageFile("Images/particle.rgb")); + tex->setImage(osgDB::readRefImageFile("Images/particle.rgb")); set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); return set; diff --git a/examples/osgposter/PosterPrinter.cpp b/examples/osgposter/PosterPrinter.cpp index 6c8c55f65..785947e11 100644 --- a/examples/osgposter/PosterPrinter.cpp +++ b/examples/osgposter/PosterPrinter.cpp @@ -11,7 +11,7 @@ struct PagedLoadingCallback : public osgUtil::IntersectionVisitor::ReadCallback { virtual osg::Node* readNodeFile( const std::string& filename ) { - return osgDB::readNodeFile( filename ); + return osgDB::readRefNodeFile( filename ).release(); } }; static osg::ref_ptr g_pagedLoadingCallback = new PagedLoadingCallback; diff --git a/examples/osgposter/osgposter.cpp b/examples/osgposter/osgposter.cpp index 3c8ccd7b7..1b5464f7d 100644 --- a/examples/osgposter/osgposter.cpp +++ b/examples/osgposter/osgposter.cpp @@ -38,14 +38,14 @@ public: : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _foundNode(0) {} - + void apply( osg::Node& node ) { T* result = dynamic_cast( &node ); if ( result ) _foundNode = result; else traverse( node ); } - + T* _foundNode; }; @@ -53,7 +53,7 @@ template T* findTopMostNodeOfType( osg::Node* node ) { if ( !node ) return 0; - + FindTopMostNodeOfTypeVisitor fnotv; node->accept( fnotv ); return fnotv._foundNode; @@ -75,31 +75,31 @@ void computeViewMatrixOnEarth( osg::Camera* camera, osg::Node* scene, { osg::CoordinateSystemNode* csn = findTopMostNodeOfType(scene); if ( !csn ) return; - + // Compute eye point in world coordiantes osg::Vec3d eye; csn->getEllipsoidModel()->convertLatLongHeightToXYZ( latLongHeight.x(), latLongHeight.y(), latLongHeight.z(), eye.x(), eye.y(), eye.z() ); - + // Build matrix for computing target vector osg::Matrixd target_matrix = osg::Matrixd::rotate( -hpr.x(), osg::Vec3d(1,0,0), -latLongHeight.x(), osg::Vec3d(0,1,0), latLongHeight.y(), osg::Vec3d(0,0,1) ); - + // Compute tangent vector osg::Vec3d tangent = target_matrix.preMult( osg::Vec3d(0,0,1) ); - + // Compute non-inclined, non-rolled up vector osg::Vec3d up( eye ); up.normalize(); - + // Incline by rotating the target- and up vector around the tangent/up-vector // cross-product osg::Vec3d up_cross_tangent = up ^ tangent; osg::Matrixd incline_matrix = osg::Matrixd::rotate( hpr.y(), up_cross_tangent ); osg::Vec3d target = incline_matrix.preMult( tangent ); - + // Roll by rotating the up vector around the target vector osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate( hpr.z(), target ); up = roll_matrix.preMult( up ); @@ -114,7 +114,7 @@ public: : osgViewer::Renderer(camera), _cullOnly(true) { } - + void setCullOnly(bool on) { _cullOnly = on; } virtual void operator ()( osg::GraphicsContext* ) @@ -125,22 +125,22 @@ public: else cull_draw(); } } - + virtual void cull() { osgUtil::SceneView* sceneView = _sceneView[0].get(); if ( !sceneView || _done || _graphicsThreadDoesCull ) return; - + updateSceneView( sceneView ); - + osgViewer::View* view = dynamic_cast( _camera->getView() ); if ( view ) sceneView->setFusionDistance( view->getFusionDistanceMode(), view->getFusionDistanceValue() ); sceneView->inheritCullSettings( *(sceneView->getCamera()) ); sceneView->cull(); } - + bool _cullOnly; }; @@ -150,12 +150,12 @@ class PrintPosterHandler : public osgGA::GUIEventHandler public: PrintPosterHandler( PosterPrinter* printer ) : _printer(printer), _started(false) {} - + bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { osgViewer::View* view = dynamic_cast( &aa ); if ( !view ) return false; - + switch( ea.getEventType() ) { case osgGA::GUIEventAdapter::FRAME: @@ -165,7 +165,7 @@ public: if ( view->getDatabasePager()->getRequestsInProgress() ) break; } - + if ( _printer.valid() ) { _printer->frame( view->getFrameStamp(), view->getSceneData() ); @@ -183,7 +183,7 @@ public: } } break; - + case osgGA::GUIEventAdapter::KEYDOWN: if ( ea.getKey()=='p' || ea.getKey()=='P' ) { @@ -196,14 +196,14 @@ public: root->setValue( 0, false ); root->setValue( 1, true ); } - + _printer->init( view->getCamera() ); _started = true; } return true; } break; - + default: break; } @@ -241,13 +241,13 @@ int main( int argc, char** argv ) usage->addCommandLineOption( "--camera-eye ", "Set eye position in inactive mode." ); usage->addCommandLineOption( "--camera-latlongheight ", "Set eye position on earth in inactive mode." ); usage->addCommandLineOption( "--camera-hpr

", "Set eye rotation in inactive mode." ); - + if ( arguments.read("-h") || arguments.read("--help") ) { usage->write( std::cout ); return 1; } - + // Poster arguments bool activeMode = true; bool outputPoster = true; @@ -257,7 +257,7 @@ int main( int argc, char** argv ) std::string posterName = "poster.bmp", extName = "bmp"; osg::Vec4 bgColor(0.2f, 0.2f, 0.6f, 1.0f); osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - + while ( arguments.read("--inactive") ) { activeMode = false; } while ( arguments.read("--color", bgColor.r(), bgColor.g(), bgColor.b()) ) {} while ( arguments.read("--tilesize", tileWidth, tileHeight) ) {} @@ -272,7 +272,7 @@ int main( int argc, char** argv ) while ( arguments.read("--use-pbuffer")) { renderImplementation = osg::Camera::PIXEL_BUFFER; } while ( arguments.read("--use-pbuffer-rtt")) { renderImplementation = osg::Camera::PIXEL_BUFFER_RTT; } while ( arguments.read("--use-fb")) { renderImplementation = osg::Camera::FRAME_BUFFER; } - + // Camera settings for inactive screenshot bool useLatLongHeight = true; osg::Vec3d eye; @@ -296,16 +296,16 @@ int main( int argc, char** argv ) hpr.y() = osg::DegreesToRadians( hpr.y() ); hpr.z() = osg::DegreesToRadians( hpr.z() ); } - + // Construct scene graph - osg::Node* scene = osgDB::readNodeFiles( arguments ); - if ( !scene ) scene = osgDB::readNodeFile( "cow.osgt" ); + osg::ref_ptr scene = osgDB::readRefNodeFiles( arguments ); + if ( !scene ) scene = osgDB::readRefNodeFile( "cow.osgt" ); if ( !scene ) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } - + // Create camera for rendering tiles offscreen. FrameBuffer is recommended because it requires less memory. osg::ref_ptr camera = new osg::Camera; camera->setClearColor( bgColor ); @@ -315,13 +315,13 @@ int main( int argc, char** argv ) camera->setRenderTargetImplementation( renderImplementation ); camera->setViewport( 0, 0, tileWidth, tileHeight ); camera->addChild( scene ); - + // Set the printer osg::ref_ptr printer = new PosterPrinter; printer->setTileSize( tileWidth, tileHeight ); printer->setPosterSize( posterWidth, posterHeight ); printer->setCamera( camera.get() ); - + osg::ref_ptr posterImage = 0; if ( outputPoster ) { @@ -330,7 +330,7 @@ int main( int argc, char** argv ) printer->setFinalPoster( posterImage.get() ); printer->setOutputPosterName( posterName ); } - + #if 0 // While recording sub-images of the poster, the scene will always be traversed twice, from its two // parent node: root and camera. Sometimes this may not be so comfortable. @@ -345,11 +345,11 @@ int main( int argc, char** argv ) root->addChild( scene ); root->addChild( camera.get() ); #endif - + osgViewer::Viewer viewer; viewer.setSceneData( root.get() ); viewer.getDatabasePager()->setDoPreCompile( false ); - + if ( renderImplementation==osg::Camera::FRAME_BUFFER ) { // FRAME_BUFFER requires the window resolution equal or greater than the to-be-copied size @@ -360,7 +360,7 @@ int main( int argc, char** argv ) // We want to see the console output, so just render in a window viewer.setUpViewInWindow( 100, 100, 800, 600 ); } - + if ( activeMode ) { viewer.addEventHandler( new PrintPosterHandler(printer.get()) ); @@ -373,21 +373,21 @@ int main( int argc, char** argv ) { osg::Camera* camera = viewer.getCamera(); if ( !useLatLongHeight ) computeViewMatrix( camera, eye, hpr ); - else computeViewMatrixOnEarth( camera, scene, latLongHeight, hpr ); - + else computeViewMatrixOnEarth( camera, scene.get(), latLongHeight, hpr ); + osg::ref_ptr renderer = new CustomRenderer( camera ); camera->setRenderer( renderer.get() ); viewer.setThreadingModel( osgViewer::Viewer::SingleThreaded ); - + // Realize and initiate the first PagedLOD request viewer.realize(); viewer.frame(); - + printer->init( camera ); while ( !printer->done() ) { viewer.advance(); - + // Keep updating and culling until full level of detail is reached renderer->setCullOnly( true ); while ( viewer.getDatabasePager()->getRequestsInProgress() ) @@ -395,7 +395,7 @@ int main( int argc, char** argv ) viewer.updateTraversal(); viewer.renderingTraversals(); } - + renderer->setCullOnly( false ); printer->frame( viewer.getFrameStamp(), viewer.getSceneData() ); viewer.renderingTraversals(); diff --git a/examples/osgprecipitation/osgprecipitation.cpp b/examples/osgprecipitation/osgprecipitation.cpp index 98ad13fb4..c8fea735e 100644 --- a/examples/osgprecipitation/osgprecipitation.cpp +++ b/examples/osgprecipitation/osgprecipitation.cpp @@ -49,7 +49,7 @@ class MyGustCallback : public osg::NodeCallback virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { osgParticle::PrecipitationEffect* pe = dynamic_cast(node); - + float value = sin(nv->getFrameStamp()->getSimulationTime()); if (value<-0.5) { @@ -59,7 +59,7 @@ class MyGustCallback : public osg::NodeCallback { pe->rain(0.5); } - + traverse(node, nv); } }; @@ -70,7 +70,7 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds.."); @@ -89,7 +89,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--fogDensity ","Set the fog density"); arguments.getApplicationUsage()->addCommandLineOption("--fogColour ","Set fog colour."); arguments.getApplicationUsage()->addCommandLineOption("-useFarLineSegments","Switch on the use of line segments"); - + // construct the viewer. osgViewer::Viewer viewer; @@ -108,7 +108,7 @@ int main( int argc, char **argv ) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -135,7 +135,7 @@ int main( int argc, char **argv ) osg::Vec3 wind; while (arguments.read("--wind", wind.x(), wind.y(), wind.z())) precipitationEffect->setWind(wind); - + while (arguments.read("--particleSpeed", value)) precipitationEffect->setParticleSpeed(value); while (arguments.read("--nearTransition", value )) precipitationEffect->setNearTransition(value); @@ -144,7 +144,7 @@ int main( int argc, char **argv ) while (arguments.read("--particleDensity", value )) precipitationEffect->setMaximumParticleDensity(value); osg::Vec3 cellSize; - while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize); + while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize); double clipDistance = 0.0; while (arguments.read("--clip",clipDistance)) {} @@ -160,10 +160,10 @@ int main( int argc, char **argv ) while (arguments.read("--fogDensity", value )) precipitationEffect->getFog()->setDensity(value); while (arguments.read("--fogColor", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); while (arguments.read("--fogColour", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); - + while (arguments.read("--useFarLineSegments")) { precipitationEffect->setUseFarLineSegments(true); } - + viewer.getCamera()->setClearColor( precipitationEffect->getFog()->getColor() ); @@ -173,21 +173,21 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->write(std::cout); return 1; } - + // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - if (!loadedModel) + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } - + // precipitationEffect->setUpdateCallback(new MyGustCallback); - + osg::ref_ptr group = new osg::Group; - + if (clipDistance!=0.0) - { + { osg::ref_ptr clipNode = new osg::ClipNode; clipNode->addClipPlane( new osg::ClipPlane( 0 ) ); clipNode->getClipPlane(0)->setClipPlane( 0.0, 0.0, -1.0, -clipDistance ); @@ -200,12 +200,12 @@ int main( int argc, char **argv ) { group->addChild(precipitationEffect.get()); } - + group->addChild(loadedModel.get()); loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog()); - - // create the light + + // create the light osg::LightSource* lightSource = new osg::LightSource; group->addChild(lightSource); diff --git a/examples/osgprerender/osgprerender.cpp b/examples/osgprerender/osgprerender.cpp index 85216b518..1e1ba7bf4 100644 --- a/examples/osgprerender/osgprerender.cpp +++ b/examples/osgprerender/osgprerender.cpp @@ -463,10 +463,10 @@ int main( int argc, char **argv ) // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessna.osgt"); if (!loadedModel) { diff --git a/examples/osgreflect/osgreflect.cpp b/examples/osgreflect/osgreflect.cpp index 66a5d991e..4be565766 100644 --- a/examples/osgreflect/osgreflect.cpp +++ b/examples/osgreflect/osgreflect.cpp @@ -63,7 +63,7 @@ osg::StateSet* createMirrorTexturedState(const std::string& filename) dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED); // set up the texture. - osg::Image* image = osgDB::readImageFile(filename.c_str()); + osg::ref_ptr image = osgDB::readRefImageFile(filename.c_str()); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -335,10 +335,10 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt"); + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessna.osgt"); // if no model has been successfully loaded report failure. if (!loadedModel) @@ -350,11 +350,11 @@ int main( int argc, char **argv ) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); // add a transform with a callback to animate the loaded model. osg::ref_ptr loadedModelTransform = new osg::MatrixTransform; - loadedModelTransform->addChild(loadedModel.get()); + loadedModelTransform->addChild(loadedModel); osg::ref_ptr nc = new osg::AnimationPathCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); loadedModelTransform->setUpdateCallback(nc.get()); @@ -364,7 +364,7 @@ int main( int argc, char **argv ) osg::ref_ptr rootNode = createMirroredScene(loadedModelTransform.get()); // set the scene to render - viewer.setSceneData(rootNode.get()); + viewer.setSceneData(rootNode); // hint to tell viewer to request stencil buffer when setting up windows osg::DisplaySettings::instance()->setMinimumNumStencilBits(8); diff --git a/examples/osgscreencapture/osgscreencapture.cpp b/examples/osgscreencapture/osgscreencapture.cpp index 2afefa359..be49dcb42 100644 --- a/examples/osgscreencapture/osgscreencapture.cpp +++ b/examples/osgscreencapture/osgscreencapture.cpp @@ -726,7 +726,7 @@ int main(int argc, char** argv) } // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; @@ -746,9 +746,9 @@ int main(int argc, char** argv) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); - viewer.setSceneData( loadedModel.get() ); + viewer.setSceneData(loadedModel); if (pbuffer.valid()) diff --git a/examples/osgscribe/osgscribe.cpp b/examples/osgscribe/osgscribe.cpp index 02b0df9ad..1f34ffa9d 100644 --- a/examples/osgscribe/osgscribe.cpp +++ b/examples/osgscribe/osgscribe.cpp @@ -40,55 +40,55 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); - + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); + if (!loadedModel) { osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."< rootnode = new osg::Group; + + osg::ref_ptr decorator = new osg::Group; + rootnode->addChild(loadedModel); - - + + rootnode->addChild(decorator); - - decorator->addChild(loadedModel); + + decorator->addChild(loadedModel); // set up the state so that the underlying color is not seen through // and that the drawing mode is changed to wireframe, and a polygon offset - // is added to ensure that we see the wireframe itself, and turn off + // is added to ensure that we see the wireframe itself, and turn off // so texturing too. - osg::StateSet* stateset = new osg::StateSet; - osg::PolygonOffset* polyoffset = new osg::PolygonOffset; + osg::ref_ptr stateset = new osg::StateSet; + osg::ref_ptr polyoffset = new osg::PolygonOffset; polyoffset->setFactor(-1.0f); polyoffset->setUnits(-1.0f); - osg::PolygonMode* polymode = new osg::PolygonMode; + osg::ref_ptr polymode = new osg::PolygonMode; polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); #if 1 - osg::Material* material = new osg::Material; + osg::ref_ptr material = new osg::Material; stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); #else // version which sets the color of the wireframe. osg::Material* material = new osg::Material; material->setColorMode(osg::Material::OFF); // switch glColor usage off - // turn all lighting off + // turn all lighting off material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); @@ -99,21 +99,21 @@ int main( int argc, char **argv ) #endif stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); - + // osg::LineStipple* linestipple = new osg::LineStipple; // linestipple->setFactor(1); // linestipple->setPattern(0xf0f0); // stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON); - + decorator->setStateSet(stateset); - - + + // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode ); - + return viewer.run(); } diff --git a/examples/osgsequence/osgsequence.cpp b/examples/osgsequence/osgsequence.cpp index c42cf087b..91d2473b2 100644 --- a/examples/osgsequence/osgsequence.cpp +++ b/examples/osgsequence/osgsequence.cpp @@ -124,7 +124,7 @@ osg::Sequence* createSequence(osg::ArgumentParser& arguments) typedef std::vector Filenames; Filenames filenames; - + if (arguments.argc() > 1) { for (int i = 1; i < arguments.argc(); ++i) @@ -139,17 +139,17 @@ osg::Sequence* createSequence(osg::ArgumentParser& arguments) filenames.push_back("cessna.osgt"); filenames.push_back("glider.osgt"); } - + for(Filenames::iterator itr = filenames.begin(); itr != filenames.end(); - ++itr) + ++itr) { // load model - osg::Node* node = osgDB::readNodeFile(*itr); + osg::ref_ptr node = osgDB::readRefNodeFile(*itr); if (node) { - seq->addChild(createScaledNode(node, 100.0f)); + seq->addChild(createScaledNode(node.get(), 100.0f)); seq->setTime(seq->getNumChildren()-1, 1.0f); } } @@ -231,7 +231,7 @@ 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; // root diff --git a/examples/osgshadercomposition/oldshadercomposition.cpp b/examples/osgshadercomposition/oldshadercomposition.cpp index 37e40f5ea..2c9e7cacf 100644 --- a/examples/osgshadercomposition/oldshadercomposition.cpp +++ b/examples/osgshadercomposition/oldshadercomposition.cpp @@ -22,7 +22,7 @@ osg::Node* createOldShaderCompositionScene(osg::ArgumentParser& arguments) { - osg::Node* node = osgDB::readNodeFiles(arguments); + osg::ref_ptr node = osgDB::readRefNodeFiles(arguments); if (!node) return 0; osg::Group* group = new osg::Group; diff --git a/examples/osgshadercomposition/osgshadercomposition.cpp b/examples/osgshadercomposition/osgshadercomposition.cpp index 002ccfaa2..d59722b62 100644 --- a/examples/osgshadercomposition/osgshadercomposition.cpp +++ b/examples/osgshadercomposition/osgshadercomposition.cpp @@ -25,7 +25,7 @@ extern osg::Node* createOldShaderCompositionScene(osg::ArgumentParser& arguments osg::Node* createNewShaderCompositionScene(osg::ArgumentParser& arguments) { - osg::ref_ptr node = osgDB::readNodeFiles(arguments); + osg::ref_ptr node = osgDB::readRefNodeFiles(arguments); if (!node) return 0; osg::ref_ptr group = new osg::Group; @@ -34,21 +34,21 @@ osg::Node* createNewShaderCompositionScene(osg::ArgumentParser& arguments) osg::ref_ptr program = new osg::Program; stateset->setAttribute(program.get()); - osg::ref_ptr lighting_shader = osgDB::readShaderFile("shaders/lighting.vert"); + osg::ref_ptr lighting_shader = osgDB::readRefShaderFile("shaders/lighting.vert"); if (lighting_shader.valid()) { program->addShader(lighting_shader.get()); OSG_NOTICE<<"Adding lighting shader"< vertex_shader = osgDB::readShaderFile("shaders/osgshadercomposition.vert"); + osg::ref_ptr vertex_shader = osgDB::readRefShaderFile("shaders/osgshadercomposition.vert"); if (vertex_shader.valid()) { program->addShader(vertex_shader.get()); OSG_NOTICE<<"Adding vertex shader"< fragment_shader = osgDB::readShaderFile("shaders/osgshadercomposition.frag"); + osg::ref_ptr fragment_shader = osgDB::readRefShaderFile("shaders/osgshadercomposition.frag"); if (fragment_shader.valid()) { program->addShader(fragment_shader.get()); diff --git a/examples/osgshadergen/osgshadergen.cpp b/examples/osgshadergen/osgshadergen.cpp index e854e64e9..042f00a02 100644 --- a/examples/osgshadergen/osgshadergen.cpp +++ b/examples/osgshadergen/osgshadergen.cpp @@ -1,9 +1,9 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This application is open source and may be redistributed and/or modified + * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial applications, * as long as this copyright notice is maintained. - * + * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -70,14 +70,14 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->write(std::cout, helpType); return 1; } - + // 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.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); @@ -98,7 +98,7 @@ int main(int argc, char** argv) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -112,13 +112,13 @@ int main(int argc, char** argv) // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); @@ -133,7 +133,7 @@ int main(int argc, char** argv) // add the screen capture handler viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); - + // Register shader generator callback ShaderGenReadFileCallback *readFileCallback = new ShaderGenReadFileCallback; // All read nodes will inherit root state set. @@ -141,8 +141,8 @@ int main(int argc, char** argv) osgDB::Registry::instance()->setReadFileCallback(readFileCallback); // load the data - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - if (!loadedModel) + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; diff --git a/examples/osgshaderterrain/osgshaderterrain.cpp b/examples/osgshaderterrain/osgshaderterrain.cpp index 8d23ffac6..cb2f5459b 100644 --- a/examples/osgshaderterrain/osgshaderterrain.cpp +++ b/examples/osgshaderterrain/osgshaderterrain.cpp @@ -121,7 +121,7 @@ osg::Node* createScene() stateset->setTextureAttributeAndModes(0,terrainTexture,osg::StateAttribute::ON); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 23f8694db..d1087711e 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -390,7 +390,7 @@ namespace ModelTwo // set up the texture of the base. osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -451,7 +451,7 @@ namespace ModelTwo osg::Group* model = new osg::Group; - osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { const osg::BoundingSphere& bs = cessna->getBound(); @@ -571,7 +571,7 @@ namespace ModelThree if (withBaseTexture) { - scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON); + scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readRefImageFile("Images/lz.rgb")), osg::StateAttribute::ON); } return scene; @@ -626,13 +626,13 @@ namespace ModelFive { // Set the ground (only receives shadow) osg::ref_ptr groundNode = new osg::MatrixTransform; - groundNode->addChild( osgDB::readNodeFile("lz.osg") ); + groundNode->addChild( osgDB::readRefNodeFile("lz.osg") ); groundNode->setMatrix( osg::Matrix::translate(200.0f, 200.0f,-200.0f) ); groundNode->setNodeMask( ReceivesShadowTraversalMask ); // Set the cessna (only casts shadow) osg::ref_ptr cessnaNode = new osg::MatrixTransform; - cessnaNode->addChild( osgDB::readNodeFile("cessna.osg.0,0,90.rot") ); + cessnaNode->addChild( osgDB::readRefNodeFile("cessna.osg.0,0,90.rot") ); cessnaNode->addUpdateCallback( createAnimationPathCallback(50.0f, 6.0f) ); cessnaNode->setNodeMask( CastsShadowTraversalMask ); @@ -1025,7 +1025,7 @@ int main(int argc, char** argv) OSG_INFO<<"shadowedScene->getShadowTechnique()="<getShadowTechnique()< model = osgDB::readNodeFiles(arguments); + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); if (model.valid()) { model->setNodeMask(CastsShadowTraversalMask | ReceivesShadowTraversalMask); @@ -1061,7 +1061,7 @@ int main(int argc, char** argv) geode->setNodeMask(shadowedScene->getReceivesShadowTraversalMask()); - geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb"))); + geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readRefImageFile("Images/lz.rgb"))); shadowedScene->addChild(geode); } diff --git a/examples/osgshape/osgshape.cpp b/examples/osgshape/osgshape.cpp index 7adff20f2..f25ac90b7 100644 --- a/examples/osgshape/osgshape.cpp +++ b/examples/osgshape/osgshape.cpp @@ -36,13 +36,13 @@ osg::Geode* createShapes() { osg::Geode* geode = new osg::Geode(); - + // --------------------------------------- // Set up a StateSet to texture the objects // --------------------------------------- osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile( "Images/lz.rgb" ); + osg::ref_ptr image = osgDB::readRefImageFile( "Images/lz.rgb" ); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -50,18 +50,18 @@ osg::Geode* createShapes() texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); stateset->setTextureAttributeAndModes(0,texture, osg::StateAttribute::ON); } - + stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); - + geode->setStateSet( stateset ); - + float radius = 0.8f; float height = 1.0f; - + osg::TessellationHints* hints = new osg::TessellationHints; hints->setDetailRatio(0.5f); - + geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius),hints)); geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(2.0f,0.0f,0.0f),2*radius),hints)); geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),radius,height),hints)); @@ -72,7 +72,7 @@ osg::Geode* createShapes() grid->allocate(38,39); grid->setXInterval(0.28f); grid->setYInterval(0.28f); - + for(unsigned int r=0;r<39;++r) { for(unsigned int c=0;c<38;++c) @@ -81,7 +81,7 @@ osg::Geode* createShapes() } } geode->addDrawable(new osg::ShapeDrawable(grid)); - + osg::ConvexHull* mesh = new osg::ConvexHull; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0].set(9.0+0.0f,-1.0f+2.0f,-1.0f+0.0f); diff --git a/examples/osgsidebyside/osgsidebyside.cpp b/examples/osgsidebyside/osgsidebyside.cpp index 1d8e8bcd2..b946b1a23 100644 --- a/examples/osgsidebyside/osgsidebyside.cpp +++ b/examples/osgsidebyside/osgsidebyside.cpp @@ -41,7 +41,7 @@ using namespace osg; using namespace osgGA; -class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler +class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler { public: SwitchDOFVisitor(): @@ -52,11 +52,11 @@ public: SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) {} META_Object(osg, SwitchDOFVisitor) - + virtual void apply(Group& node) { osgSim::MultiSwitch* pMSwitch = dynamic_cast(&node); - + if (pMSwitch) { mSwitches.push_back(pMSwitch); @@ -64,11 +64,11 @@ public: osg::NodeVisitor::apply(node); } - + virtual void apply(Transform& node) { osgSim::DOFTransform* pDof = dynamic_cast(&node); - + if (pDof) { mDofs.push_back(pDof); @@ -159,12 +159,12 @@ private: void singleWindowSideBySideCameras(osgViewer::Viewer& viewer) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) + if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); @@ -237,14 +237,14 @@ int main( int argc, char **argv ) // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - if (argc<2) + if (argc<2) { std::cout << argv[0] <<": requires filename argument." << std::endl; return 1; } osgViewer::Viewer viewer(arguments); - + std::string outputfile("output.osgt"); while (arguments.read("-o",outputfile)) {} @@ -252,7 +252,7 @@ int main( int argc, char **argv ) while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); } while (arguments.read("-d")) { viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); } while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); } - + singleWindowSideBySideCameras(viewer); viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); @@ -264,30 +264,26 @@ int main( int argc, char **argv ) SwitchDOFVisitor* visit = new SwitchDOFVisitor; viewer.addEventHandler(visit); - - osg::ref_ptr loadedModel; - // load the scene. - loadedModel = osgDB::readNodeFiles(arguments); - if (!loadedModel) + // load the scene. + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); + if (!loadedModel) { std::cout << argv[0] <<": No data loaded." << std::endl; return 1; } osg::Group* group = new osg::Group; - + osg::Group* group1 = new osg::Group; - group1->addChild(loadedModel.get()); + group1->addChild(loadedModel); group1->setNodeMask(1); // Uncomment these lines if you like to compare the loaded model to the resulting model in a merge/diff tool //osgDB::writeNodeFile(*loadedModel.get(), "dummy1.osgt"); - osgDB::writeNodeFile(*loadedModel.get(), outputfile); - osg::ref_ptr convertedModel = osgDB::readNodeFile(outputfile); - - //osgDB::writeNodeFile(*convertedModel.get(), "dummy2.osgt"); + osgDB::writeNodeFile(*loadedModel, outputfile); + osg::ref_ptr convertedModel = osgDB::readRefNodeFile(outputfile); osg::Group* group2 = new osg::Group; group2->addChild(convertedModel.get()); diff --git a/examples/osgsimplegl3/osgsimplegl3.cpp b/examples/osgsimplegl3/osgsimplegl3.cpp index 3d7bee95e..c1385d5d9 100644 --- a/examples/osgsimplegl3/osgsimplegl3.cpp +++ b/examples/osgsimplegl3/osgsimplegl3.cpp @@ -67,7 +67,7 @@ int main( int argc, char** argv ) { osg::ArgumentParser arguments( &argc, argv ); - osg::Node* root = osgDB::readNodeFiles( arguments ); + osg::ref_ptr root = osgDB::readRefNodeFiles( arguments ); if( root == NULL ) { osg::notify( osg::FATAL ) << "Unable to load model from command line." << std::endl; diff --git a/examples/osgsimplifier/osgsimplifier.cpp b/examples/osgsimplifier/osgsimplifier.cpp index 3a6d82e9e..2bef87755 100644 --- a/examples/osgsimplifier/osgsimplifier.cpp +++ b/examples/osgsimplifier/osgsimplifier.cpp @@ -26,10 +26,10 @@ class KeyboardEventHandler : public osgGA::GUIEventHandler { public: - + KeyboardEventHandler(unsigned int& flag) : _flag(flag) {} - + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) @@ -65,7 +65,7 @@ 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" examples illustrates simplification of triangle meshes."); @@ -73,7 +73,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--ratio ","Specify the sample ratio","0.5]"); arguments.getApplicationUsage()->addCommandLineOption("--max-error ","Specify the maximum error","4.0"); - + float sampleRatio = 0.5f; float maxError = 4.0f; @@ -99,18 +99,18 @@ int main( int argc, char **argv ) } // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - + osg::ref_ptr 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 no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } - + //loadedModel->accept(simplifier); unsigned int keyFlag = 0; @@ -133,29 +133,29 @@ int main( int argc, char **argv ) { // fire off the cull and draw traversals of the scene. viewer.frame(); - + if (keyFlag == 1 || keyFlag == 2) { if (keyFlag == 1) ratio *= multiplier; if (keyFlag == 2) ratio /= multiplier; if (ratio root = (osg::Node*)loadedModel->clone(osg::CopyOp::DEEP_COPY_ALL); root->accept(simplifier); - + std::cout<<"done"<setDetailRatio(5.0f); - + osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0,0.0,0.0), osg::WGS_84_RADIUS_POLAR), hints); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(sd); - + std::string filename = osgDB::findDataFile("Images/land_shallow_topo_2048.jpg"); - geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile(filename))); - + geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readRefImageFile(filename))); + osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode; csn->setEllipsoidModel(new osg::EllipsoidModel()); csn->addChild(geode); - + return csn; - + } @@ -104,7 +104,7 @@ public: { _rotation.makeRotate(osg::DegreesToRadians(90.0),0.0,0.0,1.0); } - + void updateParameters() { _longitude += _speed * ((2.0*osg::PI)/360.0)/20.0; @@ -114,7 +114,7 @@ public: virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { updateParameters(); - + osg::NodePath nodePath = nv->getNodePath(); osg::MatrixTransform* mt = nodePath.empty() ? 0 : dynamic_cast(nodePath.back()); @@ -128,7 +128,7 @@ public: { csn = dynamic_cast(nodePath[i]); } - + if (csn) { @@ -142,22 +142,22 @@ public: osg::Transform* transform = nodePath[i]->asTransform(); if (transform) transform->computeLocalToWorldMatrix(inheritedMatrix, nv); } - + osg::Matrixd matrix(inheritedMatrix); //osg::Matrixd matrix; ellipsoid->computeLocalToWorldTransformFromLatLongHeight(_latitude,_longitude,_height,matrix); matrix.preMultRotate(_rotation); - + mt->setMatrix(matrix); } - } + } } - + traverse(node,nv); - } - + } + double _latitude; double _longitude; double _height; @@ -172,7 +172,7 @@ public: FindNamedNodeVisitor(const std::string& name): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _name(name) {} - + virtual void apply(osg::Node& node) { if (node.getName()==_name) @@ -181,7 +181,7 @@ public: } traverse(node); } - + typedef std::vector< osg::ref_ptr > NodeList; std::string _name; @@ -193,28 +193,28 @@ 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 use of node tracker."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); - + // construct the viewer. osgViewer::Viewer viewer(arguments); // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); - + // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); @@ -236,7 +236,7 @@ int main(int argc, char **argv) { osg::Quat local_rotate; local_rotate.makeRotate(osg::DegreesToRadians(vec4[0]),vec4[1],vec4[2],vec4[3]); - + rotation = rotation * local_rotate; } @@ -252,7 +252,7 @@ int main(int argc, char **argv) nc = new osg::AnimationPathCallback(path); } } - + osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; std::string mode; while (arguments.read("--tracker-mode",mode)) @@ -269,8 +269,8 @@ int main(int argc, char **argv) return 1; } } - - + + osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; while (arguments.read("--rotation-mode",mode)) { @@ -287,7 +287,7 @@ int main(int argc, char **argv) bool useOverlay = true; while (arguments.read("--no-overlay") || arguments.read("-n")) useOverlay = false; - + osgSim::OverlayNode::OverlayTechnique technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; while (arguments.read("--object")) technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; while (arguments.read("--ortho") || arguments.read("--orthographic")) technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; @@ -295,7 +295,7 @@ int main(int argc, char **argv) unsigned int overlayTextureUnit = 1; while (arguments.read("--unit", overlayTextureUnit)) {} - + std::string pathfile; while (arguments.read("-p",pathfile)) {} @@ -307,15 +307,15 @@ int main(int argc, char **argv) arguments.getApplicationUsage()->write(std::cout); return 1; } - - + + osg::ref_ptr tm; - + std::string overlayFilename; while(arguments.read("--overlay", overlayFilename)) {} // read the scene from the list of file specified commandline args. - osg::ref_ptr root = osgDB::readNodeFiles(arguments); + osg::ref_ptr root = osgDB::readRefNodeFiles(arguments); if (!root) root = createEarth(); @@ -330,8 +330,8 @@ int main(int argc, char **argv) //ConvertLatLon2EllipsoidCoordinates latlon2em; //shapefile->accept(latlon2em); - osg::ref_ptr shapefile = osgDB::readNodeFile(overlayFilename); - + osg::ref_ptr shapefile = osgDB::readRefNodeFile(overlayFilename); + if (!shapefile) { osg::notify(osg::NOTICE)<<"File `"< cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { double s = 200000.0 / cessna->getBound().radius(); @@ -410,15 +410,15 @@ int main(int argc, char **argv) scaler->addChild(cessna); scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); - + if (addFireEffect) - { + { osg::Vec3d center = cessna->getBound().center(); - + osgParticle::FireEffect* fire = new osgParticle::FireEffect(center, 10.0f); scaler->addChild(fire); } - + if (false) { @@ -460,7 +460,7 @@ int main(int argc, char **argv) std::cout<<"Failed to read cessna.osgt"<valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( '5', "Path", apm ); diff --git a/examples/osgslice/osgslice.cpp b/examples/osgslice/osgslice.cpp index 465395e26..e2905e350 100644 --- a/examples/osgslice/osgslice.cpp +++ b/examples/osgslice/osgslice.cpp @@ -54,7 +54,7 @@ class SliceProcessor _nearFarOffset = _sliceDelta; } _image->allocateImage( _sliceNumber, _sliceNumber,_sliceNumber, GL_RGBA, GL_UNSIGNED_BYTE ); - + } // needs 3D-Texture object osg::Image* _image; @@ -63,7 +63,7 @@ class SliceProcessor double _nearPlane; double _farPlane; double _nearFarOffset; - + // needs function to do rendering and slicing }; @@ -77,7 +77,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-o ","Object to be loaded"); - + if( arguments.read( "-h" ) || arguments.read( "--help" ) ) { std::cout << "Argumentlist:" << std::endl; @@ -85,10 +85,10 @@ int main( int argc, char **argv ) std::cout << "\t--slices sets number of slices through the object" << std::endl; std::cout << "\t--near sets start for near clipping plane" << std::endl; std::cout << "\t--far sets start for far clipping plane" << std::endl; - + return 1; } - + std::string outputName("volume_tex.dds"); while( arguments.read( "-o", outputName ) ) { } @@ -101,10 +101,10 @@ int main( int argc, char **argv ) while( arguments.read( "--near",nearClip ) ) { } while( arguments.read( "--far", farClip) ) { } - + // load the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFiles( arguments ); - if (!loadedModel) + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles( arguments ); + if (!loadedModel) { std::cout << "No data loaded." << std::endl; return 1; @@ -124,7 +124,7 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - + osg::ref_ptr traits = new osg::GraphicsContext::Traits; @@ -144,7 +144,7 @@ int main( int argc, char **argv ) osg::notify(osg::NOTICE)<<"Error: unable to create graphics window"<realize(); gc->makeCurrent(); @@ -157,25 +157,25 @@ int main( int argc, char **argv ) osg::Matrix viewMatrix; // distance from viewport to object's center is set to be 2x bs.radius() viewMatrix.makeLookAt(bs.center()-osg::Vec3(0.0,2.0f*bs.radius(),0.0),bs.center(),osg::Vec3(0.0f,0.0f,1.0f)); - + // turn off autocompution of near and far clipping planes sceneView->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); // set the clear color of the background to make sure that the alpha is 0.0. sceneView->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); - // record the timer tick at the start of rendering. + // record the timer tick at the start of rendering. osg::Timer_t start_tick = osg::Timer::instance()->tick(); - + std::cout << "radius: " << bs.radius() << std::endl; - + unsigned int frameNum = 0; double tmpNear, tmpFar; std::string baseImageName("shot_"); std::string tmpImageName; - + osg::Image* tmpImage = new osg::Image; - + // main loop (note, window toolkits which take control over the main loop will require a window redraw callback containing the code below.) for( unsigned int i = 0 ; i < sp->_sliceNumber && gc->isRealized() ; ++i ) { @@ -183,17 +183,17 @@ int main( int argc, char **argv ) osg::ref_ptr frameStamp = new osg::FrameStamp; frameStamp->setReferenceTime(osg::Timer::instance()->delta_s(start_tick,osg::Timer::instance()->tick())); frameStamp->setFrameNumber(frameNum++); - + // pass frame stamp to the SceneView so that the update, cull and draw traversals all use the same FrameStamp sceneView->setFrameStamp(frameStamp.get()); - + // update the viewport dimensions, incase the window has been resized. sceneView->setViewport(0,0,traits->width,traits->height); - - + + // set the view sceneView->setViewMatrix(viewMatrix); - + // set Projection Matrix tmpNear = sp->_nearPlane+i*sp->_sliceDelta; tmpFar = sp->_farPlane+(i*sp->_sliceDelta)+sp->_nearFarOffset; @@ -201,24 +201,24 @@ int main( int argc, char **argv ) // do the update traversal the scene graph - such as updating animations sceneView->update(); - + // do the cull traversal, collect all objects in the view frustum into a sorted set of rendering bins sceneView->cull(); - + // draw the rendering bins. sceneView->draw(); - + // Swap Buffers gc->swapBuffers(); - + std::cout << "before readPixels: _r = " << sp->_image->r() << std::endl; - + tmpImage->readPixels(static_cast(sceneView->getViewport()->x()), static_cast(sceneView->getViewport()->y()), static_cast(sceneView->getViewport()->width()), static_cast(sceneView->getViewport()->height()), GL_RGBA,GL_UNSIGNED_BYTE); - + // std::cout << "vor copySubImage: _r = " << sp->_image->r() << std::endl; sp->_image->copySubImage( 0, 0, i, tmpImage ); diff --git a/examples/osgspheresegment/osgspheresegment.cpp b/examples/osgspheresegment/osgspheresegment.cpp index 2d658ba53..b5bacadfc 100644 --- a/examples/osgspheresegment/osgspheresegment.cpp +++ b/examples/osgspheresegment/osgspheresegment.cpp @@ -183,7 +183,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * osg::Group* model = new osg::Group; - osg::Node* glider = osgDB::readNodeFile("glider.osgt"); + osg::ref_ptr glider = osgDB::readRefNodeFile("glider.osgt"); if (glider) { const osg::BoundingSphere& bs = glider->getBound(); @@ -236,7 +236,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * model->addChild(xform); } - osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { const osg::BoundingSphere& bs = cessna->getBound(); @@ -361,12 +361,12 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi { // create terrain - osg::ref_ptr terrainGeode = 0; + osg::ref_ptr terrainGeode; { terrainGeode = new osg::Geode; - osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr stateset = new osg::StateSet(); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -385,7 +385,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi osg::Vec3 origin(0.0f,0.0f,0.0f); osg::Vec3 size(1000.0f,1000.0f,250.0f); - osg::Geometry* geometry = new osg::Geometry; + osg::ref_ptr geometry = new osg::Geometry; osg::Vec3Array& v = *(new osg::Vec3Array(numColumns*numRows)); osg::Vec2Array& tc = *(new osg::Vec2Array(numColumns*numRows)); diff --git a/examples/osgspotlight/osgspotlight.cpp b/examples/osgspotlight/osgspotlight.cpp index 5dc5fa24f..2e8d88b8d 100644 --- a/examples/osgspotlight/osgspotlight.cpp +++ b/examples/osgspotlight/osgspotlight.cpp @@ -43,8 +43,8 @@ osg::Image* createSpotLightImage(const osg::Vec4& centerColour, const osg::Vec4& osg::Image* image = new osg::Image; image->allocateImage(size,size,1, GL_RGBA,GL_UNSIGNED_BYTE); - - + + float mid = (float(size)-1)*0.5f; float div = 2.0f/float(size); for(unsigned int r=0;rsetMode(GL_LIGHT0+lightNum, osg::StateAttribute::ON); osg::Vec4 centerColour(1.0f,1.0f,1.0f,1.0f); - osg::Vec4 ambientColour(0.05f,0.05f,0.05f,1.0f); + osg::Vec4 ambientColour(0.05f,0.05f,0.05f,1.0f); // set up spot light texture osg::Texture2D* texture = new osg::Texture2D(); @@ -84,15 +84,15 @@ osg::StateSet* createSpotLightDecoratorState(unsigned int lightNum, unsigned int texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER); texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER); texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_BORDER); - + stateset->setTextureAttributeAndModes(textureUnit, texture, osg::StateAttribute::ON); - + // set up tex gens stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); - + return stateset; } @@ -100,7 +100,7 @@ osg::StateSet* createSpotLightDecoratorState(unsigned int lightNum, unsigned int osg::Node* createSpotLightNode(const osg::Vec3& position, const osg::Vec3& direction, float angle, unsigned int lightNum, unsigned int textureUnit) { osg::Group* group = new osg::Group; - + // create light source. osg::LightSource* lightsource = new osg::LightSource; osg::Light* light = lightsource->getLight(); @@ -109,13 +109,13 @@ osg::Node* createSpotLightNode(const osg::Vec3& position, const osg::Vec3& direc light->setAmbient(osg::Vec4(0.00f,0.00f,0.05f,1.0f)); light->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); group->addChild(lightsource); - + // create tex gen. - + osg::Vec3 up(0.0f,0.0f,1.0f); up = (direction ^ up) ^ direction; up.normalize(); - + osg::TexGenNode* texgenNode = new osg::TexGenNode; texgenNode->setTextureUnit(textureUnit); osg::TexGen* texgen = texgenNode->getTexGen(); @@ -125,56 +125,56 @@ osg::Node* createSpotLightNode(const osg::Vec3& position, const osg::Vec3& direc osg::Matrixd::translate(1.0,1.0,1.0)* osg::Matrixd::scale(0.5,0.5,0.5)); - + group->addChild(texgenNode); - + return group; - + } osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) { - // set up the animation path + // set up the animation path osg::AnimationPath* animationPath = new osg::AnimationPath; animationPath->setLoopMode(osg::AnimationPath::LOOP); - + int numSamples = 40; float yaw = 0.0f; float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); float roll = osg::inDegrees(30.0f); - + double time=0.0f; double time_delta = looptime/(double)numSamples; for(int i=0;iinsert(time,osg::AnimationPath::ControlPoint(position,rotation)); yaw += yaw_delta; time += time_delta; } - return animationPath; + return animationPath; } osg::Node* createBase(const osg::Vec3& center,float radius) { osg::Geode* geode = new osg::Geode; - + // set up the texture of the base. osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; texture->setImage(image); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); } - + geode->setStateSet( stateset ); @@ -183,7 +183,7 @@ osg::Node* createBase(const osg::Vec3& center,float radius) grid->setOrigin(center+osg::Vec3(-radius,-radius,0.0f)); grid->setXInterval(radius*2.0f/(float)(38-1)); grid->setYInterval(radius*2.0f/(float)(39-1)); - + float minHeight = FLT_MAX; float maxHeight = -FLT_MAX; @@ -198,7 +198,7 @@ osg::Node* createBase(const osg::Vec3& center,float radius) if (hsetHeight(c,r,(h+hieghtOffset)*hieghtScale); } } - + geode->addDrawable(new osg::ShapeDrawable(grid)); - + osg::Group* group = new osg::Group; group->addChild(geode); - + return group; } @@ -227,8 +227,8 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength); osg::Group* model = new osg::Group; - - osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); + + osg::ref_ptr cessna = osgDB::readRefNodeFile("cessna.osgt"); if (cessna) { const osg::BoundingSphere& bs = cessna->getBound(); @@ -239,9 +239,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) positioned->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,2.0f)); - + positioned->addChild(cessna); - + osg::MatrixTransform* xform = new osg::MatrixTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0)); xform->addChild(positioned); @@ -250,7 +250,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) model->addChild(xform); } - + return model; } @@ -270,7 +270,7 @@ osg::Node* createModel() // combine the models together to create one which has the shadower and the shadowed with the required callback. osg::Group* root = new osg::Group; - + root->setStateSet(createSpotLightDecoratorState(0,1)); root->addChild(shadower); @@ -284,10 +284,10 @@ int main(int, char **) { // construct the viewer. osgViewer::Viewer viewer; - + // add the spoit light model to the viewer viewer.setSceneData( createModel() ); - + // run the viewer main frame loop. return viewer.run(); } diff --git a/examples/osgstereoimage/osgstereoimage.cpp b/examples/osgstereoimage/osgstereoimage.cpp index 55ae2a673..f23fedef5 100644 --- a/examples/osgstereoimage/osgstereoimage.cpp +++ b/examples/osgstereoimage/osgstereoimage.cpp @@ -141,8 +141,8 @@ osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s osg::Group * loadImages(std::string image1, std::string image2, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length) { - osg::ref_ptr imageLeft = osgDB::readImageFile(image1); - osg::ref_ptr imageRight = osgDB::readImageFile(image2); + osg::ref_ptr imageLeft = osgDB::readRefImageFile(image1); + osg::ref_ptr imageRight = osgDB::readRefImageFile(image2); if (imageLeft.valid() && imageRight.valid()) { osg::ImageStream* streamLeft = dynamic_cast(imageLeft.get()); diff --git a/examples/osgstereomatch/osgstereomatch.cpp b/examples/osgstereomatch/osgstereomatch.cpp index 4f871b7d4..d12ba94f0 100644 --- a/examples/osgstereomatch/osgstereomatch.cpp +++ b/examples/osgstereomatch/osgstereomatch.cpp @@ -175,8 +175,8 @@ int main(int argc, char *argv[]) } // load the images - osg::ref_ptr leftIm = osgDB::readImageFile(leftName); - osg::ref_ptr rightIm = osgDB::readImageFile(rightName); + osg::ref_ptr leftIm = osgDB::readRefImageFile(leftName); + osg::ref_ptr rightIm = osgDB::readRefImageFile(rightName); osg::Node* scene = createScene(leftIm.get(), rightIm.get(), minDisparity, maxDisparity, windowSize, useSinglePass); diff --git a/examples/osgteapot/osgteapot.cpp b/examples/osgteapot/osgteapot.cpp index d11820a82..b2310bcb7 100644 --- a/examples/osgteapot/osgteapot.cpp +++ b/examples/osgteapot/osgteapot.cpp @@ -311,7 +311,7 @@ osg::Geode* createTeapot() geode->addDrawable( new Teapot ); // add a reflection map to the teapot. - osg::Image* image = osgDB::readImageFile("Images/reflect.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/reflect.rgb"); if (image) { osg::Texture2D* texture = new osg::Texture2D; diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 44165f5a0..ce2bd11cc 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -343,7 +343,7 @@ int main(int argc, char** argv) while(arguments.read("--db-affinity", cpuNum)) { setDatabaseThreadAffinity = true; } // load the nodes from the commandline arguments. - osg::ref_ptr rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode = osgDB::readRefNodeFiles(arguments); if (!rootnode) { diff --git a/examples/osgtessellate/osgtessellate.cpp b/examples/osgtessellate/osgtessellate.cpp index e0a137f10..e2e6b2b3e 100644 --- a/examples/osgtessellate/osgtessellate.cpp +++ b/examples/osgtessellate/osgtessellate.cpp @@ -98,7 +98,7 @@ osg::Geometry *makePolsTwo (void) // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Cubemap_snow/posy.jpg"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -169,7 +169,7 @@ osg::Geometry *makeSideWall (const float xpos) // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Cubemap_snow/posx.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Cubemap_snow/posx.jpg"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -265,7 +265,7 @@ osg::Geometry *makeFrontWall (const float zpos) { // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Cubemap_snow/posy.jpg"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -458,7 +458,7 @@ osg::Geometry *makePols (void) { // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Cubemap_snow/posz.jpg"); + osg::ref_ptr image = osgDB::readRefImageFile("Cubemap_snow/posz.jpg"); if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -750,7 +750,7 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer; // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if no model has been successfully loaded report failure. if (!loadedModel) diff --git a/examples/osgtext/osgtext.cpp b/examples/osgtext/osgtext.cpp index 87c2907f8..f29cf7894 100644 --- a/examples/osgtext/osgtext.cpp +++ b/examples/osgtext/osgtext.cpp @@ -75,7 +75,7 @@ osg::Group* createHUDText() osg::Group* rootNode = new osg::Group; - osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); + osg::ref_ptr font = osgText::readRefFontFile("fonts/arial.ttf"); //osg::setNotifyLevel(osg::INFO); @@ -344,7 +344,7 @@ osg::Group* createHUDText() float spacing = 40.0f; { - osgText::Text* text = new osgText::Text; + osg::ref_ptr text = new osgText::Text; text->setUseVertexBufferObjects(useVBOs); text->setColor(fontColor); text->setPosition(cursor); @@ -358,9 +358,9 @@ osg::Group* createHUDText() } { - osgText::Font* arial = osgText::readFontFile("fonts/arial.ttf"); + osg::ref_ptr arial = osgText::readRefFontFile("fonts/arial.ttf"); - osgText::Text* text = new osgText::Text; + osg::ref_ptr text = new osgText::Text; text->setUseVertexBufferObjects(useVBOs); text->setColor(fontColor); text->setPosition(cursor); @@ -376,9 +376,9 @@ osg::Group* createHUDText() } { - osgText::Font* times = osgText::readFontFile("fonts/times.ttf"); + osg::ref_ptr times = osgText::readRefFontFile("fonts/times.ttf"); - osgText::Text* text = new osgText::Text; + osg::ref_ptr text = new osgText::Text; text->setUseVertexBufferObjects(useVBOs); text->setColor(fontColor); text->setPosition(cursor); @@ -397,9 +397,9 @@ osg::Group* createHUDText() cursor.y() = margin; { - osgText::Font* dirtydoz = osgText::readFontFile("fonts/dirtydoz.ttf"); + osg::ref_ptr dirtydoz = osgText::readRefFontFile("fonts/dirtydoz.ttf"); - osgText::Text* text = new osgText::Text; + osg::ref_ptr text = new osgText::Text; text->setUseVertexBufferObjects(useVBOs); text->setColor(fontColor); text->setPosition(cursor); @@ -415,9 +415,9 @@ osg::Group* createHUDText() } { - osgText::Font* fudd = osgText::readFontFile("fonts/fudd.ttf"); + osg::ref_ptr fudd = osgText::readRefFontFile("fonts/fudd.ttf"); - osgText::Text* text = new osgText::Text; + osg::ref_ptr text = new osgText::Text; text->setUseVertexBufferObjects(useVBOs); text->setColor(fontColor); text->setPosition(cursor); @@ -706,10 +706,10 @@ int main(int argc, char** argv) osg::Vec3 center(0.5f,0.5f,0.5f); float diameter = 1.0f; - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (loadedModel.valid()) { - mainGroup->addChild(loadedModel.get()); + mainGroup->addChild(loadedModel); center = loadedModel->getBound().center(); diameter = loadedModel->getBound().radius() * 2.0f; diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 8641800f6..8c15deda5 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) std::string fontFile("arial.ttf"); while(arguments.read("-f",fontFile)) {} - osg::ref_ptr font = osgText::readFontFile(fontFile); + osg::ref_ptr font = osgText::readRefFontFile(fontFile); if (!font) return 1; OSG_NOTICE<<"Read font "<flatBevel(r); } while(arguments.read("--flat")) { bevel = new osgText::Bevel; bevel->flatBevel(0.25); } while(arguments.read("--bevel-thickness",r)) { if (bevel.valid()) bevel->setBevelThickness(r); } - - - if (bevel.valid()) + + + if (bevel.valid()) { while(arguments.read("--smooth-concave-Junctions") || arguments.read("--scj")) { @@ -72,7 +72,7 @@ int main(int argc, char** argv) } } - + style->setBevel(bevel.get()); // set up outline. @@ -139,12 +139,12 @@ int main(int argc, char** argv) while(arguments.read("--image",imageFilename)) { OSG_NOTICE<<"--image "< image = osgDB::readImageFile(imageFilename); + osg::ref_ptr image = osgDB::readRefImageFile(imageFilename); if (image.valid()) { OSG_NOTICE<<" loaded image "<getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); + stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image), osg::StateAttribute::ON); } } @@ -158,11 +158,11 @@ int main(int argc, char** argv) while(arguments.read("--wall-image",imageFilename)) { - osg::ref_ptr image = osgDB::readImageFile(imageFilename); + osg::ref_ptr image = osgDB::readRefImageFile(imageFilename); if (image.valid()) { osg::StateSet* stateset = text3D->getOrCreateWallStateSet(); - stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); + stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image), osg::StateAttribute::ON); } } @@ -176,11 +176,11 @@ int main(int argc, char** argv) while(arguments.read("--back-image",imageFilename)) { - osg::ref_ptr image = osgDB::readImageFile(imageFilename); - if (image.valid()) + osg::ref_ptr image = osgDB::readRefImageFile(imageFilename); + if (image) { osg::StateSet* stateset = text3D->getOrCreateBackStateSet(); - stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); + stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image), osg::StateAttribute::ON); } } @@ -190,8 +190,8 @@ int main(int argc, char** argv) } } - - viewer.setSceneData(group.get()); + + viewer.setSceneData(group); #endif diff --git a/examples/osgtexture1D/osgtexture1D.cpp b/examples/osgtexture1D/osgtexture1D.cpp index 8c070eae1..d4778991a 100644 --- a/examples/osgtexture1D/osgtexture1D.cpp +++ b/examples/osgtexture1D/osgtexture1D.cpp @@ -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 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;isetWrap(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(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 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)<getCommandLineUsage()< stateset = create1DTextureStateToDecorate(loadedModel.get()); if (!stateset) { std::cout<<"Error: failed to create 1D texture state."<setStateSet(stateset); - osg:: Group *root = new osg:: Group; + osg::ref_ptr root = new osg:: Group; root -> addChild( loadedModel ); // The contour banded color texture is used in conjunction with TexGenNode diff --git a/examples/osgtexture2D/osgtexture2D.cpp b/examples/osgtexture2D/osgtexture2D.cpp index e224d5ea0..a4df73a15 100644 --- a/examples/osgtexture2D/osgtexture2D.cpp +++ b/examples/osgtexture2D/osgtexture2D.cpp @@ -170,7 +170,7 @@ osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename) // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. - texture->setImage(osgDB::readImageFile(filename)); + texture->setImage(osgDB::readRefImageFile(filename)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); @@ -327,7 +327,7 @@ osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filenam // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. - texture->setImage(osgDB::readImageFile(filename)); + texture->setImage(osgDB::readRefImageFile(filename)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); @@ -485,7 +485,7 @@ osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER - texture->setImage(osgDB::readImageFile(filename)); + texture->setImage(osgDB::readRefImageFile(filename)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); @@ -535,7 +535,7 @@ public: { #if 1 - osg::ref_ptr originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg"); + osg::ref_ptr originalImage = osgDB::readRefImageFile("Images/dog_left_eye.jpg"); osg::ref_ptr subImage = new osg::Image; subImage->setUserData(originalImage.get()); // attach the originalImage as user data to prevent it being deleted. @@ -573,14 +573,14 @@ public: #endif - _imageList.push_back(subImage.get()); + _imageList.push_back(subImage); #else - _imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg")); + _imageList.push_back(osgDB::readRefImageFile("Images/dog_left_eye.jpg")); #endif _textList.push_back("Subloaded Image 1 - dog_left_eye.jpg"); - _imageList.push_back(osgDB::readImageFile("Images/dog_right_eye.jpg")); + _imageList.push_back(osgDB::readRefImageFile("Images/dog_right_eye.jpg")); _textList.push_back("Subloaded Image 2 - dog_right_eye.jpg"); setValues(); diff --git a/examples/osgtexture2DArray/osgtexture2DArray.cpp b/examples/osgtexture2DArray/osgtexture2DArray.cpp index 4671c039d..c5bd52ead 100644 --- a/examples/osgtexture2DArray/osgtexture2DArray.cpp +++ b/examples/osgtexture2DArray/osgtexture2DArray.cpp @@ -50,10 +50,10 @@ class SubloadCallback : public osg::Texture2DArray::SubloadCallback osg::StateSet* createState(osg::ArgumentParser& arguments) { // read 4 2d images - osg::ref_ptr image_0 = osgDB::readImageFile("Images/lz.rgb"); - osg::ref_ptr image_1 = osgDB::readImageFile("Images/reflect.rgb"); - osg::ref_ptr image_2 = osgDB::readImageFile("Images/tank.rgb"); - osg::ref_ptr image_3 = osgDB::readImageFile("Images/skymap.jpg"); + osg::ref_ptr image_0 = osgDB::readRefImageFile("Images/lz.rgb"); + osg::ref_ptr image_1 = osgDB::readRefImageFile("Images/reflect.rgb"); + osg::ref_ptr image_2 = osgDB::readRefImageFile("Images/tank.rgb"); + osg::ref_ptr image_3 = osgDB::readRefImageFile("Images/skymap.jpg"); if (!image_0 || !image_1 || !image_2 || !image_3) { @@ -128,10 +128,10 @@ osg::StateSet* createState(osg::ArgumentParser& arguments) osg::ref_ptr program = new osg::Program; - osg::ref_ptr vertexShader = osgDB::readShaderFile( osg::Shader::VERTEX, vsFileName) ; + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; if (vertexShader.get()) program->addShader( vertexShader.get() ); - osg::ref_ptr fragmentShader = osgDB::readShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; if (fragmentShader.get()) program->addShader( fragmentShader.get() ); // create the StateSet to store the texture data diff --git a/examples/osgtexture3D/osgtexture3D.cpp b/examples/osgtexture3D/osgtexture3D.cpp index 37e293218..b5a766b44 100644 --- a/examples/osgtexture3D/osgtexture3D.cpp +++ b/examples/osgtexture3D/osgtexture3D.cpp @@ -39,10 +39,10 @@ typedef std::vector< osg::ref_ptr > ImageList; osg::StateSet* createState() { // read 4 2d images - osg::ref_ptr image_0 = osgDB::readImageFile("Images/lz.rgb"); - osg::ref_ptr image_1 = osgDB::readImageFile("Images/reflect.rgb"); - osg::ref_ptr image_2 = osgDB::readImageFile("Images/tank.rgb"); - osg::ref_ptr image_3 = osgDB::readImageFile("Images/skymap.jpg"); + osg::ref_ptr image_0 = osgDB::readRefImageFile("Images/lz.rgb"); + osg::ref_ptr image_1 = osgDB::readRefImageFile("Images/reflect.rgb"); + osg::ref_ptr image_2 = osgDB::readRefImageFile("Images/tank.rgb"); + osg::ref_ptr image_3 = osgDB::readRefImageFile("Images/skymap.jpg"); if (!image_0 || !image_1 || !image_2 || !image_3) { diff --git a/examples/osgtexturecompression/osgtexturecompression.cpp b/examples/osgtexturecompression/osgtexturecompression.cpp index 6106f2c22..be18a9469 100644 --- a/examples/osgtexturecompression/osgtexturecompression.cpp +++ b/examples/osgtexturecompression/osgtexturecompression.cpp @@ -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."< image = osgDB::readImageFile(filename); - + osg::ref_ptr image = osgDB::readRefImageFile(filename); + if (!image) { std::cout<<"Error: unable able to read image from "<height = height; traits->windowDecoration = false; traits->doubleBuffer = true; - + osg::ref_ptr 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 trackball = new osgGA::TrackballManipulator; - + typedef std::vector< osg::ref_ptr > 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; isetSceneData(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()); diff --git a/examples/osgtexturerectangle/osgtexturerectangle.cpp b/examples/osgtexturerectangle/osgtexturerectangle.cpp index 97617cb0a..e95a2cbe3 100644 --- a/examples/osgtexturerectangle/osgtexturerectangle.cpp +++ b/examples/osgtexturerectangle/osgtexturerectangle.cpp @@ -146,7 +146,7 @@ osg::Node* createRectangle(osg::BoundingBox& bb, geom->setUseDisplayList(false); // load image - osg::Image* img = osgDB::readImageFile(filename); + osg::ref_ptr img = osgDB::readRefImageFile(filename); // setup texture osg::TextureRectangle* texture = new osg::TextureRectangle(img); diff --git a/examples/osgthirdpersonview/osgthirdpersonview.cpp b/examples/osgthirdpersonview/osgthirdpersonview.cpp index ea9e15c7f..d364c5765 100644 --- a/examples/osgthirdpersonview/osgthirdpersonview.cpp +++ b/examples/osgthirdpersonview/osgthirdpersonview.cpp @@ -140,20 +140,20 @@ main( int argc, // of the view frustum. root->addChild( makeFrustumFromCamera( NULL ) ); - osg::ref_ptr< osg::Node > scene; - scene = osgDB::readNodeFiles( arguments ); + osg::ref_ptr< osg::Node > scene = osgDB::readRefNodeFiles( arguments ); if (!scene) { // User didn't specify anything, or file(s) didn't exist. // Try to load the cow... osg::notify( osg::WARN ) << arguments.getApplicationName() << ": Could not find specified files. Trying \"cow.osgt\" instead." << std::endl; - if ( !(scene = osgDB::readNodeFile( std::string( "cow.osgt" ) ) ) ) + scene = osgDB::readRefNodeFile("cow.osgt"); + if (!scene) { osg::notify( osg::FATAL ) << arguments.getApplicationName() << ": No data loaded." << std::endl; return 1; } } - root->addChild( scene.get() ); + root->addChild( scene ); osgViewer::CompositeViewer viewer( arguments ); diff --git a/examples/osgthreadedterrain/osgthreadedterrain.cpp b/examples/osgthreadedterrain/osgthreadedterrain.cpp index 766e84d1c..7a1868ef8 100644 --- a/examples/osgthreadedterrain/osgthreadedterrain.cpp +++ b/examples/osgthreadedterrain/osgthreadedterrain.cpp @@ -66,11 +66,11 @@ struct ReleaseBlockOnCompileCompleted : public osgUtil::IncrementalCompileOperat virtual bool compileCompleted(osgUtil::IncrementalCompileOperation::CompileSet* compileSet) { if (_block.valid()) _block->completed(); - + // tell IncrementalCompileOperation that it's now safe to remove the compileSet - + osg::notify(osg::NOTICE)<<"compileCompleted("< compileSet = + osg::ref_ptr compileSet = new osgUtil::IncrementalCompileOperation::CompileSet(_loadedModel.get()); compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_block.get()); _incrementalCompileOperation->add(compileSet.get()); } - else + else { if (_block.valid()) _block->completed(); } // osg::notify(osg::NOTICE)<<"done LoadAndCompileOperation "<<_filename< _loadedModel; osg::ref_ptr _incrementalCompileOperation; @@ -135,12 +135,12 @@ public: _incrementalCompileOperation(ico) { } - - /** Set the OperationQueue that the MasterOperation can use to place tasks like file loading on for other processes to handle.*/ + + /** Set the OperationQueue that the MasterOperation can use to place tasks like file loading on for other processes to handle.*/ void setOperationQueue(osg::OperationQueue* oq) { _operationQueue = oq; } - + osg::OperationQueue* getOperationQueue() { return _operationQueue.get(); } - + bool readMasterFile(Files& files) const { osgDB::ifstream fin(_filename.c_str()); @@ -167,12 +167,12 @@ public: ++fr; } } - + return readFilename; } return false; } - + bool open(osg::Group* group) { Files files; @@ -181,7 +181,7 @@ public: itr != files.end(); ++itr) { - osg::Node* model = osgDB::readNodeFile(*itr); + osg::ref_ptr model = osgDB::readRefNodeFile(*itr); if (model) { osg::notify(osg::NOTICE)<<"open: Loaded file "<<*itr< lock(_mutex); for(Files::iterator fitr = files.begin(); @@ -255,7 +255,7 @@ public: } } } - + #if 0 if (!newFiles.empty() || !removedFiles.empty()) { @@ -270,7 +270,7 @@ public: typedef std::vector< osg::ref_ptr > GraphicsThreads; GraphicsThreads threads; - + for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i) { osg::GraphicsContext* gc = osg::GraphicsContext::getCompileContext(i); @@ -283,12 +283,12 @@ public: // osg::notify(osg::NOTICE)<<"Using OperationQueue"<reset(); - + typedef std::list< osg::ref_ptr > LoadAndCompileList; LoadAndCompileList loadAndCompileList; - + for(Files::iterator nitr = newFiles.begin(); nitr != newFiles.end(); ++nitr) @@ -307,11 +307,11 @@ public: // osg::notify(osg::NOTICE)<<"Local running of operation"<block(); // osg::notify(osg::NOTICE)<<"done ... Waiting for completion of LoadAndCompile operations"<reset(); for(Files::iterator nitr = newFiles.begin(); nitr != newFiles.end(); ++nitr) { - osg::ref_ptr loadedModel = osgDB::readNodeFile(*nitr); + osg::ref_ptr loadedModel = osgDB::readRefNodeFile(*nitr); if (loadedModel.get()) { @@ -343,7 +343,7 @@ public: if (_incrementalCompileOperation.valid()) { - osg::ref_ptr compileSet = + osg::ref_ptr compileSet = new osgUtil::IncrementalCompileOperation::CompileSet(loadedModel.get()); compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_endOfLoadBlock.get()); @@ -364,15 +364,15 @@ public: _endOfLoadBlock->block(); } - + } - + bool requiresBlock = false; - + // pass the locally peppared data to MasterOperations shared data - // so that updated thread can merge these changes with the main scene + // so that updated thread can merge these changes with the main scene // graph. This merge is carried out via the update(..) method. - if (!removedFiles.empty() || !nodesToAdd.empty()) + if (!removedFiles.empty() || !nodesToAdd.empty()) { OpenThreads::ScopedLock lock(_mutex); _nodesToRemove.swap(removedFiles); @@ -392,7 +392,7 @@ public: } } - + // merge the changes with the main scene graph. void update(osg::Node* scene) { @@ -404,9 +404,9 @@ public: osg::notify(osg::NOTICE)<<"Error, MasterOperation::update(Node*) can only work with a Group as Viewer::getSceneData()."< lock(_mutex); - + if (!_nodesToRemove.empty() || !_nodesToAdd.empty()) { osg::notify(osg::NOTICE)<<"update().................. "<removeChild(fnmItr->second.get()); _existingFilenameNodeMap.erase(fnmItr); } @@ -430,7 +430,7 @@ public: _nodesToRemove.clear(); } - + if (!_nodesToAdd.empty()) { for(FilenameNodeMap::iterator itr = _nodesToAdd.begin(); @@ -441,14 +441,14 @@ public: group->addChild(itr->second.get()); _existingFilenameNodeMap[itr->first] = itr->second; } - + _nodesToAdd.clear(); } _updatesMergedBlock.release(); } - + // add release implementation so that any thread cancellation can // work even when blocks and barriers are used. virtual void release() @@ -460,9 +460,9 @@ public: if (_endOfLoadBlock.valid()) _endOfLoadBlock.release(); } - + std::string _filename; - + OpenThreads::Mutex _mutex; FilenameNodeMap _existingFilenameNodeMap; Files _nodesToRemove; @@ -472,13 +472,13 @@ public: osg::ref_ptr _incrementalCompileOperation; osg::ref_ptr _endOfCompilebarrier; osg::ref_ptr _endOfLoadBlock; - + osg::ref_ptr _operationQueue; }; -class FilterHandler : public osgGA::GUIEventHandler +class FilterHandler : public osgGA::GUIEventHandler { -public: +public: FilterHandler(osgTerrain::GeometryTechnique* gt): _gt(gt) {} @@ -550,9 +550,9 @@ protected: -class LayerHandler : public osgGA::GUIEventHandler +class LayerHandler : public osgGA::GUIEventHandler { -public: +public: LayerHandler(osgTerrain::Layer* layer): _layer(layer) {} @@ -612,7 +612,7 @@ int main(int argc, char** argv) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -634,7 +634,7 @@ int main(int argc, char** argv) // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); - // attach an IncrementaCompileOperation to allow the master loading + // attach an IncrementaCompileOperation to allow the master loading // to be handled with an incremental compile to avoid frame drops when large objects are added. viewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation()); @@ -652,7 +652,7 @@ int main(int argc, char** argv) { masterOperation = new MasterOperation(masterFilename, viewer.getIncrementalCompileOperation()); } - + osg::ref_ptr terrainTile = new osgTerrain::TerrainTile; osg::ref_ptr locator = new osgTerrain::Locator; @@ -676,8 +676,8 @@ int main(int argc, char** argv) while(possetTreatBoundariesToValidDataAsDefaultValue(true); } - + else if (arguments.read(pos, "-e",x,y,w,h)) { // define the extents. @@ -710,42 +710,42 @@ int main(int argc, char** argv) { osg::notify(osg::NOTICE)<<"--hf "< hf = osgDB::readHeightFieldFile(filename); + osg::ref_ptr hf = osgDB::readRefHeightFieldFile(filename); if (hf.valid()) { osg::ref_ptr hfl = new osgTerrain::HeightFieldLayer; hfl->setHeightField(hf.get()); - + hfl->setLocator(locator.get()); hfl->setValidDataOperator(validDataOperator.get()); hfl->setMagFilter(filter); - + if (offset!=0.0f || scale!=1.0f) { hfl->transform(offset,scale); } - + terrainTile->setElevationLayer(hfl.get()); - + lastAppliedLayer = hfl.get(); - + osg::notify(osg::NOTICE)<<"created osgTerrain::HeightFieldLayer"< image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image.valid()) { osg::ref_ptr imageLayer = new osgTerrain::ImageLayer; @@ -753,14 +753,14 @@ int main(int argc, char** argv) imageLayer->setLocator(locator.get()); imageLayer->setValidDataOperator(validDataOperator.get()); imageLayer->setMagFilter(filter); - + if (offset!=0.0f || scale!=1.0f) { imageLayer->transform(offset,scale); } - + terrainTile->setElevationLayer(imageLayer.get()); - + lastAppliedLayer = imageLayer.get(); osg::notify(osg::NOTICE)<<"created Elevation osgTerrain::ImageLayer"<getColorLayer(layerNum)) { terrainTile->getColorLayer(layerNum)->setMagFilter(filter); } - + } else if (arguments.read(pos, "--tf",minValue, maxValue)) { osg::ref_ptr tf = new osg::TransferFunction1D; - + unsigned int numCells = 6; float delta = (maxValue-minValue)/float(numCells-1); float v = minValue; - + tf->allocate(6); tf->setColor(v, osg::Vec4(1.0,1.0,1.0,1.0)); v += delta; tf->setColor(v, osg::Vec4(1.0,0.0,1.0,1.0)); v += delta; @@ -848,7 +848,7 @@ int main(int argc, char** argv) tf->setColor(v, osg::Vec4(1.0,1.0,0.0,1.0)); v += delta; tf->setColor(v, osg::Vec4(0.0,1.0,1.0,1.0)); v += delta; tf->setColor(v, osg::Vec4(0.0,1.0,0.0,1.0)); - + osg::notify(osg::NOTICE)<<"--tf "<setColorLayer(layerNum, new osgTerrain::ContourLayer(tf.get())); @@ -859,14 +859,14 @@ int main(int argc, char** argv) } } - + osg::ref_ptr scene = new osg::Group; if (terrainTile.valid() && (terrainTile->getElevationLayer() || terrainTile->getColorLayer(0))) { osg::notify(osg::NOTICE)<<"Terrain created"<addChild(terrainTile.get()); osg::ref_ptr geometryTechnique = new osgTerrain::GeometryTechnique; @@ -881,27 +881,27 @@ int main(int argc, char** argv) masterOperation->open(scene.get()); } - + if (scene->getNumChildren()==0) { osg::notify(osg::NOTICE)<<"No model created, please specify terrain or master file on command line."< masterOperationThread; - + typedef std::list< osg::ref_ptr > OperationThreadList; OperationThreadList generalThreadList; - - if (masterOperation.valid()) + + if (masterOperation.valid()) { masterOperationThread = new osg::OperationThread; masterOperationThread->startThread(); - + masterOperationThread->add(masterOperation.get()); // if (numLoadThreads>0) @@ -910,19 +910,19 @@ int main(int argc, char** argv) masterOperation->setOperationQueue(operationQueue.get()); for(unsigned int i=0; i thread = new osg::OperationThread; thread->setOperationQueue(operationQueue.get()); thread->startThread(); generalThreadList.push_back(thread); } } - + viewer.addUpdateOperation(masterOperation.get()); } - + viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); - + // enable the use of compile contexts and associated threads. // osg::DisplaySettings::instance()->setCompileContextsHint(true); diff --git a/examples/osgtransferfunction/osgtransferfunction.cpp b/examples/osgtransferfunction/osgtransferfunction.cpp index 66710d2b2..2e625700b 100644 --- a/examples/osgtransferfunction/osgtransferfunction.cpp +++ b/examples/osgtransferfunction/osgtransferfunction.cpp @@ -512,7 +512,7 @@ int main(int argc, char ** argv) return 1; #else - osg::ref_ptr model = osgDB::readNodeFiles(arguments); + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); #endif typedef std::vector< osg::ref_ptr > Nodes; Nodes nodes; diff --git a/examples/osguniformbuffer/osguniformbuffer.cpp b/examples/osguniformbuffer/osguniformbuffer.cpp index e245a3d3c..ec7704415 100644 --- a/examples/osguniformbuffer/osguniformbuffer.cpp +++ b/examples/osguniformbuffer/osguniformbuffer.cpp @@ -118,18 +118,18 @@ public: array->dirty(); } }; - + int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); - + if (arguments.argc() <= 1) { cerr << "Need a scene.\n"; return 1; } - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { cerr << "couldn't load " << argv[1] << "\n"; return 1; @@ -167,7 +167,7 @@ int main(int argc, char** argv) ref_ptr ubb1 = new UniformBufferBinding(0, ubo.get(), 0, blockSize); ss1->setAttributeAndModes(ubb1.get(), StateAttribute::ON); - + ref_ptr colorArray2 = new FloatArray(&colors2[0], &colors2[sizeof(colors2) / sizeof(GLfloat)]); @@ -193,13 +193,13 @@ int main(int argc, char** argv) group3->setMatrix(mat3); StateSet* ss3 = group3->getOrCreateStateSet(); group3->addChild(loadedModel.get()); - scene->addChild(group3); + scene->addChild(group3); ref_ptr ubb3 = new UniformBufferBinding(0, ubo3.get(), 0, blockSize); ubb3->setUpdateCallback(new UniformBufferCallback); ubb3->setDataVariance(Object::DYNAMIC); ss3->setAttributeAndModes(ubb3.get(), StateAttribute::ON); - + viewer.setSceneData(scene); viewer.realize(); return viewer.run(); diff --git a/examples/osgunittests/MultiThreadRead.cpp b/examples/osgunittests/MultiThreadRead.cpp index c0bb228cd..260dde119 100644 --- a/examples/osgunittests/MultiThreadRead.cpp +++ b/examples/osgunittests/MultiThreadRead.cpp @@ -82,7 +82,7 @@ public: #if VERBOSE std::cout<<"Reading "< node = osgDB::readNodeFile(filename); + osg::ref_ptr node = osgDB::readRefNodeFile(filename); #if VERBOSE if (node.valid()) std::cout<<".. OK"< node = new osg::Group; if (arguments.read("--MyUserDataContainer") || arguments.read("--mydc")) { node->setUserDataContainer(new MyNamespace::MyUserDataContainer); } - + int i = 10; node->setUserValue("Int value",i); @@ -216,18 +216,18 @@ int main(int argc, char** argv) { osgDB::writeNodeFile(*node, "results.osgt"); - osg::ref_ptr from_osgt = osgDB::readNodeFile("results.osgt"); + osg::ref_ptr from_osgt = osgDB::readRefNodeFile("results.osgt"); if (from_osgt.valid()) { OSG_NOTICE< from_osgb = osgDB::readNodeFile("results.osgb"); + osg::ref_ptr from_osgb = osgDB::readRefNodeFile("results.osgb"); if (from_osgb.valid()) { OSG_NOTICE< from_osgx = osgDB::readNodeFile("results.osgx"); + osg::ref_ptr from_osgx = osgDB::readRefNodeFile("results.osgx"); if (from_osgx.valid()) { OSG_NOTICE< loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; @@ -331,9 +331,9 @@ int main(int argc, char** argv) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); - viewer.setSceneData( loadedModel.get() ); + viewer.setSceneData(loadedModel); viewer.realize(); diff --git a/examples/osgvertexattributes/osgvertexattributes.cpp b/examples/osgvertexattributes/osgvertexattributes.cpp index 28dfb2c79..4494dc9c3 100644 --- a/examples/osgvertexattributes/osgvertexattributes.cpp +++ b/examples/osgvertexattributes/osgvertexattributes.cpp @@ -372,7 +372,7 @@ osg::Node* createSimpleTextureTestModel() osg::StateSet* stateset = geometry->getOrCreateStateSet(); stateset->setAttribute(program); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + osg::ref_ptr image = osgDB::readRefImageFile("Images/lz.rgb"); osg::Texture2D* texture = new osg::Texture2D(image); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); @@ -415,7 +415,7 @@ int main(int argc, char *argv[]) while (arguments.read("--vertex-attrib")) { runConvertToVertexAttributes = true; } while (arguments.read("--no-vertex-attrib")) { runConvertToVertexAttributes = false; } - loadedModel = osgDB::readNodeFiles(arguments); + loadedModel = osgDB::readRefNodeFiles(arguments); if (!loadedModel.get()) { osg::notify(osg::NOTICE)<<"No model loaded, please specify a model filename."<imagePosX = osgDB::readRefImageFile(CUBEMAP_FILENAME(posx)); + osg::ref_ptrimageNegX = osgDB::readRefImageFile(CUBEMAP_FILENAME(negx)); + osg::ref_ptrimagePosY = osgDB::readRefImageFile(CUBEMAP_FILENAME(posy)); + osg::ref_ptrimageNegY = osgDB::readRefImageFile(CUBEMAP_FILENAME(negy)); + osg::ref_ptrimagePosZ = osgDB::readRefImageFile(CUBEMAP_FILENAME(posz)); + osg::ref_ptrimageNegZ = osgDB::readRefImageFile(CUBEMAP_FILENAME(negz)); if (imagePosX && imageNegX && imagePosY && imageNegY && imagePosZ && imageNegZ) { @@ -371,7 +371,7 @@ int main(int argc, char *argv[]) rootnode->addChild(createSkyBox()); // load the nodes from the commandline arguments. - osg::Node* model = osgDB::readNodeFiles(arguments); + osg::ref_ptr model = osgDB::readRefNodeFiles(arguments); if (!model) { const float radius = 1.0f; @@ -388,7 +388,7 @@ int main(int argc, char *argv[]) osgUtil::SmoothingVisitor smoother; model->accept(smoother); - rootnode->addChild( addRefractStateSet(model) ); + rootnode->addChild( addRefractStateSet(model.get()) ); // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(rootnode); diff --git a/examples/osgviewerGLUT/osgviewerGLUT.cpp b/examples/osgviewerGLUT/osgviewerGLUT.cpp index 5fee7d298..8694d6abb 100644 --- a/examples/osgviewerGLUT/osgviewerGLUT.cpp +++ b/examples/osgviewerGLUT/osgviewerGLUT.cpp @@ -59,7 +59,7 @@ void display(void) void reshape( int w, int h ) { // update the window dimensions, in case the window has been resized. - if (window.valid()) + if (window.valid()) { window->resized(window->getTraits()->x, window->getTraits()->y, w, h); window->getEventQueue()->windowResize(window->getTraits()->x, window->getTraits()->y, w, h ); @@ -88,7 +88,7 @@ void keyboard( unsigned char key, int /*x*/, int /*y*/ ) switch( key ) { case 27: - // clean up the viewer + // clean up the viewer if (viewer.valid()) viewer = 0; glutDestroyWindow(glutGetWindow()); break; @@ -113,7 +113,7 @@ int main( int argc, char **argv ) } // load the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFile(argv[1]); + osg::ref_ptr loadedModel = osgDB::readRefNodeFile(argv[1]); if (!loadedModel) { std::cout << argv[0] <<": No data loaded." << std::endl; @@ -139,7 +139,7 @@ int main( int argc, char **argv ) viewer->realize(); glutMainLoop(); - + return 0; } diff --git a/examples/osgviewerQt/osgviewerQt.cpp b/examples/osgviewerQt/osgviewerQt.cpp index ec4c302c4..defb79c8a 100644 --- a/examples/osgviewerQt/osgviewerQt.cpp +++ b/examples/osgviewerQt/osgviewerQt.cpp @@ -23,11 +23,11 @@ public: // disable the default setting of viewer.done() by pressing Escape. setKeyEventSetsDone(0); - QWidget* widget1 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readNodeFile("cow.osgt") ); - QWidget* widget2 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readNodeFile("glider.osgt") ); - QWidget* widget3 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readNodeFile("axes.osgt") ); - QWidget* widget4 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readNodeFile("fountain.osgt") ); - QWidget* popupWidget = addViewWidget( createGraphicsWindow(900,100,320,240,"Popup window",true), osgDB::readNodeFile("dumptruck.osgt") ); + QWidget* widget1 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("cow.osgt") ); + QWidget* widget2 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("glider.osgt") ); + QWidget* widget3 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("axes.osgt") ); + QWidget* widget4 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("fountain.osgt") ); + QWidget* popupWidget = addViewWidget( createGraphicsWindow(900,100,320,240,"Popup window",true), osgDB::readRefNodeFile("dumptruck.osgt") ); popupWidget->show(); QGridLayout* grid = new QGridLayout; @@ -41,7 +41,7 @@ public: _timer.start( 10 ); } - QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::Node* scene ) + QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr scene ) { osgViewer::View* view = new osgViewer::View; addView( view ); @@ -110,7 +110,7 @@ int main( int argc, char** argv ) if (threadingModel != osgViewer::ViewerBase::SingleThreaded) QApplication::setAttribute(Qt::AA_X11InitThreads); #endif - + QApplication app(argc, argv); ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel); viewWidget->setGeometry( 100, 100, 800, 600 ); diff --git a/examples/osgviewerSDL/osgviewerSDL.cpp b/examples/osgviewerSDL/osgviewerSDL.cpp index 2d08a7914..6c6b8bbac 100644 --- a/examples/osgviewerSDL/osgviewerSDL.cpp +++ b/examples/osgviewerSDL/osgviewerSDL.cpp @@ -78,10 +78,10 @@ int main( int argc, char **argv ) exit(1); } atexit(SDL_Quit); - + // load the scene. - osg::ref_ptr loadedModel = osgDB::readNodeFile(argv[1]); + osg::ref_ptr loadedModel = osgDB::readRefNodeFile(argv[1]); if (!loadedModel) { std::cout << argv[0] <<": No data loaded." << std::endl; @@ -111,7 +111,7 @@ int main( int argc, char **argv ) SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - + // set up the surface to render to SDL_Surface* screen = SDL_SetVideoMode(windowWidth, windowHeight, bitDepth, SDL_OPENGL | SDL_FULLSCREEN | SDL_RESIZABLE); if ( screen == NULL ) @@ -121,11 +121,11 @@ int main( int argc, char **argv ) } SDL_EnableUNICODE(1); - + // If we used 0 to set the fields, query the values so we can pass it to osgViewer windowWidth = screen->w; windowHeight = screen->h; - + osgViewer::Viewer viewer; osg::ref_ptr gw = viewer.setUpViewerAsEmbeddedInWindow(0,0,windowWidth,windowHeight); viewer.setSceneData(loadedModel.get()); @@ -153,7 +153,7 @@ int main( int argc, char **argv ) case SDL_KEYUP: if (event.key.keysym.sym==SDLK_ESCAPE) done = true; - if (event.key.keysym.sym=='f') + if (event.key.keysym.sym=='f') { SDL_WM_ToggleFullScreen(screen); gw->resized(0, 0, screen->w, screen->h ); @@ -175,7 +175,7 @@ int main( int argc, char **argv ) // Swap Buffers SDL_GL_SwapBuffers(); } - + return 0; } diff --git a/examples/osgvirtualprogram/CreateAdvancedHierachy.cpp b/examples/osgvirtualprogram/CreateAdvancedHierachy.cpp index edece33a1..883efd871 100644 --- a/examples/osgvirtualprogram/CreateAdvancedHierachy.cpp +++ b/examples/osgvirtualprogram/CreateAdvancedHierachy.cpp @@ -14,7 +14,7 @@ using osgCandidate::VirtualProgram; //////////////////////////////////////////////////////////////////////////////// // Example shaders assume: // one texture -// one directional light +// one directional light // front face lighting // color material mode not used (its not supported by GLSL anyway) // diffuse/ambient/emissive/specular factors defined in material structure @@ -50,7 +50,7 @@ char SphereMapTextureVertexShaderSource[] = " return vec4(r.x / m + 0.5, r.y / m + 0.5, 1.0, 1.0 ); \n" //6 "} \n";//7 -char PerVertexDirectionalLightingVertexShaderSource[] = +char PerVertexDirectionalLightingVertexShaderSource[] = "void lighting( in vec3 position, in vec3 normal ) \n" //1 "{ \n" //2 " float NdotL = dot( normal, normalize(gl_LightSource[0].position.xyz) );\n" //3 @@ -152,7 +152,7 @@ void AddLabel( osg::Group * group, const std::string & label, float offset ) osg::Vec3 center( 0, 0, offset * 0.5 ); osg::Geode * geode = new osg::Geode; - // Make sure no program breaks text outputs + // Make sure no program breaks text outputs geode->getOrCreateStateSet()->setAttribute ( new osg::Program, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED ); @@ -209,16 +209,16 @@ osg::Node * CreateAdvancedHierarchy( osg::Node * model ) transformRightBottom->setMatrix( osg::Matrix::translate( offset * 0.8,0, -offset * 0.8 ) ); transformRightBottom->addChild( model ); - // Set default VirtualProgram in root StateSet - // With main vertex and main fragment shaders calling + // Set default VirtualProgram in root StateSet + // With main vertex and main fragment shaders calling // lighting and texture functions defined in aditional shaders // Lighting is done per vertex using simple directional light // Texture uses stage 0 TexCoords and TexMap - if( 1 ) + if( 1 ) { // NOTE: - // duplicating the same semantics name in virtual program + // duplicating the same semantics name in virtual program // is only possible if its used for shaders of differing types // here for VERTEX and FRAGMENT @@ -251,35 +251,35 @@ osg::Node * CreateAdvancedHierarchy( osg::Node * model ) // Override default vertex ligting with pixel lighting shaders // For three bottom models - if( 1 ) + if( 1 ) { AddLabel( transformCenterBottom, "Per Pixel Lighting VP", offset ); VirtualProgram * vp = new VirtualProgram( ); transformCenterBottom->getOrCreateStateSet()->setAttribute( vp ); SetVirtualProgramShader( vp, "lighting",osg::Shader::VERTEX, - "Vertex Shader For Per Pixel Lighting", + "Vertex Shader For Per Pixel Lighting", PerFragmentLightingVertexShaderSource ); SetVirtualProgramShader( vp, "lighting",osg::Shader::FRAGMENT, - "Fragment Shader For Per Pixel Lighting", + "Fragment Shader For Per Pixel Lighting", PerFragmentDirectionalLightingFragmentShaderSource ); } - // Additionaly set bottom left model texture to procedural blue to + // Additionaly set bottom left model texture to procedural blue to // better observe smooth speculars done through per pixel lighting - if( 1 ) + if( 1 ) { AddLabel( transformLeftBottom, "Blue Tex VP", offset ); VirtualProgram * vp = new VirtualProgram( ); transformLeftBottom->getOrCreateStateSet()->setAttribute( vp ); SetVirtualProgramShader( vp, "texture",osg::Shader::FRAGMENT, - "Fragment Shader Procedural Blue Tex", + "Fragment Shader Procedural Blue Tex", ProceduralBlueTextureFragmentShaderSource ); } - // Additionaly change texture mapping to SphereMAp in bottom right model + // Additionaly change texture mapping to SphereMAp in bottom right model if( 1 ) { AddLabel( transformRightBottom, "EnvMap Sphere VP", offset ); @@ -290,13 +290,10 @@ osg::Node * CreateAdvancedHierarchy( osg::Node * model ) SetVirtualProgramShader( vp, "texture",osg::Shader::VERTEX, "Vertex Texture Sphere Map", SphereMapTextureVertexShaderSource ); - osg::Texture2D * texture = new osg::Texture2D( -// osgDB::readImageFile("Images/reflect.rgb") - osgDB::readImageFile("Images/skymap.jpg") - ); + osg::Texture2D * texture = new osg::Texture2D( osgDB::readRefImageFile("Images/skymap.jpg") ); // Texture is set on stage 1 to not interfere with label text - // The same could be achieved with texture override + // The same could be achieved with texture override // but such approach also turns off label texture ss->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON ); ss->addUniform( new osg::Uniform( "baseTexture", 1 ) ); @@ -313,7 +310,7 @@ osg::Node * CreateAdvancedHierarchy( osg::Node * model ) // Top center model usues osg::Program overriding VirtualProgram in model - if( 1 ) + if( 1 ) { AddLabel( transformCenterTop, "Fixed Vertex + Simple Fragment osg::Program", offset ); osg::Program * program = new osg::Program; @@ -339,8 +336,8 @@ osg::Node * CreateAdvancedHierarchy( osg::Node * model ) } //////////////////////////////////////////////////////////////////////////////// -// Shders not used in the example but left for fun if anyone wants to play -char LightingVertexShaderSource[] = +// Shders not used in the example but left for fun if anyone wants to play +char LightingVertexShaderSource[] = "// Forward declarations \n" //1 " \n" //2 "void SpotLight( in int i, in vec3 eye, in vec3 position, in vec3 normal, \n" //3 @@ -385,7 +382,7 @@ char LightingVertexShaderSource[] = " gl_BackSecondaryColor = gl_FrontSecondaryColor; \n" //42 "} \n";//43 -char SpotLightShaderSource[] = +char SpotLightShaderSource[] = "void SpotLight(in int i, \n" //1 " in vec3 eye, \n" //2 " in vec3 position, \n" //3 @@ -444,7 +441,7 @@ char SpotLightShaderSource[] = " specular += gl_LightSource[i].specular * pf * attenuation; \n" //56 "} \n";//57 -char PointLightShaderSource[] = +char PointLightShaderSource[] = "void PointLight(in int i, \n" //1 " in vec3 eye, \n" //2 " in vec3 position, \n" //3 diff --git a/examples/osgvirtualprogram/osgvirtualprogram.cpp b/examples/osgvirtualprogram/osgvirtualprogram.cpp index b138ed528..f564efcec 100644 --- a/examples/osgvirtualprogram/osgvirtualprogram.cpp +++ b/examples/osgvirtualprogram/osgvirtualprogram.cpp @@ -14,7 +14,7 @@ extern osg::Node * CreateAdvancedHierarchy( osg::Node * model ); //////////////////////////////////////////////////////////////////////////////// osg::Node * CreateGlobe( void ) { - // File not found - create textured sphere + // File not found - create textured sphere osg::Geode * geode = new osg::Geode; osg::ref_ptr hints = new osg::TessellationHints; hints->setDetailRatio( 0.3 ); @@ -33,8 +33,8 @@ osg::Node * CreateGlobe( void ) osg::StateSet * stateSet = new osg::StateSet; - osg::Texture2D * texture = new osg::Texture2D( - osgDB::readImageFile("Images/land_shallow_topo_2048.jpg") + osg::Texture2D * texture = new osg::Texture2D( + osgDB::readRefImageFile("Images/land_shallow_topo_2048.jpg") ); osg::Material * material = new osg::Material; @@ -68,14 +68,15 @@ int main( int argc, char **argv ) bool useSimpleExample = arguments.read("-s") || arguments.read("--simple") ; - osg::Node * model = NULL; + osg::ref_ptr model; - if (arguments.argc()>1 && !arguments.isOption(1) ) { + if (arguments.argc()>1 && !arguments.isOption(1) ) + { std::string filename = arguments[1]; - model = osgDB::readNodeFile( filename ); + model = osgDB::readRefNodeFile( filename ); if ( !model ) { - osg::notify( osg::NOTICE ) - << "Error, cannot read " << filename + osg::notify( osg::NOTICE ) + << "Error, cannot read " << filename << ". Loading default earth model instead." << std::endl; } } @@ -83,9 +84,9 @@ int main( int argc, char **argv ) if( model == NULL ) model = CreateGlobe( ); - osg::Node * node = useSimpleExample ? - CreateSimpleHierarchy( model ): - CreateAdvancedHierarchy( model ); + osg::ref_ptr node = useSimpleExample ? + CreateSimpleHierarchy( model.get() ): + CreateAdvancedHierarchy( model.get() ); viewer.setSceneData( node ); viewer.realize( ); diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 8a9785c60..1dc1a4e75 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -475,7 +475,7 @@ int main( int argc, char **argv ) std::string tranferFunctionFile; while (arguments.read("--tf",tranferFunctionFile)) { - transferFunction = osgDB::readFile(tranferFunctionFile); + transferFunction = osgDB::readRefFile(tranferFunctionFile); } while(arguments.read("--test")) @@ -597,7 +597,7 @@ int main( int argc, char **argv ) osg::ref_ptr models; while(arguments.read("--model",filename)) { - osg::ref_ptr model = osgDB::readNodeFile(filename); + osg::ref_ptr model = osgDB::readRefNodeFile(filename); if (model.valid()) { if (!models) models = new osg::Group; @@ -608,7 +608,7 @@ int main( int argc, char **argv ) osg::ref_ptr hulls; while(arguments.read("--hull",filename)) { - osg::ref_ptr hull = osgDB::readNodeFile(filename); + osg::ref_ptr hull = osgDB::readRefNodeFile(filename); if (hull.valid()) { if (!hulls) hulls = new osg::Group; @@ -713,7 +713,7 @@ int main( int argc, char **argv ) osgDB::DirectoryContents contents = osgDB::expandWildcardsInFilename(arg); for (unsigned int i = 0; i < contents.size(); ++i) { - osg::Image *image = osgDB::readImageFile( contents[i] ); + osg::ref_ptr image = osgDB::readRefImageFile( contents[i] ); if(image) { @@ -725,7 +725,7 @@ int main( int argc, char **argv ) else { // not an option so assume string is a filename. - osg::Image *image = osgDB::readImageFile( arguments[pos] ); + osg::ref_ptr image = osgDB::readRefImageFile( arguments[pos] ); if(image) { @@ -770,7 +770,7 @@ int main( int argc, char **argv ) if (osgDB::getLowerCaseFileExtension(filename)=="dicom") { // not an option so assume string is a filename. - osg::Image* image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image) { images.push_back(image); @@ -787,13 +787,13 @@ int main( int argc, char **argv ) if (fileType == osgDB::DIRECTORY) { - osg::Image* image = osgDB::readImageFile(filename+".dicom"); + osg::ref_ptr image = osgDB::readRefImageFile(filename+".dicom"); if (image) images.push_back(image); } else if (fileType == osgDB::REGULAR_FILE) { // not an option so assume string is a filename. - osg::Image* image = osgDB::readImageFile( filename ); + osg::ref_ptr image = osgDB::readRefImageFile( filename ); if (image) images.push_back(image); } else diff --git a/examples/osgwidgetbox/osgwidgetbox.cpp b/examples/osgwidgetbox/osgwidgetbox.cpp index df1394f10..91dbae4e3 100644 --- a/examples/osgwidgetbox/osgwidgetbox.cpp +++ b/examples/osgwidgetbox/osgwidgetbox.cpp @@ -23,7 +23,7 @@ struct ColorWidget: public osgWidget::Widget { bool mouseEnter(double, double, const osgWidget::WindowManager*) { addColor(-osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f)); - + // osgWidget::warn() << "enter: " << getColor() << std::endl; return true; @@ -31,14 +31,14 @@ struct ColorWidget: public osgWidget::Widget { bool mouseLeave(double, double, const osgWidget::WindowManager*) { addColor(osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f)); - + // osgWidget::warn() << "leave: " << getColor() << std::endl; - + return true; } bool mouseOver(double x, double y, const osgWidget::WindowManager*) { - + osgWidget::Color c = getImageColorAtPointerXY(x, y); if(c.a() < 0.001f) { @@ -88,7 +88,7 @@ int main(int argc, char** argv) { MASK_2D, osgWidget::WindowManager::WM_PICK_DEBUG ); - + wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY); osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL); @@ -112,9 +112,9 @@ int main(int argc, char** argv) { box4->hide(); - osg::Node* model = osgDB::readNodeFile("spaceship.osgt"); + osg::ref_ptr model = osgDB::readRefNodeFile("spaceship.osgt"); model->setNodeMask(MASK_3D); - return osgWidget::createExample(viewer, wm, model); + return osgWidget::createExample(viewer, wm, model.get()); } diff --git a/examples/osgwidgetframe/osgwidgetframe.cpp b/examples/osgwidgetframe/osgwidgetframe.cpp index 308230f70..276291765 100644 --- a/examples/osgwidgetframe/osgwidgetframe.cpp +++ b/examples/osgwidgetframe/osgwidgetframe.cpp @@ -19,7 +19,7 @@ int main(int argc, char** argv) { MASK_2D, osgWidget::WindowManager::WM_PICK_DEBUG ); - + osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame( "frame", 32.0f, @@ -30,7 +30,7 @@ int main(int argc, char** argv) { osgWidget::Frame* frame2 = osgWidget::Frame::createSimpleFrameFromTheme( "frameTheme", - osgDB::readImageFile("osgWidget/theme-1.png"), + osgDB::readRefImageFile("osgWidget/theme-1.png"), 300.0f, 300.0f, osgWidget::Frame::FRAME_ALL @@ -40,7 +40,7 @@ int main(int argc, char** argv) { osgWidget::Frame* frame22 = osgWidget::Frame::createSimpleFrameFromTheme( "frameTheme", - osgDB::readImageFile("osgWidget/theme-2.png"), + osgDB::readRefImageFile("osgWidget/theme-2.png"), 300.0f, 300.0f, osgWidget::Frame::FRAME_ALL @@ -51,14 +51,14 @@ int main(int argc, char** argv) { osgWidget::Frame* frame3 = osgWidget::Frame::createSimpleFrameFromTheme( "frameTheme", - osgDB::readImageFile("osgWidget/theme-2.png"), + osgDB::readRefImageFile("osgWidget/theme-2.png"), 300.0f, 300.0f, osgWidget::Frame::FRAME_ALL ); frame3->setPosition(300,100,0); frame3->getBackground()->setColor(0.0f, 0.0f, 0.0f, 1.0f); - + osgWidget::Table* table = new osgWidget::Table("table", 2, 2); osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL); diff --git a/examples/osgwidgetmenu/osgwidgetmenu.cpp b/examples/osgwidgetmenu/osgwidgetmenu.cpp index c4e943e84..1e5c8238e 100644 --- a/examples/osgwidgetmenu/osgwidgetmenu.cpp +++ b/examples/osgwidgetmenu/osgwidgetmenu.cpp @@ -33,13 +33,13 @@ struct ColorLabel: public osgWidget::Label { bool mouseEnter(double, double, const osgWidget::WindowManager*) { setColor(0.6f, 0.6f, 0.6f, 1.0f); - + return true; } bool mouseLeave(double, double, const osgWidget::WindowManager*) { setColor(0.3f, 0.3f, 0.3f, 1.0f); - + return true; } }; @@ -116,13 +116,13 @@ int main(int argc, char** argv) { menu->addWidget(new ColorLabelMenu("Grarar!?!")); wm->addChild(menu); - + menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f); menu->resizePercent(100.0f); - osg::Node* model = osgDB::readNodeFile("osgcool.osgt"); + osg::ref_ptr model = osgDB::readRefNodeFile("osgcool.osgt"); model->setNodeMask(MASK_3D); - return osgWidget::createExample(viewer, wm, model); + return osgWidget::createExample(viewer, wm, model.get()); } diff --git a/examples/osgwidgetmessagebox/osgwidgetmessagebox.cpp b/examples/osgwidgetmessagebox/osgwidgetmessagebox.cpp index 381a2cc45..acd1b5655 100644 --- a/examples/osgwidgetmessagebox/osgwidgetmessagebox.cpp +++ b/examples/osgwidgetmessagebox/osgwidgetmessagebox.cpp @@ -17,19 +17,19 @@ const unsigned int MASK_2D = 0xF0000000; class MessageBox { protected: - + osgWidget::Frame* createButtonOk(const std::string& theme, const std::string& text, const std::string& font, int fontSize); osgWidget::Label* createLabel(const std::string& string, const std::string& font, int size, const osgWidget::Color& color); - + osg::ref_ptr _window; osg::ref_ptr _button; public: - + osgWidget::Frame* getButton(); osgWidget::Frame* getWindow(); - bool create(const std::string& themeMessage, + bool create(const std::string& themeMessage, const std::string& themeButton, const std::string& titleText, const std::string& messageText, @@ -56,7 +56,7 @@ struct AlphaSetterVisitor : public osg::NodeVisitor for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++) { // osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl; - + osgWidget::Color color = it->get()->getColor(); color[3] = color[3] *_alpha; it->get()->setColor(color); @@ -87,7 +87,7 @@ struct ColorSetterVisitor : public osg::NodeVisitor for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++) { // osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl; - + // osgWidget::Color color = it->get()->getColor(); // color[3] = color[3] *_alpha; it->get()->setColor(_color); @@ -110,7 +110,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback // typedef osgAnimation::OutQuartMotion WidgetMotion; WidgetMotion _motionOver; WidgetMotion _motionLeave; - + double _lastUpdate; osgWidget::Color _defaultColor; osgWidget::Color _overColor; @@ -119,7 +119,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback float _width; float _height; osg::Matrix _matrix; - EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame) + EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame) { _motionOver = WidgetMotion(0.0, 0.4); _motionLeave = WidgetMotion(0.0, 0.5); @@ -204,15 +204,15 @@ osgWidget::Label* MessageBox::createLabel(const std::string& string, const std:: return label; } -osgWidget::Frame* MessageBox::createButtonOk(const std::string& theme, - const std::string& text, - const std::string& font, +osgWidget::Frame* MessageBox::createButtonOk(const std::string& theme, + const std::string& text, + const std::string& font, int fontSize) { osg::ref_ptr frame = osgWidget::Frame::createSimpleFrameFromTheme( "ButtonOK", - osgDB::readImageFile(theme), - 300.0f, + osgDB::readRefImageFile(theme), + 300.0f, 50.0f, osgWidget::Frame::FRAME_TEXTURE ); @@ -240,7 +240,7 @@ osgWidget::Frame* MessageBox::createButtonOk(const std::string& theme, return frame.release(); } -bool MessageBox::create(const std::string& themeMessage, +bool MessageBox::create(const std::string& themeMessage, const std::string& themeButton, const std::string& titleText, const std::string& messageText, @@ -251,7 +251,7 @@ bool MessageBox::create(const std::string& themeMessage, osg::ref_ptr frame = osgWidget::Frame::createSimpleFrameFromTheme( "error", - osgDB::readImageFile(themeMessage), + osgDB::readRefImageFile(themeMessage), 300.0f, 50.0f, osgWidget::Frame::FRAME_ALL @@ -300,7 +300,7 @@ const char* LABEL1 = "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..." ; -int main(int argc, char** argv) +int main(int argc, char** argv) { osgViewer::Viewer viewer; @@ -319,7 +319,7 @@ int main(int argc, char** argv) std::string borderTheme = "osgWidget/theme-8.png"; MessageBox message; - message.create(borderTheme, + message.create(borderTheme, buttonTheme, "Error - Critical", LABEL1, @@ -422,7 +422,7 @@ struct AlphaSetterVisitor : public osg::NodeVisitor for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++) { // osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl; - + osgWidget::Color color = it->get()->getColor(); color[3] = color[3] *_alpha; it->get()->setColor(color); @@ -453,7 +453,7 @@ struct ColorSetterVisitor : public osg::NodeVisitor for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++) { // osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl; - + // osgWidget::Color color = it->get()->getColor(); // color[3] = color[3] *_alpha; it->get()->setColor(_color); @@ -474,7 +474,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback typedef osgAnimation::OutQuartMotion WidgetMotion; WidgetMotion _motionOver; WidgetMotion _motionLeave; - + double _lastUpdate; osgWidget::Color _defaultColor; osgWidget::Color _overColor; @@ -482,7 +482,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback osg::ref_ptr _frame; float _width; float _height; - EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame) + EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame) { _motionOver = WidgetMotion(0.0, 0.4); _motionLeave = WidgetMotion(0.0, 0.5); @@ -507,7 +507,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback // _frame->resize(_width * 1.2, _height * 1.2); return true; } - else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE) + else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE) { _over = false; // std::cout << "Leave" << std::endl; @@ -568,7 +568,7 @@ osgWidget::Window* createButtonOk(const std::string& theme, const std::string& t osg::ref_ptr frame = osgWidget::Frame::createSimpleFrameFromTheme( "ButtonOK", osgDB::readImageFile(theme), - 300.0f, + 300.0f, 50.0f, osgWidget::Frame::FRAME_TEXTURE ); @@ -596,7 +596,7 @@ osgWidget::Window* createButtonOk(const std::string& theme, const std::string& t return frame.release(); } -osgWidget::Frame* createErrorMessage(const std::string& themeMessage, +osgWidget::Frame* createErrorMessage(const std::string& themeMessage, const std::string& themeButton, const std::string& titleText, const std::string& messageText, @@ -645,7 +645,7 @@ const char* LABEL1 = "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..." ; -int main(int argc, char** argv) +int main(int argc, char** argv) { std::string theme = "osgWidget/theme-1.png"; if (argc > 1) diff --git a/examples/osgwidgetscrolled/osgwidgetscrolled.cpp b/examples/osgwidgetscrolled/osgwidgetscrolled.cpp index f092addf7..21f984b04 100644 --- a/examples/osgwidgetscrolled/osgwidgetscrolled.cpp +++ b/examples/osgwidgetscrolled/osgwidgetscrolled.cpp @@ -22,9 +22,9 @@ bool scrollWindow(osgWidget::Event& ev) { osgWidget::Window::EmbeddedWindow* ew = dynamic_cast(frame->getEmbeddedWindow()) ; - + if(!ew) return false; - + // Lets get the visible area so that we can use it to make sure our scrolling action // is necessary in the first place. const osgWidget::Quad& va = ew->getWindow()->getVisibleArea(); @@ -34,7 +34,7 @@ bool scrollWindow(osgWidget::Event& ev) { if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f) ew->getWindow()->addVisibleArea(0, -20) ; - + else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight())) ew->getWindow()->addVisibleArea(0, 20) ; @@ -88,10 +88,10 @@ int main(int argc, char** argv) { osgWidget::WindowManager::WM_PICK_DEBUG //osgWidget::WindowManager::WM_NO_INVERT_Y ); - + osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameFromTheme( "frame", - osgDB::readImageFile("osgWidget/theme.png"), + osgDB::readRefImageFile("osgWidget/theme.png"), 40.0f, 40.0f, osgWidget::Frame::FRAME_ALL diff --git a/examples/osgwidgetwindow/osgwidgetwindow.cpp b/examples/osgwidgetwindow/osgwidgetwindow.cpp index 1bd7d5f32..96a5e8a9f 100644 --- a/examples/osgwidgetwindow/osgwidgetwindow.cpp +++ b/examples/osgwidgetwindow/osgwidgetwindow.cpp @@ -53,14 +53,14 @@ struct CallbackObject: public osgWidget::Callback { virtual bool operator()(osgWidget::Event& ev) { std::cout << "here" << std::endl; - + return false; } }; int main(int argc, char** argv) { osgViewer::Viewer viewer; - + // Let's get busy! The WindowManager class is actually an osg::Switch, // so you can add it to (ideally) an orthographic camera and have it behave as // expected. Note that you create a WindowManager with a NodeMask--it is very important @@ -117,7 +117,7 @@ int main(int argc, char** argv) { widget1->setCanFill(true); widget3->setColor(0.0f, 1.0f, 0.0f, 1.0f); - widget1->setImage(osgDB::readImageFile("Images/Saturn.TGA"), true); + widget1->setImage(osgDB::readRefImageFile("Images/Saturn.TGA"), true); // Set the color of widget2, to differentiate it and make it sassy. This is // like a poor man's gradient! @@ -166,16 +166,16 @@ int main(int argc, char** argv) { // simply use the createParentOrthoCamera method of the WindowManager class, // which will wrap the calls to createOrthoCamera and addChild for us! Check out // some of the other examples to see this in action... - osg::Group* group = new osg::Group(); - osg::Camera* camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f); - osg::Node* model = osgDB::readNodeFile("cow.osgt"); + osg::ref_ptr group = new osg::Group(); + osg::ref_ptr camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f); + osg::ref_ptr model = osgDB::readRefNodeFile("cow.osgt"); // Add our event handler; is this better as a MatrixManipulator? Add a few other // helpful ViewerEventHandlers. viewer.addEventHandler(new osgWidget::MouseHandler(wm)); viewer.addEventHandler(new osgWidget::KeyboardHandler(wm)); - viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera)); - viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera)); + viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera.get())); + viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera.get())); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator( @@ -210,7 +210,7 @@ int main(int argc, char** argv) { viewer.setSceneData(group); /* - osgViewer::Viewer::Cameras cameras; + osgViewer::Viewer::Cameras cameras; viewer.getCameras(cameras); osg::Camera* c = cameras[0]; osg::Matrix s = osg::Matrix::scale(1.0f, -1.0f, 1.0f); diff --git a/examples/osgwindows/osgwindows.cpp b/examples/osgwindows/osgwindows.cpp index ee3380960..c8fbce589 100644 --- a/examples/osgwindows/osgwindows.cpp +++ b/examples/osgwindows/osgwindows.cpp @@ -29,13 +29,13 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args. - osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + osg::ref_ptr loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. - if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); - + if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt"); + // if no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; @@ -70,7 +70,7 @@ int main( int argc, char **argv ) // add this slave camera to the viewer, with a shift left of the projection matrix viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd()); } - + // right window + right slave camera { osg::ref_ptr traits = new osg::GraphicsContext::Traits; @@ -98,10 +98,10 @@ int main( int argc, char **argv ) // optimize the scene graph, remove redundant nodes and state etc. osgUtil::Optimizer optimizer; - optimizer.optimize(loadedModel.get()); + optimizer.optimize(loadedModel); // set the scene to render - viewer.setSceneData(loadedModel.get()); + viewer.setSceneData(loadedModel); return viewer.run(); } diff --git a/include/osg/Drawable b/include/osg/Drawable index c88492bc3..52e0d2040 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -191,6 +191,8 @@ class OSG_EXPORT Drawable : public Node */ inline void setShape(Shape* shape) { _shape = shape; } + template void setShape(const ref_ptr& shape) { setShape(shape.get()); } + /** Get the Shape of the Drawable.*/ inline Shape* getShape() { return _shape.get(); } diff --git a/include/osg/Geode b/include/osg/Geode index 550adbcfc..089665974 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -49,6 +49,8 @@ class OSG_EXPORT Geode : public Group */ virtual bool addDrawable( Drawable *drawable ); + template bool addDrawable( const ref_ptr& drawable ) { return addDrawable(drawable.get()); } + /** Remove a \c Drawable from the \c Geode. * Equivalent to removeDrawable(getDrawableIndex(drawable). * @param drawable The drawable to be removed. @@ -57,6 +59,8 @@ class OSG_EXPORT Geode : public Group */ virtual bool removeDrawable( Drawable *drawable ); + template bool removeDrawable( const ref_ptr& drawable ) { return removeDrawable( drawable.get() ); } + /** Remove Drawable(s) from the specified position in * Geode's drawable list. * @param i The index of the first \c Drawable to remove. @@ -73,6 +77,8 @@ class OSG_EXPORT Geode : public Group */ virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw ); + template bool replaceDrawable( const ref_ptr& origDraw, const ref_ptr& newDraw ) { return replaceDrawable(origDraw.get(), newDraw.get()); } + /** Set \c Drawable at position \c i. * Decrement the reference count origGSet and increments the * reference count of newGset, and dirty the bounding sphere @@ -85,6 +91,8 @@ class OSG_EXPORT Geode : public Group */ virtual bool setDrawable( unsigned int i, Drawable* drawable ); + template bool setDrawable( unsigned int i, const ref_ptr& drawable ) { return setDrawable(i, drawable.get()); } + /** Return the number of Drawables currently attached to the * \c Geode. */ @@ -108,6 +116,8 @@ class OSG_EXPORT Geode : public Group return false; } + template bool containsDrawable(const ref_ptr& drawable) const { return containsDrawable(drawable.get()); } + /** Get the index number of \c drawable. * @return A value between 0 and getNumDrawables()-1 if * \c drawable is found; if not found, then @@ -118,6 +128,8 @@ class OSG_EXPORT Geode : public Group return getChildIndex(drawable); } + template unsigned int getDrawableIndex( const ref_ptr& drawable ) const { return getDrawableIndex(drawable.get()); } + /** Compile OpenGL Display List for each drawable.*/ void compileDrawables(RenderInfo& renderInfo); diff --git a/include/osg/Group b/include/osg/Group index f0b1617bf..126cd714b 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -50,6 +50,8 @@ class OSG_EXPORT Group : public Node */ virtual bool addChild( Node *child ); + template bool addChild( const ref_ptr& child ) { return addChild(child.get()); } + /** Insert Node to Group at specific location. * The new child node is inserted into the child list * before the node at the specified index. No nodes @@ -57,6 +59,8 @@ class OSG_EXPORT Group : public Node */ virtual bool insertChild( unsigned int index, Node *child ); + template bool insertChild( unsigned int index, const ref_ptr& child ) { return insertChild(index, child.get()); } + /** Remove Node from Group. * If Node is contained in Group then remove it from the child * list, decrement its reference count, and dirty the @@ -67,6 +71,8 @@ class OSG_EXPORT Group : public Node */ virtual bool removeChild( Node *child ); + template bool removeChild( const ref_ptr& child ) { return removeChild(child.get()); } + /** Remove Node from Group. * If Node is contained in Group then remove it from the child * list, decrement its reference count, and dirty the @@ -91,6 +97,8 @@ class OSG_EXPORT Group : public Node */ virtual bool replaceChild( Node *origChild, Node* newChild ); + template bool replaceChild( const ref_ptr& origChild, const ref_ptr& newChild ) { return replaceChild( origChild.get(), newChild.get()); } + /** Return the number of children nodes. */ virtual unsigned int getNumChildren() const; @@ -124,6 +132,8 @@ class OSG_EXPORT Group : public Node return false; } + template bool conatainsNode(const ref_ptr& node) const { return containsNode(node.get()); } + /** Get the index number of child, return a value between * 0 and _children.size()-1 if found, if not found then * return _children.size(). diff --git a/include/osg/Image b/include/osg/Image index b227eaaf8..b1e467caa 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -542,11 +542,17 @@ class Geode; * Use the image's s and t values to scale the dimensions of the image. */ extern OSG_EXPORT Geode* createGeodeForImage(Image* image); + +template Geode* createGeodeForImage(const ref_ptr& image) { return createGeodeForImage(image.get()); } + + /** Convenience function to be used by image loaders to generate a valid geode * to return for readNode(). * Use the specified s and t values to scale the dimensions of the image. */ -extern OSG_EXPORT Geode* createGeodeForImage(Image* image,float s,float t); +extern OSG_EXPORT Geode* createGeodeForImage(Image* image, float s, float t); + +template Geode* createGeodeForImage(const ref_ptr& image, float s, float t) { return createGeodeForImage(image.get(), s, t); } } diff --git a/include/osg/ImageSequence b/include/osg/ImageSequence index cd967a714..29297dc21 100644 --- a/include/osg/ImageSequence +++ b/include/osg/ImageSequence @@ -92,6 +92,8 @@ class OSG_EXPORT ImageSequence : public ImageStream void addImage(osg::Image* image); + template void addImage(const osg::ref_ptr& image) { addImage(image.get()); } + void setImage(int s,int t,int r, GLint internalTextureformat, GLenum pixelFormat,GLenum type, @@ -100,6 +102,9 @@ class OSG_EXPORT ImageSequence : public ImageStream int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); } void setImage(unsigned int pos, osg::Image* image); + + template void setImage(unsigned int pos, const osg::ref_ptr& image) { setImage(pos, image.get()); } + Image* getImage(unsigned int pos); const Image* getImage(unsigned int pos) const; @@ -108,7 +113,7 @@ class OSG_EXPORT ImageSequence : public ImageStream ImageDataList& getImageDataList() { return _imageDataList; } const ImageDataList& getImageDataList() const { return _imageDataList; } - + /** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/ virtual bool requiresUpdateCall() const { return true; } diff --git a/include/osg/LOD b/include/osg/LOD index 0d636ec6c..3a2a09e12 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -48,9 +48,13 @@ class OSG_EXPORT LOD : public Group virtual void traverse(NodeVisitor& nv); + using osg::Group::addChild; + virtual bool addChild(Node *child); - virtual bool addChild(Node *child, float min, float max); + virtual bool addChild(Node *child, float rmin, float rmax); + + template bool addChild( const ref_ptr& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); } virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1); diff --git a/include/osg/Node b/include/osg/Node index 77c06e08a..b820b48ec 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -212,6 +212,8 @@ class OSG_EXPORT Node : public Object /** Set update node callback, called during update traversal. */ void setUpdateCallback(Callback* nc); + template void setUpdateCallback(const ref_ptr& nc) { setUpdateCallback(nc.get()); } + /** Get update node callback, called during update traversal. */ inline Callback* getUpdateCallback() { return _updateCallback.get(); } @@ -226,6 +228,8 @@ class OSG_EXPORT Node : public Object } } + template void addUpdateCallback(const ref_ptr& nc) { addUpdateCallback(nc.get()); } + /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ inline void removeUpdateCallback(Callback* nc) { if (nc != NULL && _updateCallback.valid()) { @@ -239,6 +243,8 @@ class OSG_EXPORT Node : public Object } } + template void removeUpdateCallback(const ref_ptr& nc) { removeUpdateCallback(nc.get()); } + /** Get the number of Children of this node which require Update traversal, * since they have an Update Callback attached to them or their children.*/ inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; } @@ -247,6 +253,8 @@ class OSG_EXPORT Node : public Object /** Set event node callback, called during event traversal. */ void setEventCallback(Callback* nc); + template void setEventCallback(const ref_ptr& nc) { setEventCallback(nc.get()); } + /** Get event node callback, called during event traversal. */ inline Callback* getEventCallback() { return _eventCallback.get(); } @@ -261,6 +269,8 @@ class OSG_EXPORT Node : public Object } } + template void addEventCallback(const ref_ptr& nc) { addEventCallback(nc.get()); } + /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ inline void removeEventCallback(Callback* nc) { if (nc != NULL && _eventCallback.valid()) { @@ -274,7 +284,9 @@ class OSG_EXPORT Node : public Object } } - /** Get the number of Children of this node which require Event traversal, + template void removeEventCallback(const ref_ptr& nc) { removeEventCallback(nc.get()); } + + /** Get the number of Children of this node which require Event traversal, * since they have an Event Callback attached to them or their children.*/ inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; } @@ -282,6 +294,8 @@ class OSG_EXPORT Node : public Object /** Set cull node callback, called during cull traversal. */ void setCullCallback(Callback* nc) { _cullCallback = nc; } + template void setCullCallback(const ref_ptr& nc) { setCullCallback(nc.get()); } + /** Get cull node callback, called during cull traversal. */ inline Callback* getCullCallback() { return _cullCallback.get(); } @@ -296,6 +310,8 @@ class OSG_EXPORT Node : public Object } } + template void addCullCallback(const ref_ptr& nc) { addCullCallback(nc.get()); } + /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ inline void removeCullCallback(Callback* nc) { if (nc != NULL && _cullCallback.valid()) { @@ -309,6 +325,8 @@ class OSG_EXPORT Node : public Object } } + template void removeCullCallback(const ref_ptr& nc) { removeCullCallback(nc.get()); } + /** Set the view frustum/small feature culling of this node to be active or inactive. * The default value is true for _cullingActive. Used as a guide * to the cull traversal.*/ @@ -360,6 +378,8 @@ class OSG_EXPORT Node : public Object /** Set the node's StateSet.*/ void setStateSet(osg::StateSet* stateset); + template void setStateSet(const osg::ref_ptr& stateset) { setStateSet(stateset.get()); } + /** return the node's StateSet, if one does not already exist create it * set the node and return the newly created StateSet. This ensures * that a valid StateSet is always returned and can be used directly.*/ @@ -444,6 +464,8 @@ class OSG_EXPORT Node : public Object /** Set the compute bound callback to override the default computeBound.*/ void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback* callback) { _computeBoundCallback = callback; } + template void setComputeBoundingSphereCallback(const ref_ptr& callback) { setComputeBoundingSphereCallback(callback.get()); } + /** Get the compute bound callback.*/ ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() { return _computeBoundCallback.get(); } diff --git a/include/osg/NodeVisitor b/include/osg/NodeVisitor index 2b0bb6177..6d1f8eb6b 100644 --- a/include/osg/NodeVisitor +++ b/include/osg/NodeVisitor @@ -104,7 +104,7 @@ class OSG_EXPORT NodeVisitor : public virtual Object * Equivalent to dynamic_cast(this).*/ virtual const NodeVisitor* asNodeVisitor() const { return this; } - + /** Method to call to reset visitor. Useful if your visitor accumulates state during a traversal, and you plan to reuse the visitor. To flush that state for the next traversal: call reset() prior diff --git a/include/osg/Object b/include/osg/Object index 4a9c1e1a8..b2ffe7d37 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -92,8 +92,8 @@ class OSG_EXPORT Object : public Referenced /** return the compound class name that combines the library name and class name.*/ std::string getCompoundClassName() const { return std::string(libraryName()) + std::string("::") + std::string(className()); } - - + + /** Convert 'this' into a Node pointer if Object is a Node, otherwise return 0. * Equivalent to dynamic_cast(this).*/ virtual Node* asNode() { return 0; } @@ -168,6 +168,8 @@ class OSG_EXPORT Object : public Referenced /** set the UserDataContainer object.*/ void setUserDataContainer(osg::UserDataContainer* udc); + template void setUserDataContainer(const ref_ptr& udc) { setUserDataContainer(udc.get()); } + /** get the UserDataContainer attached to this object.*/ osg::UserDataContainer* getUserDataContainer() { return _userDataContainer; } @@ -187,6 +189,8 @@ class OSG_EXPORT Object : public Referenced */ virtual void setUserData(Referenced* obj); + template void setUserData(const ref_ptr& ud) { setUserData(ud.get()); } + /** Get user data.*/ virtual Referenced* getUserData(); diff --git a/include/osg/PagedLOD b/include/osg/PagedLOD index b2798240d..d5115d058 100644 --- a/include/osg/PagedLOD +++ b/include/osg/PagedLOD @@ -31,15 +31,19 @@ class OSG_EXPORT PagedLOD : public LOD META_Node(osg, PagedLOD); - - virtual void traverse(NodeVisitor& nv); + using osg::Group::addChild; + virtual bool addChild(Node *child); - virtual bool addChild(Node *child, float min, float max); + virtual bool addChild(Node *child, float rmin, float rmax); - virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f); + template bool addChild( const ref_ptr& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); } + + virtual bool addChild(Node *child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f); + + template bool addChild( const ref_ptr& child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f) { return addChild(child.get(), rmin, rmax, filename, priorityOffset, priorityScale); } virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1); diff --git a/include/osg/Program b/include/osg/Program index 0cd786a08..79d7a761f 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -86,6 +86,8 @@ class OSG_EXPORT Program : public osg::StateAttribute * Mark Program as needing relink. Return true for success */ bool addShader( Shader* shader ); + template bool addShader( const ref_ptr& shader ) { return addShader(shader.get()); } + unsigned int getNumShaders() const { return static_cast(_shaderList.size()); } Shader* getShader( unsigned int i ) { return _shaderList[i].get(); } @@ -95,6 +97,8 @@ class OSG_EXPORT Program : public osg::StateAttribute * Mark Program as needing relink. Return true for success */ bool removeShader( Shader* shader ); + template bool removeShader( const ref_ptr& shader ) { return removeShader(shader.get()); } + /** Set/get GL program parameters */ void setParameter( GLenum pname, GLint value ); GLint getParameter( GLenum pname ) const; diff --git a/include/osg/ProxyNode b/include/osg/ProxyNode index 797f777ee..5473d09c8 100644 --- a/include/osg/ProxyNode +++ b/include/osg/ProxyNode @@ -36,9 +36,14 @@ class OSG_EXPORT ProxyNode : public Group virtual void traverse(NodeVisitor& nv); + using osg::Group::addChild; + virtual bool addChild(Node *child); + virtual bool addChild(Node *child, const std::string& filename); + template bool addChild( const ref_ptr& child, const std::string& filename) { return addChild(child.get(), filename); } + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); diff --git a/include/osg/Sequence b/include/osg/Sequence index 542b81c13..f96c08bfb 100644 --- a/include/osg/Sequence +++ b/include/osg/Sequence @@ -41,14 +41,22 @@ class OSG_EXPORT Sequence : public Group // maintained. New code should set defaultTime and use addChild, and // not mess with the setTime method + using osg::Group::addChild; + using osg::Group::insertChild; + using osg::Group::removeChild; + virtual bool addChild( Node *child); virtual bool addChild( Node *child, double t); + template bool addChild( const ref_ptr& child, double t) { return addChild(child.get(), t); } + virtual bool insertChild( unsigned int index, Node *child); virtual bool insertChild( unsigned int index, Node *child, double t); + template bool insertChild( unsigned int index, const ref_ptr& child, double t) { return insertChild(index, child.get(), t); } + virtual bool removeChild( Node *child ); virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); diff --git a/include/osg/Shape b/include/osg/Shape index f64ea62aa..6ae501cad 100644 --- a/include/osg/Shape +++ b/include/osg/Shape @@ -622,6 +622,8 @@ class OSG_EXPORT CompositeShape : public Shape /** Add a child to the list.*/ void addChild(Shape* shape) { _children.push_back(shape); } + template void addChild( const ref_ptr& child ) { addChild(child.get()); } + /** remove a child from the list.*/ void removeChild(unsigned int i) { _children.erase(_children.begin()+i); } diff --git a/include/osg/ShapeDrawable b/include/osg/ShapeDrawable index a0fcd0c07..4da4cae6d 100644 --- a/include/osg/ShapeDrawable +++ b/include/osg/ShapeDrawable @@ -132,6 +132,12 @@ class OSG_EXPORT ShapeDrawable : public Drawable ShapeDrawable(Shape* shape, TessellationHints* hints=0); + template ShapeDrawable(const ref_ptr& shape, TessellationHints* hints=0): + _color(1.0f,1.0f,1.0f,1.0f), + _tessellationHints(hints) { setShape(shape.get()); } + + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY); diff --git a/include/osg/StateSet b/include/osg/StateSet index 25ce0a1b4..35f4a2369 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -160,15 +160,21 @@ class OSG_EXPORT StateSet : public Object /** Set this StateSet to contain specified attribute and override flag.*/ void setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF); + template void setAttribute(const ref_ptr& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setAttribute(attribute.get(), value); } + /** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/ void setAttributeAndModes(StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON); + template void setAttributeAndModes(const ref_ptr& attribute, StateAttribute::GLModeValue value=StateAttribute::ON) { setAttribute(attribute.get(), value); } + /** remove attribute of specified type from StateSet.*/ void removeAttribute(StateAttribute::Type type, unsigned int member=0); /** remove attribute from StateSet.*/ void removeAttribute(StateAttribute *attribute); + template void removeAttribute(const ref_ptr& attribute) { removeAttribute(attribute.get()); } + /** Get specified StateAttribute for specified type. * Returns NULL if no type is contained within StateSet.*/ StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0); @@ -226,15 +232,22 @@ class OSG_EXPORT StateSet : public Object /** Set this StateSet to contain specified attribute and override flag.*/ void setTextureAttribute(unsigned int unit,StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF); + + template void setTextureAttribute(unsigned int unit, const ref_ptr& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttribute( unit, attribute.get(), value); } + /** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/ void setTextureAttributeAndModes(unsigned int unit,StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON); + template void setTextureAttributeAndModes(unsigned int unit, const ref_ptr& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttributeAndModes( unit, attribute.get(), value); } + /** remove texture attribute of specified type from StateSet.*/ void removeTextureAttribute(unsigned int unit, StateAttribute::Type type); /** remove texture attribute from StateSet.*/ void removeTextureAttribute(unsigned int unit, StateAttribute *attribute); + template void removeTextureAttribute(unsigned int unit, const ref_ptr& attribute) { removeTextureAttribute(unit, attribute.get()); } + /** Get specified Texture related StateAttribute for specified type. * Returns NULL if no type is contained within StateSet.*/ StateAttribute* getTextureAttribute(unsigned int unit,StateAttribute::Type type); @@ -278,12 +291,16 @@ class OSG_EXPORT StateSet : public Object /** Set this StateSet to contain specified uniform and override flag.*/ void addUniform(Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::ON); + template void addUniform(const ref_ptr& uniform, StateAttribute::OverrideValue value=StateAttribute::ON) { addUniform( uniform.get(), value); } + /** remove uniform of specified name from StateSet.*/ void removeUniform(const std::string& name); /** remove Uniform from StateSet.*/ void removeUniform(Uniform* uniform); + template void removeUniform(const ref_ptr& uniform) { removeUniform(uniform.get()); } + /** Get Uniform for specified name. * Returns NULL if no matching Uniform is contained within StateSet.*/ Uniform* getUniform(const std::string& name); @@ -427,6 +444,8 @@ class OSG_EXPORT StateSet : public Object /** Set the Update Callback which allows users to attach customize the updating of an object during the update traversal.*/ void setUpdateCallback(Callback* ac); + template void setUpdateCallback(const ref_ptr& ac) { setUpdateCallback(ac.get()); } + /** Get the non const Update Callback.*/ Callback* getUpdateCallback() { return _updateCallback.get(); } @@ -447,6 +466,8 @@ class OSG_EXPORT StateSet : public Object /** Set the Event Callback which allows users to attach customize the updating of an object during the event traversal.*/ void setEventCallback(Callback* ac); + template void setEventCallback(const ref_ptr& ec) { setEventCallback(ec.get()); } + /** Get the non const Event Callback.*/ Callback* getEventCallback() { return _eventCallback.get(); } diff --git a/include/osg/Switch b/include/osg/Switch index 65635d22d..9f770f5d6 100644 --- a/include/osg/Switch +++ b/include/osg/Switch @@ -45,6 +45,9 @@ class OSG_EXPORT Switch : public Group bool getNewChildDefaultValue() const { return _newChildDefaultValue; } + using osg::Group::addChild; + using osg::Group::insertChild; + virtual bool addChild( Node *child ); virtual bool addChild( Node *child, bool value ); diff --git a/include/osg/Texture b/include/osg/Texture index cd6cd753b..37e79e6c9 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -740,6 +740,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Sets the texture image for the specified face. */ virtual void setImage(unsigned int face, Image* image) = 0; + template void setImage(unsigned int face, const ref_ptr& image) { setImage(face, image.get()); } + /** Gets the texture image for the specified face. */ virtual Image* getImage(unsigned int face) = 0; @@ -753,6 +755,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Set the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/ void setReadPBuffer(GraphicsContext* context) { _readPBuffer = context; } + template void setReadPBuffer(const ref_ptr& context) { setReadPBuffer(context.get()); } + /** Get the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/ GraphicsContext* getReadPBuffer() { return _readPBuffer.get(); } diff --git a/include/osg/Texture1D b/include/osg/Texture1D index 65f48d686..f70f5a1b6 100644 --- a/include/osg/Texture1D +++ b/include/osg/Texture1D @@ -36,6 +36,13 @@ class OSG_EXPORT Texture1D : public Texture Texture1D(Image* image); + template Texture1D(const osg::ref_ptr& image): + _textureWidth(0), + _numMipmapLevels(0) + { + setImage(image.get()); + } + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ Texture1D(const Texture1D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); @@ -49,6 +56,8 @@ class OSG_EXPORT Texture1D : public Texture /** Sets the texture image. */ void setImage(Image* image); + template void setImage(const ref_ptr& image) { setImage(image.get()); } + /** Gets the texture image. */ Image* getImage() { return _image.get(); } diff --git a/include/osg/Texture2D b/include/osg/Texture2D index d04deb41f..c1b708ba9 100644 --- a/include/osg/Texture2D +++ b/include/osg/Texture2D @@ -30,6 +30,15 @@ class OSG_EXPORT Texture2D : public Texture Texture2D(Image* image); + template Texture2D(const osg::ref_ptr& image): + _textureWidth(0), + _textureHeight(0), + _numMipmapLevels(0) + { + setUseHardwareMipMapGeneration(true); + setImage(image.get()); + } + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ Texture2D(const Texture2D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); @@ -43,6 +52,8 @@ class OSG_EXPORT Texture2D : public Texture /** Sets the texture image. */ void setImage(Image* image); + template void setImage(const ref_ptr& image) { setImage(image.get()); } + /** Gets the texture image. */ Image* getImage() { return _image.get(); } @@ -59,6 +70,8 @@ class OSG_EXPORT Texture2D : public Texture /** Sets the texture image, ignoring face. */ virtual void setImage(unsigned int, Image* image) { setImage(image); } + template void setImage(unsigned int, const ref_ptr& image) { setImage(image.get()); } + /** Gets the texture image, ignoring face. */ virtual Image* getImage(unsigned int) { return _image.get(); } diff --git a/include/osg/Texture2DArray b/include/osg/Texture2DArray index 0f866d670..e410cd8f1 100644 --- a/include/osg/Texture2DArray +++ b/include/osg/Texture2DArray @@ -48,6 +48,8 @@ class OSG_EXPORT Texture2DArray : public Texture /** Set the texture image for specified layer. */ virtual void setImage(unsigned int layer, Image* image); + template void setImage(unsigned int layer, const ref_ptr& image) { setImage(layer, image.get()); } + /** Get the texture image for specified layer. */ virtual Image* getImage(unsigned int layer); diff --git a/include/osg/Texture2DMultisample b/include/osg/Texture2DMultisample index 32ca18f1a..13c55ed52 100644 --- a/include/osg/Texture2DMultisample +++ b/include/osg/Texture2DMultisample @@ -63,6 +63,7 @@ class OSG_EXPORT Texture2DMultisample : public Texture // unnecessary for Texture2DMultisample virtual void setImage(unsigned int /*face*/, Image* /*image*/) {} + virtual Image* getImage(unsigned int /*face*/) { return NULL; } virtual const Image* getImage(unsigned int /*face*/) const { return NULL; } virtual unsigned int getNumImages() const {return 0; } diff --git a/include/osg/Texture3D b/include/osg/Texture3D index b13caead4..f1ebfda4e 100644 --- a/include/osg/Texture3D +++ b/include/osg/Texture3D @@ -30,6 +30,16 @@ class OSG_EXPORT Texture3D : public Texture Texture3D(Image* image); + + template Texture3D(const osg::ref_ptr& image): + _textureWidth(0), + _textureHeight(0), + _textureDepth(0), + _numMipmapLevels(0) + { + setImage(image.get()); + } + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); @@ -43,6 +53,8 @@ class OSG_EXPORT Texture3D : public Texture /** Sets the texture image. */ void setImage(Image* image); + template void setImage(const ref_ptr& image) { setImage(image.get()); } + /** Gets the texture image. */ Image* getImage() { return _image.get(); } diff --git a/include/osg/TextureCubeMap b/include/osg/TextureCubeMap index b8ce1cae3..3ab3f8929 100644 --- a/include/osg/TextureCubeMap +++ b/include/osg/TextureCubeMap @@ -49,6 +49,8 @@ class OSG_EXPORT TextureCubeMap : public Texture /** Set the texture image for specified face. */ virtual void setImage(unsigned int face, Image* image); + template void setImage(unsigned int face, const ref_ptr& image) { setImage(face, image.get()); } + /** Get the texture image for specified face. */ virtual Image* getImage(unsigned int face); diff --git a/include/osg/TextureRectangle b/include/osg/TextureRectangle index d6332150d..f389523e3 100644 --- a/include/osg/TextureRectangle +++ b/include/osg/TextureRectangle @@ -36,6 +36,19 @@ class OSG_EXPORT TextureRectangle : public Texture TextureRectangle(Image* image); + template TextureRectangle(const osg::ref_ptr& image): + _textureWidth(0), + _textureHeight(0) + { + setWrap(WRAP_S, CLAMP); + setWrap(WRAP_T, CLAMP); + + setFilter(MIN_FILTER, LINEAR); + setFilter(MAG_FILTER, LINEAR); + + setImage(image.get()); + } + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ TextureRectangle(const TextureRectangle& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); @@ -49,6 +62,8 @@ class OSG_EXPORT TextureRectangle : public Texture /** Set the texture image. */ void setImage(Image* image); + template void setImage(const ref_ptr& image) { setImage(image.get()); } + /** Get the texture image. */ Image* getImage() { return _image.get(); } diff --git a/include/osg/UserDataContainer b/include/osg/UserDataContainer index a02023bf6..98b2406e4 100644 --- a/include/osg/UserDataContainer +++ b/include/osg/UserDataContainer @@ -47,6 +47,8 @@ class OSG_EXPORT UserDataContainer : public osg::Object */ virtual void setUserData(Referenced* obj) = 0; + using osg::Object::setUserData; + /** Get user data.*/ virtual Referenced* getUserData() = 0; @@ -56,6 +58,8 @@ class OSG_EXPORT UserDataContainer : public osg::Object /** Add user data object. Returns the index position of object added. */ virtual unsigned int addUserObject(Object* obj) = 0; + template unsigned int addUserObject(const osg::ref_ptr& obj) { return addUserObject(obj.get()); } + /** Add element to list of user data objects.*/ virtual void setUserObject(unsigned int i, Object* obj) = 0; @@ -127,6 +131,9 @@ class OSG_EXPORT DefaultUserDataContainer : public osg::UserDataContainer */ virtual void setUserData(Referenced* obj); + using osg::Object::setUserData; + using osg::UserDataContainer::addUserObject; + /** Get user data.*/ virtual Referenced* getUserData(); diff --git a/include/osgDB/ReadFile b/include/osgDB/ReadFile index f01becb0f..dfe87ae1b 100644 --- a/include/osgDB/ReadFile +++ b/include/osgDB/ReadFile @@ -26,6 +26,215 @@ namespace osgDB { +/** Read an osg::Object from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefObjectFile(const std::string& filename,const Options* options); + +/** Read an osg::Object from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefObjectFile(const std::string& filename) +{ + return readRefObjectFile(filename, Registry::instance()->getOptions()); +} + +template +inline osg::ref_ptr readRefFile(const std::string& filename, const Options* options) +{ + osg::ref_ptr object = readRefObjectFile(filename, options); + osg::ref_ptr t = dynamic_cast(object.get()); + return t; +} + +template +inline osg::ref_ptr readRefFile(const std::string& filename) +{ + return readRefFile(filename, Registry::instance()->getOptions()); +} + + +/** Read an osg::Image from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefImageFile(const std::string& filename,const Options* options); + +/** Read an osg::Image from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefImageFile(const std::string& filename) +{ + return readRefImageFile(filename,Registry::instance()->getOptions()); +} + +/** Read an osg::HeightField from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefHeightFieldFile(const std::string& filename,const Options* options); + +/** Read an osg::HeightField from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefHeightFieldFile(const std::string& filename) +{ + return readRefHeightFieldFile(filename,Registry::instance()->getOptions()); +} + +/** Read an osg::Node from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefNodeFile(const std::string& filename,const Options* options); + +/** Read an osg::Node from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefNodeFile(const std::string& filename) +{ + return readRefNodeFile(filename,Registry::instance()->getOptions()); +} + +/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more + * than one subgraph has been loaded. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * Does NOT ignore strings beginning with a dash '-' character. */ +extern OSGDB_EXPORT osg::ref_ptr readRefNodeFiles(std::vector& fileList,const Options* options); + +/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more + * than one subgraph has been loaded.*/ +inline osg::ref_ptr readRefNodeFiles(std::vector& fileList) +{ + return readRefNodeFiles(fileList, Registry::instance()->getOptions()); +} + + +/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more + * than one subgraph has been loaded. + * Use the Options object to control cache operations and file search paths in osgDB::Registry.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefNodeFiles(osg::ArgumentParser& parser,const Options* options); + +/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more + * than one subgraph has been loaded.*/ +inline osg::ref_ptr readRefNodeFiles(osg::ArgumentParser& parser) +{ + return readRefNodeFiles(parser,Registry::instance()->getOptions()); +} + +/** Read an osg::Shader from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefShaderFile(const std::string& filename,const Options* options); + +/** Read an osg::Shader from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefShaderFile(const std::string& filename) +{ + return readRefShaderFile(filename, Registry::instance()->getOptions()); +} + +/** Read an osg::Shader from file and set to specified shader type. + * Return valid osg::Shader on success, + * return NULL on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options) +{ + osg::ref_ptr shader = readRefShaderFile(filename, options); + if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type); + return shader; +} + +/** Read an osg::Shader from file and set to specified shader type + * Return valid osg::Shader on success, + * return NULL on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefShaderFile(osg::Shader::Type type, const std::string& filename) +{ + return readRefShaderFile(type, filename, Registry::instance()->getOptions()); +} + +/** Read an osg::Shader from file and set to specified shader type, if a shader isn't loaded fallback to specific shader source. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const Options* options, const char* fallback) +{ + osg::ref_ptr shader = readRefShaderFile(filename, options); + if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type); + if (!shader) shader = new osg::Shader(type, fallback); + return shader; +} + +/** Read an osg::Shader from file and set to specified shader type, if a shader isn't loaded fallback to specific shader source. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const char* fallback) +{ + return osgDB::readRefShaderFileWithFallback(type, filename, Registry::instance()->getOptions(), fallback); +} + +/** Read an osg::Script from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * Use the Options object to control cache operations and file search paths in osgDB::Registry. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +extern OSGDB_EXPORT osg::ref_ptr readRefScriptFile(const std::string& filename,const Options* options); + +/** Read an osg::Script from file. + * Return an assigned osg::ref_ptr on success, + * return an osg::ref_ptr with a NULL pointer assigned to it on failure. + * The osgDB::Registry is used to load the appropriate ReaderWriter plugin + * for the filename extension, and this plugin then handles the request + * to read the specified file.*/ +inline osg::ref_ptr readRefScriptFile(const std::string& filename) +{ + return readRefScriptFile(filename,Registry::instance()->getOptions()); +} + +#ifdef OSG_PROVIDE_READFILE /** Read an osg::Object from file. * Return valid osg::Object on success, * return NULL on failure. @@ -49,7 +258,7 @@ inline osg::Object* readObjectFile(const std::string& filename) template inline T* readFile(const std::string& filename, const Options* options) { - osg::ref_ptr object = readObjectFile(filename, options); + osg::ref_ptr object = readRefObjectFile(filename, options); osg::ref_ptr t = dynamic_cast(object.get()); object = 0; return t.release(); @@ -236,155 +445,9 @@ inline osg::Script* readScriptFile(const std::string& filename) { return readScriptFile(filename,Registry::instance()->getOptions()); } +#endif - -/** Read an osg::Object from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefObjectFile(const std::string& filename,const Options* options); - -/** Read an osg::Object from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefObjectFile(const std::string& filename) -{ - return readRefObjectFile(filename,Registry::instance()->getOptions()); -} - -/** Read an osg::Image from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefImageFile(const std::string& filename,const Options* options); - -/** Read an osg::Image from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefImageFile(const std::string& filename) -{ - return readRefImageFile(filename,Registry::instance()->getOptions()); -} - -/** Read an osg::HeightField from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefHeightFieldFile(const std::string& filename,const Options* options); - -/** Read an osg::HeightField from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefHeightFieldFile(const std::string& filename) -{ - return readRefHeightFieldFile(filename,Registry::instance()->getOptions()); -} - -/** Read an osg::Node from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefNodeFile(const std::string& filename,const Options* options); - -/** Read an osg::Node from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefNodeFile(const std::string& filename) -{ - return readRefNodeFile(filename,Registry::instance()->getOptions()); -} - -/** Read an osg::Shader from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefShaderFile(const std::string& filename,const Options* options); - -/** Read an osg::Shader from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefShaderFile(const std::string& filename) -{ - return readRefShaderFile(filename, Registry::instance()->getOptions()); -} - -/** Read an osg::Shader from file and set to specified shader type. - * Return valid osg::Shader on success, - * return NULL on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options) -{ - osg::ref_ptr shader = readShaderFile(filename, options); - if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type); - return shader; -} - -/** Read an osg::Shader from file and set to specified shader type - * Return valid osg::Shader on success, - * return NULL on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefShaderFile(osg::Shader::Type type, const std::string& filename) -{ - return readRefShaderFile(type, filename, Registry::instance()->getOptions()); -} - - -/** Read an osg::Script from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * Use the Options object to control cache operations and file search paths in osgDB::Registry. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -extern OSGDB_EXPORT osg::ref_ptr readRefScriptFile(const std::string& filename,const Options* options); - -/** Read an osg::Script from file. - * Return an assigned osg::ref_ptr on success, - * return an osg::ref_ptr with a NULL pointer assigned to it on failure. - * The osgDB::Registry is used to load the appropriate ReaderWriter plugin - * for the filename extension, and this plugin then handles the request - * to read the specified file.*/ -inline osg::ref_ptr readRefScriptFile(const std::string& filename) -{ - return readRefScriptFile(filename,Registry::instance()->getOptions()); -} - } #endif diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index 9bd3beea8..81de7f583 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -123,8 +123,12 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object ReadResult(ReadStatus status=FILE_NOT_HANDLED):_status(status) {} ReadResult(const std::string& m):_status(ERROR_IN_READING_FILE),_message(m) {} + ReadResult(osg::Object* obj, ReadStatus status=FILE_LOADED):_status(status),_object(obj) {} + template + ReadResult(const osg::ref_ptr& obj, ReadStatus status=FILE_LOADED):_status(status),_object(obj.get()) {} + ReadResult(const ReadResult& rr):_status(rr._status),_message(rr._message),_object(rr._object) {} ReadResult& operator = (const ReadResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message;_object=rr._object; return *this; } diff --git a/include/osgManipulator/Dragger b/include/osgManipulator/Dragger index 384ade5eb..7b3888dac 100644 --- a/include/osgManipulator/Dragger +++ b/include/osgManipulator/Dragger @@ -204,6 +204,7 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform * this dragger. */ virtual void setParentDragger(Dragger* parent) { _parentDragger = parent; } + Dragger* getParentDragger() { return _parentDragger; } const Dragger* getParentDragger() const { return _parentDragger; } @@ -236,7 +237,10 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform typedef std::vector< osg::ref_ptr > Constraints; void addConstraint(Constraint* constraint); + template void addConstraint(const osg::ref_ptr& c) { addConstraint(c.get()); } + void removeConstraint(Constraint* constraint); + template void removeConstraint(const osg::ref_ptr& c) { removeConstraint(c.get()); } Constraints& getConstraints() { return _constraints; } const Constraints& getConstraints() const { return _constraints; } @@ -245,7 +249,10 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform typedef std::vector< osg::ref_ptr > DraggerCallbacks; void addDraggerCallback(DraggerCallback* dc); + template void addDraggerCallback(const osg::ref_ptr& dc) { addDraggerCallback(dc.get()); } + void removeDraggerCallback(DraggerCallback* dc); + template void removeDraggerCallback(const osg::ref_ptr& dc) { removeDraggerCallback(dc.get()); } DraggerCallbacks& getDraggerCallbacks() { return _draggerCallbacks; } const DraggerCallbacks& getDraggerCallbacks() const { return _draggerCallbacks; } @@ -320,11 +327,19 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger // Composite-specific methods below virtual bool addDragger(Dragger* dragger); + template bool addDragger(const osg::ref_ptr& dc) { return addDragger(dc.get()); } + virtual bool removeDragger(Dragger* dragger); + template bool removeDragger(const osg::ref_ptr& dc) { return removeDragger(dc.get()); } + unsigned int getNumDraggers() const { return _draggerList.size(); } + Dragger* getDragger(unsigned int i) { return _draggerList[i].get(); } const Dragger* getDragger(unsigned int i) const { return _draggerList[i].get(); } + bool containsDragger(const Dragger* dragger) const; + template bool containsDragger(const osg::ref_ptr& dc) const { return containsDragger(dc.get()); } + DraggerList::iterator findDragger(const Dragger* dragger); virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask); diff --git a/include/osgParticle/Particle b/include/osgParticle/Particle index ea34ee856..7f0758275 100644 --- a/include/osgParticle/Particle +++ b/include/osgParticle/Particle @@ -179,12 +179,15 @@ namespace osgParticle /// Set the interpolator for computing size values. inline void setSizeInterpolator(Interpolator* ri); + template void setSizeInterpolator(const osg::ref_ptr& ri) { setSizeInterpolator(ri.get()); } /// Set the interpolator for computing alpha values. inline void setAlphaInterpolator(Interpolator* ai); + template void setAlphaInterpolator(const osg::ref_ptr& ri) { setAlphaInterpolator(ri.get()); } /// Set the interpolator for computing color values. inline void setColorInterpolator(Interpolator* ci); + template void setColorInterpolator(const osg::ref_ptr& ri) { setColorInterpolator(ri.get()); } /** Set the physical radius of the particle. For built-in operators to work correctly, lengths must be expressed in meters. diff --git a/include/osgParticle/ParticleEffect b/include/osgParticle/ParticleEffect index f6df65739..13ea70802 100644 --- a/include/osgParticle/ParticleEffect +++ b/include/osgParticle/ParticleEffect @@ -85,6 +85,8 @@ namespace osgParticle virtual const Program* getProgram() const = 0; void setParticleSystem(ParticleSystem* ps); + template void setParticleSystem(const osg::ref_ptr& ri) { setParticleSystem(ri.get()); } + inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); } inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); } diff --git a/include/osgShadow/ShadowedScene b/include/osgShadow/ShadowedScene index ed401a28f..9a36ad2cf 100644 --- a/include/osgShadow/ShadowedScene +++ b/include/osgShadow/ShadowedScene @@ -38,10 +38,14 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group virtual void traverse(osg::NodeVisitor& nv); void setShadowSettings(ShadowSettings* ss); + template void setShadowSettings(const osg::ref_ptr& ss) { setShadowSettings(ss.get()); } + ShadowSettings* getShadowSettings() { return _shadowSettings.get(); } const ShadowSettings* getShadowSettings() const { return _shadowSettings.get(); } void setShadowTechnique(ShadowTechnique* technique); + template void setShadowTechnique(const osg::ref_ptr& ss) { setShadowTechnique(ss.get()); } + ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); } const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); } diff --git a/include/osgSim/OverlayNode b/include/osgSim/OverlayNode index ff13fe3b8..c59e6b7e2 100644 --- a/include/osgSim/OverlayNode +++ b/include/osgSim/OverlayNode @@ -57,6 +57,8 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group /** Set the overlay subgraph which will be rendered to texture.*/ void setOverlaySubgraph(osg::Node* node); + template void setOverlaySubgraph(const osg::ref_ptr& node) { setOverlaySubgraph(node.get()); } + /** Get the overlay subgraph which will be rendered to texture.*/ osg::Node* getOverlaySubgraph() { return _overlaySubgraph.get(); } diff --git a/include/osgTerrain/Layer b/include/osgTerrain/Layer index 9835a69f0..5a17e9f00 100644 --- a/include/osgTerrain/Layer +++ b/include/osgTerrain/Layer @@ -60,6 +60,9 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object std::string getCompoundName() const { return createCompoundSetNameAndFileName(getName(), getFileName()); } void setLocator(Locator* locator) { _locator = locator; } + + template void setLocator(const osg::ref_ptr& locator) { setLocator(locator.get()); } + Locator* getLocator() { return _locator.get(); } const Locator* getLocator() const { return _locator.get(); } @@ -314,6 +317,8 @@ class OSGTERRAIN_EXPORT ImageLayer : public Layer void setImage(osg::Image* image); + template void setImage(const osg::ref_ptr& image) { return setImage(image.get()); } + /** Return image associated with layer. */ virtual osg::Image* getImage() { return _image.get(); } @@ -354,6 +359,9 @@ class OSGTERRAIN_EXPORT ContourLayer : public Layer virtual bool transform(float offset, float scale); void setTransferFunction(osg::TransferFunction1D* tf); + + template void setTransferFunction(const osg::ref_ptr& tf) { return setTransferFunction(tf.get()); } + osg::TransferFunction1D* getTransferFunction() { return _tf.get(); } const osg::TransferFunction1D* getTransferFunction() const { return _tf.get(); } @@ -401,6 +409,9 @@ class OSGTERRAIN_EXPORT HeightFieldLayer : public Layer virtual bool transform(float offset, float scale); void setHeightField(osg::HeightField* hf); + + template void setHeightField(const osg::ref_ptr& hf) { return setHeightField(hf.get()); } + osg::HeightField* getHeightField() { return _heightField.get(); } const osg::HeightField* getHeightField() const { return _heightField.get(); } @@ -516,14 +527,21 @@ class OSGTERRAIN_EXPORT CompositeLayer : public Layer void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; } + + template void setLayer(unsigned int i, const osg::ref_ptr& layer) { setLayer(i, layer.get()); } + Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; } + const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; } void addLayer(const std::string& compoundname); + void addLayer(const std::string& setname, const std::string& filename); void addLayer(Layer* layer) { _layers.push_back(CompoundNameLayer(layer->getName(),layer->getFileName(),layer)); } + template void addLayer(const osg::ref_ptr& layer) { return addLayer(layer.get()); } + void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); } unsigned int getNumLayers() const { return static_cast(_layers.size()); } diff --git a/include/osgTerrain/TerrainTile b/include/osgTerrain/TerrainTile index 9b2de4af7..c4eee38fd 100644 --- a/include/osgTerrain/TerrainTile +++ b/include/osgTerrain/TerrainTile @@ -102,6 +102,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group /** Set the TerrainTechnique*/ void setTerrainTechnique(TerrainTechnique* terrainTechnique); + template void setTerrainTechnique(const osg::ref_ptr& terrainTechnique) { setTerrainTechnique(terrainTechnique.get()); } + /** Get the TerrainTechnique*/ TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); } @@ -113,6 +115,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group * The locator takes non-dimensional s,t coordinates into the X,Y,Z world coords and back.*/ void setLocator(Locator* locator) { _locator = locator; } + template void setLocator(const osg::ref_ptr& locator) { setLocator(locator.get()); } + /** Get the coordinate frame locator of the terrain node.*/ Locator* getLocator() { return _locator.get(); } @@ -122,6 +126,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group /** Set the layer to use to define the elevations of the terrain.*/ void setElevationLayer(Layer* layer); + template void setElevationLayer(const osg::ref_ptr& layer) { setElevationLayer(layer.get()); } + /** Get the layer to use to define the elevations of the terrain.*/ Layer* getElevationLayer() { return _elevationLayer.get(); } @@ -132,6 +138,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group /** Set a color layer with specified layer number.*/ void setColorLayer(unsigned int i, Layer* layer); + template void setColorLayer(unsigned int i, const osg::ref_ptr& layer) { setColorLayer(i, layer.get()); } + /** Get color layer with specified layer number.*/ Layer* getColorLayer(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; } @@ -139,7 +147,7 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group const Layer* getColorLayer(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; } /** Get the number of colour layers.*/ - unsigned int getNumColorLayers() const { return static_cast(_colorLayers.size()); } + unsigned int getNumColorLayers() const { return _colorLayers.size(); } /** Set hint to whether the TerrainTechnique should create per vertex normals for lighting purposes.*/ diff --git a/include/osgText/Font b/include/osgText/Font index 6ca770749..b14e723c8 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -28,6 +28,7 @@ namespace osgText { // forward declare Font class Font; +#ifdef OSG_PROVIDE_READFILE /** Read a font from specified file. The filename may contain a path. * It will search for the font file in the following places in this order: * - In the current directory @@ -51,6 +52,7 @@ extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgD /** read a font from specified stream.*/ extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::Options* userOptions = 0); +#endif extern OSGTEXT_EXPORT osg::ref_ptr readRefFontFile(const std::string& filename, const osgDB::Options* userOptions = 0); diff --git a/include/osgText/Font3D b/include/osgText/Font3D index 8d9d05a9d..c3d550cba 100644 --- a/include/osgText/Font3D +++ b/include/osgText/Font3D @@ -20,6 +20,7 @@ namespace osgText { typedef Font Font3D; +#ifdef OSG_PROVIDE_READFILE /** deprecated, use readFontFile() instead.*/ inline Font* readFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0) { @@ -31,6 +32,7 @@ inline Font* readFont3DStream(std::istream& stream, const osgDB::ReaderWriter::O { return readFontStream(stream, userOptions); } +#endif /** deprecated, use readRefFontFile() instead.*/ inline osg::ref_ptr readRefFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0) diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index 7fbf20a19..a6ce889ce 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -122,10 +122,14 @@ class OSGUTIL_EXPORT Optimizer * visitors, specified by the OptimizationOptions.*/ void optimize(osg::Node* node); + template void optimize(const osg::ref_ptr& node) { optimize(node.get()); } + /** Traverse the node and its subgraph with a series of optimization * visitors, specified by the OptimizationOptions.*/ virtual void optimize(osg::Node* node, unsigned int options); + template void optimize(const osg::ref_ptr& node, unsigned int options) { optimize(node.get(), options); } + /** Callback for customizing what operations are permitted on objects in the scene graph.*/ struct IsOperationPermissibleForObjectCallback : public osg::Referenced diff --git a/include/osgViewer/View b/include/osgViewer/View index 8d17aff38..472b48920 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -103,6 +103,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Set the scene graph that the View will use.*/ virtual void setSceneData(osg::Node* node); + template void setSceneData(const osg::ref_ptr& node) { setSceneData(node.get()); } + /** Get the View's scene graph.*/ osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; } @@ -113,6 +115,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Set the View's database pager.*/ void setDatabasePager(osgDB::DatabasePager* dp); + template void setDatabasePager(const osg::ref_ptr& dp) { setDatabasePager(dp.get()); } + /** Get the View's database pager.*/ osgDB::DatabasePager* getDatabasePager(); @@ -123,6 +127,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Set the View's image pager.*/ void setImagePager(osgDB::ImagePager* ip); + template void setImagePager(const osg::ref_ptr* ip) { setImagePager(ip.get()); } + /** Get the View's image pager.*/ osgDB::ImagePager* getImagePager(); @@ -134,9 +140,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter * The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/ void addDevice(osgGA::Device* eventSource); + template void addDevice(const osg::ref_ptr& eventSource) { addDevice(eventSource.get()); } + /** Remove a Device. /*/ void removeDevice(osgGA::Device* eventSource); + template void removeDevice(const osg::ref_ptr& eventSource) { removeDevice(eventSource.get()); } + typedef std::vector< osg::ref_ptr > Devices; Devices& getDevices() { return _eventSources; } @@ -146,6 +156,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /* Set the EventQueue that the View uses to integrate external non window related events.*/ void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } + template void setEventQueue(const osg::ref_ptr& eventQueue) { setEventQueue(eventQueue.get()); } + /* Get the View's EventQueue.*/ osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } @@ -156,6 +168,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter * The parameter resetPosition determines whether manipulator is set to its home position.*/ void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true); + template void setCameraManipulator(const osg::ref_ptr& manipulator, bool resetPosition = true) { setCameraManipulator(manipulator.get(), resetPosition); } + /** Get the View's CameraManipulator.*/ osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); } @@ -172,9 +186,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Add an EventHandler that adds handling of events to the View.*/ void addEventHandler(osgGA::EventHandler* eventHandler); + template void addEventHandler(const osg::ref_ptr& eventHandler) { addEventHandler(eventHandler.get()); } + /** Remove an EventHandler from View.*/ void removeEventHandler(osgGA::EventHandler* eventHandler); + template void removeEventHandler(const osg::ref_ptr& eventHandler) { removeEventHandler(eventHandler.get()); } + /** Get the View's list of EventHandlers.*/ EventHandlers& getEventHandlers() { return _eventHandlers; } @@ -197,6 +215,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Set the DisplaySettings object associated with this view.*/ void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; } + template void setDisplaySettings(const osg::ref_ptr& ds) { setDisplaySettings(ds.get()); } + /** Set the DisplaySettings object associated with this view.*/ osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); } @@ -220,6 +240,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Apply a viewer configuration to set up Cameras and Windowing. */ void apply(ViewConfig* config); + template void apply(const osg::ref_ptr& config) { apply(config.get()); } + ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); } const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); } @@ -254,6 +276,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Return true if this view contains a specified camera.*/ bool containsCamera(const osg::Camera* camera) const; + template bool containsCamera(const osg::ref_ptr& camera) const { return containsCamera(camera.get()); } /** deprecated. */ const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const; diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 8928d35b7..b02d98cea 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -64,6 +64,8 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View virtual void setStartTick(osg::Timer_t tick); void setReferenceTime(double time=0.0); + using osgViewer::View::setSceneData; + /** Set the sene graph data that viewer with view.*/ virtual void setSceneData(osg::Node* node); diff --git a/include/osgVolume/Layer b/include/osgVolume/Layer index c3fd08d4a..567b76361 100644 --- a/include/osgVolume/Layer +++ b/include/osgVolume/Layer @@ -71,6 +71,9 @@ class OSGVOLUME_EXPORT Layer : public osg::Object virtual const std::string& getFileName() const { return _filename; } void setLocator(Locator* locator) { _locator = locator; } + + template void setLocator(const osg::ref_ptr& locator) { setLocator(locator.get()); } + Locator* getLocator() { return _locator.get(); } const Locator* getLocator() const { return _locator.get(); } @@ -99,6 +102,8 @@ class OSGVOLUME_EXPORT Layer : public osg::Object /** Set the Property (or Properties via the CompositeProperty) that informs the VolumeTechnique how this layer should be rendered.*/ void setProperty(Property* property) { _property = property; } + template void setProperty(const osg::ref_ptr& p) { setProperty(p.get()); } + /** Get the Property that informs the VolumeTechnique how this layer should be rendered.*/ Property* getProperty() { return _property.get(); } @@ -108,6 +113,7 @@ class OSGVOLUME_EXPORT Layer : public osg::Object /** Add a property, automatically creating a CompositePorperty if one isn't already assigned.*/ void addProperty(Property* property); + template void addProperty(const osg::ref_ptr& p) { addProperty(p.get()); } /** Specify whether ImageLayer requires update traversal. */ virtual bool requiresUpdateTraversal() const { return false; } @@ -156,6 +162,8 @@ class OSGVOLUME_EXPORT ImageLayer : public Layer void setImage(osg::Image* image); + template void setImage(const osg::ref_ptr& image) { setImage(image.get()); } + /** Return image associated with layer. */ virtual osg::Image* getImage() { return _image.get(); } @@ -217,11 +225,17 @@ class OSGVOLUME_EXPORT CompositeLayer : public Layer const std::string& getFileName(unsigned int i) const { return _layers[i].layer.valid() ? _layers[i].layer->getFileName() : _layers[i].filename; } void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; } + + template void setLayer(unsigned int i, const osg::ref_ptr& layer) { setLayer(i, layer.get()); } + Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; } + const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; } void addLayer(Layer* layer) { _layers.push_back(NameLayer(layer->getFileName(),layer)); } + template void addLayer(const osg::ref_ptr& layer) { addLayer(layer.get()); } + void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); } unsigned int getNumLayers() const { return _layers.size(); } diff --git a/include/osgVolume/Locator b/include/osgVolume/Locator index e57135983..07da1bd55 100644 --- a/include/osgVolume/Locator +++ b/include/osgVolume/Locator @@ -83,6 +83,9 @@ class OSGVOLUME_EXPORT Locator : public osg::Object }; void addCallback(LocatorCallback* callback); + template void addCallback(const osg::ref_ptr& callback) { addCallback(callback.get()); } + + void removeCallback(LocatorCallback* callback); typedef std::vector< osg::ref_ptr > LocatorCallbacks; diff --git a/include/osgVolume/Property b/include/osgVolume/Property index c749b94a0..70ad136ce 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -126,12 +126,16 @@ class OSGVOLUME_EXPORT CompositeProperty : public Property void setProperty(unsigned int i, Property* property) { if (i>=_properties.size()) _properties.resize(i+1); _properties[i] = property; } + template void setProperty(unsigned int i, const osg::ref_ptr& p) { setProperty(i, p.get()); } + Property* getProperty(unsigned int i) { return i<_properties.size() ? _properties[i].get() : 0; } const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; } void addProperty(Property* property) { _properties.push_back(property); dirty(); } + template void addProperty(const osg::ref_ptr& p) { addProperty(p.get()); } + void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); } unsigned int getNumProperties() const { return _properties.size(); } diff --git a/include/osgWidget/Frame b/include/osgWidget/Frame index ad8d3509c..01b897780 100644 --- a/include/osgWidget/Frame +++ b/include/osgWidget/Frame @@ -175,6 +175,18 @@ class OSGWIDGET_EXPORT Frame: public Table Frame* = 0 ); + template + static Frame* createSimpleFrameWithSingleTexture( + const std::string& name, + const osg::ref_ptr& image, + point_type width, + point_type height, + unsigned int flags = 0, + Frame* exFrame = 0) + { + return Frame::createSimpleFrameWithSingleTexture(name, image.get(), width, height, flags, exFrame); + } + static Frame* createSimpleFrameFromTheme( const std::string&, osg::Image*, @@ -184,6 +196,18 @@ class OSGWIDGET_EXPORT Frame: public Table Frame* = 0 ); + template + static Frame* createSimpleFrameFromTheme( + const std::string& name, + const osg::ref_ptr& image, + point_type width, + point_type height, + unsigned int flags = 0, + Frame* exFrame = 0) + { + return Frame::createSimpleFrameFromTheme(name, image.get(), width, height, flags, exFrame); + } + void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) { createSimpleFrame(_name, cw, ch, w, h, 0, this); diff --git a/include/osgWidget/Widget b/include/osgWidget/Widget index 54d906678..5c2d3d962 100644 --- a/include/osgWidget/Widget +++ b/include/osgWidget/Widget @@ -129,6 +129,10 @@ public: void setTexCoordWrapVertical (); bool setImage (osg::Image*, bool = false, bool = false); + + template bool setImage(const osg::ref_ptr& image, bool f1 = false, bool f2 = false) { return setImage(image.get(), f1, f2); } + + bool setImage (const std::string&, bool = false, bool = false); bool setTexture (osg::Texture*, bool = false, bool = false); diff --git a/src/osg/Config.in b/src/osg/Config.in index 0bc618c14..245af70bb 100644 --- a/src/osg/Config.in +++ b/src/osg/Config.in @@ -31,5 +31,6 @@ #cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION #cmakedefine OSG_USE_UTF8_FILENAME #cmakedefine OSG_DISABLE_MSVC_WARNINGS +#cmakedefine OSG_PROVIDE_READFILE #endif diff --git a/src/osgDB/FileCache.cpp b/src/osgDB/FileCache.cpp index 36ab81a45..22f43b88e 100644 --- a/src/osgDB/FileCache.cpp +++ b/src/osgDB/FileCache.cpp @@ -343,7 +343,7 @@ bool FileCache::loadDatabaseRevisionsForFile(const std::string& originalFileName if (!cacheFileName.empty() && osgDB::fileExists(cacheFileName)) { OSG_INFO<<" found revisions file in local cache, now loading it"< object = osgDB::readObjectFile(cacheFileName); + osg::ref_ptr object = osgDB::readRefObjectFile(cacheFileName); dr_local = dynamic_cast(object.get()); if (dr_local) { @@ -357,7 +357,7 @@ bool FileCache::loadDatabaseRevisionsForFile(const std::string& originalFileName } // now load revision file from remote server - osg::ref_ptr object = osgDB::readObjectFile(revisionsFileName+".curl"); + osg::ref_ptr object = osgDB::readRefObjectFile(revisionsFileName+".curl"); osg::ref_ptr dr_remote = dynamic_cast(object.get()); if (dr_remote.valid()) @@ -463,7 +463,7 @@ FileList* FileCache::readFileList(const std::string& originalFileName) const std::string cacheFileListName = createCacheFileName(originalFileName); if (!cacheFileListName.empty() && osgDB::fileExists(cacheFileListName)) { - osg::ref_ptr object = osgDB::readObjectFile(cacheFileListName); + osg::ref_ptr object = osgDB::readRefObjectFile(cacheFileListName); fileList = dynamic_cast(object.get()); if (fileList) OSG_INFO<<" loadeded FileList from local cache "<getName()< object = osgDB::readRefObjectFile(originalFileName+".curl"); fileList = dynamic_cast(object.get()); if (fileList) { diff --git a/src/osgDB/ImagePager.cpp b/src/osgDB/ImagePager.cpp index 603b0141f..be8a379ef 100644 --- a/src/osgDB/ImagePager.cpp +++ b/src/osgDB/ImagePager.cpp @@ -211,7 +211,7 @@ void ImagePager::ImageThread::run() if (imageRequest.valid()) { // OSG_NOTICE<<"doing readImageFile("<_fileName<<") index to assign = "<_attachmentIndex< image = osgDB::readImageFile(imageRequest->_fileName, imageRequest->_readOptions.get()); + osg::ref_ptr image = osgDB::readRefImageFile(imageRequest->_fileName, imageRequest->_readOptions.get()); if (image.valid()) { // OSG_NOTICE<<" successful readImageFile("<_fileName<<") index to assign = "<_attachmentIndex<(const_cast(options)); - return osgDB::readImageFile(fileName, readOptions); + return osgDB::readRefImageFile(fileName, readOptions).release(); } void ImagePager::requestImageFile(const std::string& fileName, osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* /*framestamp*/, osg::ref_ptr& imageRequest, const osg::Referenced* options) { - osgDB::Options* readOptions = dynamic_cast(const_cast(options)); if (!readOptions) { diff --git a/src/osgDB/Input.cpp b/src/osgDB/Input.cpp index 12edf9686..8dc3235c7 100644 --- a/src/osgDB/Input.cpp +++ b/src/osgDB/Input.cpp @@ -87,7 +87,7 @@ osg::Node* Input::readNode() osg::Object* Input::readObject(const std::string& fileName) { - return readObjectFile(fileName,_options.get()); + return readRefObjectFile(fileName,_options.get()).release(); } osg::Shader* Input::readShader() @@ -97,17 +97,17 @@ osg::Shader* Input::readShader() osg::Image* Input::readImage(const std::string& fileName) { - return readImageFile(fileName,_options.get()); + return readRefImageFile(fileName,_options.get()).release(); } osg::Node* Input::readNode(const std::string& fileName) { - return readNodeFile(fileName,_options.get()); + return readRefNodeFile(fileName,_options.get()).release(); } osg::Shader* Input::readShader(const std::string& fileName) { - return readShaderFile(fileName,_options.get()); + return readRefShaderFile(fileName,_options.get()).release(); } bool Input::read(Parameter value1) diff --git a/src/osgDB/ReadFile.cpp b/src/osgDB/ReadFile.cpp index deb16ad7f..49993bd2d 100644 --- a/src/osgDB/ReadFile.cpp +++ b/src/osgDB/ReadFile.cpp @@ -29,6 +29,7 @@ using namespace osg; using namespace osgDB; +#ifdef OSG_PROVIDE_READFILE Object* osgDB::readObjectFile(const std::string& filename,const Options* options) { ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options); @@ -75,14 +76,82 @@ Node* osgDB::readNodeFile(const std::string& filename,const Options* options) Node* osgDB::readNodeFiles(std::vector& fileList,const Options* options) { - typedef std::vector NodeList; + return readRefNodeFiles(fileList, options).release(); +} + +Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options) +{ + return readRefNodeFiles(arguments, options).release(); +} + + +Script* osgDB::readScriptFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options); + if (rr.validScript()) return rr.takeScript(); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} +#endif + +osg::ref_ptr osgDB::readRefObjectFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options); + if (rr.validObject()) return osg::ref_ptr(rr.getObject()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefImageFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options); + if (rr.validImage()) return osg::ref_ptr(rr.getImage()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefShaderFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readShader(filename,options); + if (rr.validShader()) return osg::ref_ptr(rr.getShader()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefHeightFieldFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options); + if (rr.validHeightField()) return osg::ref_ptr(rr.getHeightField()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefNodeFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options); + if (rr.validNode()) return osg::ref_ptr(rr.getNode()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefScriptFile(const std::string& filename,const Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options); + if (rr.validScript()) return osg::ref_ptr(rr.getScript()); + if (rr.error()) OSG_WARN << rr.message() << std::endl; + return NULL; +} + +osg::ref_ptr osgDB::readRefNodeFiles(std::vector& fileList,const Options* options) +{ + typedef std::vector< osg::ref_ptr > NodeList; NodeList nodeList; for(std::vector::iterator itr=fileList.begin(); itr!=fileList.end(); ++itr) { - osg::Node *node = osgDB::readNodeFile( *itr , options ); + osg::ref_ptr node = osgDB::readRefNodeFile( *itr , options ); if( node != (osg::Node *)0L ) { @@ -103,7 +172,7 @@ Node* osgDB::readNodeFiles(std::vector& fileList,const Options* opt } else // size >1 { - osg::Group* group = new osg::Group; + osg::ref_ptr group = new osg::Group; for(NodeList::iterator itr=nodeList.begin(); itr!=nodeList.end(); ++itr) @@ -116,7 +185,7 @@ Node* osgDB::readNodeFiles(std::vector& fileList,const Options* opt } -Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options) +osg::ref_ptr osgDB::readRefNodeFiles(osg::ArgumentParser& arguments,const Options* options) { typedef std::vector< osg::ref_ptr > NodeList; @@ -131,7 +200,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options while (arguments.read("--image",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), options); + osg::ref_ptr image = readRefImageFile(filename.c_str(), options); if (image.valid()) { osg::Geode* geode = osg::createGeodeForImage(image.get()); @@ -149,7 +218,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options while (arguments.read("--movie",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), options); + osg::ref_ptr image = readRefImageFile(filename.c_str(), options); osg::ref_ptr imageStream = dynamic_cast(image.get()); if (imageStream.valid()) { @@ -200,11 +269,11 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options while (arguments.read("--dem",filename)) { - osg::HeightField* hf = readHeightFieldFile(filename.c_str(), options); + osg::ref_ptr hf = readRefHeightFieldFile(filename.c_str(), options); if (hf) { - osg::Geode* geode = new osg::Geode; - geode->addDrawable(new osg::ShapeDrawable(hf)); + osg::ref_ptr geode = new osg::Geode; + geode->addDrawable(new osg::ShapeDrawable(hf.get())); nodeList.push_back(geode); } } @@ -215,7 +284,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options if (!arguments.isOption(pos)) { // not an option so assume string is a filename. - osg::Node *node = osgDB::readNodeFile( arguments[pos], options); + osg::ref_ptr node = osgDB::readRefNodeFile( arguments[pos], options); if(node) { @@ -237,73 +306,15 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options } else // size >1 { - osg::Group* group = new osg::Group; + osg::ref_ptr group = new osg::Group; for(NodeList::iterator itr=nodeList.begin(); itr!=nodeList.end(); ++itr) { - group->addChild((*itr).get()); + group->addChild(*itr); } return group; } } - - -Script* osgDB::readScriptFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options); - if (rr.validScript()) return rr.takeScript(); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - - -osg::ref_ptr osgDB::readRefObjectFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options); - if (rr.validObject()) return osg::ref_ptr(rr.getObject()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - -osg::ref_ptr osgDB::readRefImageFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options); - if (rr.validImage()) return osg::ref_ptr(rr.getImage()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - -osg::ref_ptr osgDB::readRefShaderFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readShader(filename,options); - if (rr.validShader()) return osg::ref_ptr(rr.getShader()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - -osg::ref_ptr osgDB::readRefHeightFieldFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options); - if (rr.validHeightField()) return osg::ref_ptr(rr.getHeightField()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - -osg::ref_ptr osgDB::readRefNodeFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options); - if (rr.validNode()) return osg::ref_ptr(rr.getNode()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} - -osg::ref_ptr osgDB::readRefScriptFile(const std::string& filename,const Options* options) -{ - ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options); - if (rr.validScript()) return osg::ref_ptr(rr.getScript()); - if (rr.error()) OSG_WARN << rr.message() << std::endl; - return NULL; -} diff --git a/src/osgFX/BumpMapping.cpp b/src/osgFX/BumpMapping.cpp index 005b85ffb..3659d6ce5 100644 --- a/src/osgFX/BumpMapping.cpp +++ b/src/osgFX/BumpMapping.cpp @@ -626,7 +626,7 @@ void BumpMapping::setUpDemo() // set up diffuse texture if (!_diffuse_tex.valid()) { _diffuse_tex = new osg::Texture2D; - _diffuse_tex->setImage(osgDB::readImageFile("Images/whitemetal_diffuse.jpg")); + _diffuse_tex->setImage(osgDB::readRefImageFile("Images/whitemetal_diffuse.jpg")); _diffuse_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); _diffuse_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); _diffuse_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); @@ -637,7 +637,7 @@ void BumpMapping::setUpDemo() // set up normal map texture if (!_normal_tex.valid()) { _normal_tex = new osg::Texture2D; - _normal_tex->setImage(osgDB::readImageFile("Images/whitemetal_normal.jpg")); + _normal_tex->setImage(osgDB::readRefImageFile("Images/whitemetal_normal.jpg")); _normal_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); _normal_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); _normal_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 3e84bb79c..0b05952ea 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -249,7 +249,7 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur if (!texturefile.empty()) { osg::Texture2D *texture = new osg::Texture2D; - texture->setImage(osgDB::readImageFile(texturefile)); + texture->setImage(osgDB::readRefImageFile(texturefile)); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); @@ -292,7 +292,7 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st if (!texturefile.empty()) { osg::Texture2D *texture = new osg::Texture2D; - texture->setImage(osgDB::readImageFile(texturefile)); + texture->setImage(osgDB::readRefImageFile(texturefile)); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR); diff --git a/src/osgPlugins/Inventor/ConvertFromInventor.cpp b/src/osgPlugins/Inventor/ConvertFromInventor.cpp index b77c3e6b7..9d202a62c 100644 --- a/src/osgPlugins/Inventor/ConvertFromInventor.cpp +++ b/src/osgPlugins/Inventor/ConvertFromInventor.cpp @@ -1088,7 +1088,7 @@ static osgDB::ReaderWriter::Options* createOptions() static osg::Image* loadImage(const char *fileName, osgDB::ReaderWriter::Options *options) { - osg::ref_ptr osgImage = osgDB::readImageFile(fileName, options); + osg::ref_ptr osgImage = osgDB::readRefImageFile(fileName, options); if (!osgImage) { diff --git a/src/osgPlugins/OpenFlight/PaletteRecords.cpp b/src/osgPlugins/OpenFlight/PaletteRecords.cpp index 707f0ad38..659736a4e 100644 --- a/src/osgPlugins/OpenFlight/PaletteRecords.cpp +++ b/src/osgPlugins/OpenFlight/PaletteRecords.cpp @@ -220,9 +220,9 @@ protected: material->setDiffuse (osg::Material::FRONT_AND_BACK,osg::Vec4(diffuse,alpha)); material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(specular,alpha)); material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha)); - + if (shininess>=0.0f) - { + { material->setShininess(osg::Material::FRONT_AND_BACK,shininess); } else @@ -276,7 +276,7 @@ protected: material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha)); if (shininess>=0.0f) - { + { material->setShininess(osg::Material::FRONT_AND_BACK,shininess); } else @@ -346,7 +346,7 @@ protected: // Read attribute file std::string attrname = filename + ".attr"; - osg::ref_ptr attr = dynamic_cast(osgDB::readObjectFile(attrname,document.getOptions())); + osg::ref_ptr attr = osgDB::readRefFile(attrname,document.getOptions()); if (attr.valid()) { // Wrap mode @@ -899,7 +899,7 @@ protected: std::string vertexProgramFilePath = osgDB::findDataFile(vertexProgramFilename,document.getOptions()); if (!vertexProgramFilePath.empty()) { - osg::Shader* vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexProgramFilePath); + osg::ref_ptr vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, vertexProgramFilePath); if (vertexShader) program->addShader( vertexShader ); } @@ -913,7 +913,7 @@ protected: std::string fragmentProgramFilePath = osgDB::findDataFile(fragmentProgramFilename,document.getOptions()); if (!fragmentProgramFilePath.empty()) { - osg::Shader* fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath); + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath); if (fragmentShader) program->addShader( fragmentShader ); } diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index 8a76f50a7..d19714827 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -12,7 +12,7 @@ */ // -// OpenFlight� loader for OpenSceneGraph +// OpenFlight loader for OpenSceneGraph // // Copyright (C) 2005-2007 Brede Johansen // @@ -174,7 +174,7 @@ public: std::string filename = node.getFileName(pos); // read external - osg::ref_ptr external = osgDB::readNodeFile(filename,_options.get()); + osg::ref_ptr external = osgDB::readRefNodeFile(filename,_options.get()); if (external.valid()) { if (_cloneExternalReferences) diff --git a/src/osgPlugins/bsp/VBSPEntity.cpp b/src/osgPlugins/bsp/VBSPEntity.cpp index 8127f146d..443d12e55 100644 --- a/src/osgPlugins/bsp/VBSPEntity.cpp +++ b/src/osgPlugins/bsp/VBSPEntity.cpp @@ -518,7 +518,7 @@ ref_ptr VBSPEntity::createModelGeometry() ref_ptr entityGroup; // Try to load the model - modelNode = osgDB::readNodeFile(entity_model); + modelNode = osgDB::readRefNodeFile(entity_model); if (modelNode.valid()) { // Create a group and add the model to it diff --git a/src/osgPlugins/bsp/VBSPReader.cpp b/src/osgPlugins/bsp/VBSPReader.cpp index 8db6607f2..df60ded40 100644 --- a/src/osgPlugins/bsp/VBSPReader.cpp +++ b/src/osgPlugins/bsp/VBSPReader.cpp @@ -1094,7 +1094,7 @@ void VBSPReader::createScene() // Load the prop's model propModel = bsp_data->getStaticPropModel(staticProp.prop_type); - propNode = osgDB::readNodeFile(propModel); + propNode = osgDB::readRefNodeFile(propModel); // If we loaded the prop correctly, add it to the scene if (propNode.valid()) diff --git a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp index 12f8b65da..88a277f5e 100644 --- a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp +++ b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp @@ -62,7 +62,7 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) if (transparentColor[0] < 1.0 || transparentColor[1] < 1.0 || transparentColor[2] < 1.0) { transparencyColorFactor = transparentColor[0]*0.30 + transparentColor[1]*0.59 + transparentColor[2]*0.11; useTransparencyColorFactor = true; - } + } int lNbTex = lOpacityProperty.GetSrcObjectCount(); for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++) @@ -187,7 +187,7 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) static_cast(color[1] * factor), static_cast(color[2] * factor), 1.0f)); - // Since Maya and 3D studio Max stores their glossiness values in exponential format (2^(log2(x)) + // Since Maya and 3D studio Max stores their glossiness values in exponential format (2^(log2(x)) // We need to linearize to values between 0-100 and then scale to values between 0-128. // Glossiness values above 100 will result in shininess larger than 128.0 and will be clamped double shininess = (64.0 * log (pFbxPhong->Shininess.Get())) / (5.0 * log(2.0)); @@ -226,9 +226,9 @@ FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const FbxFileTexture* fbx) // Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR // fbx->GetFileName() is as stored initially in the FBX - if ((pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fbx->GetFileName()), _options)) || // First try "export dir/name" - (pImage = osgDB::readImageFile(fbx->GetFileName(), _options)) || // Then try "name" (if absolute) - (pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()), _options))) // Else try "current dir/name" + if ((pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetFileName()), _options)) || // First try "export dir/name" + (pImage = osgDB::readRefImageFile(fbx->GetFileName(), _options)) || // Then try "name" (if absolute) + (pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()), _options))) // Else try "current dir/name" { osg::ref_ptr pOsgTex = new osg::Texture2D; pOsgTex->setImage(pImage.get()); diff --git a/src/osgPlugins/gles/ReaderWriterGLES.cpp b/src/osgPlugins/gles/ReaderWriterGLES.cpp index df56f71f7..2c7133382 100644 --- a/src/osgPlugins/gles/ReaderWriterGLES.cpp +++ b/src/osgPlugins/gles/ReaderWriterGLES.cpp @@ -133,7 +133,7 @@ public: return ReadResult::FILE_NOT_HANDLED; // recursively load the subfile. - osg::ref_ptr node = osgDB::readNodeFile( realName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( realName, options ); if( !node ) { // propagate the read failure upwards diff --git a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp index 8a34e61a0..60c4842a4 100644 --- a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp +++ b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp @@ -57,7 +57,7 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter const std::string filename = code.substr( pos2 + 1, pos3 - pos2 - 1 ); - osg::ref_ptr innerShader = osgDB::readShaderFile( shader->getType(), filename, options ); + osg::ref_ptr innerShader = osgDB::readRefShaderFile( shader->getType(), filename, options ); if ( !innerShader.valid() ) { diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 7ba4eda72..fc296c056 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -1914,7 +1914,7 @@ osgTerrain::Layer* DataInputStream::readLayer() else if (layerid==IVEPROXYLAYER) { std::string filename = readString(); - osg::ref_ptr object = osgDB::readObjectFile(filename+".gdal"); + osg::ref_ptr object = osgDB::readRefObjectFile(filename+".gdal"); osgTerrain::ProxyLayer* proxyLayer = dynamic_cast(object.get()); osg::ref_ptr locator = readLocator(); diff --git a/src/osgPlugins/ive/HeightFieldLayer.cpp b/src/osgPlugins/ive/HeightFieldLayer.cpp index 2f0b6645b..874b02c2b 100644 --- a/src/osgPlugins/ive/HeightFieldLayer.cpp +++ b/src/osgPlugins/ive/HeightFieldLayer.cpp @@ -107,7 +107,7 @@ void HeightFieldLayer::read(DataInputStream* in) if (in->getVersion()>=VERSION_0035) { - osg::HeightField* hf = new osg::HeightField; + osg::ref_ptr hf = new osg::HeightField; // Read HeightField's properties //setColor(in->readVec4()); @@ -128,13 +128,13 @@ void HeightFieldLayer::read(DataInputStream* in) in->readPackedFloatArray(hf->getFloatArray()); } - setHeightField(hf); + setHeightField(hf.get()); } else { - osg::Shape* shape = in->readShape(); - setHeightField(dynamic_cast(shape)); + osg::ref_ptr shape = in->readShape(); + setHeightField(dynamic_cast(shape.get())); } } @@ -143,7 +143,8 @@ void HeightFieldLayer::read(DataInputStream* in) std::string filename = in->readString(); setFileName(filename); - setHeightField(osgDB::readHeightFieldFile(filename,in->getOptions())); + osg::ref_ptr hf = osgDB::readRefHeightFieldFile(filename,in->getOptions()); + if (hf) setHeightField(hf.get()); } } diff --git a/src/osgPlugins/ive/Layer.cpp b/src/osgPlugins/ive/Layer.cpp index 079164ddc..ab00c9842 100644 --- a/src/osgPlugins/ive/Layer.cpp +++ b/src/osgPlugins/ive/Layer.cpp @@ -190,8 +190,7 @@ osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in) else if (id==IVEPROXYLAYER) { std::string filename = in->readString(); - osg::ref_ptr object = osgDB::readObjectFile(filename+".gdal"); - osgTerrain::ProxyLayer* proxyLayer = dynamic_cast(object.get()); + osg::ref_ptr proxyLayer = osgDB::readRefFile(filename+".gdal"); osg::ref_ptr locator = readLocator(in); unsigned int minLevel = in->readUInt(); @@ -205,7 +204,7 @@ osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in) proxyLayer->setMaxLevel(maxLevel); } - return proxyLayer; + return proxyLayer.release(); } return new osgTerrain::ImageLayer; diff --git a/src/osgPlugins/ive/ProxyNode.cpp b/src/osgPlugins/ive/ProxyNode.cpp index cba0bab3d..181a4331c 100644 --- a/src/osgPlugins/ive/ProxyNode.cpp +++ b/src/osgPlugins/ive/ProxyNode.cpp @@ -205,7 +205,7 @@ void ProxyNode::read(DataInputStream* in) { osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)in->getOptions())->getDatabasePathList(); fpl.push_front( fpl.empty() ? osgDB::getFilePath(getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(getFileName(i))); - osg::Node *node = osgDB::readNodeFile(getFileName(i), in->getOptions()); + osg::ref_ptr node = osgDB::readRefNodeFile(getFileName(i), in->getOptions()); fpl.pop_front(); if(node) diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index 36e8e8da6..93dcabd6b 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -1767,7 +1767,7 @@ static int readObjectFile(lua_State * _lua) if (n==1 && lua_type(_lua, 1)==LUA_TSTRING) { std::string filename = lua_tostring(_lua, 1); - osg::ref_ptr object = osgDB::readObjectFile(filename); + osg::ref_ptr object = osgDB::readRefObjectFile(filename); if (object.valid()) { lse->pushObject(object.get()); @@ -1785,7 +1785,7 @@ static int readImageFile(lua_State * _lua) if (n==1 && lua_type(_lua, 1)==LUA_TSTRING) { std::string filename = lua_tostring(_lua, 1); - osg::ref_ptr image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); if (image.valid()) { lse->pushObject(image.get()); @@ -1803,7 +1803,7 @@ static int readNodeFile(lua_State * _lua) if (n==1 && lua_type(_lua, 1)==LUA_TSTRING) { std::string filename = lua_tostring(_lua, 1); - osg::ref_ptr node = osgDB::readNodeFile(filename); + osg::ref_ptr node = osgDB::readRefNodeFile(filename); if (node.valid()) { lse->pushObject(node.get()); diff --git a/src/osgPlugins/lws/SceneLoader.cpp b/src/osgPlugins/lws/SceneLoader.cpp index a1fea9fe8..a3ecdbda0 100644 --- a/src/osgPlugins/lws/SceneLoader.cpp +++ b/src/osgPlugins/lws/SceneLoader.cpp @@ -107,7 +107,7 @@ osg::Group *SceneLoader::load(const std::string &filename, const osgDB::ReaderWr std::getline(ifs, field); version_ = atoi(field.c_str()); - + std::string identifier; while (ifs >> identifier) { @@ -256,7 +256,7 @@ bool SceneLoader::parse_block(const std::string &name, const std::string &data) OSG_NOTICE << "Loading object \"" << filename << "\"" << std::endl; - objnode = dynamic_cast(osgDB::readNodeFile(filename)); + objnode = osgDB::readRefFile(filename); if (!objnode.valid()) return false; objects_[filename] = objnode; diff --git a/src/osgPlugins/normals/ReaderWriterNormals.cpp b/src/osgPlugins/normals/ReaderWriterNormals.cpp index 58f6e69d4..a3a88f194 100644 --- a/src/osgPlugins/normals/ReaderWriterNormals.cpp +++ b/src/osgPlugins/normals/ReaderWriterNormals.cpp @@ -77,7 +77,7 @@ class NormalsReader: public osgDB::ReaderWriter std::string nodeName = osgDB::getNameLessExtension( fileName ); if( !nodeName.empty() ) { - osg::ref_ptr node = osgDB::readNodeFile( nodeName ); + osg::ref_ptr node = osgDB::readRefNodeFile( nodeName ); if( node.valid() ) { osg::ref_ptr group = new osg::Group; diff --git a/src/osgPlugins/osg/ReaderWriterOSG2.cpp b/src/osgPlugins/osg/ReaderWriterOSG2.cpp index d5d26dbb3..52d0ffb67 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG2.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG2.cpp @@ -201,7 +201,7 @@ public: } is.decompress(); CATCH_EXCEPTION(is); - osg::Object* obj = is.readObject(); CATCH_EXCEPTION(is); + osg::ref_ptr obj = is.readObject(); CATCH_EXCEPTION(is); return obj; } @@ -231,7 +231,7 @@ public: } is.decompress(); CATCH_EXCEPTION(is); - osg::Image* image = is.readImage(); CATCH_EXCEPTION(is); + osg::ref_ptr image = is.readImage(); CATCH_EXCEPTION(is); return image; } @@ -262,7 +262,7 @@ public: } is.decompress(); CATCH_EXCEPTION(is); - osg::Node* node = dynamic_cast(is.readObject()); CATCH_EXCEPTION(is); + osg::ref_ptr node = is.readObjectOfType(); CATCH_EXCEPTION(is); if ( !node ) return ReadResult::FILE_NOT_HANDLED; return node; } diff --git a/src/osgPlugins/osgjs/ReaderWriterJSON.cpp b/src/osgPlugins/osgjs/ReaderWriterJSON.cpp index ad514c7a0..21960cf8c 100644 --- a/src/osgPlugins/osgjs/ReaderWriterJSON.cpp +++ b/src/osgPlugins/osgjs/ReaderWriterJSON.cpp @@ -231,7 +231,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterJSON::readNode(const std::string& fi fileName = osgDB::findDataFile( fileName, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - osg::Node *node = osgDB::readNodeFile( fileName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( fileName, options ); if (!node) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/osgjs/WriteVisitor.cpp b/src/osgPlugins/osgjs/WriteVisitor.cpp index 9f2b3c7fd..dad0c3d36 100644 --- a/src/osgPlugins/osgjs/WriteVisitor.cpp +++ b/src/osgPlugins/osgjs/WriteVisitor.cpp @@ -656,7 +656,7 @@ JSONObject* WriteVisitor::createJSONPagedLOD(osg::PagedLOD *plod) ss << i; std::string str = ss.str(); // We need to convert first from osg format to osgjs format. - osg::ref_ptr n = osgDB::readNodeFile(plod->getFileName(i)+".gles"); + osg::ref_ptr n = osgDB::readRefNodeFile(plod->getFileName(i)+".gles"); if (n) { std::string filename(osgDB::getStrippedName(plod->getFileName(i))+".osgjs"); diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index afbb20071..7d6cdbdcf 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -91,7 +91,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter std::string file_ext = osgDB::getLowerCaseFileExtension(*itr); if (osgDB::equalCaseInsensitive(file_ext,"osg")) { - osg::Node *node = osgDB::readNodeFile( *itr, local_options.get() ); + osg::ref_ptr node = osgDB::readRefNodeFile( *itr, local_options.get() ); grp->addChild( node ); } } diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index dd01e10b6..aa1c663fb 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -1370,7 +1370,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons std::string vs; if (getProperty(cur, "vs", vs) || getProperty(cur, "VolumeSettings", vs)) { - volumeData.volumeSettings = osgDB::readFile(vs); + volumeData.volumeSettings = osgDB::readRefFile(vs); if (volumeData.volumeSettings.valid()) { OSG_NOTICE<<"VolumeSetting read "<(transferFunctionFile); + volumeData.transferFunction = osgDB::readRefFile(transferFunctionFile); } if (getTrimmedProperty(cur, "tf-255", transferFunctionFile)) { - volumeData.transferFunction = osgDB::readFile(transferFunctionFile); + volumeData.transferFunction = osgDB::readRefFile(transferFunctionFile); } if (getProperty(cur, "options", volumeData.options)) {} @@ -2567,7 +2567,7 @@ void ReaderWriterP3DXML::parseRunScriptFile(osgPresentation::SlideShowConstructo std::string function = ""; getProperty(cur, "function", function); - osg::ref_ptr script = osgDB::readFile(cur->getTrimmedContents()); + osg::ref_ptr script = osgDB::readRefFile(cur->getTrimmedContents()); if (script.valid()) { osg::ScriptEngine* se = constructor.getOrCreateScriptEngine(script->getLanguage()); diff --git a/src/osgPlugins/revisions/ReaderWriterRevisions.cpp b/src/osgPlugins/revisions/ReaderWriterRevisions.cpp index 859f2db34..2dac02fbf 100644 --- a/src/osgPlugins/revisions/ReaderWriterRevisions.cpp +++ b/src/osgPlugins/revisions/ReaderWriterRevisions.cpp @@ -114,8 +114,7 @@ class ReaderWriterRevisions : public osgDB::ReaderWriter { std::string complete_path = osgDB::concatPaths(revisions_path, filename); OSG_INFO<<" complete_path="< object = osgDB::readObjectFile(complete_path, options); - fileList = dynamic_cast(object.get()); + fileList = osgDB::readRefFile(complete_path, options); } if (!fileList) diff --git a/src/osgPlugins/rot/ReaderWriterROT.cpp b/src/osgPlugins/rot/ReaderWriterROT.cpp index f61fb385d..cf4d20399 100644 --- a/src/osgPlugins/rot/ReaderWriterROT.cpp +++ b/src/osgPlugins/rot/ReaderWriterROT.cpp @@ -139,7 +139,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards @@ -147,7 +147,7 @@ public: return ReadResult::FILE_NOT_HANDLED; } - osg::MatrixTransform *xform = new osg::MatrixTransform; + osg::ref_ptr xform = new osg::MatrixTransform; xform->setDataVariance( osg::Object::STATIC ); xform->setMatrix( osg::Matrix::rotate( osg::DegreesToRadians( rx ), osg::Vec3( 1, 0, 0 ), diff --git a/src/osgPlugins/scale/ReaderWriterSCALE.cpp b/src/osgPlugins/scale/ReaderWriterSCALE.cpp index 247c82856..6b4da131d 100644 --- a/src/osgPlugins/scale/ReaderWriterSCALE.cpp +++ b/src/osgPlugins/scale/ReaderWriterSCALE.cpp @@ -152,7 +152,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards @@ -160,7 +160,7 @@ public: return ReadResult::FILE_NOT_HANDLED; } - osg::MatrixTransform *xform = new osg::MatrixTransform; + osg::ref_ptr xform = new osg::MatrixTransform; xform->setDataVariance( osg::Object::STATIC ); xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) ); xform->addChild( node ); diff --git a/src/osgPlugins/shadow/ReaderWriterOsgShadow.cpp b/src/osgPlugins/shadow/ReaderWriterOsgShadow.cpp index a72e51119..723c219ee 100644 --- a/src/osgPlugins/shadow/ReaderWriterOsgShadow.cpp +++ b/src/osgPlugins/shadow/ReaderWriterOsgShadow.cpp @@ -121,7 +121,7 @@ public: if (!technique) technique = new osgShadow::ShadowVolume; // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards @@ -130,7 +130,7 @@ public: } osgShadow::ShadowedScene* shadowedScene = new osgShadow::ShadowedScene; - shadowedScene->setShadowTechnique(technique.get()); + shadowedScene->setShadowTechnique(technique); shadowedScene->addChild( node ); return shadowedScene; } diff --git a/src/osgPlugins/terrain/ReaderWriterOsgTerrain.cpp b/src/osgPlugins/terrain/ReaderWriterOsgTerrain.cpp index 1ddd972df..ce83dc1d9 100644 --- a/src/osgPlugins/terrain/ReaderWriterOsgTerrain.cpp +++ b/src/osgPlugins/terrain/ReaderWriterOsgTerrain.cpp @@ -83,7 +83,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter if (fr.matchSequence("file %s") || fr.matchSequence("file %w") ) { - osg::Node* node = osgDB::readNodeFile(fr[1].getStr()); + osg::ref_ptr node = osgDB::readRefNodeFile(fr[1].getStr()); if (node) group->addChild(node); @@ -94,7 +94,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter osg::ref_ptr node = fr.readNode(); if (node.valid()) { - group->addChild(node.get()); + group->addChild(node); itrAdvanced = true; } @@ -105,7 +105,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter } } - if (group->getNumChildren()>0) return group.release(); + if (group->getNumChildren()>0) return group; else return 0; } diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index dcfaf207b..4972c6172 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -113,8 +113,8 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter *itr!=std::string(".") && *itr!=std::string("..")) { - osg::Node *node = osgDB::readNodeFile(*itr, local_options.get()); - grp->addChild( node ); + osg::ref_ptr node = osgDB::readRefNodeFile(*itr, local_options.get()); + if (node) grp->addChild( node ); } } @@ -136,7 +136,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter return ReadResult::FILE_NOT_HANDLED; } - return grp.get(); + return grp; } diff --git a/src/osgPlugins/trans/ReaderWriterTRANS.cpp b/src/osgPlugins/trans/ReaderWriterTRANS.cpp index c130044cb..0195c62b9 100644 --- a/src/osgPlugins/trans/ReaderWriterTRANS.cpp +++ b/src/osgPlugins/trans/ReaderWriterTRANS.cpp @@ -139,7 +139,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); + osg::ref_ptr node = osgDB::readRefNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards @@ -147,7 +147,7 @@ public: return ReadResult::FILE_NOT_HANDLED; } - osg::MatrixTransform *xform = new osg::MatrixTransform; + osg::ref_ptr xform = new osg::MatrixTransform; xform->setDataVariance( osg::Object::STATIC ); xform->setMatrix( osg::Matrix::translate( tx, ty, tz ) ); xform->addChild( node ); diff --git a/src/osgPlugins/trk/ReaderWriterTRK.cpp b/src/osgPlugins/trk/ReaderWriterTRK.cpp index e0d82ce4b..dcd0d2f14 100644 --- a/src/osgPlugins/trk/ReaderWriterTRK.cpp +++ b/src/osgPlugins/trk/ReaderWriterTRK.cpp @@ -169,7 +169,7 @@ struct AssignDirectionColour osg::ref_ptr stateset = geometry->getOrCreateStateSet(); osg::ref_ptr program = new osg::Program; - osg::ref_ptr vertexShader = osgDB::readShaderFile(osg::Shader::VERTEX, vertexShaderFile); + osg::ref_ptr vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, vertexShaderFile); if (!vertexShader) { vertexShader = new osg::Shader(osg::Shader::VERTEX, vert_shader_str); diff --git a/src/osgPlugins/txp/TXPArchive.cpp b/src/osgPlugins/txp/TXPArchive.cpp index 3fa00f25e..8af552efd 100644 --- a/src/osgPlugins/txp/TXPArchive.cpp +++ b/src/osgPlugins/txp/TXPArchive.cpp @@ -434,7 +434,7 @@ bool TXPArchive::loadModel(int ix) mod->GetName(name,1023); // Load the model. It's probably not TerraPage - osg::Node *osg_model = osgDB::readNodeFile( name ); + osg::ref_ptr osg_model = osgDB::readRefNodeFile( name ); if ( !osg_model ) { OSG_WARN << "TrPageArchive::LoadModels() error: " @@ -642,9 +642,8 @@ bool TXPArchive::loadTextStyles() continue; std::string fontfilename = fontmap[*fontName]; - if ( !fontfilename.length() ) - fontfilename = "arial.ttf"; - osg::ref_ptr< osgText::Font > font = osgText::readFontFile(fontfilename); + if ( !fontfilename.length() ) fontfilename = "arial.ttf"; + osg::ref_ptr< osgText::Font > font = osgText::readRefFontFile(fontfilename); _fonts[itr->first] = font; diff --git a/src/osgPlugins/vrml/ConvertToVRML.cpp b/src/osgPlugins/vrml/ConvertToVRML.cpp index 7440b1d65..4ada5d0e6 100644 --- a/src/osgPlugins/vrml/ConvertToVRML.cpp +++ b/src/osgPlugins/vrml/ConvertToVRML.cpp @@ -845,7 +845,7 @@ void ToVRML::findTextureName(osg::Texture2D* tex, std::string& name, bool& alrea std::string::size_type pos = nameInput.find_last_of("."); std::string ext = nameInput.substr(pos, nameInput.length() - pos); - osg::ref_ptr < osg::Image > imgIn = osgDB::readImageFile(nameInput); + osg::ref_ptr < osg::Image > imgIn = osgDB::readRefImageFile(nameInput); if (!imgIn.valid()) { osg::notify(osg::ALWAYS) << "WARNING: couldn't read texture named: -" << nameOri << "- use default one instead -" << _defaultImage->getFileName() << "-" << std::endl; tex->setImage(_defaultImage.get()); diff --git a/src/osgPresentation/Cursor.cpp b/src/osgPresentation/Cursor.cpp index 733f9438c..e0f605c9a 100644 --- a/src/osgPresentation/Cursor.cpp +++ b/src/osgPresentation/Cursor.cpp @@ -77,7 +77,7 @@ void Cursor::initializeCursor() osg::ref_ptr geode = new osg::Geode; - osg::ref_ptr image = osgDB::readImageFile(osgDB::findDataFile(_filename)); + osg::ref_ptr image = osgDB::readRefImageFile(osgDB::findDataFile(_filename)); osg::ref_ptr texture = (image.valid()) ? new osg::Texture2D(image.get()) : 0; // full cursor diff --git a/src/osgPresentation/SlideShowConstructor.cpp b/src/osgPresentation/SlideShowConstructor.cpp index ca7461d74..d192f7052 100644 --- a/src/osgPresentation/SlideShowConstructor.cpp +++ b/src/osgPresentation/SlideShowConstructor.cpp @@ -321,7 +321,7 @@ void SlideShowConstructor::addScriptEngine(const std::string& scriptEngineName) OSG_NOTICE<<"Script engine "< scriptEngine = osgDB::readFile(std::string("ScriptEngine.")+scriptEngineName); + osg::ref_ptr scriptEngine = osgDB::readRefFile(std::string("ScriptEngine.")+scriptEngineName); if (scriptEngine.valid()) { _scriptEngines[scriptEngineName] = scriptEngine; @@ -340,7 +340,7 @@ void SlideShowConstructor::addScriptEngine(const std::string& scriptEngineName) void SlideShowConstructor::addScriptFile(const std::string& name, const std::string& filename) { OSG_NOTICE<<"addScriptFile() name="< loadedImage = osgDB::readImageFile(*itr, options.get()); + osg::ref_ptr loadedImage = osgDB::readRefImageFile(*itr, options.get()); if (loadedImage.valid()) { OSG_INFO<<"Loaded image "<<*itr<addImageFile(*itr); if (firstLoad) { - osg::ref_ptr loadedImage = osgDB::readImageFile(*itr, options.get()); + osg::ref_ptr loadedImage = osgDB::readRefImageFile(*itr, options.get()); if (loadedImage.valid()) { imageSequence->addImage(loadedImage.get()); @@ -1732,7 +1732,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD } else { - osg::ref_ptr model = osgDB::readNodeFile(filename, _options.get()); + osg::ref_ptr model = osgDB::readRefNodeFile(filename, _options.get()); if (!model) return; dotFileName = tmpDirectory+osgDB::getStrippedName(filename)+std::string(".dot"); @@ -1823,7 +1823,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam options->setOptionString(imageData.options); } - osg::Image* image = osgDB::readImageFile(filename, options.get()); + osg::ref_ptr image = osgDB::readRefImageFile(filename, options.get()); OSG_INFO<<"addInteractiveImage("< handler = new osgViewer::InteractiveImageHandler(image); + osg::ref_ptr handler = new osgViewer::InteractiveImageHandler(image.get()); pictureQuad->setEventCallback(handler.get()); pictureQuad->setCullCallback(handler.get()); @@ -1939,7 +1939,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam addToCurrentLayer(subgraph); - osgWidget::PdfImage* pdfImage = dynamic_cast(image); + osgWidget::PdfImage* pdfImage = dynamic_cast(image.get()); if (pdfImage && imageData.page>=0) { getOrCreateLayerAttributes(_currentLayer.get())->addEnterCallback(new SetPageCallback(pdfImage, imageData.page)); @@ -1959,7 +1959,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph); - return image; + return image.release(); } std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filename) @@ -2070,7 +2070,7 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD } else { - subgraph = osgDB::readNodeFile(filename, options.get()); + subgraph = osgDB::readRefNodeFile(filename, options.get()); if (subgraph) recordOptionsFilePath(options.get()); } @@ -2682,7 +2682,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position itr != filenames.end(); ++itr) { - osg::ref_ptr loadedImage = osgDB::readImageFile(*itr, options.get()); + osg::ref_ptr loadedImage = osgDB::readRefImageFile(*itr, options.get()); if (loadedImage.valid()) { images.push_back(loadedImage.get()); @@ -2702,26 +2702,26 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (fileType == osgDB::DIRECTORY) { - image = osgDB::readImageFile(foundFile+".dicom", options.get()); + image = osgDB::readRefImageFile(foundFile+".dicom", options.get()); } else if (fileType == osgDB::REGULAR_FILE) { std::string ext = osgDB::getFileExtension(foundFile); if (ext=="osg" || ext=="ive" || ext=="osgx" || ext=="osgb" || ext=="osgt") { - osg::ref_ptr obj = osgDB::readObjectFile(foundFile); + osg::ref_ptr obj = osgDB::readRefObjectFile(foundFile); image = dynamic_cast(obj.get()); volume = dynamic_cast(obj.get()); } else { - image = osgDB::readImageFile( foundFile, options.get() ); + image = osgDB::readRefImageFile( foundFile, options.get() ); } } else { // not found image, so fallback to plugins/callbacks to find the model. - image = osgDB::readImageFile( filename, options.get() ); + image = osgDB::readRefImageFile( filename, options.get() ); if (image) recordOptionsFilePath(options.get() ); } } @@ -3056,7 +3056,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (!volumeData.hull.empty()) { - osg::ref_ptr hull = osgDB::readNodeFile(volumeData.hull, _options.get()); + osg::ref_ptr hull = osgDB::readRefNodeFile(volumeData.hull, _options.get()); if (hull.valid()) { hull = decorateSubgraphForPositionAndAnimation(hull.get(), volumeData.hullPositionData); @@ -3100,7 +3100,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position #if 1 - osgUI::Widget* widget = vs.valid() ? osgDB::readFile("ui/VolumeSettings.lua") : 0; + osg::ref_ptr widget = vs.valid() ? osgDB::readRefFile("ui/VolumeSettings.lua") : 0; if (widget) { OSG_NOTICE<<"Adding widget"< animationMaterial = 0; if (!positionData.animation_material_filename.empty()) { @@ -3186,8 +3186,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const } } #else - osg::ref_ptr object = osgDB::readObjectFile(positionData.animation_material_filename, _options.get()); - animationMaterial = dynamic_cast(object.get()); + animationMaterial = osgDB::readRefFile(positionData.animation_material_filename, _options.get()); #endif } @@ -3214,7 +3213,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const { animationMaterial->setLoopMode(positionData.animation_material_loop_mode); - AnimationMaterialCallback* animationMaterialCallback = new AnimationMaterialCallback(animationMaterial); + AnimationMaterialCallback* animationMaterialCallback = new AnimationMaterialCallback(animationMaterial.get()); animationMaterialCallback->setTimeOffset(positionData.animation_material_time_offset); animationMaterialCallback->setTimeMultiplier(positionData.animation_material_time_multiplier); @@ -3243,7 +3242,7 @@ osg::AnimationPathCallback* SlideShowConstructor::getAnimationPathCallback(const osg::ref_ptr options = _options.valid() ? _options->cloneOptions() : new osgDB::Options; options->setObjectCacheHint(osgDB::Options::CACHE_NONE); - osg::ref_ptr object = osgDB::readObjectFile(positionData.path, options.get()); + osg::ref_ptr object = osgDB::readRefObjectFile(positionData.path, options.get()); osg::AnimationPath* animation = dynamic_cast(object.get()); if (animation) { diff --git a/src/osgSim/LineOfSight.cpp b/src/osgSim/LineOfSight.cpp index 48b6f735e..b8a58a1aa 100644 --- a/src/osgSim/LineOfSight.cpp +++ b/src/osgSim/LineOfSight.cpp @@ -50,7 +50,7 @@ osg::Node* DatabaseCacheReadCallback::readNodeFile(const std::string& filename) } // now load the file. - osg::ref_ptr node = osgDB::readNodeFile(filename); + osg::ref_ptr node = osgDB::readRefNodeFile(filename); // insert into the cache. if (node.valid()) diff --git a/src/osgSim/ScalarBar.cpp b/src/osgSim/ScalarBar.cpp index 8e52fb0d9..e225c1fef 100644 --- a/src/osgSim/ScalarBar.cpp +++ b/src/osgSim/ScalarBar.cpp @@ -205,7 +205,7 @@ void ScalarBar::createDrawables() float characterSize = _textProperties._characterSize; if(characterSize == 0) characterSize = _width * 0.03f; - osgText::Font* font = osgText::readFontFile(_textProperties._fontFile.c_str()); + osg::ref_ptr font = osgText::readRefFontFile(_textProperties._fontFile.c_str()); std::vector texts(_numLabels); // We'll need to collect pointers to these for later float labelIncr = (_numLabels>0) ? (_stc->getMax()-_stc->getMin())/(_numLabels-1) : 0.0f; diff --git a/src/osgTerrain/GeometryPool.cpp b/src/osgTerrain/GeometryPool.cpp index a06e3c87f..4baa4abf5 100644 --- a/src/osgTerrain/GeometryPool.cpp +++ b/src/osgTerrain/GeometryPool.cpp @@ -601,21 +601,18 @@ osg::ref_ptr GeometryPool::getOrCreateProgram(LayerTypes& layerTyp _programMap[layerTypes] = program; // add shader that provides the lighting functions - program->addShader(osgDB::readShaderFile("shaders/lighting.vert")); + program->addShader(osgDB::readRefShaderFile("shaders/lighting.vert")); // OSG_NOTICE<<") creating new Program "< shader = osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", terrain_displacement_mapping_vert); - - program->addShader(shader.get()); + program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", terrain_displacement_mapping_vert)); } { #include "shaders/terrain_displacement_mapping_geom.cpp" - osg::ref_ptr shader = osgDB::readShaderFileWithFallback(osg::Shader::GEOMETRY, "shaders/terrain_displacement_mapping.geom", terrain_displacement_mapping_geom); - program->addShader(shader.get()); + program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::GEOMETRY, "shaders/terrain_displacement_mapping.geom", terrain_displacement_mapping_geom)); program->setParameter( GL_GEOMETRY_VERTICES_OUT, 4 ); program->setParameter( GL_GEOMETRY_INPUT_TYPE, GL_LINES_ADJACENCY ); @@ -629,13 +626,7 @@ osg::ref_ptr GeometryPool::getOrCreateProgram(LayerTypes& layerTyp { #include "shaders/terrain_displacement_mapping_frag.cpp" - osg::ref_ptr shader = osgDB::readShaderFileWithFallback(osg::Shader::FRAGMENT, "shaders/terrain_displacement_mapping.frag", terrain_displacement_mapping_frag); - - if (shader.valid()) - { - program->addShader(shader.get()); - } - + program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::FRAGMENT, "shaders/terrain_displacement_mapping.frag", terrain_displacement_mapping_frag)); } return program; diff --git a/src/osgTerrain/TerrainTile.cpp b/src/osgTerrain/TerrainTile.cpp index 0f4afd8be..5d063e196 100644 --- a/src/osgTerrain/TerrainTile.cpp +++ b/src/osgTerrain/TerrainTile.cpp @@ -305,7 +305,7 @@ bool WhiteListTileLoadedCallback::readImageLayer(osgTerrain::ImageLayer* imageLa { if (layerAcceptable(imageLayer->getSetName())) { - osg::ref_ptr image = osgDB::readImageFile(imageLayer->getFileName(), options); + osg::ref_ptr image = osgDB::readRefImageFile(imageLayer->getFileName(), options); imageLayer->setImage(image.get()); } } diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 2426ffdd5..d2585c5bd 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -107,6 +107,7 @@ std::string osgText::findFontFile(const std::string& str) return std::string(); } +#ifdef OSG_PROVIDE_READFILE osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions) { if (filename.empty()) return 0; @@ -167,6 +168,7 @@ osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::Reader if (object && object->referenceCount()==0) object->unref(); return 0; } +#endif osg::ref_ptr osgText::readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions) { diff --git a/src/osgUI/Style.cpp b/src/osgUI/Style.cpp index 2b80ae4b7..1a36a4f5c 100644 --- a/src/osgUI/Style.cpp +++ b/src/osgUI/Style.cpp @@ -259,7 +259,7 @@ osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSet osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& filename, const osg::Vec4& color) { - osg::ref_ptr object = osgDB::readObjectFile(filename); + osg::ref_ptr object = osgDB::readRefObjectFile(filename); if (!object) { //OSG_NOTICE<<"Warning: Style::createIcon(.., "< obj = osgDB::readObjectFile(filename); + osg::ref_ptr obj = osgDB::readRefObjectFile(filename); osgViewer::View * view = dynamic_cast(obj.get()); if (view) { @@ -1114,7 +1114,7 @@ void CompositeViewer::eventTraversal() // create a frame event for the new frame. { osg::ref_ptr event = view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() ); - + if (!_previousEvent || _previousEvent->getNumPointerData()<2) { generatePointerData(*event); @@ -1124,7 +1124,7 @@ void CompositeViewer::eventTraversal() reprojectPointerData(*_previousEvent, *event); } } - + view->getEventQueue()->takeEvents(viewEventsMap[view], cutOffTime); } diff --git a/src/osgViewer/Keystone.cpp b/src/osgViewer/Keystone.cpp index 8a68a5c45..acdda8c6d 100644 --- a/src/osgViewer/Keystone.cpp +++ b/src/osgViewer/Keystone.cpp @@ -573,7 +573,7 @@ bool Keystone::loadKeystoneFiles(osg::DisplaySettings* ds) ++itr) { const std::string& filename = *itr; - osg::ref_ptr keystone = osgDB::readFile(filename); + osg::ref_ptr keystone = osgDB::readRefFile(filename); if (keystone.valid()) { keystone->setUserValue("filename",filename); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index bde60d5fc..4c984e663 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -165,7 +165,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments) std::string intensityMapFilename; while (arguments.read("--im",intensityMapFilename)) {} - osg::ref_ptr intensityMap = intensityMapFilename.empty() ? 0 : osgDB::readImageFile(intensityMapFilename); + osg::ref_ptr intensityMap = intensityMapFilename.empty() ? 0 : osgDB::readRefImageFile(intensityMapFilename); if (screenNum<0) screenNum = 0; @@ -297,7 +297,7 @@ bool Viewer::readConfiguration(const std::string& filename) { OSG_INFO<<"Viewer::readConfiguration("< object = osgDB::readObjectFile(filename); + osg::ref_ptr object = osgDB::readRefObjectFile(filename); if (!object) { //OSG_NOTICE<<"Error: Unable to load configuration file \""<className()<configure(*this); //osgDB::writeObjectFile(*config,"test.osgt"); @@ -986,7 +986,7 @@ void Viewer::eventTraversal() // create a frame event for the new frame. { osg::ref_ptr event = _eventQueue->frame( getFrameStamp()->getReferenceTime() ); - + if (!eventState || eventState->getNumPointerData()<2) { generatePointerData(*event); @@ -996,7 +996,7 @@ void Viewer::eventTraversal() reprojectPointerData(*eventState, *event); } } - + // OSG_NOTICE<<"mouseEventState Xmin = "<getXmin()<<" Ymin="<getYmin()<<" xMax="<getXmax()<<" Ymax="<getYmax()<takeEvents(events, cutOffTime); diff --git a/src/osgWidget/Browser.cpp b/src/osgWidget/Browser.cpp index aeafa7ca7..50433620b 100644 --- a/src/osgWidget/Browser.cpp +++ b/src/osgWidget/Browser.cpp @@ -105,7 +105,7 @@ bool Browser::assign(BrowserImage* browserImage, const GeometryHints& hints) bool Browser::open(const std::string& hostname, const GeometryHints& hints) { - osg::ref_ptr image = osgDB::readImageFile(hostname+".gecko"); + osg::ref_ptr image = osgDB::readRefImageFile(hostname+".gecko"); return assign(dynamic_cast(image.get()), hints); } diff --git a/src/osgWidget/PdfReader.cpp b/src/osgWidget/PdfReader.cpp index b1a7661ba..759d5159c 100644 --- a/src/osgWidget/PdfReader.cpp +++ b/src/osgWidget/PdfReader.cpp @@ -67,7 +67,7 @@ bool PdfReader::assign(PdfImage* pdfImage, const GeometryHints& hints) osg::StateAttribute::ON); osg::ref_ptr iih = new osgViewer::InteractiveImageHandler(_pdfImage.get()); - + pictureQuad->setEventCallback(iih.get()); pictureQuad->setCullCallback(iih.get()); @@ -78,7 +78,7 @@ bool PdfReader::assign(PdfImage* pdfImage, const GeometryHints& hints) bool PdfReader::open(const std::string& filename, const GeometryHints& hints) { - osg::ref_ptr image = osgDB::readImageFile(filename); + osg::ref_ptr image = osgDB::readRefImageFile(filename); return assign(dynamic_cast(image.get()), hints); } diff --git a/src/osgWidget/VncClient.cpp b/src/osgWidget/VncClient.cpp index 116da8a85..51552d677 100644 --- a/src/osgWidget/VncClient.cpp +++ b/src/osgWidget/VncClient.cpp @@ -62,7 +62,7 @@ bool VncClient::assign(VncImage* vncImage, const GeometryHints& hints) osg::StateAttribute::ON); osg::ref_ptr iih = new osgViewer::InteractiveImageHandler(_vncImage.get()); - + pictureQuad->setEventCallback(iih.get()); pictureQuad->setCullCallback(iih.get()); @@ -73,7 +73,7 @@ bool VncClient::assign(VncImage* vncImage, const GeometryHints& hints) bool VncClient::connect(const std::string& hostname, const GeometryHints& hints) { - osg::ref_ptr image = osgDB::readImageFile(hostname+".vnc"); + osg::ref_ptr image = osgDB::readRefImageFile(hostname+".vnc"); return assign(dynamic_cast(image.get()), hints); } diff --git a/src/osgWidget/Widget.cpp b/src/osgWidget/Widget.cpp index 279bd69a5..b49303fc8 100644 --- a/src/osgWidget/Widget.cpp +++ b/src/osgWidget/Widget.cpp @@ -339,7 +339,8 @@ bool Widget::setImage(const std::string& filePath, bool setTexCoords, bool useTe return false; } - return setImage(osgDB::readImageFile(filePath), setTexCoords, useTextRect); + osg::ref_ptr image = osgDB::readRefImageFile(filePath); + return setImage(image.get(), setTexCoords, useTextRect); } bool Widget::setTexture(osg::Texture* texture, bool setTexCoords, bool useTextRect) { diff --git a/src/osgWrappers/deprecated-dotosg/osg/ProxyNode.cpp b/src/osgWrappers/deprecated-dotosg/osg/ProxyNode.cpp index 5c3317d72..8db72b9c1 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/ProxyNode.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/ProxyNode.cpp @@ -147,7 +147,7 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr) { osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)fr.getOptions())->getDatabasePathList(); fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i))); - osg::Node *node = osgDB::readNodeFile(proxyNode.getFileName(i), fr.getOptions()); + osg::ref_ptr node = osgDB::readRefNodeFile(proxyNode.getFileName(i), fr.getOptions()); fpl.pop_front(); if(node) { diff --git a/src/osgWrappers/deprecated-dotosg/osg/Shader.cpp b/src/osgWrappers/deprecated-dotosg/osg/Shader.cpp index 43451a5ca..8ea9d5a49 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Shader.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Shader.cpp @@ -46,7 +46,7 @@ bool Shader_readLocalData(Object& obj, Input& fr) if (fr.matchSequence("file %w") || fr.matchSequence("file %s") ) { - osg::ref_ptr s = osgDB::readShaderFile(fr[1].getStr(), fr.getOptions()); + osg::ref_ptr s = osgDB::readRefShaderFile(fr[1].getStr(), fr.getOptions()); if(s.get()) shader.setShaderSource(s->getShaderSource()); else diff --git a/src/osgWrappers/deprecated-dotosg/osg/Texture1D.cpp b/src/osgWrappers/deprecated-dotosg/osg/Texture1D.cpp index 2561ffcce..018b95b08 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Texture1D.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Texture1D.cpp @@ -41,7 +41,7 @@ bool Texture1D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("file") && fr[1].isString()) { std::string filename = fr[1].getStr(); - Image* image = fr.readImage(filename.c_str()); + osg::ref_ptr image = fr.readImage(filename.c_str()); if (image) { // name will have already been set by the image plugin, @@ -57,7 +57,7 @@ bool Texture1D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) { - osg::Image* image = fr.readImage(); + osg::ref_ptr image = fr.readImage(); if (image) texture.setImage(image); } diff --git a/src/osgWrappers/deprecated-dotosg/osg/Texture2D.cpp b/src/osgWrappers/deprecated-dotosg/osg/Texture2D.cpp index ead96e47f..4b00cfdcc 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Texture2D.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Texture2D.cpp @@ -50,7 +50,7 @@ bool Texture2D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("file") && fr[1].isString()) { std::string filename = fr[1].getStr(); - Image* image = fr.readImage(filename.c_str()); + osg::ref_ptr image = fr.readImage(filename.c_str()); if (image) { // name will have already been set by the image plugin, @@ -66,7 +66,7 @@ bool Texture2D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) { - osg::Image* image = fr.readImage(); + osg::ref_ptr image = fr.readImage(); if (image) texture.setImage(image); } diff --git a/src/osgWrappers/deprecated-dotosg/osg/Texture2DArray.cpp b/src/osgWrappers/deprecated-dotosg/osg/Texture2DArray.cpp index 82d85f313..73e356b89 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Texture2DArray.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Texture2DArray.cpp @@ -33,12 +33,10 @@ bool Texture2DArray_readLocalData(Object& obj, Input& fr) Texture2DArray& texture = static_cast(obj); - while (fr[0].matchWord("file") || - fr[0].matchWord("ImageSequence") || - fr[0].matchWord("Image") && matched) + while (matched && (fr[0].matchWord("file") || fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))) { matched = false; - Image* image = NULL; + osg::ref_ptr image; if (fr[0].matchWord("file") && fr[1].isString()) { std::string filename = fr[1].getStr(); @@ -62,8 +60,8 @@ bool Texture2DArray_readLocalData(Object& obj, Input& fr) textureW = image->s(); textureH = image->t(); } - else if(textureW != image->s() || - textureH != image->t()) + else if(textureW != image->s() || + textureH != image->t()) { //scale to match size of first image. image->scaleImage(textureW,textureH,1); @@ -108,4 +106,4 @@ bool Texture2DArray_writeLocalData(const Object& obj, Output& fw) } } return true; -} \ No newline at end of file +} diff --git a/src/osgWrappers/deprecated-dotosg/osg/Texture3D.cpp b/src/osgWrappers/deprecated-dotosg/osg/Texture3D.cpp index d21d6092a..03d1d64b4 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/Texture3D.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/Texture3D.cpp @@ -41,7 +41,7 @@ bool Texture3D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("file") && fr[1].isString()) { std::string filename = fr[1].getStr(); - Image* image = fr.readImage(filename.c_str()); + osg::ref_ptr image = fr.readImage(filename.c_str()); if (image) { // name will have already been set by the image plugin, @@ -57,7 +57,7 @@ bool Texture3D_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) { - osg::Image* image = fr.readImage(); + osg::ref_ptr image = fr.readImage(); if (image) texture.setImage(image); } diff --git a/src/osgWrappers/deprecated-dotosg/osg/TextureCubeMap.cpp b/src/osgWrappers/deprecated-dotosg/osg/TextureCubeMap.cpp index 9dbc981eb..402f6341e 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/TextureCubeMap.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/TextureCubeMap.cpp @@ -38,8 +38,8 @@ REGISTER_DOTOSGWRAPPER(TextureCubeMap) } \ else if (fr[2].isString())\ { \ - Image* image = fr.readImage(fr[2].getStr());\ - if (image) texture.setImage(osg::TextureCubeMap::FACE,image);\ + osg::ref_ptr image = fr.readImage(fr[2].getStr());\ + if (image) texture.setImage(osg::TextureCubeMap::FACE,image.get());\ fr += 3;\ iteratorAdvanced = true; \ matched = true;\ diff --git a/src/osgWrappers/deprecated-dotosg/osg/TextureRectangle.cpp b/src/osgWrappers/deprecated-dotosg/osg/TextureRectangle.cpp index ba7710a3c..0c040f1eb 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/TextureRectangle.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/TextureRectangle.cpp @@ -41,7 +41,7 @@ bool TextureRectangle_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("file") && fr[1].isString()) { std::string filename = fr[1].getStr(); - Image* image = fr.readImage(filename.c_str()); + osg::ref_ptr image = fr.readImage(filename.c_str()); if (image) { // name will have already been set by the image plugin, @@ -57,7 +57,7 @@ bool TextureRectangle_readLocalData(Object& obj, Input& fr) if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) { - osg::Image* image = fr.readImage(); + osg::ref_ptr image = fr.readImage(); if (image) texture.setImage(image); } diff --git a/src/osgWrappers/deprecated-dotosg/osgFX/IO_AnisotropicLighting.cpp b/src/osgWrappers/deprecated-dotosg/osgFX/IO_AnisotropicLighting.cpp index e503ce5f5..e7f4e3b93 100644 --- a/src/osgWrappers/deprecated-dotosg/osgFX/IO_AnisotropicLighting.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgFX/IO_AnisotropicLighting.cpp @@ -31,9 +31,9 @@ bool AnisotropicLighting_readLocalData(osg::Object &obj, osgDB::Input &fr) } if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) { - osg::Image *lmap = fr.readImage(fr[1].getStr()); + osg::ref_ptr lmap = fr.readImage(fr[1].getStr()); if (lmap) { - myobj.setLightingMap(lmap); + myobj.setLightingMap(lmap.get()); } fr += 2; itAdvanced = true; diff --git a/src/osgWrappers/deprecated-dotosg/osgTerrain/HeightFieldLayer.cpp b/src/osgWrappers/deprecated-dotosg/osgTerrain/HeightFieldLayer.cpp index 478887f63..abd9f4a29 100644 --- a/src/osgWrappers/deprecated-dotosg/osgTerrain/HeightFieldLayer.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgTerrain/HeightFieldLayer.cpp @@ -38,7 +38,7 @@ bool HeightFieldLayer_readLocalData(osg::Object& obj, osgDB::Input &fr) osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename); if (!filename.empty()) { - osg::ref_ptr hf = osgDB::readHeightFieldFile(filename); + osg::ref_ptr hf = osgDB::readRefHeightFieldFile(filename); if (hf.valid()) { layer.setName(setname); diff --git a/src/osgWrappers/deprecated-dotosg/osgTerrain/TerrainTile.cpp b/src/osgWrappers/deprecated-dotosg/osgTerrain/TerrainTile.cpp index e1a29a7a7..4f2db1113 100644 --- a/src/osgWrappers/deprecated-dotosg/osgTerrain/TerrainTile.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgTerrain/TerrainTile.cpp @@ -143,7 +143,7 @@ bool TerrainTile_readLocalData(osg::Object& obj, osgDB::Input &fr) if (fr.matchSequence("ProxyFile %s") || fr.matchSequence("ProxyFile %w") ) { - osg::ref_ptr image = osgDB::readObjectFile(std::string(fr[1].getStr())+".gdal"); + osg::ref_ptr image = osgDB::readRefObjectFile(std::string(fr[1].getStr())+".gdal"); osgTerrain::ProxyLayer* proxyLayer = dynamic_cast(image.get()); if (proxyLayer) { diff --git a/src/osgWrappers/serializers/osg/Camera.cpp b/src/osgWrappers/serializers/osg/Camera.cpp index aa121b82d..1338b7388 100644 --- a/src/osgWrappers/serializers/osg/Camera.cpp +++ b/src/osgWrappers/serializers/osg/Camera.cpp @@ -54,12 +54,12 @@ static osg::Camera::Attachment readBufferAttachment( osgDB::InputStream& is ) else if ( type==1 ) { is >> is.PROPERTY("Image"); - attachment._image = dynamic_cast( is.readObject() ); + attachment._image = is.readObjectOfType(); } else if ( type==2 ) { is >> is.PROPERTY("Texture"); - attachment._texture = dynamic_cast( is.readObject() ); + attachment._texture = is.readObjectOfType(); is >> is.PROPERTY("Level") >> attachment._level; is >> is.PROPERTY("Face") >> attachment._face; is >> is.PROPERTY("MipMapGeneration") >> attachment._mipMapGeneration; diff --git a/src/osgWrappers/serializers/osg/CompositeShape.cpp b/src/osgWrappers/serializers/osg/CompositeShape.cpp index 9cb3e6bb7..758b70f12 100644 --- a/src/osgWrappers/serializers/osg/CompositeShape.cpp +++ b/src/osgWrappers/serializers/osg/CompositeShape.cpp @@ -13,7 +13,7 @@ static bool readChildren( osgDB::InputStream& is, osg::CompositeShape& shape ) unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) shape.addChild( child ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osg/Geode.cpp b/src/osgWrappers/serializers/osg/Geode.cpp index e9f3c3ee9..252de6b0f 100644 --- a/src/osgWrappers/serializers/osg/Geode.cpp +++ b/src/osgWrappers/serializers/osg/Geode.cpp @@ -15,7 +15,7 @@ static bool readDrawables( osgDB::InputStream& is, osg::Geode& node ) unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr drawable = is.readObjectOfType(); if ( drawable ) { node.addDrawable( drawable ); diff --git a/src/osgWrappers/serializers/osg/HeightField.cpp b/src/osgWrappers/serializers/osg/HeightField.cpp index ce64e301e..bc7409441 100644 --- a/src/osgWrappers/serializers/osg/HeightField.cpp +++ b/src/osgWrappers/serializers/osg/HeightField.cpp @@ -31,17 +31,18 @@ static bool checkHeights( const osg::HeightField& shape ) static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape ) { - osg::FloatArray* array = dynamic_cast( is.readArray() ); - if ( array ) + osg::ref_ptr array = is.readArray(); + osg::FloatArray* farray = dynamic_cast( array.get() ); + if ( farray ) { unsigned int numCols = shape.getNumColumns(), numRows = shape.getNumRows(); - if ( array->size()size()> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr img = is.readImage(); if ( img ) image.addImage( img ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osg/Object.cpp b/src/osgWrappers/serializers/osg/Object.cpp index d2a068807..1ffd0c929 100644 --- a/src/osgWrappers/serializers/osg/Object.cpp +++ b/src/osgWrappers/serializers/osg/Object.cpp @@ -14,7 +14,7 @@ static bool checkUserData( const osg::Object& obj ) static bool readUserData( osgDB::InputStream& is, osg::Object& obj ) { is >> is.BEGIN_BRACKET; - osg::Object* object = is.readObject(); + osg::ref_ptr object = is.readObject(); if(object) obj.setUserData(object); is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osg/PagedLOD.cpp b/src/osgWrappers/serializers/osg/PagedLOD.cpp index e74c9e658..9bd8b1b73 100644 --- a/src/osgWrappers/serializers/osg/PagedLOD.cpp +++ b/src/osgWrappers/serializers/osg/PagedLOD.cpp @@ -102,7 +102,7 @@ static bool readChildren( osgDB::InputStream& is, osg::PagedLOD& node ) is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) node.addChild( child ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osg/Program.cpp b/src/osgWrappers/serializers/osg/Program.cpp index d884bd98c..d00096d5c 100644 --- a/src/osgWrappers/serializers/osg/Program.cpp +++ b/src/osgWrappers/serializers/osg/Program.cpp @@ -58,7 +58,7 @@ static bool readShaders( osgDB::InputStream& is, osg::Program& attr ) unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr shader = is.readObjectOfType(); if ( shader ) attr.addShader( shader ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osg/ProxyNode.cpp b/src/osgWrappers/serializers/osg/ProxyNode.cpp index 1c6542e38..5ed6b868a 100644 --- a/src/osgWrappers/serializers/osg/ProxyNode.cpp +++ b/src/osgWrappers/serializers/osg/ProxyNode.cpp @@ -50,7 +50,7 @@ static bool readChildren( osgDB::InputStream& is, osg::ProxyNode& node ) is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) node.addChild( child ); } is >> is.END_BRACKET; @@ -117,7 +117,7 @@ struct ProxyNodeFinishedObjectReadCallback : public osgDB::FinishedObjectReadCal { osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)is.getOptions())->getDatabasePathList(); fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i))); - osg::Node* node = osgDB::readNodeFile(proxyNode.getFileName(i), is.getOptions()); + osg::ref_ptr node = osgDB::readRefNodeFile(proxyNode.getFileName(i), is.getOptions()); fpl.pop_front(); if(node) proxyNode.insertChild(i, node); diff --git a/src/osgWrappers/serializers/osg/StateSet.cpp b/src/osgWrappers/serializers/osg/StateSet.cpp index ff891b615..8a94d1875 100644 --- a/src/osgWrappers/serializers/osg/StateSet.cpp +++ b/src/osgWrappers/serializers/osg/StateSet.cpp @@ -46,7 +46,7 @@ static void readAttributes( osgDB::InputStream& is, osg::StateSet::AttributeList is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr sa = is.readObjectOfType(); is >> is.PROPERTY("Value"); int value = readValue( is ); if ( sa ) @@ -144,7 +144,7 @@ static bool readAttributeList( osgDB::InputStream& is, osg::StateSet& ss ) for ( osg::StateSet::AttributeList::iterator itr=attrs.begin(); itr!=attrs.end(); ++itr ) { - ss.setAttribute( itr->second.first.get(), itr->second.second ); + ss.setAttribute( itr->second.first, itr->second.second ); } return true; } @@ -211,7 +211,7 @@ static bool readTextureAttributeList( osgDB::InputStream& is, osg::StateSet& ss for ( osg::StateSet::AttributeList::iterator itr=attrs.begin(); itr!=attrs.end(); ++itr ) { - ss.setTextureAttribute( i, itr->second.first.get(), itr->second.second ); + ss.setTextureAttribute( i, itr->second.first, itr->second.second ); } attrs.clear(); } @@ -244,7 +244,7 @@ static bool readUniformList( osgDB::InputStream& is, osg::StateSet& ss ) unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr uniform = is.readObjectOfType(); is >> is.PROPERTY("Value"); int value = readValue( is ); if ( uniform ) diff --git a/src/osgWrappers/serializers/osg/Texture2DArray.cpp b/src/osgWrappers/serializers/osg/Texture2DArray.cpp index e351aff94..f704559df 100644 --- a/src/osgWrappers/serializers/osg/Texture2DArray.cpp +++ b/src/osgWrappers/serializers/osg/Texture2DArray.cpp @@ -13,7 +13,7 @@ static bool readImages( osgDB::InputStream& is, osg::Texture2DArray& tex ) unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i image = is.readImage(); if ( image ) tex.setImage( i, image ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osg/TriangleMesh.cpp b/src/osgWrappers/serializers/osg/TriangleMesh.cpp index 7a8f21fbb..4a5652973 100644 --- a/src/osgWrappers/serializers/osg/TriangleMesh.cpp +++ b/src/osgWrappers/serializers/osg/TriangleMesh.cpp @@ -8,7 +8,8 @@ return shape.get##PROP()!=NULL; \ } \ static bool read##PROP(osgDB::InputStream& is, osg::TriangleMesh& shape) { \ - shape.set##PROP( dynamic_cast(is.readArray()) ); \ + osg::ref_ptr array = is.readArray(); \ + shape.set##PROP( dynamic_cast(array.get()) ); \ return true; \ } \ static bool write##PROP(osgDB::OutputStream& os, const osg::TriangleMesh& shape) { \ diff --git a/src/osgWrappers/serializers/osg/Uniform.cpp b/src/osgWrappers/serializers/osg/Uniform.cpp index b42278b4b..37d531fd2 100644 --- a/src/osgWrappers/serializers/osg/Uniform.cpp +++ b/src/osgWrappers/serializers/osg/Uniform.cpp @@ -13,17 +13,17 @@ static bool readElements( osgDB::InputStream& is, osg::Uniform& uniform ) bool hasArray; is >> hasArray; if ( hasArray ) { - osg::Array* array = is.readArray(); + osg::ref_ptr array = is.readArray(); switch ( array->getType() ) { case osg::Array::FloatArrayType: - uniform.setArray( static_cast(array) ); break; + uniform.setArray( static_cast(array.get()) ); break; case osg::Array::DoubleArrayType: - uniform.setArray( static_cast(array) ); break; + uniform.setArray( static_cast(array.get()) ); break; case osg::Array::IntArrayType: - uniform.setArray( static_cast(array) ); break; + uniform.setArray( static_cast(array.get()) ); break; case osg::Array::UIntArrayType: - uniform.setArray( static_cast(array) ); break; + uniform.setArray( static_cast(array.get()) ); break; default: break; } } diff --git a/src/osgWrappers/serializers/osg/UserDataContainer.cpp b/src/osgWrappers/serializers/osg/UserDataContainer.cpp index 2f011c1ca..250500f79 100644 --- a/src/osgWrappers/serializers/osg/UserDataContainer.cpp +++ b/src/osgWrappers/serializers/osg/UserDataContainer.cpp @@ -12,7 +12,7 @@ static bool checkUDC_UserData( const osg::DefaultUserDataContainer& udc ) static bool readUDC_UserData( osgDB::InputStream& is, osg::DefaultUserDataContainer& udc ) { is >> is.BEGIN_BRACKET; - osg::Object* object = is.readObject(); + osg::ref_ptr object = is.readObject(); if(object) udc.setUserData(object); is >> is.END_BRACKET; return true; @@ -70,7 +70,7 @@ static bool readUDC_UserObjects( osgDB::InputStream& is, osg::DefaultUserDataCon unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for( unsigned int i=0; i read_object = is.readObject(); if (read_object) udc.addUserObject( read_object ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgAnimation/UpdateMatrixTransform.cpp b/src/osgWrappers/serializers/osgAnimation/UpdateMatrixTransform.cpp index 4c78bc52e..4e6f6c67f 100644 --- a/src/osgWrappers/serializers/osgAnimation/UpdateMatrixTransform.cpp +++ b/src/osgWrappers/serializers/osgAnimation/UpdateMatrixTransform.cpp @@ -17,9 +17,8 @@ static bool readStackedTransforms( osgDB::InputStream& is, osgAnimation::UpdateM unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); - if ( element ) transform.push_back( element ); + osg::ref_ptr element = is.readObjectOfType(); + if ( element ) transform.push_back( element.get() ); } is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osgFX/AnisotropicLighting.cpp b/src/osgWrappers/serializers/osgFX/AnisotropicLighting.cpp index 4fb8d2785..38f622c70 100644 --- a/src/osgWrappers/serializers/osgFX/AnisotropicLighting.cpp +++ b/src/osgWrappers/serializers/osgFX/AnisotropicLighting.cpp @@ -13,7 +13,8 @@ static bool checkLightingMap( const osgFX::AnisotropicLighting& effect ) static bool readLightingMap( osgDB::InputStream& is, osgFX::AnisotropicLighting& effect ) { std::string fileName; is.readWrappedString( fileName ); - effect.setLightingMap( osgDB::readImageFile(fileName) ); + osg::ref_ptr image = osgDB::readRefImageFile(fileName, is.getOptions()); + effect.setLightingMap( image.get() ); return true; } diff --git a/src/osgWrappers/serializers/osgManipulator/CompositeDragger.cpp b/src/osgWrappers/serializers/osgManipulator/CompositeDragger.cpp index dded9d1ac..b15883380 100644 --- a/src/osgWrappers/serializers/osgManipulator/CompositeDragger.cpp +++ b/src/osgWrappers/serializers/osgManipulator/CompositeDragger.cpp @@ -13,7 +13,7 @@ static bool readDraggers( osgDB::InputStream& is, osgManipulator::CompositeDragg unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) dragger.addDragger( child ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgManipulator/Dragger.cpp b/src/osgWrappers/serializers/osgManipulator/Dragger.cpp index ded8e1fa7..d25161239 100644 --- a/src/osgWrappers/serializers/osgManipulator/Dragger.cpp +++ b/src/osgWrappers/serializers/osgManipulator/Dragger.cpp @@ -18,8 +18,8 @@ static bool readTransformUpdating( osgDB::InputStream& is, osgManipulator::Dragg std::string name; is >> name >> is.BEGIN_BRACKET; if ( name=="DraggerTransformCallback" ) { - osg::MatrixTransform* transform = dynamic_cast( is.readObject() ); - if ( transform ) dragger.addTransformUpdating( transform ); + osg::ref_ptr transform = is.readObjectOfType(); + if ( transform ) dragger.addTransformUpdating( transform.get() ); } is >> is.END_BRACKET; } diff --git a/src/osgWrappers/serializers/osgManipulator/Scale1DDragger.cpp b/src/osgWrappers/serializers/osgManipulator/Scale1DDragger.cpp index e78aa5c92..d7365abcc 100644 --- a/src/osgWrappers/serializers/osgManipulator/Scale1DDragger.cpp +++ b/src/osgWrappers/serializers/osgManipulator/Scale1DDragger.cpp @@ -7,7 +7,7 @@ static bool check##PROP( const osgManipulator::Scale1DDragger& dragger ) \ { return dragger.get##PROP()!=NULL; } \ static bool read##PROP( osgDB::InputStream& is, osgManipulator::Scale1DDragger& dragger ) { \ - osg::Node* node = dynamic_cast( is.readObject() ); \ + osg::ref_ptr node = is.readObjectOfType(); \ if ( node ) dragger.set##PROP( *node ); return true; \ } \ static bool write##PROP( osgDB::OutputStream& os, const osgManipulator::Scale1DDragger& dragger ) { \ diff --git a/src/osgWrappers/serializers/osgManipulator/Scale2DDragger.cpp b/src/osgWrappers/serializers/osgManipulator/Scale2DDragger.cpp index 7a1e14c39..fa011c8b9 100644 --- a/src/osgWrappers/serializers/osgManipulator/Scale2DDragger.cpp +++ b/src/osgWrappers/serializers/osgManipulator/Scale2DDragger.cpp @@ -7,7 +7,7 @@ static bool check##PROP( const osgManipulator::Scale2DDragger& dragger ) \ { return dragger.get##PROP()!=NULL; } \ static bool read##PROP( osgDB::InputStream& is, osgManipulator::Scale2DDragger& dragger ) { \ - osg::Node* node = dynamic_cast( is.readObject() ); \ + osg::ref_ptr node = is.readObjectOfType(); \ if ( node ) dragger.set##PROP( *node ); return true; \ } \ static bool write##PROP( osgDB::OutputStream& os, const osgManipulator::Scale2DDragger& dragger ) { \ diff --git a/src/osgWrappers/serializers/osgParticle/CompositePlacer.cpp b/src/osgWrappers/serializers/osgParticle/CompositePlacer.cpp index c0bd0b7f4..2b48a8895 100644 --- a/src/osgWrappers/serializers/osgParticle/CompositePlacer.cpp +++ b/src/osgWrappers/serializers/osgParticle/CompositePlacer.cpp @@ -13,8 +13,8 @@ static bool readPlacers( osgDB::InputStream& is, osgParticle::CompositePlacer& c unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); - if ( p ) cp.addPlacer( p ); + osg::ref_ptr p = is.readObjectOfType(); + if ( p ) cp.addPlacer( p.get() ); } is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osgParticle/ModularProgram.cpp b/src/osgWrappers/serializers/osgParticle/ModularProgram.cpp index d5a8d1110..3c4812934 100644 --- a/src/osgWrappers/serializers/osgParticle/ModularProgram.cpp +++ b/src/osgWrappers/serializers/osgParticle/ModularProgram.cpp @@ -13,8 +13,8 @@ static bool readOperators( osgDB::InputStream& is, osgParticle::ModularProgram& unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); - if ( op ) prog.addOperator( op ); + osg::ref_ptr op = is.readObjectOfType(); + if ( op ) prog.addOperator( op.get() ); } is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osgParticle/Particle.cpp b/src/osgWrappers/serializers/osgParticle/Particle.cpp index 91733f9fb..c92716e41 100644 --- a/src/osgWrappers/serializers/osgParticle/Particle.cpp +++ b/src/osgWrappers/serializers/osgParticle/Particle.cpp @@ -35,21 +35,21 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p ) if ( hasInterpolator ) { is >> is.BEGIN_BRACKET; - p.setSizeInterpolator( static_cast(is.readObject()) ); + p.setAlphaInterpolator( is.readObjectOfType() ); is >> is.END_BRACKET; } is >> is.PROPERTY("AlphaInterpolator") >> hasInterpolator; if ( hasInterpolator ) { is >> is.BEGIN_BRACKET; - p.setAlphaInterpolator( static_cast(is.readObject()) ); + p.setAlphaInterpolator( is.readObjectOfType() ); is >> is.END_BRACKET; } is >> is.PROPERTY("ColorInterpolator") >> hasInterpolator; if ( hasInterpolator ) { is >> is.BEGIN_BRACKET; - p.setColorInterpolator( static_cast(is.readObject()) ); + p.setAlphaInterpolator( is.readObjectOfType() ); is >> is.END_BRACKET; } @@ -73,7 +73,7 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p ) if ( hasObject ) { is >> is.BEGIN_BRACKET; - p.setDrawable( dynamic_cast(is.readObject()) ); + p.setDrawable( is.readObjectOfType() ); is >> is.END_BRACKET; } diff --git a/src/osgWrappers/serializers/osgParticle/ParticleEffect.cpp b/src/osgWrappers/serializers/osgParticle/ParticleEffect.cpp index 804abae6f..e3a9d16b5 100644 --- a/src/osgWrappers/serializers/osgParticle/ParticleEffect.cpp +++ b/src/osgWrappers/serializers/osgParticle/ParticleEffect.cpp @@ -13,7 +13,8 @@ static bool readParticleSystem( osgDB::InputStream& is, osgParticle::ParticleEff { is >> is.BEGIN_BRACKET; effect.setUseLocalParticleSystem( false ); - effect.setParticleSystem( static_cast(is.readObject()) ); + osg::ref_ptr ps = is.readObjectOfType(); + effect.setParticleSystem( ps.get() ); is >> is.END_BRACKET; return true; } diff --git a/src/osgWrappers/serializers/osgParticle/ParticleSystemUpdater.cpp b/src/osgWrappers/serializers/osgParticle/ParticleSystemUpdater.cpp index 9a263e038..04fd53dc8 100644 --- a/src/osgWrappers/serializers/osgParticle/ParticleSystemUpdater.cpp +++ b/src/osgWrappers/serializers/osgParticle/ParticleSystemUpdater.cpp @@ -13,8 +13,8 @@ static bool readParticleSystems( osgDB::InputStream& is, osgParticle::ParticleSy unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); - if ( ps ) updater.addParticleSystem( ps ); + osg::ref_ptr ps = is.readObjectOfType(); + if ( ps ) updater.addParticleSystem( ps.get() ); } is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osgSim/LightPointNode.cpp b/src/osgWrappers/serializers/osgSim/LightPointNode.cpp index 75f62e7d0..4c725aae6 100644 --- a/src/osgWrappers/serializers/osgSim/LightPointNode.cpp +++ b/src/osgWrappers/serializers/osgSim/LightPointNode.cpp @@ -26,14 +26,14 @@ static bool readLightPointList( osgDB::InputStream& is, osgSim::LightPointNode& if ( hasObject ) { is >> is.BEGIN_BRACKET; - pt._sector = dynamic_cast( is.readObject() ); + pt._sector = is.readObjectOfType(); is >> is.END_BRACKET; } hasObject = false; is >> is.PROPERTY("BlinkSequence") >> hasObject; if ( hasObject ) { is >> is.BEGIN_BRACKET; - pt._blinkSequence = dynamic_cast( is.readObject() ); + pt._blinkSequence = is.readObjectOfType(); is >> is.END_BRACKET; } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgTerrain/CompositeLayer.cpp b/src/osgWrappers/serializers/osgTerrain/CompositeLayer.cpp index efa6e2cfc..591c33257 100644 --- a/src/osgWrappers/serializers/osgTerrain/CompositeLayer.cpp +++ b/src/osgWrappers/serializers/osgTerrain/CompositeLayer.cpp @@ -17,7 +17,7 @@ static bool readLayers( osgDB::InputStream& is, osgTerrain::CompositeLayer& laye is >> type; if ( type=="Object" ) { - osgTerrain::Layer* child = dynamic_cast( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) layer.addLayer( child ); } else if ( type=="File" ) diff --git a/src/osgWrappers/serializers/osgTerrain/TerrainTile.cpp b/src/osgWrappers/serializers/osgTerrain/TerrainTile.cpp index 2cdcacacb..58bc00063 100644 --- a/src/osgWrappers/serializers/osgTerrain/TerrainTile.cpp +++ b/src/osgWrappers/serializers/osgTerrain/TerrainTile.cpp @@ -36,7 +36,7 @@ static bool readColorLayers( osgDB::InputStream& is, osgTerrain::TerrainTile& ti for ( unsigned int i=0; i> is.PROPERTY("Layer") >> layerNum; - osgTerrain::Layer* layer = dynamic_cast( is.readObject() ); + osg::ref_ptr layer = is.readObjectOfType(); if ( layer ) tile.setColorLayer( layerNum, layer ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgText/TextBase.cpp b/src/osgWrappers/serializers/osgText/TextBase.cpp index eb78ccac7..3885461e6 100644 --- a/src/osgWrappers/serializers/osgText/TextBase.cpp +++ b/src/osgWrappers/serializers/osgText/TextBase.cpp @@ -12,7 +12,8 @@ static bool checkFont( const osgText::TextBase& text ) static bool readFont( osgDB::InputStream& is, osgText::TextBase& text ) { std::string fontName; is.readWrappedString( fontName ); - text.setFont( osgText::readFontFile(fontName) ); + osg::ref_ptr font = osgText::readRefFontFile(fontName); + text.setFont( font ); return true; } @@ -77,11 +78,12 @@ static bool readText( osgDB::InputStream& is, osgText::TextBase& text ) } else { - osg::UIntArray* array = dynamic_cast( is.readArray() ); - if ( array ) + osg::ref_ptr array = is.readArray(); + osg::UIntArray* uiarray = dynamic_cast( array.get() ); + if ( uiarray ) { osgText::String string; - for ( osg::UIntArray::iterator itr=array->begin(); itr!=array->end(); ++itr ) + for ( osg::UIntArray::iterator itr=uiarray->begin(); itr!=uiarray->end(); ++itr ) { string.push_back( *itr ); } diff --git a/src/osgWrappers/serializers/osgVolume/CompositeLayer.cpp b/src/osgWrappers/serializers/osgVolume/CompositeLayer.cpp index f97712b23..d6d20b805 100644 --- a/src/osgWrappers/serializers/osgVolume/CompositeLayer.cpp +++ b/src/osgWrappers/serializers/osgVolume/CompositeLayer.cpp @@ -13,7 +13,7 @@ static bool readLayers( osgDB::InputStream& is, osgVolume::CompositeLayer& layer unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) layer.addLayer( child ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgVolume/CompositeProperty.cpp b/src/osgWrappers/serializers/osgVolume/CompositeProperty.cpp index b61ec7ca4..7d5aab323 100644 --- a/src/osgWrappers/serializers/osgVolume/CompositeProperty.cpp +++ b/src/osgWrappers/serializers/osgVolume/CompositeProperty.cpp @@ -13,7 +13,7 @@ static bool readProperties( osgDB::InputStream& is, osgVolume::CompositeProperty unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr child = is.readObjectOfType(); if ( child ) prop.addProperty( child ); } is >> is.END_BRACKET; diff --git a/src/osgWrappers/serializers/osgVolume/Locator.cpp b/src/osgWrappers/serializers/osgVolume/Locator.cpp index 1ec24b0d5..d14183ca6 100644 --- a/src/osgWrappers/serializers/osgVolume/Locator.cpp +++ b/src/osgWrappers/serializers/osgVolume/Locator.cpp @@ -13,8 +13,7 @@ static bool readLocatorCallbacks( osgDB::InputStream& is, osgVolume::Locator& lo unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); + osg::ref_ptr cb = is.readObjectOfType(); if ( cb ) locator.addCallback( cb ); } is >> is.END_BRACKET;