Added LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL and LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL ImageSequence::Mode's to allow for ImageSequence usage without using background paging threads, instead loading all the images on demand in the update traversal.
This commit is contained in:
parent
e7e517f2d0
commit
a0980734ac
@ -73,7 +73,9 @@ class OSG_EXPORT ImageSequence : public ImageStream
|
||||
{
|
||||
PRE_LOAD_ALL_IMAGES,
|
||||
PAGE_AND_RETAIN_IMAGES,
|
||||
PAGE_AND_DISCARD_USED_IMAGES
|
||||
PAGE_AND_DISCARD_USED_IMAGES,
|
||||
LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL,
|
||||
LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL
|
||||
};
|
||||
|
||||
void setMode(Mode mode);
|
||||
@ -135,6 +137,8 @@ protected:
|
||||
|
||||
int imageIndex(double time);
|
||||
|
||||
// setImage without aquiring mutex.
|
||||
void _setImage(unsigned int pos, osg::Image* image);
|
||||
|
||||
double _referenceTime;
|
||||
double _timeMultiplier;
|
||||
|
@ -148,6 +148,11 @@ void ImageSequence::setImage(unsigned int pos, osg::Image* image)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
|
||||
_setImage(pos,image);
|
||||
}
|
||||
|
||||
void ImageSequence::_setImage(unsigned int pos, osg::Image* image)
|
||||
{
|
||||
if (pos>=_imageDataList.size()) _imageDataList.resize(pos+1);
|
||||
|
||||
_imageDataList[pos]._image = image;
|
||||
@ -196,8 +201,8 @@ void ImageSequence::setImageToChild(int pos)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_mode==PAGE_AND_DISCARD_USED_IMAGES && _previousAppliedImageIndex>=0)
|
||||
bool discardOldImages = _mode==PAGE_AND_DISCARD_USED_IMAGES || _mode==LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL;
|
||||
if (discardOldImages && _previousAppliedImageIndex>=0)
|
||||
{
|
||||
if (_previousAppliedImageIndex<pos)
|
||||
{
|
||||
@ -351,6 +356,8 @@ void ImageSequence::update(osg::NodeVisitor* nv)
|
||||
|
||||
if (!irh) return;
|
||||
|
||||
bool loadDirectly = (_mode==LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL) || (_mode==LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL);
|
||||
|
||||
if (useDirectTimeRequest)
|
||||
{
|
||||
int i = osg::maximum<int>(0, int(time/_timePerImage));
|
||||
@ -358,8 +365,26 @@ void ImageSequence::update(osg::NodeVisitor* nv)
|
||||
{
|
||||
i = osg::minimum<int>(i, _imageDataList.size()-1);
|
||||
|
||||
OSG_INFO<<"Requesting file, entry="<<i<<" : _fileNames[i]="<<_imageDataList[i]._filename<<std::endl;
|
||||
irh->requestImageFile(_imageDataList[i]._filename, this, i, time, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
||||
if (loadDirectly)
|
||||
{
|
||||
OSG_NOTICE<<"Reading file, entry="<<i<<" : _fileNames[i]="<<_imageDataList[i]._filename<<std::endl;
|
||||
osg::ref_ptr<osg::Image> image = irh->readImageFile(_imageDataList[i]._filename); // TODO, need _readOptions object.
|
||||
if (image.valid())
|
||||
{
|
||||
OSG_NOTICE<<" Assigning image "<<_imageDataList[i]._filename<<std::endl;
|
||||
_setImage(i, image);
|
||||
setImageToChild(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" Failed to read file "<<_imageDataList[i]._filename<<std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"Requesting file, entry="<<i<<" : _fileNames[i]="<<_imageDataList[i]._filename<<std::endl;
|
||||
irh->requestImageFile(_imageDataList[i]._filename, this, i, time, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -935,6 +935,8 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
if (str=="PRE_LOAD_ALL_IMAGES") value.imageSequencePagingMode = osg::ImageSequence::PRE_LOAD_ALL_IMAGES;
|
||||
else if (str=="PAGE_AND_RETAIN_IMAGES") value.imageSequencePagingMode = osg::ImageSequence::PAGE_AND_RETAIN_IMAGES;
|
||||
else if (str=="PAGE_AND_DISCARD_USED_IMAGES") value.imageSequencePagingMode = osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES;
|
||||
else if (str=="LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL") value.imageSequencePagingMode = osg::ImageSequence::LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL;
|
||||
else if (str=="LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL") value.imageSequencePagingMode = osg::ImageSequence::LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL;
|
||||
|
||||
OSG_NOTIFY(_notifyLevel)<<"read imageSequencePagingMode \""<<value.imageSequencePagingMode<<"\""<<std::endl;
|
||||
}
|
||||
|
@ -42,6 +42,14 @@ bool ImageSequence_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
is.setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES);
|
||||
}
|
||||
else if (modeStr=="LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL")
|
||||
{
|
||||
is.setMode(osg::ImageSequence::LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL);
|
||||
}
|
||||
else if (modeStr=="LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL")
|
||||
{
|
||||
is.setMode(osg::ImageSequence::LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL);
|
||||
}
|
||||
}
|
||||
|
||||
double length;
|
||||
@ -103,6 +111,12 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
|
||||
case(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES):
|
||||
fw.indent()<<"Mode PAGE_AND_DISCARD_USED_IMAGES"<<std::endl;
|
||||
break;
|
||||
case(osg::ImageSequence::LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL):
|
||||
fw.indent()<<"Mode LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL"<<std::endl;
|
||||
break;
|
||||
case(osg::ImageSequence::LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL):
|
||||
fw.indent()<<"Mode LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL"<<std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
fw.indent()<<"Length "<<is.getLength()<<std::endl;
|
||||
|
@ -80,6 +80,8 @@ REGISTER_OBJECT_WRAPPER( ImageSequence,
|
||||
ADD_ENUM_VALUE( PRE_LOAD_ALL_IMAGES );
|
||||
ADD_ENUM_VALUE( PAGE_AND_RETAIN_IMAGES );
|
||||
ADD_ENUM_VALUE( PAGE_AND_DISCARD_USED_IMAGES );
|
||||
ADD_ENUM_VALUE( LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL );
|
||||
ADD_ENUM_VALUE( LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL );
|
||||
END_ENUM_SERIALIZER(); // _mode
|
||||
|
||||
ADD_DOUBLE_SERIALIZER( Length, 1.0 ); // _length
|
||||
|
Loading…
Reference in New Issue
Block a user