diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-04-02 14:11:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-05-28 16:11:05 +0200 |
commit | 7f9274035bad30980e03574c315904ab7a85fe83 (patch) | |
tree | 7b9cd0f2e2883d6da22611eaa68fae07bb7245b6 /include | |
parent | 33ee7e23de24bd3c076eafef819029cf45451d23 (diff) | |
download | qtlocation-mapboxgl-7f9274035bad30980e03574c315904ab7a85fe83.tar.gz |
[core] refactor program object creation
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/gfx/backend.hpp | 44 | ||||
-rw-r--r-- | include/mbgl/gfx/renderer_backend.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/gl/renderer_backend.hpp | 3 |
3 files changed, 49 insertions, 3 deletions
diff --git a/include/mbgl/gfx/backend.hpp b/include/mbgl/gfx/backend.hpp new file mode 100644 index 0000000000..eed63dfcba --- /dev/null +++ b/include/mbgl/gfx/backend.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <cstdint> +#include <cstdlib> +#include <memory> + +namespace mbgl { +namespace gfx { + +class Backend { +public: + enum class Type : uint8_t { + OpenGL, + }; + + static constexpr Type DefaultType = Type::OpenGL; + + static void SetType(const Type value) { + if (Value(value) != value) { + abort(); // SetType must be called prior to any GetType calls. + } + } + + static Type GetType() { + return Value(DefaultType); + } + + template <typename T, typename... Args> + static std::unique_ptr<T> Create(Args... args) { + return Create<Type::OpenGL, T, Args...>(std::forward<Args>(args)...); + } + +private: + template <Type, typename T, typename... Args> + static std::unique_ptr<T> Create(Args...); + + static Type Value(Type value) { + static const Type type = value; + return type; + } +}; + +} // namespace gfx +} // namespace mbgl diff --git a/include/mbgl/gfx/renderer_backend.hpp b/include/mbgl/gfx/renderer_backend.hpp index 29f6b43a8f..aa76d7e502 100644 --- a/include/mbgl/gfx/renderer_backend.hpp +++ b/include/mbgl/gfx/renderer_backend.hpp @@ -30,6 +30,11 @@ public: // Returns the device's context. Context& getContext(); + template <typename T> + T& getContext() { + return static_cast<T&>(getContext()); + } + bool contextIsShared() const { return contextMode == ContextMode::Shared; } diff --git a/include/mbgl/gl/renderer_backend.hpp b/include/mbgl/gl/renderer_backend.hpp index ba87e4ce4f..cfa28ddaeb 100644 --- a/include/mbgl/gl/renderer_backend.hpp +++ b/include/mbgl/gl/renderer_backend.hpp @@ -17,9 +17,6 @@ public: RendererBackend(gfx::ContextMode); ~RendererBackend() override; - // Returns the backend's context which manages OpenGL state. - Context& getGLContext(); - // Called prior to rendering to update the internally assumed OpenGL state. virtual void updateAssumedState() = 0; |