| | 196 | |
| | 197 | ///////////////////////////////////////////////////////////////// |
| | 198 | // |
| | 199 | // IncrementalCompileOperation |
| | 200 | // |
| | 201 | IncrementalCompileOperation::IncrementalCompileOperation(): |
| | 202 | osg::GraphicsOperation("IncrementalCompileOperation",true) |
| | 203 | { |
| | 204 | } |
| | 205 | |
| | 206 | IncrementalCompileOperation::~IncrementalCompileOperation() |
| | 207 | { |
| | 208 | } |
| | 209 | |
| | 210 | void IncrementalCompileOperation::assignContexts(Contexts& contexts) |
| | 211 | { |
| | 212 | for(Contexts::iterator itr = contexts.begin(); |
| | 213 | itr != contexts.end(); |
| | 214 | ++itr) |
| | 215 | { |
| | 216 | osg::GraphicsContext* gc = *itr; |
| | 217 | addGraphicsContext(gc); |
| | 218 | } |
| | 219 | } |
| | 220 | |
| | 221 | void IncrementalCompileOperation::removeContexts(Contexts& contexts) |
| | 222 | { |
| | 223 | for(Contexts::iterator itr = contexts.begin(); |
| | 224 | itr != contexts.end(); |
| | 225 | ++itr) |
| | 226 | { |
| | 227 | osg::GraphicsContext* gc = *itr; |
| | 228 | removeGraphicsContext(gc); |
| | 229 | } |
| | 230 | } |
| | 231 | |
| | 232 | |
| | 233 | void IncrementalCompileOperation::addGraphicsContext(osg::GraphicsContext* gc) |
| | 234 | { |
| | 235 | if (_contexts.count(gc)==0) |
| | 236 | { |
| | 237 | gc->add(this); |
| | 238 | _contexts.insert(gc); |
| | 239 | } |
| | 240 | } |
| | 241 | |
| | 242 | void IncrementalCompileOperation::removeGraphicsContext(osg::GraphicsContext* gc) |
| | 243 | { |
| | 244 | if (_contexts.count(gc)!=0) |
| | 245 | { |
| | 246 | gc->remove(this); |
| | 247 | _contexts.erase(gc); |
| | 248 | } |
| | 249 | } |
| | 250 | |
| | 251 | void IncrementalCompileOperation::add(osg::Node* subgraphToCompile) |
| | 252 | { |
| | 253 | osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add("<<subgraphToCompile<<")"<<std::endl; |
| | 254 | add(new CompileSet(subgraphToCompile)); |
| | 255 | } |
| | 256 | |
| | 257 | void IncrementalCompileOperation::add(osg::Group* attachmentPoint, osg::Node* subgraphToCompile) |
| | 258 | { |
| | 259 | osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add("<<attachmentPoint<<", "<<subgraphToCompile<<")"<<std::endl; |
| | 260 | add(new CompileSet(attachmentPoint, subgraphToCompile)); |
| | 261 | } |
| | 262 | |
| | 263 | |
| | 264 | void IncrementalCompileOperation::add(CompileSet* compileSet, bool callBuildCompileMap) |
| | 265 | { |
| | 266 | if (!compileSet) return; |
| | 267 | |
| | 268 | if (callBuildCompileMap) compileSet->buildCompileMap(_contexts); |
| | 269 | |
| | 270 | osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add(CompileSet = "<<compileSet<<", "<<", "<<callBuildCompileMap<<")"<<std::endl; |
| | 271 | |
| | 272 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_toCompileMutex); |
| | 273 | _toCompile.push_back(compileSet); |
| | 274 | } |
| | 275 | |
| | 276 | void IncrementalCompileOperation::mergeCompiledSubgraphs() |
| | 277 | { |
| | 278 | osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::mergeCompiledSubgraphs()"<<std::endl; |
| | 279 | |
| | 280 | OpenThreads::ScopedLock<OpenThreads::Mutex> compilded_lock(_compiledMutex); |
| | 281 | |
| | 282 | for(CompileSets::iterator itr = _compiled.begin(); |
| | 283 | itr != _compiled.end(); |
| | 284 | ++itr) |
| | 285 | { |
| | 286 | CompileSet* cs = itr->get(); |
| | 287 | if (cs->_attachmentPoint.valid()) |
| | 288 | { |
| | 289 | cs->_attachmentPoint->addChild(cs->_subgraphToCompile.get()); |
| | 290 | } |
| | 291 | } |
| | 292 | |
| | 293 | _compiled.clear(); |
| | 294 | } |
| | 295 | |
| | 296 | void IncrementalCompileOperation::CompileSet::buildCompileMap(ContextSet& context) |
| | 297 | { |
| | 298 | } |
| | 299 | |
| | 300 | void IncrementalCompileOperation::operator () (osg::GraphicsContext* context) |
| | 301 | { |
| | 302 | osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::operator () ("<<context<<")"<<std::endl; |
| | 303 | |
| | 304 | OpenThreads::ScopedLock<OpenThreads::Mutex> toCompile_lock(_toCompileMutex); |
| | 305 | for(CompileSets::iterator itr = _toCompile.begin(); |
| | 306 | itr != _toCompile.end(); |
| | 307 | ) |
| | 308 | { |
| | 309 | CompileSet* cs = itr->get(); |
| | 310 | CompileMap& cm = cs->_compileMap; |
| | 311 | CompileData* cd = cm[context].get(); |
| | 312 | |
| | 313 | if (cd) |
| | 314 | { |
| | 315 | // compile textures |
| | 316 | cd->_textures.clear(); |
| | 317 | |
| | 318 | // compile drawables |
| | 319 | cd->_drawables.clear(); |
| | 320 | |
| | 321 | // compile programs |
| | 322 | cd->_programs.clear(); |
| | 323 | } |
| | 324 | |
| | 325 | if (!cd || cd->empty()) |
| | 326 | { |
| | 327 | if (cs->_compileCompletedCallback.valid()) |
| | 328 | { |
| | 329 | if (cs->_compileCompletedCallback->compileCompleted(cs)) |
| | 330 | { |
| | 331 | // callback will handle merging of subgraph so no need to place CompileSet in merge. |
| | 332 | } |
| | 333 | else |
| | 334 | { |
| | 335 | OpenThreads::ScopedLock<OpenThreads::Mutex> compilded_lock(_compiledMutex); |
| | 336 | _compiled.push_back(cs); |
| | 337 | } |
| | 338 | } |
| | 339 | |
| | 340 | // remove from toCompileSet; |
| | 341 | itr = _toCompile.erase(itr); |
| | 342 | } |
| | 343 | else |
| | 344 | { |
| | 345 | ++itr; |
| | 346 | } |
| | 347 | } |
| | 348 | } |