MCPcopy Index your code
hub / github.com/ad-si/LuaCAD / calcMaxDepthComplexity

Function calcMaxDepthComplexity

OpenCSG/src/primitiveHelper.cpp:79–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77 namespace OpenGL {
78
79 unsigned int calcMaxDepthComplexity(const std::vector<Primitive*>& primitives,
80 const PCArea& area) {
81
82 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
83
84 glDisable(GL_DEPTH_TEST);
85 glStencilMask(255);
86 glEnable(GL_STENCIL_TEST);
87 glStencilFunc(GL_ALWAYS, 0, 255);
88 glStencilOp(GL_INCR, GL_INCR, GL_INCR);
89
90 glEnable(GL_CULL_FACE);
91
92 for (std::vector<Primitive*>::const_iterator itr = primitives.begin(); itr != primitives.end(); ++itr) {
93 glCullFace((*itr)->getOperation() == Intersection ? GL_BACK : GL_FRONT);
94 (*itr)->render();
95 }
96
97 glDisable(GL_CULL_FACE);
98 glDisable(GL_STENCIL_TEST);
99 glEnable(GL_DEPTH_TEST);
100
101 int dx = area.maxx - area.minx;
102 int dy = area.maxy - area.miny;
103
104 std::size_t size = static_cast<std::size_t>(dx) * dy;
105 GLubyte * buf = new GLubyte[size];
106
107 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
108 glPixelStorei(GL_PACK_ALIGNMENT, 1);
109 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
110 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
111 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
112
113 // This is pathologically slow on ATI HD4670 if not the complete viewport is read back.
114 // So better always read the complete viewport or make this configurable?
115 glReadPixels(area.minx, area.miny, dx, dy, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf);
116
117 unsigned char m = *std::max_element(buf, buf+size);
118
119 unsigned int max = m;
120
121 delete[] buf;
122
123 return max;
124 }
125
126 void renderLayer(unsigned int layer, const std::vector<Primitive*>& primitives) {
127 glStencilFunc(GL_EQUAL, layer, 255);

Callers 2

renderSCSFunction · 0.85

Calls 4

beginMethod · 0.80
endMethod · 0.80
getOperationMethod · 0.80
renderMethod · 0.45

Tested by

no test coverage detected