diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-03-05 16:07:58 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-06 16:12:51 +0100 |
commit | 4737a45383911fcddf93f0a33e7e25246a5da07e (patch) | |
tree | a41a32f4d05297ede3c6d685cabf81a0f6dadcdc /src/mbgl/gl | |
parent | f13c2b86e427e29a856ca8f0f79379203c61f431 (diff) | |
download | qtlocation-mapboxgl-4737a45383911fcddf93f0a33e7e25246a5da07e.tar.gz |
[core] move IndexBuffer to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/gl/index_buffer.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/gl/program.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/gl/vertex_array.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/gl/vertex_array.hpp | 7 |
6 files changed, 33 insertions, 20 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 72d59737f3..6fda803a94 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -1,5 +1,6 @@ #include <mbgl/gl/context.hpp> #include <mbgl/gl/enum.hpp> +#include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/debugging_extension.hpp> #include <mbgl/gl/vertex_array_extension.hpp> #include <mbgl/gl/program_binary_extension.hpp> @@ -261,21 +262,22 @@ void Context::updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::si MBGL_CHECK_ERROR(glBufferSubData(GL_ARRAY_BUFFER, 0, size, data)); } -UniqueBuffer Context::createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage) { +std::unique_ptr<const gfx::IndexBufferResource> +Context::createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; bindVertexArray = 0; globalVertexArrayState.indexBuffer = result; MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, static_cast<GLenum>(usage))); - return result; + return std::make_unique<gl::IndexBufferResource>(std::move(result)); } -void Context::updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size) { +void Context::updateIndexBuffer(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; - globalVertexArrayState.indexBuffer = buffer; + globalVertexArrayState.indexBuffer = reinterpret_cast<const gl::IndexBufferResource&>(resource).buffer; MBGL_CHECK_ERROR(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, size, data)); } diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index ad62853495..2fe0d788bf 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -8,7 +8,7 @@ #include <mbgl/gl/renderbuffer.hpp> #include <mbgl/gl/framebuffer.hpp> #include <mbgl/gl/vertex_buffer.hpp> -#include <mbgl/gl/index_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> @@ -80,17 +80,17 @@ public: } template <class DrawMode> - IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { - return IndexBuffer { + gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { + return { v.elements(), createIndexBuffer(v.data(), v.bytes(), usage) }; } template <class DrawMode> - void updateIndexBuffer(IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) { + void updateIndexBuffer(gfx::IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) { assert(v.elements() == buffer.elements); - updateIndexBuffer(buffer.buffer, v.data(), v.bytes()); + updateIndexBuffer(*buffer.resource, v.data(), v.bytes()); } template <RenderbufferType type> @@ -276,8 +276,8 @@ private: UniqueBuffer createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage); void updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); - UniqueBuffer createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage); - void updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); + std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage); + void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size); UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType); void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType); UniqueFramebuffer createFramebuffer(); diff --git a/src/mbgl/gl/index_buffer.hpp b/src/mbgl/gl/index_buffer.hpp index 3b66e2b69c..2da25fdb96 100644 --- a/src/mbgl/gl/index_buffer.hpp +++ b/src/mbgl/gl/index_buffer.hpp @@ -1,13 +1,16 @@ #pragma once +#include <mbgl/gfx/index_buffer.hpp> #include <mbgl/gl/object.hpp> namespace mbgl { namespace gl { -class IndexBuffer { +class IndexBufferResource : public gfx::IndexBufferResource { public: - std::size_t elements; + IndexBufferResource(UniqueBuffer&& buffer_) : buffer(std::move(buffer_)) { + } + UniqueBuffer buffer; }; diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 45aaa3eebb..6d3a4ce266 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -4,7 +4,7 @@ #include <mbgl/gl/object.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/gl/vertex_buffer.hpp> -#include <mbgl/gl/index_buffer.hpp> +#include <mbgl/gfx/index_buffer.hpp> #include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/uniform.hpp> @@ -120,9 +120,9 @@ public: gfx::ColorMode colorMode, gfx::CullFaceMode cullFaceMode, const UniformValues& uniformValues, - VertexArray& vertexArray, + gl::VertexArray& vertexArray, const AttributeBindings& attributeBindings, - const IndexBuffer& indexBuffer, + const gfx::IndexBuffer& indexBuffer, std::size_t indexOffset, std::size_t indexLength) { static_assert(std::is_same<Primitive, typename DrawMode::Primitive>::value, "incompatible draw mode"); @@ -138,7 +138,7 @@ public: Uniforms::bind(uniformsState, uniformValues); vertexArray.bind(context, - indexBuffer.buffer, + indexBuffer, Attributes::toBindingArray(attributeLocations, attributeBindings)); context.draw(drawMode.primitiveType, diff --git a/src/mbgl/gl/vertex_array.cpp b/src/mbgl/gl/vertex_array.cpp index 0892c3b08b..a73e50ae73 100644 --- a/src/mbgl/gl/vertex_array.cpp +++ b/src/mbgl/gl/vertex_array.cpp @@ -1,12 +1,15 @@ #include <mbgl/gl/vertex_array.hpp> +#include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/context.hpp> namespace mbgl { namespace gl { -void VertexArray::bind(Context& context, BufferID indexBuffer, const AttributeBindingArray& bindings) { +void VertexArray::bind(Context& context, + const gfx::IndexBuffer& indexBuffer, + const AttributeBindingArray& bindings) { context.bindVertexArray = state->vertexArray; - state->indexBuffer = indexBuffer; + state->indexBuffer = reinterpret_cast<const gl::IndexBufferResource&>(*indexBuffer.resource).buffer; state->bindings.reserve(bindings.size()); for (AttributeLocation location = 0; location < bindings.size(); ++location) { diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp index 604754f672..70413050b2 100644 --- a/src/mbgl/gl/vertex_array.hpp +++ b/src/mbgl/gl/vertex_array.hpp @@ -9,6 +9,11 @@ #include <memory> namespace mbgl { + +namespace gfx { +class IndexBuffer; +} // namespace gfx + namespace gl { class Context; @@ -56,7 +61,7 @@ public: : state(std::move(state_)) { } - void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&); + void bind(Context&, const gfx::IndexBuffer&, const AttributeBindingArray&); private: UniqueVertexArrayState state; |