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

Method merge

OpenCSG/src/renderSCS.cpp:75–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 };
74
75 void SCSChannelManagerAlphaOnly::merge() {
76
77 ProjTextureSetup setup = FixedFunction;
78 setupProjectiveTexture(setup);
79
80 glEnable(GL_ALPHA_TEST);
81 glEnable(GL_CULL_FACE);
82 glEnable(GL_DEPTH_TEST);
83 glDepthFunc(GL_LESS);
84 glDepthMask(GL_TRUE);
85 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
86
87 std::vector<Channel> channels = occupied();
88 for (std::vector<Channel>::const_iterator c = channels.begin(); c!=channels.end(); ++c) {
89
90 setupTexEnv(*c);
91 scissor->recall(*c);
92 scissor->enableScissor();
93
94 const std::vector<Primitive*> primitives = getPrimitives(*c);
95 for (std::vector<Primitive*>::const_iterator j = primitives.begin(); j != primitives.end(); ++j) {
96 glCullFace((*j)->getOperation() == Intersection ? GL_BACK : GL_FRONT);
97 RenderData* primitiveData = getRenderData(*j);
98 GLubyte id = primitiveData->bufferId.a;
99
100 // Here is an interesting bug, which happened on an ATI HD4670, but actually
101 // might happen on every hardware. I am not sure whether it can be solved
102 // correctly.
103
104 // Problem is that in optimized mode with some compilers (VC6, Visual Studio 2003
105 // in particular), when setting the alpha func as follows:
106 // glAlphaFunc(GL_EQUAL, static_cast<float>(id) / 255.0f);
107 // the division is optimized as multiplication with 1.0f/255.0f.
108 // This is a fine and valid optimization. Unfortunately, the results
109 // are not exactly the same as the direct division for some ids.
110 // Which is apparently what the ATI driver is doing internally.
111 // So with comparison with GL_EQUAL fails.
112
113 // Fortunately the OpenGL standard enforces that the mapping of color byte
114 // values to float fragment values be done by division. So if the
115 // solution found below (just working at double precision) proves
116 // to work once, it should work forever, such that a precompiling
117 // lookup table containing the correct alpha reference values is
118 // not required. However a bad feeling remains.
119
120 // The SCSChannelManagerFragmentProgram path implemented below should fix this.
121
122 double alpha = static_cast<double>(id) / 255.0;
123 GLfloat fAlpha = static_cast<float>(alpha);
124 glAlphaFunc(GL_EQUAL, fAlpha);
125
126 (*j)->render();
127 }
128 }
129
130 scissor->disableScissor();
131
132 glDisable(GL_ALPHA_TEST);

Callers

nothing calls this directly

Calls 13

getRenderDataFunction · 0.85
getARBVertexProgramFunction · 0.85
getARBFragmentProgramFunction · 0.85
getVertexShaderFunction · 0.85
getGLSLProgramFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
recallMethod · 0.80
enableScissorMethod · 0.80
getOperationMethod · 0.80
disableScissorMethod · 0.80
vecMethod · 0.80

Tested by

no test coverage detected