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/gl | |
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/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 46 |
2 files changed, 12 insertions, 42 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 514bc0115e..df304eb7d4 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -246,7 +246,7 @@ void Context::verifyProgramLinkage(ProgramID program_) { } std::unique_ptr<const gfx::VertexBufferResource> -Context::createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) { +Context::createVertexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType usage) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; @@ -255,13 +255,13 @@ Context::createVertexBuffer(const void* data, std::size_t size, const gfx::Buffe return std::make_unique<gl::VertexBufferResource>(std::move(result)); } -void Context::updateVertexBuffer(const gfx::VertexBufferResource& resource, const void* data, std::size_t size) { +void Context::updateVertexBufferResource(const gfx::VertexBufferResource& resource, const void* data, std::size_t size) { vertexBuffer = reinterpret_cast<const gl::VertexBufferResource&>(resource).buffer; MBGL_CHECK_ERROR(glBufferSubData(GL_ARRAY_BUFFER, 0, size, data)); } std::unique_ptr<const gfx::IndexBufferResource> -Context::createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) { +Context::createIndexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType usage) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; @@ -271,7 +271,7 @@ Context::createIndexBuffer(const void* data, std::size_t size, const gfx::Buffer return std::make_unique<gl::IndexBufferResource>(std::move(result)); } -void Context::updateIndexBuffer(const gfx::IndexBufferResource& resource, const void* data, std::size_t size) { +void Context::updateIndexBufferResource(const gfx::IndexBufferResource& resource, const void* data, std::size_t size) { // Be sure to unbind any existing vertex array object before binding the index buffer // so that we don't mess up another VAO bindVertexArray = 0; diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 585ee286c4..70ba1ec107 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/gfx/context.hpp> #include <mbgl/gl/features.hpp> #include <mbgl/gl/object.hpp> #include <mbgl/gl/state.hpp> @@ -7,12 +8,8 @@ #include <mbgl/gl/texture.hpp> #include <mbgl/gl/renderbuffer.hpp> #include <mbgl/gl/framebuffer.hpp> -#include <mbgl/gfx/vertex_buffer.hpp> -#include <mbgl/gfx/index_buffer.hpp> #include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/types.hpp> -#include <mbgl/gfx/vertex_vector.hpp> -#include <mbgl/gfx/index_vector.hpp> #include <mbgl/gfx/draw_mode.hpp> #include <mbgl/gfx/depth_mode.hpp> #include <mbgl/gfx/stencil_mode.hpp> @@ -39,10 +36,10 @@ class Debugging; class ProgramBinary; } // namespace extension -class Context { +class Context final : public gfx::Context { public: Context(); - ~Context(); + ~Context() override; Context(const Context&) = delete; Context& operator=(const Context& other) = delete; @@ -65,34 +62,6 @@ public: #endif optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const; - template <class Vertex> - gfx::VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) { - return { - v.elements(), - createVertexBuffer(v.data(), v.bytes(), usage) - }; - } - - template <class Vertex> - void updateVertexBuffer(gfx::VertexBuffer<Vertex>& buffer, gfx::VertexVector<Vertex>&& v) { - assert(v.elements() == buffer.elements); - updateVertexBuffer(*buffer.resource, v.data(), v.bytes()); - } - - template <class DrawMode> - gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) { - return { - v.elements(), - createIndexBuffer(v.data(), v.bytes(), usage) - }; - } - - template <class DrawMode> - void updateIndexBuffer(gfx::IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) { - assert(v.elements() == buffer.elements); - updateIndexBuffer(*buffer.resource, v.data(), v.bytes()); - } - template <RenderbufferType type> Renderbuffer<type> createRenderbuffer(const Size size) { static_assert(type == RenderbufferType::RGBA || @@ -274,10 +243,11 @@ private: State<value::PointSize> pointSize; #endif // MBGL_USE_GLES2 - std::unique_ptr<const gfx::VertexBufferResource> createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage); - void updateVertexBuffer(const gfx::VertexBufferResource&, const void* data, std::size_t size); - std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage); - void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size); + std::unique_ptr<const gfx::VertexBufferResource> createVertexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType) override; + void updateVertexBufferResource(const gfx::VertexBufferResource&, const void* data, std::size_t size) override; + std::unique_ptr<const gfx::IndexBufferResource> createIndexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType) override; + void updateIndexBufferResource(const gfx::IndexBufferResource&, const void* data, std::size_t size) override; + UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType); void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType); UniqueFramebuffer createFramebuffer(); |