From: Mikko Rasa Date: Tue, 9 Nov 2021 12:53:34 +0000 (+0200) Subject: Don't store a View's target framebuffer in the base class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b752e5384eb56a389d50e0527529d410e6455ba9;p=libs%2Fgl.git Don't store a View's target framebuffer in the base class Instead access it through a virtual function. Vulkan requires a separate framebuffer per swapchain image. --- diff --git a/source/render/offscreenview.cpp b/source/render/offscreenview.cpp index 6d0d88b0..71851c72 100644 --- a/source/render/offscreenview.cpp +++ b/source/render/offscreenview.cpp @@ -5,11 +5,11 @@ namespace Msp { namespace GL { OffscreenView::OffscreenView(Framebuffer &t): - View(t) + target(t) { } OffscreenView::OffscreenView(RenderTarget &t): - View(t.get_framebuffer()) + target(t.get_framebuffer()) { } } // namespace GL diff --git a/source/render/offscreenview.h b/source/render/offscreenview.h index 0801c3bf..c72c1dd3 100644 --- a/source/render/offscreenview.h +++ b/source/render/offscreenview.h @@ -14,9 +14,15 @@ A View targeting an offscreen framebuffer. */ class OffscreenView: public View { +private: + Framebuffer ⌖ + public: OffscreenView(Framebuffer &); OffscreenView(RenderTarget &); + +private: + virtual const Framebuffer &get_target() const { return target; } }; } // namespace GL diff --git a/source/render/view.cpp b/source/render/view.cpp index ac244335..54828c7b 100644 --- a/source/render/view.cpp +++ b/source/render/view.cpp @@ -6,8 +6,7 @@ namespace Msp { namespace GL { -View::View(Framebuffer &t): - target(t), +View::View(): camera(0), content(0), internal_renderer(0) @@ -41,7 +40,7 @@ void View::render() void View::render(Renderer &renderer) { Renderer::Push _push(renderer); - renderer.set_framebuffer(&target); + renderer.set_framebuffer(&get_target()); if(content) { if(camera) diff --git a/source/render/view.h b/source/render/view.h index 23425a86..b7cb2256 100644 --- a/source/render/view.h +++ b/source/render/view.h @@ -20,17 +20,16 @@ Sequence can be used to specify other tags and add post-processing. class View { protected: - Framebuffer ⌖ Camera *camera; Renderable *content; Renderer *internal_renderer; - View(Framebuffer &); + View(); public: virtual ~View(); - virtual unsigned get_width() const { return target.get_width(); } - virtual unsigned get_height() const { return target.get_height(); } + virtual unsigned get_width() const { return get_target().get_width(); } + virtual unsigned get_height() const { return get_target().get_height(); } float get_aspect_ratio() const { return static_cast(get_width())/get_height(); } /** Sets the camera to render with. The camera's aspect ratio is set to @@ -41,6 +40,8 @@ public: virtual void render(); virtual void render(Renderer &); +protected: + virtual const Framebuffer &get_target() const = 0; }; } // namespace GL diff --git a/source/render/windowview.cpp b/source/render/windowview.cpp index e139436b..bbc7bb00 100644 --- a/source/render/windowview.cpp +++ b/source/render/windowview.cpp @@ -7,7 +7,6 @@ namespace Msp { namespace GL { WindowView::WindowView(Graphics::Window &w): - View(Framebuffer::system()), window(w), device(Device::get_current()) { @@ -29,5 +28,10 @@ void WindowView::window_resized(unsigned w, unsigned h) camera->set_aspect_ratio(aspect); } +const Framebuffer &WindowView::get_target() const +{ + return Framebuffer::system(); +} + } // namespace GL } // namespace Msp diff --git a/source/render/windowview.h b/source/render/windowview.h index 028e9805..031cd49d 100644 --- a/source/render/windowview.h +++ b/source/render/windowview.h @@ -35,6 +35,8 @@ public: private: void window_resized(unsigned, unsigned); + + virtual const Framebuffer &get_target() const; }; } // namespace GL