From 8848413f6f794f38aa9e1860b2e2019f89d07610 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 2 Aug 2023 23:33:30 +0300 Subject: [PATCH] Redesign OffscreenView to own the render target Change RenderTarget::get_framebuffer to const to accommodate this; outsiders should not modify the framebuffer's structure anyway. --- source/render/offscreenview.cpp | 8 ++------ source/render/offscreenview.h | 14 +++++++------- source/render/rendertarget.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/source/render/offscreenview.cpp b/source/render/offscreenview.cpp index 71851c72..a79de1db 100644 --- a/source/render/offscreenview.cpp +++ b/source/render/offscreenview.cpp @@ -4,12 +4,8 @@ namespace Msp { namespace GL { -OffscreenView::OffscreenView(Framebuffer &t): - target(t) -{ } - -OffscreenView::OffscreenView(RenderTarget &t): - target(t.get_framebuffer()) +OffscreenView::OffscreenView(unsigned w, unsigned h, const FrameFormat &f): + target(w, h, f) { } } // namespace GL diff --git a/source/render/offscreenview.h b/source/render/offscreenview.h index e845aea2..bd2e22e2 100644 --- a/source/render/offscreenview.h +++ b/source/render/offscreenview.h @@ -2,28 +2,28 @@ #define MSP_GL_OFFSCREENVIEW_H_ #include "mspgl_api.h" +#include "rendertarget.h" #include "view.h" namespace Msp { namespace GL { -class Framebuffer; -class RenderTarget; - /** A View targeting an offscreen framebuffer. */ class MSPGL_API OffscreenView: public View { private: - Framebuffer ⌖ + RenderTarget target; public: - OffscreenView(Framebuffer &); - OffscreenView(RenderTarget &); + OffscreenView(unsigned, unsigned, const FrameFormat &); + + const Texture2D &get_target_texture(unsigned i = 0) const { return target.get_target_texture(i); } + const Texture2D &get_target_texture(FrameAttachment a) const { return target.get_target_texture(a); } private: - virtual const Framebuffer &get_target() const { return target; } + virtual const Framebuffer &get_target() const { return target.get_framebuffer(); } }; } // namespace GL diff --git a/source/render/rendertarget.h b/source/render/rendertarget.h index 1646abce..f3406f0b 100644 --- a/source/render/rendertarget.h +++ b/source/render/rendertarget.h @@ -34,7 +34,7 @@ public: unsigned get_width() const { return width; } unsigned get_height() const { return height; } const FrameFormat &get_format() const { return fbo.get_format(); } - Framebuffer &get_framebuffer() { return fbo; } + const Framebuffer &get_framebuffer() const { return fbo; } const Texture2D &get_target_texture(unsigned) const; const Texture2D &get_target_texture(FrameAttachment) const; -- 2.45.2