]> git.tdb.fi Git - libs/gl.git/commitdiff
Support rendering View with an externally provided Renderer
authorMikko Rasa <tdb@tdb.fi>
Thu, 31 Oct 2019 11:47:22 +0000 (13:47 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 1 Nov 2019 08:20:39 +0000 (10:20 +0200)
This can be useful if an OffscreenView is used to render a sub-scene in
some renderable's setup_frame function.

source/view.cpp
source/view.h
source/windowview.cpp
source/windowview.h

index fe783110fefa8551620d90d8384c4e48af8bf7d8..ad6e266c4468ba477e9f8f72ad55423fce8ee8b1 100644 (file)
@@ -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();
index cf0f4d64ed8d8feceabdcf10522782ce97c335b0..b34ae5c75abf070ecd1f9100548744d773b9b7d2 100644 (file)
@@ -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
index a11f738c87915d7b7cec975d25f69f6aae0cdfc6..2cce075c9b5f80509c5bc98e1fc889a4d63039ae 100644 (file)
@@ -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();
 }
 
index 6ba93f88b735e44e30e9182fc8bda1daae30091f..0c5e1b1d72b796b15a7133b3ad54609956e81367 100644 (file)
@@ -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);