Centralize osgDB::Option handling in SGReaderWriterOptions.

This commit is contained in:
Mathias Froehlich 2012-03-04 08:33:21 +01:00
parent 5ad6eb937b
commit 49d8b96768
9 changed files with 19 additions and 99 deletions

View File

@ -1793,14 +1793,6 @@
RelativePath="..\..\simgear\scene\util\NodeAndDrawableVisitor.hxx"
>
</File>
<File
RelativePath="..\..\simgear\scene\util\PathOptions.cxx"
>
</File>
<File
RelativePath="..\..\simgear\scene\util\PathOptions.hxx"
>
</File>
<File
RelativePath="..\..\simgear\scene\util\PrimitiveUtils.cxx"
>

View File

@ -43,12 +43,9 @@
#include <osg/TextureCubeMap>
#include <osg/TexMat>
#include <osg/Fog>
#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
#include <osgDB/Options>
#endif
#include <simgear/math/sg_random.h>
#include <simgear/scene/util/PathOptions.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/scene/util/RenderConstants.hxx>
@ -94,8 +91,8 @@ SGMakeState(const SGPath &path, const char* colorTexture,
{
osg::StateSet *stateSet = new osg::StateSet;
osg::ref_ptr<osgDB::Options> options
= makeOptionsFromPath(path);
osg::ref_ptr<SGReaderWriterOptions> options;
options = SGReaderWriterOptions::fromPath(path.str());
stateSet->setTextureAttribute(0, SGLoadTexture2D(colorTexture,
options.get()));
stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);

View File

@ -43,14 +43,11 @@
#include <osg/ShadeModel>
#include <osg/TexEnv>
#include <osg/Texture2D>
#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
#include <osgDB/Options>
#endif
#include <simgear/constants.h>
#include <simgear/screen/colors.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/scene/util/PathOptions.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include "sphere.hxx"
#include "moon.hxx"
@ -78,8 +75,8 @@ SGMoon::build( SGPath path, double moon_size ) {
stateSet->setRenderBinDetails(-5, "RenderBin");
// set up the orb state
osg::ref_ptr<osgDB::Options> options
= makeOptionsFromPath(path);
osg::ref_ptr<SGReaderWriterOptions> options;
options = SGReaderWriterOptions::fromPath(path.str());
osg::Texture2D* texture = SGLoadTexture2D("moon.png", options.get());
stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

View File

@ -42,7 +42,6 @@
#include <simgear/math/sg_random.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/util/PathOptions.hxx>
#include <simgear/props/props.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
@ -110,11 +109,9 @@ SGNewCloud::SGNewCloud(const SGPath &texture_root, const SGPropertyNode *cld_def
"texture"),
"image"),
texture);
ref_ptr<osgDB::Options> options
= makeOptionsFromPath(texture_root);
ref_ptr<SGReaderWriterOptions> sgOptions
= new SGReaderWriterOptions(*options.get());
if ((effect = makeEffect(pcloudEffect, true, sgOptions.get())))
ref_ptr<SGReaderWriterOptions> options;
options = SGReaderWriterOptions::fromPath(texture_root.str());
if ((effect = makeEffect(pcloudEffect, true, options.get())))
effectMap.insert(EffectMap::value_type(texture, effect));
} else {
effect = iter->second.get();

View File

@ -42,7 +42,7 @@
#include <osgDB/ReadFile>
#include <simgear/math/SGMath.hxx>
#include <simgear/scene/util/PathOptions.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/screen/colors.hxx>
#include <simgear/scene/model/model.hxx>
#include "oursun.hxx"
@ -69,8 +69,8 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node )
env_node = property_tree_Node;
osg::ref_ptr<osgDB::Options> options
= makeOptionsFromPath(path);
osg::ref_ptr<SGReaderWriterOptions> options;
options = SGReaderWriterOptions::fromPath(path.str());
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
sun_transform = new osg::MatrixTransform;

View File

@ -22,7 +22,6 @@ set(HEADERS
StateAttributeFactory.hxx
UpdateOnceCallback.hxx
VectorArrayAdapter.hxx
PathOptions.hxx
project.hxx
)
@ -39,7 +38,6 @@ set(SOURCES
SplicingVisitor.cxx
StateAttributeFactory.cxx
UpdateOnceCallback.cxx
PathOptions.cxx
project.cxx
)

View File

@ -1,37 +0,0 @@
// PathOptions.cxx -- make an osgDB Options object from a path
// Copyright (C) 2007 Tim Moore timoore@redhat.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// 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 GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <simgear_config.h>
#endif
#include <osgDB/Registry>
#include "PathOptions.hxx"
using namespace simgear;
osgDB::Options* simgear::makeOptionsFromPath(const SGPath& path)
{
using namespace osgDB;
Options *options
= new Options(*(Registry::instance()->getOptions()));
options->setDatabasePath(path.str());
return options;
}

View File

@ -1,31 +0,0 @@
// PathOptions.hxx -- make an osgDB Options object from a path
// Copyright (C) 2007 Tim Moore timoore@redhat.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// 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 GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef PATHOPTIONSHXX
#define PATHOPTIONSHXX 1
#include <osgDB/ReaderWriter>
#include <simgear/misc/sg_path.hxx>
namespace simgear
{
osgDB::Options* makeOptionsFromPath(const SGPath&);
}
#endif

View File

@ -104,6 +104,13 @@ public:
return new SGReaderWriterOptions(*static_cast<const SGReaderWriterOptions*>(options));
}
static SGReaderWriterOptions* fromPath(const std::string& path)
{
SGReaderWriterOptions* options = copyOrCreate(0);
options->setDatabasePath(path);
return options;
}
protected:
virtual ~SGReaderWriterOptions() {}