MCPcopy Create free account
hub / github.com/ad-si/LuaCAD / subtractPrimitivesWithOcclusionQueries

Function subtractPrimitivesWithOcclusionQueries

OpenCSG/src/renderSCS.cpp:607–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605 }
606
607 bool subtractPrimitivesWithOcclusionQueries(const std::vector<Batch>& batches) {
608
609 OpenGL::OcclusionQuery* occlusionTest = OpenGL::getOcclusionQuery(true);
610 if (!occlusionTest) {
611 return false;
612 }
613
614 const std::size_t numberOfBatches = batches.size();
615
616 int setting = getOption(CameraOutsideOptimization);
617 bool cameraInsideModel = (setting == OptimizationOff);
618
619 glStencilMask(OpenGL::stencilMask);
620 glEnable(GL_STENCIL_TEST);
621 glEnable(GL_CULL_FACE);
622
623 std::vector<unsigned int> fragmentcount(numberOfBatches, 0);
624 unsigned int shapesWithoutUpdate = 0;
625
626 SimpleSequencer sequencer(numberOfBatches);
627 size_t numIterations = sequencer.size();
628
629 unsigned int stencilref = 0;
630
631 for (size_t i = 0; i < numIterations; ++i)
632 {
633 size_t idx = sequencer.index(i);
634 const Batch& batch = batches[idx];
635
636 // create a distinct reference value
637 ++stencilref;
638 if (stencilref == OpenGL::stencilMax) {
639 glClear(GL_STENCIL_BUFFER_BIT);
640 stencilref = 1;
641 }
642
643 channelMgr->renderToChannel(false);
644
645 glDepthMask(GL_FALSE);
646 glStencilFunc(GL_ALWAYS, stencilref, OpenGL::stencilMask);
647 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
648
649 occlusionTest->beginQuery();
650 if (cameraInsideModel)
651 {
652 glDepthFunc(GL_GREATER);
653 glCullFace(GL_FRONT);
654
655 {
656 for (Batch::const_iterator j = batch.begin(); j != batch.end(); ++j) {
657 (*j)->render();
658 }
659 }
660
661 glStencilFunc(GL_EQUAL, stencilref, OpenGL::stencilMask);
662 glStencilOp(GL_ZERO, GL_ZERO, GL_KEEP);
663 }
664

Callers 1

renderSCSFunction · 0.85

Calls 13

getOcclusionQueryFunction · 0.85
getOptionFunction · 0.85
getRenderDataFunction · 0.85
renderToChannelMethod · 0.80
beginQueryMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
endQueryMethod · 0.80
vecMethod · 0.80
getQueryResultMethod · 0.80
sizeMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected