| | 133 | class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation |
| | 134 | { |
| | 135 | public: |
| | 136 | |
| | 137 | IncrementalCompileOperation(); |
| | 138 | |
| | 139 | typedef std::vector<osg::GraphicsContext*> Contexts; |
| | 140 | void assignContexts(Contexts& contexts); |
| | 141 | void removeContexts(Contexts& contexts); |
| | 142 | |
| | 143 | void addGraphicsContext(osg::GraphicsContext* gc); |
| | 144 | void removeGraphicsContext(osg::GraphicsContext* gc); |
| | 145 | |
| | 146 | |
| | 147 | /** Merge subgraphs that have been compiled.*/ |
| | 148 | void mergeCompiledSubgraphs(); |
| | 149 | |
| | 150 | virtual void operator () (osg::GraphicsContext* context); |
| | 151 | |
| | 152 | |
| | 153 | |
| | 154 | struct CompileData : public osg::Referenced |
| | 155 | { |
| | 156 | typedef std::list< osg::ref_ptr<osg::Texture> > Textures; |
| | 157 | typedef std::list< osg::ref_ptr<osg::Drawable> > Drawables; |
| | 158 | typedef std::list< osg::ref_ptr<osg::Program> > Programs; |
| | 159 | |
| | 160 | bool empty() const { return _textures.empty() && _drawables.empty() && _programs.empty(); } |
| | 161 | |
| | 162 | Textures _textures; |
| | 163 | Drawables _drawables; |
| | 164 | Programs _programs; |
| | 165 | }; |
| | 166 | |
| | 167 | class CompileSet; |
| | 168 | typedef std::set<osg::GraphicsContext*> ContextSet; |
| | 169 | typedef std::map<osg::GraphicsContext*, osg::ref_ptr<CompileData> > CompileMap; |
| | 170 | |
| | 171 | struct CompileCompletedCallback : public osg::Referenced |
| | 172 | { |
| | 173 | virtual bool compileCompleted(CompileSet* compileSet) = 0; |
| | 174 | }; |
| | 175 | |
| | 176 | class CompileSet : public osg::Referenced |
| | 177 | { |
| | 178 | public: |
| | 179 | |
| | 180 | |
| | 181 | CompileSet() {} |
| | 182 | |
| | 183 | CompileSet(osg::Node*subgraphToCompile): |
| | 184 | _subgraphToCompile(subgraphToCompile) {} |
| | 185 | |
| | 186 | CompileSet(osg::Group* attachmentPoint, osg::Node*subgraphToCompile): |
| | 187 | _attachmentPoint(attachmentPoint), |
| | 188 | _subgraphToCompile(subgraphToCompile) {} |
| | 189 | |
| | 190 | void buildCompileMap(ContextSet& context); |
| | 191 | |
| | 192 | osg::ref_ptr<osg::Group> _attachmentPoint; |
| | 193 | osg::ref_ptr<osg::Node> _subgraphToCompile; |
| | 194 | osg::ref_ptr<CompileCompletedCallback> _compileCompletedCallback; |
| | 195 | CompileMap _compileMap; |
| | 196 | |
| | 197 | // protected: |
| | 198 | |
| | 199 | virtual ~CompileSet() {} |
| | 200 | }; |
| | 201 | |
| | 202 | typedef std::list< osg::ref_ptr<CompileSet> > CompileSets; |
| | 203 | |
| | 204 | |
| | 205 | /** Add a subgraph to be compiled.*/ |
| | 206 | void add(osg::Node* subgraphToCompile); |
| | 207 | |
| | 208 | /** Add a subgraph to be compiled and add automatically to attachPoint on call to mergeCompiledSubgraphs.*/ |
| | 209 | void add(osg::Group* attachmentPoint, osg::Node* subgraphToCompile); |
| | 210 | |
| | 211 | /** Add a CompileSet to be compiled.*/ |
| | 212 | void add(CompileSet* compileSet, bool callBuildCompileMap=true); |
| | 213 | |
| | 214 | |
| | 215 | OpenThreads::Mutex& getToCompiledMutex() { return _toCompileMutex; } |
| | 216 | CompileSets& getToCompile() { return _compiled; } |
| | 217 | |
| | 218 | OpenThreads::Mutex& getCompiledMutex() { return _compiledMutex; } |
| | 219 | CompileSets& getCompiled() { return _compiled; } |
| | 220 | |
| | 221 | protected: |
| | 222 | |
| | 223 | virtual ~IncrementalCompileOperation(); |
| | 224 | |
| | 225 | |
| | 226 | OpenThreads::Mutex _toCompileMutex; |
| | 227 | CompileSets _toCompile; |
| | 228 | |
| | 229 | OpenThreads::Mutex _compiledMutex; |
| | 230 | CompileSets _compiled; |
| | 231 | |
| | 232 | ContextSet _contexts; |
| | 233 | |
| | 234 | }; |
| | 235 | |
| | 236 | |