summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-20 21:22:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-20 21:22:07 +0200
commit8ee0ff58ef0e09fd510ab0ba7bb9957c5e6461a5 (patch)
treef0d9bac3ef81d0c44b73d0f3648f1f522a3c9496
parent2ff4e6203f7d895d88ab9bb4a4415a884a8f3075 (diff)
only do MSAAA for isometrically projected entities
-rw-r--r--main/app.cpp53
-rw-r--r--main/app.hpp7
-rw-r--r--main/draw.cpp18
3 files changed, 65 insertions, 13 deletions
diff --git a/main/app.cpp b/main/app.cpp
index c39b272c..b1e616e4 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -5,6 +5,7 @@
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h>
#include <Magnum/GL/DefaultFramebuffer.h>
+#include <Magnum/GL/TextureFormat.h>
#include <Magnum/ImGuiIntegration/Context.h>
#include <Magnum/ImGuiIntegration/Context.hpp>
#include <SDL_events.h>
@@ -38,9 +39,11 @@ app::app(const Arguments& arguments, app_settings opts):
.setSize({1024, 768}, dpi_policy::Physical)
.setWindowFlags(Configuration::WindowFlag::Resizable),
GLConfiguration{}
- .setSampleCount(4)
+ //.setSampleCount(4)
}
{
+ SDL_MaximizeWindow(window());
+
if (opts.vsync)
{
if (!setSwapInterval(-1))
@@ -50,10 +53,21 @@ app::app(const Arguments& arguments, app_settings opts):
setSwapInterval(0);
set_fp_mask();
reset_camera_offset();
+
+#if 1
+ ASSERT(framebufferSize() == windowSize());
+ _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize());
+ recalc_viewport(windowSize());
+#else
+ _msaa_color_texture.setStorage(1, GL::TextureFormat::RGBA8, windowSize());
+ _framebuffer = GL::Framebuffer{GL::defaultFramebuffer.viewport()};
+ _framebuffer.attachTexture(GL::Framebuffer::ColorAttachment{0}, _msaa_color_texture);
+#endif
+ //_framebuffer.attachRenderbuffer(GL::Framebuffer::BufferAttachment::DepthStencil, depthStencil);
+
update_window_scale(windowSize());
+
setMinimalLoopPeriod(5);
- _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize());
- SDL_MaximizeWindow(window());
{
auto c = _world[chunk_coords{0, 0}];
make_test_chunk(*c);
@@ -61,13 +75,25 @@ app::app(const Arguments& arguments, app_settings opts):
timeline.start();
}
-void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
+void app::recalc_viewport(Vector2i size)
{
- update_window_scale(event.windowSize());
- GL::defaultFramebuffer.setViewport({{}, event.windowSize()});
- _imgui.relayout(Vector2{event.windowSize()}, event.windowSize(), event.framebufferSize());
+ update_window_scale(size);
+
+ GL::defaultFramebuffer.setViewport({{}, size });
+ _framebuffer.detach(GL::Framebuffer::ColorAttachment{0});
+ _msaa_color_texture = GL::MultisampleTexture2D{};
+ _msaa_color_texture.setStorage(1, GL::TextureFormat::RGBA8, size);
+ _framebuffer.setViewport({{}, size });
+ _framebuffer.attachTexture(GL::Framebuffer::ColorAttachment{0}, _msaa_color_texture);
+
+ _imgui.relayout(Vector2{ size }, size, size);
}
+void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
+{
+ ASSERT(event.framebufferSize() == event.windowSize());
+ recalc_viewport(event.windowSize());
+}
void app::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
{
@@ -120,20 +146,29 @@ void app::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
{
if (_imgui.handleTextInputEvent(event))
- return keys = {}, event.setAccepted();
+ {
+ keys = {};
+ event.setAccepted();
+ }
}
void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
{
if (_imgui.handleKeyPressEvent(event))
+ {
+ keys = {};
return event.setAccepted();
+ }
do_key(event.key(), event.modifiers(), true, event.isRepeated());
}
void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
{
if (_imgui.handleKeyReleaseEvent(event))
- return keys = {}, event.setAccepted();
+ {
+ keys = {};
+ return event.setAccepted();
+ }
do_key(event.key(), event.modifiers(), false, false);
}
diff --git a/main/app.hpp b/main/app.hpp
index a4da922c..b6fb5605 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -14,6 +14,8 @@
#include <Magnum/Timeline.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/GL/DebugOutput.h>
+#include <Magnum/GL/Framebuffer.h>
+#include <Magnum/GL/MultisampleTexture.h>
#include <Magnum/ImGuiIntegration/Context.h>
#include <memory>
@@ -42,6 +44,7 @@ private:
void reset_camera_offset();
void update_window_scale(Vector2i window_size);
void recalc_cursor_tile();
+ void recalc_viewport(Vector2i size);
void viewportEvent(ViewportEvent& event) override;
void mousePressEvent(MouseEvent& event) override;
@@ -60,6 +63,7 @@ private:
std::array<std::int16_t, 4> get_draw_bounds() const noexcept;
void drawEvent() override;
+ void draw_msaa();
void draw_world();
void draw_cursor_tile();
void draw_wireframe_quad(global_coords pt);
@@ -89,6 +93,9 @@ private:
[[maybe_unused]] void* _dummy = register_debug_callback();
+ GL::Framebuffer _framebuffer{{{}, windowSize()}};
+ GL::MultisampleTexture2D _msaa_color_texture{};
+
tile_shader _shader;
tile_atlas_ floor1 = loader.tile_atlas("floor-tiles.tga", {44, 4});
tile_atlas_ floor2 = loader.tile_atlas("metal1.tga", {2, 2});
diff --git a/main/draw.cpp b/main/draw.cpp
index 5eeb413c..d633db73 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -29,12 +29,15 @@ void app::drawEvent()
update(dt);
}
- GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
_shader.set_tint({1, 1, 1, 1});
+
{
- const with_shifted_camera_offset o{_shader, BASE_X, BASE_Y};
- draw_world();
- draw_cursor_tile();
+ //GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
+ _framebuffer.clear(GL::FramebufferClear::Color);
+ _framebuffer.bind();
+ draw_msaa();
+ GL::defaultFramebuffer.bind();
+ GL::Framebuffer::blit(_framebuffer, GL::defaultFramebuffer, {{}, windowSize()}, GL::FramebufferBlit::Color);
}
render_menu();
@@ -44,6 +47,13 @@ void app::drawEvent()
timeline.nextFrame();
}
+void app::draw_msaa()
+{
+ const with_shifted_camera_offset o{_shader, BASE_X, BASE_Y};
+ draw_world();
+ draw_cursor_tile();
+}
+
void app::draw_world()
{
#if 0