diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-03-06 10:38:58 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-06 16:12:51 +0100 |
commit | 8a8291d8f4ce39d341f42c6d14b2aaad28cd854e (patch) | |
tree | 14204115c7087ed4ccf6e38b40a84dea33575b00 /src/mbgl/gfx/context.hpp | |
parent | ec42b2a5a409d767655a61228f951e1f37835d44 (diff) | |
download | qtlocation-mapboxgl-8a8291d8f4ce39d341f42c6d14b2aaad28cd854e.tar.gz |
[core] introduce gfx::Context and move Buffer creation/update methods to it
Diffstat (limited to 'src/mbgl/gfx/context.hpp')
-rw-r--r-- | src/mbgl/gfx/context.hpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp new file mode 100644 index 0000000000..b57cfcb65c --- /dev/null +++ b/src/mbgl/gfx/context.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include <mbgl/gfx/vertex_vector.hpp> +#include <mbgl/gfx/vertex_buffer.hpp> +#include <mbgl/gfx/index_vector.hpp> +#include <mbgl/gfx/index_buffer.hpp> +#include <mbgl/gfx/types.hpp> + +namespace mbgl { +namespace gfx { + +class Context { +protected: + Context() = default; + +public: + Context(Context&&) = delete; + Context(const Context&) = delete; + Context& operator=(Context&& other) = delete; + Context& operator=(const Context& other) = delete; + virtual ~Context() = default; + +public: + template <class Vertex> + VertexBuffer<Vertex> + createVertexBuffer(VertexVector<Vertex>&& v, + const BufferUsageType usage = BufferUsageType::StaticDraw) { + return { v.elements(), createVertexBufferResource(v.data(), v.bytes(), usage) }; + } + + template <class Vertex> + void updateVertexBuffer(VertexBuffer<Vertex>& buffer, VertexVector<Vertex>&& v) { + assert(v.elements() == buffer.elements); + updateVertexBufferResource(*buffer.resource, v.data(), v.bytes()); + } + + template <class DrawMode> + IndexBuffer createIndexBuffer(IndexVector<DrawMode>&& v, + const BufferUsageType usage = BufferUsageType::StaticDraw) { + return { v.elements(), createIndexBufferResource(v.data(), v.bytes(), usage) }; + } + + template <class DrawMode> + void updateIndexBuffer(IndexBuffer& buffer, IndexVector<DrawMode>&& v) { + assert(v.elements() == buffer.elements); + updateIndexBufferResource(*buffer.resource, v.data(), v.bytes()); + } + +protected: + virtual std::unique_ptr<const VertexBufferResource> + createVertexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0; + virtual void + updateVertexBufferResource(const VertexBufferResource&, const void* data, std::size_t size) = 0; + + virtual std::unique_ptr<const IndexBufferResource> + createIndexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0; + virtual void + updateIndexBufferResource(const IndexBufferResource&, const void* data, std::size_t size) = 0; +}; + +} // namespace gfx +} // namespace mbgl |