diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-07 20:44:42 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-07 20:44:49 +0200 |
commit | 21eaaee936a47742f59eb6b5665422de2bd8e7ae (patch) | |
tree | aeb89f45aaee920eeb88dd14ce53b76eb818d047 /main | |
parent | 82ec1a07c79b1c96688464609d043d6ce23685b1 (diff) |
fix closed doors clipping through walls
Diffstat (limited to 'main')
-rw-r--r-- | main/draw.cpp | 37 | ||||
-rw-r--r-- | main/main-impl.hpp | 20 |
2 files changed, 56 insertions, 1 deletions
diff --git a/main/draw.cpp b/main/draw.cpp index f87f2e9c..521cad30 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -8,6 +8,8 @@ #include <Corrade/Containers/ArrayView.h> #include <Magnum/GL/DefaultFramebuffer.h> #include <Magnum/GL/Renderer.h> +#include <Magnum/GL/RenderbufferFormat.h> +#include <Magnum/GL/TextureFormat.h> #include <Magnum/Math/Color.h> #include <algorithm> #include <thread> @@ -20,6 +22,27 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept _virtual_scale = Vector2(fb_size) / Vector2(win_size); update_window_state(); _shader.set_scale(Vector2{fb_size}); + + GL::defaultFramebuffer.bind(); + +#ifdef FM_USE_DEPTH32 + { + framebuffer.fb = GL::Framebuffer{{ {}, fb_size }}; + + framebuffer.color = GL::Texture2D{}; + framebuffer.color.setStorage(1, GL::TextureFormat::RGBA8, fb_size); + framebuffer.depth = GL::Renderbuffer{}; + framebuffer.depth.setStorage(GL::RenderbufferFormat::DepthComponent32F, fb_size); + + framebuffer.fb.attachTexture(GL::Framebuffer::ColorAttachment{0}, framebuffer.color, 0); + framebuffer.fb.attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, framebuffer.depth); + framebuffer.fb.clearColor(0, Color4{0.f, 0.f, 0.f, 1.f}); + framebuffer.fb.clearDepth(0); + + framebuffer.fb.bind(); + } +#endif + GL::defaultFramebuffer.setViewport({{}, fb_size }); // -- state --- @@ -109,7 +132,11 @@ void main_impl::draw_world() noexcept } GL::Renderer::enable(GL::Renderer::Feature::DepthTest); - GL::defaultFramebuffer.clearDepthStencil(0, 0); +#ifdef FM_USE_DEPTH32 + framebuffer.fb.clearDepth(0); +#else + GL::defaultFramebuffer.clearDepth(0); +#endif for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -193,7 +220,11 @@ void main_impl::drawEvent() { _shader.set_tint({1, 1, 1, 1}); const auto clear_color = 0x222222ff_rgbaf; +#ifdef FM_USE_DEPTH32 + framebuffer.fb.clearColor(0, clear_color); +#else GL::defaultFramebuffer.clearColor(clear_color); +#endif draw_world(); GL::Renderer::disable(GL::Renderer::Feature::DepthTest); } @@ -203,6 +234,10 @@ void main_impl::drawEvent() do_update(); +#ifdef FM_USE_DEPTH32 + GL::Framebuffer::blit(framebuffer.fb, GL::defaultFramebuffer, framebuffer.fb.viewport(), GL::FramebufferBlit::Color); +#endif + swapBuffers(); redraw(); diff --git a/main/main-impl.hpp b/main/main-impl.hpp index dae4286e..859f2a8f 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -14,6 +14,14 @@ #include <Magnum/GL/DebugOutput.h> #include <Magnum/Platform/Sdl2Application.h> +//#define FM_USE_DEPTH32 + +#ifdef FM_USE_DEPTH32 +#include <Magnum/GL/Framebuffer.h> +#include <Magnum/GL/Renderbuffer.h> +#include <Magnum/GL/Texture.h> +#endif + namespace floormat { struct floormat_app; @@ -23,6 +31,14 @@ struct clickable; struct main_impl final : Platform::Sdl2Application, floormat_main { +#ifdef FM_USE_DEPTH32 + struct Framebuffer final { + GL::Framebuffer fb{NoCreate}; + GL::Renderbuffer depth{NoCreate}; + GL::Texture2D color{NoCreate}; + }; +#endif + explicit main_impl(floormat_app& app, fm_settings&& opts, int& argc, char** argv) noexcept; ~main_impl() noexcept override; @@ -86,6 +102,10 @@ private: floor_mesh _floor_mesh; wall_mesh _wall_mesh; anim_mesh _anim_mesh; +#ifdef FM_USE_DEPTH32 + Framebuffer framebuffer; +#endif + struct { float value = 0; float jitter = 0; |