| 518 | } |
| 519 | |
| 520 | void subtractPrimitives(const std::vector<Batch>& batches, |
| 521 | const unsigned int depthComplexity = 0) { |
| 522 | |
| 523 | int setting = getOption(CameraOutsideOptimization); |
| 524 | bool cameraInsideModel = (setting == OptimizationOff); |
| 525 | |
| 526 | glStencilMask(OpenGL::stencilMask); |
| 527 | glEnable(GL_STENCIL_TEST); |
| 528 | glEnable(GL_CULL_FACE); |
| 529 | |
| 530 | size_t numberOfBatches = batches.size(); |
| 531 | BouncingSequencer bounce(numberOfBatches); |
| 532 | SchoenfieldSequencer schoenfield(numberOfBatches); |
| 533 | Sequencer * sequencer = 0; |
| 534 | size_t numIterations; |
| 535 | if (depthComplexity == 0) |
| 536 | { |
| 537 | sequencer = &schoenfield; |
| 538 | numIterations = sequencer->size(); |
| 539 | } |
| 540 | else |
| 541 | { |
| 542 | sequencer = &bounce; |
| 543 | numIterations = sequencer->sizeForDepthComplexity(depthComplexity); |
| 544 | } |
| 545 | |
| 546 | unsigned int stencilref = 0; |
| 547 | for (size_t i = 0; i < numIterations; ++i) |
| 548 | { |
| 549 | const Batch& batch = batches[sequencer->index(i)]; |
| 550 | |
| 551 | // create a distinct reference value |
| 552 | ++stencilref; |
| 553 | if (stencilref == OpenGL::stencilMax) { |
| 554 | glClear(GL_STENCIL_BUFFER_BIT); |
| 555 | stencilref = 1; |
| 556 | } |
| 557 | |
| 558 | channelMgr->renderToChannel(false); |
| 559 | |
| 560 | glDepthMask(GL_FALSE ); |
| 561 | glStencilFunc(GL_ALWAYS, stencilref, OpenGL::stencilMask); |
| 562 | glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); |
| 563 | |
| 564 | if (cameraInsideModel) |
| 565 | { |
| 566 | glDepthFunc(GL_GREATER); |
| 567 | glCullFace(GL_FRONT); |
| 568 | |
| 569 | for (Batch::const_iterator j = batch.begin(); j != batch.end(); ++j) { |
| 570 | (*j)->render(); |
| 571 | } |
| 572 | |
| 573 | glStencilFunc(GL_EQUAL, stencilref, OpenGL::stencilMask); |
| 574 | glStencilOp(GL_ZERO, GL_ZERO, GL_KEEP); |
| 575 | } |
| 576 | |
| 577 | glDepthFunc(GL_LESS); |
no test coverage detected