| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string> |
| 4 |
#include <sigc++/signal.h> |
| 5 |
#include <GL/glew.h> |
| 6 |
|
| 7 |
#include "imodule.h" |
| 8 |
|
| 9 |
namespace gl |
| 10 |
{ |
| 11 |
|
| 12 |
// Base type of any object representing a GL context |
| 13 |
class IGLContext |
| 14 |
{ |
| 15 |
public: |
| 16 |
typedef std::shared_ptr<IGLContext> Ptr; |
| 17 |
|
| 18 |
virtual ~IGLContext() {} |
| 19 |
}; |
| 20 |
|
| 21 |
// Interface of the module holding the shared GL context |
| 22 |
// of this application. When the shared GL context has been |
| 23 |
// created or destroyed, the corresponding events are fired. |
| 24 |
class ISharedGLContextHolder : |
| 25 |
public RegisterableModule |
| 26 |
{ |
| 27 |
public: |
| 28 |
virtual ~ISharedGLContextHolder() {} |
| 29 |
|
| 30 |
// Get the shared context object (might be empty) |
| 31 |
virtual const IGLContext::Ptr& getSharedContext() = 0; |
| 32 |
|
| 33 |
// Set the shared context object. Invoking this method |
| 34 |
// while a shared context is already registered will cause an |
| 35 |
// exception to be thrown |
| 36 |
virtual void setSharedContext(const IGLContext::Ptr& context) = 0; |
| 37 |
|
| 38 |
// Fired right after the shared context instance has been registered |
| 39 |
virtual sigc::signal<void>& signal_sharedContextCreated() = 0; |
| 40 |
|
| 41 |
// Fired when the shared context instance has been destroyed |
| 42 |
virtual sigc::signal<void>& signal_sharedContextDestroyed() = 0; |
| 43 |
}; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
const char* const MODULE_GL_CONTEXT_PROVIDER("GLContextProvider"); |
| 48 |
const char* const MODULE_SHARED_GL_CONTEXT("SharedGLContextHolder"); |
| 49 |
|
| 50 |
inline gl::ISharedGLContextHolder& GlobalOpenGLContext() |
| 51 |
{ |
| 52 |
static module::InstanceReference<gl::ISharedGLContextHolder> _reference(MODULE_SHARED_GL_CONTEXT); |
| 53 |
return _reference; |
| 54 |
} |
| 55 |
|
| 56 |
const char* const MODULE_OPENGL("OpenGL"); |
| 57 |
|
| 58 |
class IGLFont |
| 59 |
{ |
| 60 |
public: |
| 61 |
using Ptr = std::shared_ptr<IGLFont>; |
| 62 |
|
| 63 |
enum class Style |
| 64 |
{ |
| 65 |
Sans, // free sans |
| 66 |
Mono, // free mono |
| 67 |
}; |
| 68 |
|
| 69 |
virtual ~IGLFont() {} |
| 70 |
|
| 71 |
// Returns the line spacing of this font |
| 72 |
virtual float getLineHeight() const = 0; |
| 73 |
|
| 74 |
/// \brief Renders \p string at the current raster-position of the current context. |
| 75 |
virtual void drawString(const std::string& string) = 0; |
| 76 |
}; |
| 77 |
|
| 78 |
class OpenGLBinding : |
| 79 |
public RegisterableModule |
| 80 |
{ |
| 81 |
public: |
| 82 |
virtual ~OpenGLBinding() {} |
| 83 |
|
| 84 |
// Acquires a shared reference to the font of the given style and size |
| 85 |
virtual IGLFont::Ptr getFont(IGLFont::Style style, std::size_t size) = 0; |
| 86 |
|
| 87 |
// Deprecated |
| 88 |
virtual int getFontHeight() = 0; |
| 89 |
|
| 90 |
// Deprecated |
| 91 |
/// \brief Renders \p string at the current raster-position of the current context. |
| 92 |
virtual void drawString(const std::string& string) const = 0; |
| 93 |
}; |
| 94 |
|
| 95 |
inline OpenGLBinding& GlobalOpenGL() |
| 96 |
{ |
| 97 |
static module::InstanceReference<OpenGLBinding> _reference(MODULE_OPENGL); |
| 98 |
return _reference; |
| 99 |
} |