summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-03-05 18:36:41 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-03-06 16:12:51 +0100
commit3a57aa65d75af0d71bda9c1bde8fe8118ce7c7d1 (patch)
tree5e5e149094a45a1b3b0457b2f698661c66741428 /src/mbgl/gl
parent4737a45383911fcddf93f0a33e7e25246a5da07e (diff)
downloadqtlocation-mapboxgl-3a57aa65d75af0d71bda9c1bde8fe8118ce7c7d1.tar.gz
[core] move VertexBuffer<> to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/attribute.hpp19
-rw-r--r--src/mbgl/gl/context.cpp10
-rw-r--r--src/mbgl/gl/context.hpp14
-rw-r--r--src/mbgl/gl/program.hpp2
-rw-r--r--src/mbgl/gl/value.cpp3
-rw-r--r--src/mbgl/gl/vertex_buffer.hpp8
6 files changed, 31 insertions, 25 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index 53ba71a89f..dc112c1ad8 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -2,7 +2,7 @@
#include <mbgl/gfx/attribute.hpp>
#include <mbgl/gl/types.hpp>
-#include <mbgl/gl/vertex_buffer.hpp>
+#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/util/ignore.hpp>
#include <mbgl/util/indexed_tuple.hpp>
#include <mbgl/util/optional.hpp>
@@ -22,13 +22,14 @@ class AttributeBinding {
public:
gfx::AttributeDescriptor attribute;
uint8_t vertexStride;
- BufferID vertexBuffer;
+ const gfx::VertexBufferResource* vertexBufferResource;
uint32_t vertexOffset;
- friend bool operator==(const AttributeBinding& lhs,
- const AttributeBinding& rhs) {
- return std::tie(lhs.attribute, lhs.vertexStride, lhs.vertexBuffer, lhs.vertexOffset)
- == std::tie(rhs.attribute, rhs.vertexStride, rhs.vertexBuffer, rhs.vertexOffset);
+ friend bool operator==(const AttributeBinding& lhs, const AttributeBinding& rhs) {
+ return lhs.attribute == rhs.attribute &&
+ lhs.vertexStride == rhs.vertexStride &&
+ lhs.vertexBufferResource == rhs.vertexBufferResource &&
+ lhs.vertexOffset == rhs.vertexOffset;
}
};
@@ -40,12 +41,12 @@ using AttributeBindingArray = std::vector<optional<AttributeBinding>>;
a buffer with only one float for each vertex can be bound to a `vec2` attribute
*/
template <std::size_t I, typename Vertex>
-AttributeBinding attributeBinding(const VertexBuffer<Vertex>& buffer) {
+AttributeBinding attributeBinding(const gfx::VertexBuffer<Vertex>& buffer) {
static_assert(I < gfx::VertexDescriptorOf<Vertex>::data.count, "vertex attribute index out of range");
return {
gfx::VertexDescriptorOf<Vertex>::data.attributes[I],
gfx::VertexDescriptorOf<Vertex>::data.stride,
- buffer.buffer,
+ buffer.resource.get(),
0,
};
}
@@ -106,7 +107,7 @@ public:
return result;
}
- static Bindings bindings(const VertexBuffer<gfx::Vertex<Types>>& buffer) {
+ static Bindings bindings(const gfx::VertexBuffer<gfx::Vertex<Types>>& buffer) {
return Bindings { attributeBinding<TypeIndex<As, As...>::value>(buffer)... };
}
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 6fda803a94..9904c43145 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/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/gl/vertex_array_extension.hpp>
@@ -248,17 +249,18 @@ void Context::verifyProgramLinkage(ProgramID program_) {
throw std::runtime_error("program failed to link");
}
-UniqueBuffer Context::createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage) {
+std::unique_ptr<const gfx::VertexBufferResource>
+Context::createVertexBuffer(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 } };
vertexBuffer = result;
MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, size, data, static_cast<GLenum>(usage)));
- return result;
+ return std::make_unique<gl::VertexBufferResource>(std::move(result));
}
-void Context::updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size) {
- vertexBuffer = buffer;
+void Context::updateVertexBuffer(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));
}
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 2fe0d788bf..4d4a538234 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -7,7 +7,7 @@
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/renderbuffer.hpp>
#include <mbgl/gl/framebuffer.hpp>
-#include <mbgl/gl/vertex_buffer.hpp>
+#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/types.hpp>
@@ -66,17 +66,17 @@ public:
optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const;
template <class Vertex>
- VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const BufferUsage usage = BufferUsage::StaticDraw) {
- return VertexBuffer<Vertex> {
+ gfx::VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const BufferUsage usage = BufferUsage::StaticDraw) {
+ return {
v.elements(),
createVertexBuffer(v.data(), v.bytes(), usage)
};
}
template <class Vertex>
- void updateVertexBuffer(VertexBuffer<Vertex>& buffer, gfx::VertexVector<Vertex>&& v) {
+ void updateVertexBuffer(gfx::VertexBuffer<Vertex>& buffer, gfx::VertexVector<Vertex>&& v) {
assert(v.elements() == buffer.elements);
- updateVertexBuffer(buffer.buffer, v.data(), v.bytes());
+ updateVertexBuffer(*buffer.resource, v.data(), v.bytes());
}
template <class DrawMode>
@@ -274,8 +274,8 @@ private:
State<value::PointSize> pointSize;
#endif // MBGL_USE_GLES2
- UniqueBuffer createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage);
- void updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size);
+ std::unique_ptr<const gfx::VertexBufferResource> createVertexBuffer(const void* data, std::size_t size, const BufferUsage 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 BufferUsage usage);
void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size);
UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType);
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 6d3a4ce266..df48dfea38 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -3,7 +3,7 @@
#include <mbgl/gl/types.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/context.hpp>
-#include <mbgl/gl/vertex_buffer.hpp>
+#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/attribute.hpp>
diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp
index b290cde50c..b205f0f358 100644
--- a/src/mbgl/gl/value.cpp
+++ b/src/mbgl/gl/value.cpp
@@ -1,5 +1,6 @@
#include <mbgl/gl/value.hpp>
#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/vertex_array_extension.hpp>
#include <mbgl/gl/enum.hpp>
@@ -485,7 +486,7 @@ GLint components(const gfx::AttributeDataType type) {
void VertexAttribute::Set(const optional<AttributeBinding>& binding, Context& context, AttributeLocation location) {
if (binding) {
- context.vertexBuffer = binding->vertexBuffer;
+ context.vertexBuffer = reinterpret_cast<const gl::VertexBufferResource&>(*binding->vertexBufferResource).buffer;
MBGL_CHECK_ERROR(glEnableVertexAttribArray(location));
MBGL_CHECK_ERROR(glVertexAttribPointer(
location,
diff --git a/src/mbgl/gl/vertex_buffer.hpp b/src/mbgl/gl/vertex_buffer.hpp
index 94963ce878..95e5e75d45 100644
--- a/src/mbgl/gl/vertex_buffer.hpp
+++ b/src/mbgl/gl/vertex_buffer.hpp
@@ -1,14 +1,16 @@
#pragma once
+#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/gl/object.hpp>
namespace mbgl {
namespace gl {
-template <class V>
-class VertexBuffer {
+class VertexBufferResource : public gfx::VertexBufferResource {
public:
- std::size_t elements;
+ VertexBufferResource(UniqueBuffer&& buffer_) : buffer(std::move(buffer_)) {
+ }
+
UniqueBuffer buffer;
};