DesertPillars::DesertPillars(int, char **):
window(display, opts.wnd_opts),
- gl_ctx(window, opts.gl_opts),
+ gl_device(window, opts.gl_opts),
keyboard(window),
resources(&res_mgr),
- view(window, gl_ctx),
+ view(window),
camera(resources.get<GL::Camera>("Camera.camera")),
lighting(resources.get<GL::Lighting>("Desert.lightn")),
sphere(resources.get<GL::Object>("Sphere.object")),
#include <msp/core/application.h>
#include <msp/datafile/directorysource.h>
#include <msp/gl/camera.h>
+#include <msp/gl/device.h>
#include <msp/gl/environmentmap.h>
#include <msp/gl/objectinstance.h>
#include <msp/gl/orderedscene.h>
#include <msp/gl/technique.h>
#include <msp/gl/windowview.h>
#include <msp/graphics/display.h>
-#include <msp/graphics/glcontext.h>
#include <msp/graphics/window.h>
#include <msp/input/keyboard.h>
#include <msp/time/timestamp.h>
Msp::Graphics::Display display;
Options opts;
Msp::Graphics::Window window;
- Msp::Graphics::GLContext gl_ctx;
+ Msp::GL::Device gl_device;
Msp::Input::Keyboard keyboard;
Msp::GL::ResourceManager res_mgr;
Resources resources;
--- /dev/null
+#include "device_backend.h"
+
+namespace Msp {
+namespace GL {
+
+OpenGLDevice::OpenGLDevice(Graphics::Window &wnd, const Graphics::GLOptions &opts):
+ context(wnd, opts)
+{ }
+
+} // namespace GL
+} // namespace Msp
--- /dev/null
+#ifndef MSP_GL_DEVICE_BACKEND_H_
+#define MSP_GL_DEVICE_BACKEND_H_
+
+#include <msp/core/noncopyable.h>
+#include <msp/graphics/glcontext.h>
+
+namespace Msp {
+namespace GL {
+
+class OpenGLDevice: public NonCopyable
+{
+protected:
+ Graphics::GLContext context;
+
+ OpenGLDevice(Graphics::Window &, const Graphics::GLOptions &);
+
+ Graphics::GLContext &get_context() { return context; }
+};
+
+using DeviceBackend = OpenGLDevice;
+using DeviceOptions = Graphics::GLOptions;
+
+} // namespace GL
+} // namespace Msp
+
+#endif
--- /dev/null
+#include "device.h"
+#include "error.h"
+
+namespace Msp {
+namespace GL {
+
+Device *Device::current = 0;
+
+Device::Device(Graphics::Window &w, const DeviceOptions &o):
+ DeviceBackend(w, o)
+{
+ current = this;
+}
+
+Device::~Device()
+{
+ if(this==current)
+ current = 0;
+}
+
+Device &Device::get_current()
+{
+ if(!current)
+ throw invalid_operation("no current device");
+ return *current;
+}
+
+} // namespace GL
+} // namespace Msp
--- /dev/null
+#ifndef MSP_GL_DEVICE_H_
+#define MSP_GL_DEVICE_H_
+
+#include <msp/graphics/window.h>
+#include "device_backend.h"
+
+namespace Msp {
+namespace GL {
+
+/**
+Represents a graphics device. An instance must be created to use the library.
+*/
+class Device: public DeviceBackend
+{
+ friend DeviceBackend;
+
+private:
+ static Device *current;
+
+public:
+ Device(Graphics::Window &, const DeviceOptions & = DeviceOptions());
+ ~Device();
+
+ using DeviceBackend::get_context;
+
+ static Device &get_current();
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
namespace Msp {
namespace GL {
-WindowView::WindowView(Graphics::Window &w, Graphics::GLContext &c):
+WindowView::WindowView(Graphics::Window &w):
View(Framebuffer::system()),
window(w),
- context(c)
+ device(Device::get_current())
{
window.signal_resize.connect(sigc::mem_fun(this, &WindowView::window_resized));
window_resized(window.get_width(), window.get_height());
void WindowView::render(Renderer &renderer)
{
View::render(renderer);
- context.swap_buffers();
+ device.get_context().swap_buffers();
}
void WindowView::window_resized(unsigned w, unsigned h)
#define MSP_GL_WINDOWVIEW_H_
#include <sigc++/trackable.h>
-#include <msp/graphics/glcontext.h>
#include <msp/graphics/window.h>
+#include "device.h"
#include "view.h"
namespace Msp {
{
private:
Graphics::Window &window;
- Graphics::GLContext &context;
+ Device &device;
public:
- WindowView(Graphics::Window &, Graphics::GLContext &);
+ WindowView(Graphics::Window &);
Graphics::Window &get_window() { return window; }
- Graphics::GLContext &get_context() { return context; }
virtual unsigned get_width() const { return window.get_width(); }
virtual unsigned get_height() const { return window.get_height(); }
#include <msp/datafile/packsource.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
-#include <msp/graphics/simplewindow.h>
+#include <msp/graphics/display.h>
+#include <msp/graphics/window.h>
#include <msp/gl/animatedobject.h>
#include <msp/gl/animation.h>
#include <msp/gl/animationplayer.h>
#include <msp/gl/blend.h>
#include <msp/gl/camera.h>
+#include <msp/gl/device.h>
#include <msp/gl/directionallight.h>
#include <msp/gl/framebuffer.h>
#include <msp/gl/lighting.h>
Options opts;
Graphics::Display display;
Graphics::Window window;
- Graphics::GLContext gl_ctx;
+ GL::Device gl_device;
Input::Mouse mouse;
Resources resources;
GL::WindowView view;
Viewer::Viewer(int argc, char **argv):
opts(argc, argv),
window(display, opts.wnd_opts),
- gl_ctx(window, opts.gl_opts),
+ gl_device(window, opts.gl_opts),
mouse(window),
- view(window, gl_ctx),
+ view(window),
sequence(0),
renderable(0),
anim_object(0),