Hi Robert,
Sorry for reviving this old thread.
But I stumbled across the exact same problem, and solving this issue
with the FindFileCallback is a real PITA.
I tried the patch Katharina provided (there is still a typo in here, but
nevertheless, it solves the issue.)
The problem with the FindFileCallback is that it simply gives you no
context. In my compiler I need to distinguish files that are referenced
inside the openflight from those which are searched from other sources
(e.g. looking up additional textures based on a name scheme).
With the the ReadFileCallback it is much easier to maintain such context.
So I second Katharinas idea.
Implementation-wise I'd provide an option to support calling the
readfile even if no valid path was found through the FindFileCallback
and leave the default option to the old behavior.
Would that be exectable?
cheers
Sebastian
HI Katharina,
In the svn/trunk version of the OSG I added support for overriding the
find file operation using an osgDB::FindFileCallback, that you attach
to the osgDB::Registry or an osgDB::Options object. Perhaps this
would be the best way for you to intercept and do something special
when texture files are not found.
Cheers,
Robert.
On Mon, Sep 21, 2009 at 1:49 PM, Katharina Plugge
<[email protected]> wrote:
Hello,
the OpenFlight-Plugin prevents reacting on missing Textures via a
ReadFileCallback, because osgDB::readRefImageFile (called by function
readTexture) is not called if the file does not exist. Would be great if this
could be changed.
A fix could look like this (file PaletteRecords.cpp, line 436):
Code:
virtual void readRecord(RecordInputStream& in, Document& document)
{
if (document.getTexturePoolParent())
// Using parent's texture pool -- ignore this record.
return;
int maxLength = (document.version() < VERSION_14) ? 80 : 200;
std::string filename = in.readString(maxLength);
int32 index = in.readInt32(-1);
/*int32 x =*/ in.readInt32();
/*int32 y =*/ in.readInt32();
osg::StateSet* stateset = NULL;
// Need full path for unique key in local texture cache.
std::string pathname =
osgDB::findDataFile(filename,document.getOptions());
if (pathname.empty())
{
// allow the aplication to react on missing texture via
ReadFileCallback
stateset = readTexture(filename,document);
if( !stateset)
{
osg::notify(osg::WARN) << "Can't find texture (" << index << ") " <<
filename << std::endl;
return;
}
}
else
{
// Is texture in local cache?
osg::StateSet* stateset =
flt::Registry::instance()->getTextureFromLocalCache(pathname);
}
// Read file if not in cache.
if (!stateset)
{
stateset = readTexture(pathname,document);
// Add to texture cache.
flt::Registry::instance()->addTextureToLocalCache(pathname,stateset);
}
// Add to texture pool.
TexturePool* tp = document.getOrCreateTexturePool();
(*tp)[index] = stateset;
}
Thank you!
Greetings,
Katharina[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=17525#17525
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org