From: Mikko Rasa Date: Thu, 31 Oct 2019 11:47:22 +0000 (+0200) Subject: Support rendering View with an externally provided Renderer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d531a1f0a8ea50eb6ff1a372aca81e827e1d2034;p=libs%2Fgl.git Support rendering View with an externally provided Renderer This can be useful if an OffscreenView is used to render a sub-scene in some renderable's setup_frame function. --- diff --git a/source/view.cpp b/source/view.cpp index fe783110..ad6e266c 100644 --- a/source/view.cpp +++ b/source/view.cpp @@ -25,12 +25,19 @@ void View::set_content(Renderable *r) } void View::render() +{ + Renderer renderer; + render(renderer); +} + +void View::render(Renderer &renderer) { Bind bind_fbo(target); target.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); if(content) { - Renderer renderer(camera); + Renderer::Push push(renderer); + renderer.set_camera(*camera); content->setup_frame(renderer); content->render(renderer); content->finish_frame(); diff --git a/source/view.h b/source/view.h index cf0f4d64..b34ae5c7 100644 --- a/source/view.h +++ b/source/view.h @@ -9,6 +9,7 @@ namespace GL { class Camera; class Renderable; +class Renderer; /** Manages the presentation of rendering results on the screen. @@ -31,6 +32,7 @@ public: void set_content(Renderable *); virtual void render(); + virtual void render(Renderer &); }; } // namespace GL diff --git a/source/windowview.cpp b/source/windowview.cpp index a11f738c..2cce075c 100644 --- a/source/windowview.cpp +++ b/source/windowview.cpp @@ -15,9 +15,9 @@ WindowView::WindowView(Graphics::Window &w, Graphics::GLContext &c): window_resized(window.get_width(), window.get_height()); } -void WindowView::render() +void WindowView::render(Renderer &renderer) { - View::render(); + View::render(renderer); context.swap_buffers(); } diff --git a/source/windowview.h b/source/windowview.h index 6ba93f88..0c5e1b1d 100644 --- a/source/windowview.h +++ b/source/windowview.h @@ -23,7 +23,7 @@ public: virtual unsigned get_width() const { return window.get_width(); } virtual unsigned get_height() const { return window.get_height(); } - virtual void render(); + virtual void render(Renderer &); private: void window_resized(unsigned, unsigned);