diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 13:06:32 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 13:06:32 +0200 |
| commit | 55f284c6e3d2da6774f758e047945b102b9f5b23 (patch) | |
| tree | be5abe0eca392f345680a713240fcf7a84ee8088 | |
| parent | a62bd981c2a973952f3f5e22ca768dd961991d21 (diff) | |
fix msaa fbo
| -rw-r--r-- | main/app.cpp | 24 | ||||
| -rw-r--r-- | main/app.hpp | 19 | ||||
| -rw-r--r-- | main/draw.cpp | 13 |
3 files changed, 36 insertions, 20 deletions
diff --git a/main/app.cpp b/main/app.cpp index 92ac68dc..1cbb5b2a 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -11,6 +11,10 @@ #include <SDL_events.h> #include <SDL_video.h> +#ifdef FM_MSAA +#include <Magnum/GL/RenderbufferFormat.h> +#endif + namespace floormat { int app::run_from_argv(int argc, char** argv) @@ -57,16 +61,8 @@ app::app(const Arguments& arguments, app_settings opts): set_fp_mask(); reset_camera_offset(); -#if 1 fm_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); setMinimalLoopPeriod(5); { @@ -85,11 +81,13 @@ void app::recalc_viewport(Vector2i size) recalc_cursor_tile(); 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); +#ifdef FM_MSAA + _msaa_framebuffer.detach(GL::Framebuffer::ColorAttachment{0}); + _msaa_renderbuffer = Magnum::GL::Renderbuffer{}; + _msaa_renderbuffer.setStorageMultisample(msaa_samples, GL::RenderbufferFormat::RGBA8, size); + _msaa_framebuffer.setViewport({{}, size }); + _msaa_framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, _msaa_renderbuffer); +#endif } void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event) diff --git a/main/app.hpp b/main/app.hpp index 1ac23dd2..27508bdb 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -14,11 +14,17 @@ #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/Platform/Sdl2Application.h> #include <Magnum/ImGuiIntegration/Context.h> #include <memory> +#define FM_MSAA + +#ifdef FM_MSAA +#include <Magnum/GL/Framebuffer.h> +#include <Magnum/GL/Renderbuffer.h> +#endif + namespace floormat { struct app final : private Platform::Application @@ -95,8 +101,10 @@ private: [[maybe_unused]] void* _dummy = register_debug_callback(); - GL::Framebuffer _framebuffer{{{}, windowSize()}}; - GL::MultisampleTexture2D _msaa_color_texture{}; +#ifdef FM_MSAA + GL::Framebuffer _msaa_framebuffer{{{}, windowSize()}}; + GL::Renderbuffer _msaa_renderbuffer{}; +#endif tile_shader _shader; tile_atlas_ floor1 = loader.tile_atlas("floor-tiles", {44, 4}); @@ -127,6 +135,9 @@ private: app_settings _settings; static constexpr std::int16_t BASE_X = 0, BASE_Y = 0; +#ifdef FM_MSAA + static constexpr int msaa_samples = 16; +#endif }; } // namespace floormat diff --git a/main/draw.cpp b/main/draw.cpp index e634823f..b2e0a637 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -4,6 +4,8 @@ #include <Magnum/GL/DefaultFramebuffer.h> #include <Magnum/GL/Renderer.h> +//#define FM_SKIP_MSAA + namespace floormat { void app::drawEvent() @@ -29,11 +31,16 @@ void app::drawEvent() _shader.set_tint({1, 1, 1, 1}); { - _framebuffer.clear(GL::FramebufferClear::Color); - _framebuffer.bind(); + GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); +#if defined FM_MSAA && !defined FM_SKIP_MSAA + _msaa_framebuffer.clear(GL::FramebufferClear::Color); + _msaa_framebuffer.bind(); +#endif draw_msaa(); +#if defined FM_MSAA && !defined FM_SKIP_MSAA GL::defaultFramebuffer.bind(); - GL::Framebuffer::blit(_framebuffer, GL::defaultFramebuffer, {{}, windowSize()}, GL::FramebufferBlit::Color); + GL::Framebuffer::blit(_msaa_framebuffer, GL::defaultFramebuffer, {{}, windowSize()}, GL::FramebufferBlit::Color); +#endif } render_menu(); |
