|
20 | 20 | #include "renderer/camera/camera.h" |
21 | 21 | #include "renderer/gui/gui.h" |
22 | 22 | #include "renderer/gui/integration/public/gui_application_with_logger.h" |
23 | | -#include "renderer/opengl/context.h" |
24 | | -#include "renderer/opengl/lookup.h" |
25 | 23 | #include "renderer/render_factory.h" |
26 | 24 | #include "renderer/render_pass.h" |
27 | 25 | #include "renderer/render_target.h" |
@@ -167,10 +165,19 @@ void Presenter::init_graphics(const renderer::window_settings &window_settings) |
167 | 165 | this->asset_manager, |
168 | 166 | this->time_loop->get_clock()); |
169 | 167 | this->render_passes.push_back(this->hud_renderer->get_render_pass()); |
| 168 | + |
| 169 | + for (auto& render_pass : render_passes) { |
| 170 | + render_pass->set_stencil_state(renderer::StencilState::USE_STENCIL_TEST); |
| 171 | + } |
170 | 172 |
|
171 | 173 | this->init_gui(); |
172 | 174 | this->init_final_render_pass(); |
173 | 175 |
|
| 176 | + // set passes indices |
| 177 | + this->index_gui_stencil_pass = this->render_passes.size() - 3; |
| 178 | + this->index_gui_render_pass = this->render_passes.size() - 2; |
| 179 | + this->index_final_render_pass = this->render_passes.size() - 1; |
| 180 | + |
174 | 181 | if (this->simulation) { |
175 | 182 | auto render_factory = std::make_shared<renderer::RenderFactory>(this->terrain_renderer, this->world_renderer); |
176 | 183 | this->simulation->attach_renderer(render_factory); |
@@ -213,7 +220,10 @@ void Presenter::init_gui() { |
213 | 220 | qml_root, // directory to watch for qml file changes |
214 | 221 | qml_assets, // qml data: Engine *, the data directory, ... |
215 | 222 | this->renderer // openage renderer |
216 | | - ); |
| 223 | + ); |
| 224 | + |
| 225 | + auto stencil_pass = this->gui->get_stencil_pass(); |
| 226 | + this->render_passes.push_back(stencil_pass); |
217 | 227 |
|
218 | 228 | auto gui_pass = this->gui->get_render_pass(); |
219 | 229 | this->render_passes.push_back(gui_pass); |
@@ -309,57 +319,24 @@ void Presenter::init_final_render_pass() { |
309 | 319 | }); |
310 | 320 | } |
311 | 321 |
|
312 | | -void Presenter::init_stencil_test() { |
313 | | - glEnable(GL_STENCIL_TEST); |
314 | | - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); |
315 | | - glClear(GL_STENCIL_BUFFER_BIT); |
316 | | -} |
317 | | - |
318 | | -void Presenter::enable_stencil_for_gui_mask() { |
319 | | - // Replace stencil value with 1 when depth test passes |
320 | | - glStencilFunc(GL_ALWAYS, 1, 0xFF); |
321 | | - glStencilMask(0xFF); |
322 | | - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
323 | | -} |
324 | | - |
325 | | -void Presenter::enable_stencil_for_world() { |
326 | | - // Only pass if stencil value is not 1 |
327 | | - glStencilFunc(GL_NOTEQUAL, 1, 0xFF); |
328 | | - glStencilMask(0x00); |
329 | | - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
330 | | -} |
331 | | - |
332 | | -void Presenter::disable_stencil() { |
333 | | - glDisable(GL_STENCIL_TEST); |
334 | | - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
335 | | -} |
336 | | - |
337 | 322 | void Presenter::render() { |
338 | 323 | // TODO: Pass current time to update() instead of fetching it in renderer |
339 | 324 | this->camera_manager->update(); |
340 | 325 | this->terrain_renderer->update(); |
341 | 326 | this->world_renderer->update(); |
342 | 327 | this->hud_renderer->update(); |
343 | 328 |
|
344 | | - this->init_stencil_test(); |
345 | | - |
346 | | - // First Pass: Render GUI to stencil buffer |
347 | | - this->enable_stencil_for_gui_mask(); |
348 | 329 | this->gui->render(); |
| 330 | + this->renderer->render(this->render_passes[this->index_gui_stencil_pass]); |
349 | 331 |
|
350 | | - // Second Pass: Render game world with stencil buffer |
351 | | - this->enable_stencil_for_world(); |
352 | | - for (size_t i = 0; i < this->render_passes.size() - 2; ++i) { |
| 332 | + for (size_t i = 0; i < this->index_gui_stencil_pass; ++i) { |
353 | 333 | this->renderer->render(this->render_passes[i]); |
354 | 334 | } |
355 | 335 |
|
356 | | - // Third Pass: Render GUI to screen |
357 | | - this->disable_stencil(); |
358 | 336 | this->gui->render(); |
359 | | - this->renderer->render(this->render_passes[this->render_passes.size() - 2]); |
| 337 | + this->renderer->render(this->render_passes[this->index_gui_render_pass]); |
360 | 338 |
|
361 | | - // Fourth Pass: Render screen to window |
362 | | - this->renderer->render(this->render_passes.back()); |
| 339 | + this->renderer->render(this->render_passes[this->index_final_render_pass]); |
363 | 340 | } |
364 | 341 |
|
365 | 342 | } // namespace openage::presenter |
0 commit comments