MCPcopy Create free account
hub / github.com/ddiakopoulos/polymer / run_stencil_prepass

Method run_stencil_prepass

libraries/lib-engine/src/renderer-pbr.cpp:162–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void pbr_renderer::run_stencil_prepass(const view_data & view, const render_payload & scene)
163{
164 gl_check_error(__FILE__, __LINE__);
165
166 GLboolean colorMask[4];
167 glGetBooleanv(GL_COLOR_WRITEMASK, &colorMask[0]);
168 GLboolean wasCullingEnabled = glIsEnabled(GL_CULL_FACE);
169 GLboolean wasDepthTestingEnabled = glIsEnabled(GL_DEPTH_TEST);
170 GLboolean wasBlendingEnabled = glIsEnabled(GL_BLEND);
171
172 glColorMask(0, 0, 0, 0); // do not write color
173 glDepthMask(GL_FALSE); // do not write depth
174 glStencilMask(GL_TRUE); // only write stencil
175
176 glDisable(GL_BLEND); // 0 into alpha
177 glDisable(GL_DEPTH_TEST); // disable depth
178 glDisable(GL_CULL_FACE); // do not cull since winding will might be flipped per-eye
179 glEnable(GL_STENCIL_TEST); // enable stencil test
180
181 glStencilFunc(GL_ALWAYS, 1, 1); // set stencil func
182 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // set stencil op (GL_REPLACE, GL_REPLACE, GL_REPLACE)
183
184 auto & shader = no_op.get()->get_variant()->shader;
185 shader.bind();
186 if (view.index == 0) left_stencil_mask.draw_elements();
187 else if (view.index == 1) right_stencil_mask.draw_elements();
188 shader.unbind();
189
190 glStencilFunc(GL_EQUAL, 0, 1); // reset stencil func
191 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // reset stencil op
192
193 glDepthMask(GL_TRUE); // it's ok to write depth
194 glStencilMask(GL_FALSE); // no other passes should write to stencil
195 glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); // Restore color mask state
196 if (wasCullingEnabled) glEnable(GL_CULL_FACE);
197 if (wasDepthTestingEnabled) glEnable(GL_DEPTH_TEST);
198 if (wasBlendingEnabled) glEnable(GL_BLEND);
199
200 gl_check_error(__FILE__, __LINE__);
201}
202
203void pbr_renderer::set_stencil_mask(const uint32_t idx, gl_mesh && m)
204{

Callers

nothing calls this directly

Calls 6

gl_check_errorFunction · 0.85
get_variantMethod · 0.80
draw_elementsMethod · 0.80
getMethod · 0.45
bindMethod · 0.45
unbindMethod · 0.45

Tested by

no test coverage detected