summaryrefslogtreecommitdiffhomepage
path: root/main/draw.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-07 20:44:42 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-07 20:44:49 +0200
commit21eaaee936a47742f59eb6b5665422de2bd8e7ae (patch)
treeaeb89f45aaee920eeb88dd14ce53b76eb818d047 /main/draw.cpp
parent82ec1a07c79b1c96688464609d043d6ce23685b1 (diff)
fix closed doors clipping through walls
Diffstat (limited to 'main/draw.cpp')
-rw-r--r--main/draw.cpp37
1 files changed, 36 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();