Changeset 13041 for OpenSceneGraph/trunk/include/osgDB/ImagePager
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osgDB/ImagePager (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgDB/ImagePager
r12139 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 32 32 { 33 33 public: 34 34 35 35 ImagePager(); 36 36 37 37 class OSGDB_EXPORT ImageThread : public osg::Referenced, public OpenThreads::Thread 38 38 { 39 39 public: 40 40 41 41 enum Mode 42 42 { … … 45 45 HANDLE_ONLY_HTTP 46 46 }; 47 47 48 48 ImageThread(ImagePager* pager, Mode mode, const std::string& name); 49 49 50 50 ImageThread(const ImageThread& dt, ImagePager* pager); 51 51 52 52 void setDone(bool done) { _done = done; } 53 53 bool getDone() const { return _done; } 54 54 55 55 virtual int cancel(); 56 56 57 57 virtual void run(); 58 58 59 59 protected: 60 60 61 61 virtual ~ImageThread(); 62 62 63 63 bool _done; 64 64 Mode _mode; … … 69 69 70 70 ImageThread* getImageThread(unsigned int i) { return _imageThreads[i].get(); } 71 71 72 72 const ImageThread* getImageThread(unsigned int i) const { return _imageThreads[i].get(); } 73 73 74 74 unsigned int getNumImageThreads() const { return _imageThreads.size(); } 75 75 76 76 77 77 void setPreLoadTime(double preLoadTime) { _preLoadTime=preLoadTime; } … … 85 85 /** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */ 86 86 virtual bool requiresUpdateSceneGraph() const; 87 87 88 88 /** Merge the changes to the scene graph. */ 89 89 virtual void updateSceneGraph(const osg::FrameStamp &frameStamp); 90 90 91 91 int cancel(); 92 92 93 93 protected: 94 94 95 95 virtual ~ImagePager(); 96 // forward declare 96 // forward declare 97 97 struct RequestQueue; 98 98 99 99 struct SortFileRequestFunctor; 100 100 friend struct SortFileRequestFunctor; 101 101 102 102 struct ImageRequest : public osg::Referenced 103 103 { … … 106 106 _timeToMergeBy(0.0), 107 107 _attachmentIndex(-1) {} 108 108 109 109 double _timeToMergeBy; 110 110 std::string _fileName; … … 114 114 osg::ref_ptr<osg::Image> _loadedImage; 115 115 RequestQueue* _requestQueue; 116 116 117 117 }; 118 118 119 119 struct RequestQueue : public osg::Referenced 120 120 { … … 122 122 123 123 void sort(); 124 124 125 125 RequestList _requestList; 126 126 OpenThreads::Mutex _requestMutex; 127 127 }; 128 128 129 129 130 130 struct ReadQueue : public RequestQueue 131 131 { 132 132 ReadQueue(ImagePager* pager, const std::string& name); 133 133 134 134 void block() { _block->block(); } 135 135 136 136 void release() { _block->release(); } 137 137 138 138 void updateBlock() 139 139 { 140 140 _block->set((!_requestList.empty() || !_pager->_databasePagerThreadPaused)); 141 141 } 142 142 143 143 void clear(); 144 144 145 145 void add(ImageRequest* imageRequest); 146 146 147 147 void takeFirst(osg::ref_ptr<ImageRequest>& databaseRequest); 148 148 149 149 osg::ref_ptr<osg::RefBlock> _block; 150 150 151 151 ImagePager* _pager; 152 152 std::string _name; 153 153 }; 154 154 155 155 OpenThreads::Mutex _run_mutex; 156 156 bool _startThreadCalled; … … 158 158 bool _done; 159 159 bool _databasePagerThreadPaused; 160 160 161 161 osg::ref_ptr<ReadQueue> _readQueue; 162 162 163 163 typedef std::vector< osg::ref_ptr<ImageThread> > ImageThreads; 164 164 ImageThreads _imageThreads; 165 165 166 166 osg::ref_ptr<RequestQueue> _completedQueue; 167 167 168 168 double _preLoadTime; 169 169 };
