]> git.tdb.fi Git - libs/gl.git/commitdiff
Split the Window-specific parts out of View
authorMikko Rasa <tdb@tdb.fi>
Tue, 19 Dec 2017 09:21:55 +0000 (11:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 19 Dec 2017 09:21:55 +0000 (11:21 +0200)
This should allow other types of views, such as VR::StereoView, to derive
from GL::View and present a uniform API.

source/view.cpp
source/view.h
source/windowview.cpp [new file with mode: 0644]
source/windowview.h [new file with mode: 0644]

index b4dcca99cc4a4f6b6bb6839df1ee39bf8f99fc23..f531905f59e1ae387908538c4198489f27fa79ad 100644 (file)
@@ -1,30 +1,22 @@
 #include "camera.h"
-#include "framebuffer.h"
 #include "renderable.h"
 #include "renderer.h"
 #include "view.h"
 
-using namespace std;
-
 namespace Msp {
 namespace GL {
 
-View::View(Graphics::Window &w, Graphics::GLContext &c):
-       window(w),
-       context(c),
+View::View():
        target(Framebuffer::system()),
        camera(0),
        content(0)
-{
-       window.signal_resize.connect(sigc::mem_fun(this, &View::window_resized));
-       window_resized(window.get_width(), window.get_height());
-}
+{ }
 
 void View::set_camera(Camera *c)
 {
        camera = c;
        if(camera)
-               camera->set_aspect(static_cast<float>(window.get_width())/window.get_height());
+               camera->set_aspect(get_aspect());
 }
 
 void View::set_content(Renderable *r)
@@ -35,7 +27,7 @@ void View::set_content(Renderable *r)
 void View::synchronize_camera_aspect(Camera &c)
 {
        synced_cameras.push_back(&c);
-       c.set_aspect(static_cast<float>(window.get_width())/window.get_height());
+       c.set_aspect(get_aspect());
 }
 
 void View::render()
@@ -48,17 +40,6 @@ void View::render()
                content->render(renderer);
                content->finish_frame();
        }
-       context.swap_buffers();
-}
-
-void View::window_resized(unsigned w, unsigned h)
-{
-       target.viewport(0, 0, w, h);
-       float aspect = static_cast<float>(w)/h;
-       if(camera)
-               camera->set_aspect(aspect);
-       for(list<Camera *>::iterator i=synced_cameras.begin(); i!=synced_cameras.end(); ++i)
-               (*i)->set_aspect(aspect);
 }
 
 } // namespace GL
index f7f47fc7b48fd7d37f349f73823fee017a3d5ad5..08629fa065ab159725a5d025ca0b4dc1093f488b 100644 (file)
@@ -2,15 +2,12 @@
 #define MSP_GL_VIEW_H_
 
 #include <list>
-#include <sigc++/trackable.h>
-#include <msp/graphics/glcontext.h>
-#include <msp/graphics/window.h>
+#include "framebuffer.h"
 
 namespace Msp {
 namespace GL {
 
 class Camera;
-class Framebuffer;
 class Renderable;
 
 /**
@@ -18,21 +15,17 @@ Manages the presentation of rendering results on the screen.
 */
 class View: public sigc::trackable
 {
-private:
-       Graphics::Window &window;
-       Graphics::GLContext &context;
+protected:
        Framebuffer &target;
        Camera *camera;
        Renderable *content;
        std::list<Camera *> synced_cameras;
 
-public:
-       View(Graphics::Window &, Graphics::GLContext &);
+       View();
 
-       Graphics::Window &get_window() { return window; }
-       Graphics::GLContext &get_context() { return context; }
-       unsigned get_width() const { return window.get_width(); }
-       unsigned get_height() const { return window.get_height(); }
+public:
+       virtual unsigned get_width() const { return target.get_width(); }
+       virtual unsigned get_height() const { return target.get_height(); }
        float get_aspect() const { return static_cast<float>(get_width())/get_height(); }
 
        void set_camera(Camera *);
@@ -41,10 +34,7 @@ public:
        // Deprecated
        void synchronize_camera_aspect(Camera &);
 
-       void render();
-
-private:
-       void window_resized(unsigned, unsigned);
+       virtual void render();
 };
 
 } // namespace GL
diff --git a/source/windowview.cpp b/source/windowview.cpp
new file mode 100644 (file)
index 0000000..61027ac
--- /dev/null
@@ -0,0 +1,34 @@
+#include "camera.h"
+#include "windowview.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+WindowView::WindowView(Graphics::Window &w, Graphics::GLContext &c):
+       window(w),
+       context(c)
+{
+       window.signal_resize.connect(sigc::mem_fun(this, &WindowView::window_resized));
+       window_resized(window.get_width(), window.get_height());
+}
+
+void WindowView::render()
+{
+       View::render();
+       context.swap_buffers();
+}
+
+void WindowView::window_resized(unsigned w, unsigned h)
+{
+       target.viewport(0, 0, w, h);
+       float aspect = static_cast<float>(w)/h;
+       if(camera)
+               camera->set_aspect(aspect);
+       for(list<Camera *>::iterator i=synced_cameras.begin(); i!=synced_cameras.end(); ++i)
+               (*i)->set_aspect(aspect);
+}
+
+} // namespace GL
+} // namespace Msp
diff --git a/source/windowview.h b/source/windowview.h
new file mode 100644 (file)
index 0000000..825601f
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef MSP_GL_WINDOWVIEW_H_
+#define MSP_GL_WINDOWVIEW_H_
+
+#include <sigc++/trackable.h>
+#include <msp/graphics/glcontext.h>
+#include <msp/graphics/window.h>
+#include "view.h"
+
+namespace Msp {
+namespace GL {
+
+class WindowView: public View
+{
+private:
+       Graphics::Window &window;
+       Graphics::GLContext &context;
+
+public:
+       WindowView(Graphics::Window &, Graphics::GLContext &);
+
+       Graphics::Window &get_window() { return window; }
+       Graphics::GLContext &get_context() { return context; }
+       unsigned get_width() const { return window.get_width(); }
+       unsigned get_height() const { return window.get_height(); }
+
+       virtual void render();
+
+private:
+       void window_resized(unsigned, unsigned);
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif