#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)
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()
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
#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;
/**
*/
class View: public sigc::trackable
{
-private:
- Graphics::Window &window;
- Graphics::GLContext &context;
+protected:
Framebuffer ⌖
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 *);
// Deprecated
void synchronize_camera_aspect(Camera &);
- void render();
-
-private:
- void window_resized(unsigned, unsigned);
+ virtual void render();
};
} // namespace GL
--- /dev/null
+#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
--- /dev/null
+#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