Updated to reflect changes in NodeVistor::ImageRequestHandler.
This commit is contained in:
parent
8147bd4df8
commit
400e6eb09a
@ -78,7 +78,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
|
|||||||
|
|
||||||
virtual osg::Image* readImageFile(const std::string& fileName);
|
virtual osg::Image* readImageFile(const std::string& fileName);
|
||||||
|
|
||||||
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, double timeToMergeBy, const osg::FrameStamp* framestamp);
|
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* framestamp);
|
||||||
|
|
||||||
|
|
||||||
/** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */
|
/** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */
|
||||||
@ -102,12 +102,14 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
|
|||||||
{
|
{
|
||||||
ImageRequest():
|
ImageRequest():
|
||||||
osg::Referenced(true),
|
osg::Referenced(true),
|
||||||
_timeToMergeBy(0.0) {}
|
_timeToMergeBy(0.0),
|
||||||
|
_attachmentIndex(-1) {}
|
||||||
|
|
||||||
double _timeToMergeBy;
|
double _timeToMergeBy;
|
||||||
std::string _fileName;
|
std::string _fileName;
|
||||||
osg::ref_ptr<ReaderWriter::Options> _loadOptions;
|
osg::ref_ptr<ReaderWriter::Options> _loadOptions;
|
||||||
osg::observer_ptr<osg::Object> _objectToAttachTo;
|
osg::observer_ptr<osg::Object> _attachmentPoint;
|
||||||
|
int _attachmentIndex;
|
||||||
osg::ref_ptr<osg::Image> _loadedImage;
|
osg::ref_ptr<osg::Image> _loadedImage;
|
||||||
RequestQueue* _requestQueue;
|
RequestQueue* _requestQueue;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void ImagePager::ReadQueue::clear()
|
|||||||
citr != _requestList.end();
|
citr != _requestList.end();
|
||||||
++citr)
|
++citr)
|
||||||
{
|
{
|
||||||
(*citr)->_objectToAttachTo = 0;
|
(*citr)->_attachmentPoint = 0;
|
||||||
(*citr)->_requestQueue = 0;
|
(*citr)->_requestQueue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ int ImagePager::ImageThread::cancel()
|
|||||||
|
|
||||||
void ImagePager::ImageThread::run()
|
void ImagePager::ImageThread::run()
|
||||||
{
|
{
|
||||||
osg::notify(osg::NOTICE)<<"ImagePager::ImageThread::run()"<<std::endl;
|
osg::notify(osg::INFO)<<"ImagePager::ImageThread::run() "<<this<<std::endl;
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
|
|
||||||
osg::ref_ptr<ImagePager::ReadQueue> read_queue;
|
osg::ref_ptr<ImagePager::ReadQueue> read_queue;
|
||||||
@ -192,11 +192,18 @@ void ImagePager::ImageThread::run()
|
|||||||
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageRequest->_fileName);
|
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageRequest->_fileName);
|
||||||
if (image.valid())
|
if (image.valid())
|
||||||
{
|
{
|
||||||
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(imageRequest->_objectToAttachTo.get());
|
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(imageRequest->_attachmentPoint.get());
|
||||||
if (is)
|
if (is)
|
||||||
|
{
|
||||||
|
if (imageRequest->_attachmentIndex >= 0)
|
||||||
|
{
|
||||||
|
is->setImage(imageRequest->_attachmentIndex, image.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
is->addImage(image.get());
|
is->addImage(image.get());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imageRequest->_loadedImage = image;
|
imageRequest->_loadedImage = image;
|
||||||
@ -225,7 +232,7 @@ void ImagePager::ImageThread::run()
|
|||||||
|
|
||||||
} while (!testCancel() && !_done);
|
} while (!testCancel() && !_done);
|
||||||
|
|
||||||
osg::notify(osg::NOTICE)<<"ImagePager::ImageThread::done()"<<std::endl;
|
osg::notify(osg::INFO)<<"ImagePager::ImageThread::done()"<<std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,11 +249,11 @@ ImagePager::ImagePager():
|
|||||||
_readQueue = new ReadQueue(this,"Image Queue");
|
_readQueue = new ReadQueue(this,"Image Queue");
|
||||||
_completedQueue = new RequestQueue;
|
_completedQueue = new RequestQueue;
|
||||||
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 1"));
|
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 1"));
|
||||||
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 2"));
|
//_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 2"));
|
||||||
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 3"));
|
//_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 3"));
|
||||||
|
|
||||||
// 100ms
|
// 1 second
|
||||||
_preLoadTime = 0.1;
|
_preLoadTime = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagePager::~ImagePager()
|
ImagePager::~ImagePager()
|
||||||
@ -287,15 +294,15 @@ osg::Image* ImagePager::readImageFile(const std::string& fileName)
|
|||||||
return osgDB::readImageFile(fileName);
|
return osgDB::readImageFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImagePager::requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, double timeToMergeBy, const osg::FrameStamp* framestamp)
|
void ImagePager::requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* framestamp)
|
||||||
{
|
{
|
||||||
// osg::notify(osg::NOTICE)<<"ImagePager::requestNodeFile("<<fileName<<")"<<std::endl;
|
osg::notify(osg::INFO)<<"ImagePager::requestNodeFile("<<fileName<<")"<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
osg::ref_ptr<ImageRequest> request = new ImageRequest;
|
osg::ref_ptr<ImageRequest> request = new ImageRequest;
|
||||||
request->_timeToMergeBy = timeToMergeBy;
|
request->_timeToMergeBy = timeToMergeBy;
|
||||||
request->_fileName = fileName;
|
request->_fileName = fileName;
|
||||||
request->_objectToAttachTo = attachmentPoint;
|
request->_attachmentPoint = attachmentPoint;
|
||||||
|
request->_attachmentIndex = attachmentIndex;
|
||||||
request->_requestQueue = _readQueue.get();
|
request->_requestQueue = _readQueue.get();
|
||||||
|
|
||||||
_readQueue->add(request.get());
|
_readQueue->add(request.get());
|
||||||
@ -335,10 +342,11 @@ void ImagePager::updateSceneGraph(const osg::FrameStamp &frameStamp)
|
|||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
ImageRequest* imageRequest = itr->get();
|
ImageRequest* imageRequest = itr->get();
|
||||||
osg::Texture* texture = dynamic_cast<osg::Texture*>(imageRequest->_objectToAttachTo.get());
|
osg::Texture* texture = dynamic_cast<osg::Texture*>(imageRequest->_attachmentPoint.get());
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
texture->setImage(0, imageRequest->_loadedImage.get());
|
int attachmentIndex = imageRequest->_attachmentIndex > 0 ? imageRequest->_attachmentIndex : 0;
|
||||||
|
texture->setImage(attachmentIndex, imageRequest->_loadedImage.get());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user