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

Function parityTestAndDiscard

OpenCSG/src/renderGoldfeather.cpp:322–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320 }
321
322 void parityTestAndDiscard(
323 const Batch& shapesOfInterest,
324 const std::vector<Primitive*>& primitives,
325 bool layered,
326 unsigned int stencilMax) {
327
328 glDepthMask(GL_FALSE);
329 glDepthFunc(getParityDepthFunc());
330
331 glEnable(GL_STENCIL_TEST);
332
333 unsigned int parityValue = 1;
334 unsigned int allParityTestValues = 0;
335
336 // for all shapes of the intersection, we conduct the parity test.
337 // for fragments for which it fails, we mark them as not visible
338 // (parity testing means to check whether the number of surfaces in front
339 // of the current z-buffer is even or uneven. As all shapes are closed,
340 // this is equivalent to check the number of surfaces behind the current
341 // z-buffer. This is what we effectively do by default, because
342 // that approach is more robust)
343 for (std::vector<Primitive*>::const_iterator itr = primitives.begin(); itr != primitives.end(); ++itr ) {
344 if (!layered) {
345
346 // substracted shapes that form a part of the shapes of interest
347 // can not alter the visibility of the other shapes of interest. the reason:
348 // for other substracted shapes: by definition
349 // for other intersecting shapes: since the bounding boxes do no overlap
350 //
351 // for intersecting shapes, the above only is true if it is the only shape
352 // in the list of shapes of interest
353 Batch::const_iterator res =
354 std::find(shapesOfInterest.begin(), shapesOfInterest.end(), *itr);
355 bool isContained = (res != shapesOfInterest.end());
356
357 if (isContained && ((*itr)->getOperation() == Subtraction || shapesOfInterest.size() == 1)) {
358 continue;
359 }
360
361 // for substracted shapes that don't touch the shapes of interest,
362 // the parity test would always fail. thus, they are omited here.
363 bool needParityTest = ((*itr)->getOperation() == Intersection);
364 if (!needParityTest) {
365 for (Batch::const_iterator k = shapesOfInterest.begin(); k != shapesOfInterest.end(); ++k) {
366 if (Algo::intersectXYZ(*itr, *k)) {
367 needParityTest = true;
368 break;
369 }
370 }
371 }
372 if (!needParityTest)
373 continue;
374 }
375
376 // we only need one bit in the stencil buffer for each parity test.
377 // Thus we iterate over all bits, and only when all bits have been
378 // used, we discard fragments marked invisible by the parity test,
379 // and clear the stencil buffer.

Calls 9

getParityDepthFuncFunction · 0.85
intersectXYZFunction · 0.85
discardFragmentsFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
getOperationMethod · 0.80
renderToChannelMethod · 0.80
sizeMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected