| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,163 @@ |
| 1 |
+/// Include guard |
|
| 2 |
+ |
|
| 3 |
+#ifndef GLBACKEND_HPP_ |
|
| 4 |
+#define GLBACKEND_HPP_ |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+/// Includes |
|
| 8 |
+ |
|
| 9 |
+#include <array> |
|
| 10 |
+#include <functional> |
|
| 11 |
+#include <ostream> |
|
| 12 |
+#include <string> |
|
| 13 |
+#include <utility> |
|
| 14 |
+#include <vector> |
|
| 15 |
+ |
|
| 16 |
+#include <glbase.hpp> |
|
| 17 |
+ |
|
| 18 |
+ |
|
| 19 |
+/// Class definition |
|
| 20 |
+ |
|
| 21 |
+class GLBackend : public GLBase |
|
| 22 |
+{
|
|
| 23 |
+ |
|
| 24 |
+public: |
|
| 25 |
+ |
|
| 26 |
+ //// Context |
|
| 27 |
+ |
|
| 28 |
+ void virtual current() = 0; |
|
| 29 |
+ |
|
| 30 |
+ //// Render loop |
|
| 31 |
+ |
|
| 32 |
+ void virtual swap() = 0; |
|
| 33 |
+ |
|
| 34 |
+ void virtual events() = 0; |
|
| 35 |
+ |
|
| 36 |
+ bool virtual running() const = 0; |
|
| 37 |
+ bool virtual running(bool running) = 0; |
|
| 38 |
+ |
|
| 39 |
+ float virtual time() const = 0; |
|
| 40 |
+ float virtual time(float time) = 0; |
|
| 41 |
+ |
|
| 42 |
+ void run(float dt_fixed = 0.0F); |
|
| 43 |
+ |
|
| 44 |
+ using CallbackUpdate = std::function<void(float t, float dt, bool last)>; |
|
| 45 |
+ using CallbackRender = std::function<void()>; |
|
| 46 |
+ |
|
| 47 |
+ GLBASE_ACCESS(CallbackUpdate, callback_update) |
|
| 48 |
+ GLBASE_ACCESS(CallbackRender, callback_render) |
|
| 49 |
+ |
|
| 50 |
+ //// Input and output |
|
| 51 |
+ |
|
| 52 |
+ using Point = std::array<GLfloat, 2>; |
|
| 53 |
+ using Size = std::array<GLsizei, 2>; |
|
| 54 |
+ |
|
| 55 |
+ void virtual lock(bool lock) = 0; |
|
| 56 |
+ |
|
| 57 |
+ bool virtual key (std::string const & key) const = 0; |
|
| 58 |
+ bool virtual button(int button) const = 0; |
|
| 59 |
+ |
|
| 60 |
+ GLBASE_GET(Point, scroll) |
|
| 61 |
+ GLBASE_GET(Point, position) |
|
| 62 |
+ GLBASE_GET(Point, move) |
|
| 63 |
+ GLBASE_GET(Size, size) |
|
| 64 |
+ |
|
| 65 |
+ using CallbackKey = std::function<void(std::string const &)>; |
|
| 66 |
+ using CallbackButton = std::function<void(int)>; |
|
| 67 |
+ using CallbackScroll = std::function<void(Point)>; |
|
| 68 |
+ using CallbackPosition = std::function<void(Point)>; |
|
| 69 |
+ using CallbackMove = std::function<void(Point)>; |
|
| 70 |
+ using CallbackSize = std::function<void(Size)>; |
|
| 71 |
+ |
|
| 72 |
+ GLBASE_ACCESS(CallbackKey, callback_key) |
|
| 73 |
+ GLBASE_ACCESS(CallbackButton, callback_button) |
|
| 74 |
+ GLBASE_ACCESS(CallbackScroll, callback_scroll) |
|
| 75 |
+ GLBASE_ACCESS(CallbackPosition, callback_position) |
|
| 76 |
+ GLBASE_ACCESS(CallbackMove, callback_move) |
|
| 77 |
+ GLBASE_ACCESS(CallbackSize, callback_size) |
|
| 78 |
+ |
|
| 79 |
+ //// Path |
|
| 80 |
+ |
|
| 81 |
+ GLBASE_ACCESS_GLOBAL(Path, prefix) |
|
| 82 |
+ |
|
| 83 |
+ //// TGA |
|
| 84 |
+ |
|
| 85 |
+ void tga_write( |
|
| 86 |
+ Path const & path |
|
| 87 |
+ ) const; |
|
| 88 |
+ |
|
| 89 |
+ bool tga_compare( |
|
| 90 |
+ Path const & path, |
|
| 91 |
+ bool write_on_failed_read = false |
|
| 92 |
+ ) const; |
|
| 93 |
+ |
|
| 94 |
+ //// Debug |
|
| 95 |
+ |
|
| 96 |
+ std::string virtual debug_info() const; |
|
| 97 |
+ |
|
| 98 |
+protected: |
|
| 99 |
+ |
|
| 100 |
+ //// Special member functions |
|
| 101 |
+ |
|
| 102 |
+ GLBackend(); |
|
| 103 |
+ GLBackend(GLBackend &&) = default; |
|
| 104 |
+ virtual ~GLBackend() = default; |
|
| 105 |
+ |
|
| 106 |
+ void static init_(); |
|
| 107 |
+ |
|
| 108 |
+ //// TGA |
|
| 109 |
+ |
|
| 110 |
+ TGA_ tga_() const; |
|
| 111 |
+ |
|
| 112 |
+ //// Debug |
|
| 113 |
+ |
|
| 114 |
+ void static debug_info_( |
|
| 115 |
+ std::ostream & ostream, |
|
| 116 |
+ std::string const & category, |
|
| 117 |
+ std::vector<std::pair<std::string, std::string>> const & values, |
|
| 118 |
+ char fill = '.' |
|
| 119 |
+ ); |
|
| 120 |
+ |
|
| 121 |
+ void static GLAPIENTRY debug_gl_message_callback_( |
|
| 122 |
+ GLenum source, |
|
| 123 |
+ GLenum type, |
|
| 124 |
+ GLuint id, |
|
| 125 |
+ GLenum severity, |
|
| 126 |
+ GLsizei length, |
|
| 127 |
+ GLchar const * message, |
|
| 128 |
+ void const * user_param |
|
| 129 |
+ ); |
|
| 130 |
+ |
|
| 131 |
+ std::string static debug_gl_message_(std::string message); |
|
| 132 |
+ |
|
| 133 |
+protected: |
|
| 134 |
+ |
|
| 135 |
+ //// Render loop |
|
| 136 |
+ |
|
| 137 |
+ CallbackUpdate callback_update_; |
|
| 138 |
+ CallbackRender callback_render_; |
|
| 139 |
+ |
|
| 140 |
+ //// Input and output |
|
| 141 |
+ |
|
| 142 |
+ Point scroll_; |
|
| 143 |
+ Point position_; |
|
| 144 |
+ Point move_; |
|
| 145 |
+ Size size_; |
|
| 146 |
+ |
|
| 147 |
+ CallbackKey callback_key_; |
|
| 148 |
+ CallbackButton callback_button_; |
|
| 149 |
+ CallbackScroll callback_scroll_; |
|
| 150 |
+ CallbackPosition callback_position_; |
|
| 151 |
+ CallbackMove callback_move_; |
|
| 152 |
+ CallbackSize callback_size_; |
|
| 153 |
+ |
|
| 154 |
+ //// Path |
|
| 155 |
+ |
|
| 156 |
+ Path static thread_local prefix_; |
|
| 157 |
+ |
|
| 158 |
+}; |
|
| 159 |
+ |
|
| 160 |
+ |
|
| 161 |
+/// Include guard |
|
| 162 |
+ |
|
| 163 |
+#endif |