From: Mikko Rasa Date: Sun, 3 Nov 2019 17:41:37 +0000 (+0200) Subject: Use a persistent Renderer in View X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e8e31f9203eb6a2a83a30341505b5360e9ffd0fb;p=libs%2Fgl.git Use a persistent Renderer in View --- diff --git a/source/view.cpp b/source/view.cpp index ad6e266c..8c77054f 100644 --- a/source/view.cpp +++ b/source/view.cpp @@ -9,9 +9,15 @@ namespace GL { View::View(Framebuffer &t): target(t), camera(0), - content(0) + content(0), + internal_renderer(0) { } +View::~View() +{ + delete internal_renderer; +} + void View::set_camera(Camera *c) { camera = c; @@ -26,8 +32,9 @@ void View::set_content(Renderable *r) void View::render() { - Renderer renderer; - render(renderer); + if(!internal_renderer) + internal_renderer = new Renderer; + render(*internal_renderer); } void View::render(Renderer &renderer) diff --git a/source/view.h b/source/view.h index b34ae5c7..df623c3a 100644 --- a/source/view.h +++ b/source/view.h @@ -20,10 +20,12 @@ protected: Framebuffer ⌖ Camera *camera; Renderable *content; + Renderer *internal_renderer; View(Framebuffer &); - public: + virtual ~View(); + virtual unsigned get_width() const { return target.get_width(); } virtual unsigned get_height() const { return target.get_height(); } float get_aspect_ratio() const { return static_cast(get_width())/get_height(); }