Added support for setting the <image> paging_mode property to PRE_LOAD_ALL_IMAGES, PAGE_AND_RETAIN_IMAGES or PAGE_AND_DICARD_IMAGE for osg::ImageStream,

with PAGE_AND_DICARD_IMAGE set as the default.
This commit is contained in:
Robert Osfield 2012-06-11 19:54:07 +00:00
parent c39ee015d6
commit 2faeaf553b
3 changed files with 38 additions and 3 deletions

View File

@ -21,6 +21,7 @@
#include <osg/AnimationPath> #include <osg/AnimationPath>
#include <osg/TransferFunction> #include <osg/TransferFunction>
#include <osg/ImageStream> #include <osg/ImageStream>
#include <osg/ImageSequence>
#include <osgText/Text> #include <osgText/Text>
#include <osgGA/GUIEventAdapter> #include <osgGA/GUIEventAdapter>
@ -240,7 +241,9 @@ public:
page(-1), page(-1),
backgroundColor(1.0f,1.0f,1.0f,1.0f), backgroundColor(1.0f,1.0f,1.0f,1.0f),
fps(30.0), fps(30.0),
duration(-1.0) {} duration(-1.0),
imageSequencePagingMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES)
{}
std::string options; std::string options;
float width; float width;
@ -253,6 +256,7 @@ public:
osg::Vec4 backgroundColor; osg::Vec4 backgroundColor;
double fps; double fps;
double duration; double duration;
osg::ImageSequence::Mode imageSequencePagingMode;
}; };
struct VolumeData struct VolumeData

View File

@ -879,6 +879,16 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
OSG_NOTIFY(_notifyLevel)<<"read duration \""<<value.duration<<"\""<<std::endl; OSG_NOTIFY(_notifyLevel)<<"read duration \""<<value.duration<<"\""<<std::endl;
} }
if (getProperty(cur, "paging_mode", str))
{
propertiesRead = true;
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;
OSG_NOTIFY(_notifyLevel)<<"read imageSequencePagingMode \""<<value.imageSequencePagingMode<<"\""<<std::endl;
}
/* /*
if (getProperty(cur, "texcoord_offset", value.texcoord_offset)) if (getProperty(cur, "texcoord_offset", value.texcoord_offset))
{ {

View File

@ -429,6 +429,10 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
{ {
osg::Texture2D* texture = new osg::Texture2D(image.get()); osg::Texture2D* texture = new osg::Texture2D(image.get());
texture->setResizeNonPowerOfTwoHint(false); texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setClientStorageHint(true);
backgroundStateSet->setTextureAttributeAndModes(0, backgroundStateSet->setTextureAttributeAndModes(0,
texture, texture,
osg::StateAttribute::ON); osg::StateAttribute::ON);
@ -820,6 +824,9 @@ osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3&
texture = new osg::Texture2D(image); texture = new osg::Texture2D(image);
texture->setResizeNonPowerOfTwoHint(false); texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setClientStorageHint(true);
stateset->setTextureAttributeAndModes(0, stateset->setTextureAttributeAndModes(0,
texture, texture,
@ -854,7 +861,6 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
osg::ref_ptr<osg::Image> image; osg::ref_ptr<osg::Image> image;
osgDB::DirectoryContents filenames; osgDB::DirectoryContents filenames;
bool preLoad = true;
std::string foundFile = filename; std::string foundFile = filename;
@ -923,11 +929,15 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
imageSequence->setMode(imageData.imageSequencePagingMode);
bool firstLoad = true;
for(osgDB::DirectoryContents::iterator itr = filenames.begin(); for(osgDB::DirectoryContents::iterator itr = filenames.begin();
itr != filenames.end(); itr != filenames.end();
++itr) ++itr)
{ {
if (preLoad) if (imageSequence->getMode()==osg::ImageSequence::PRE_LOAD_ALL_IMAGES)
{ {
OSG_INFO<<"Attempting to read "<<*itr<<std::endl; OSG_INFO<<"Attempting to read "<<*itr<<std::endl;
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get()); osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
@ -941,6 +951,15 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
{ {
OSG_INFO<<"Adding filename for load image on demand "<<*itr<<std::endl; OSG_INFO<<"Adding filename for load image on demand "<<*itr<<std::endl;
imageSequence->addImageFile(*itr); imageSequence->addImageFile(*itr);
if (firstLoad)
{
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
if (loadedImage.valid())
{
imageSequence->addImage(loadedImage.get());
firstLoad = false;
}
}
} }
} }
@ -956,6 +975,8 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
imageSequence->setLength(double(maxNum)*(1.0/imageData.fps)); imageSequence->setLength(double(maxNum)*(1.0/imageData.fps));
} }
imageSequence->play();
image = imageSequence; image = imageSequence;
} }