diff options
Diffstat (limited to 'src/mbgl/gl/segment.hpp')
-rw-r--r-- | src/mbgl/gl/segment.hpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp index 8f74afd237..bb9f2f1ee8 100644 --- a/src/mbgl/gl/segment.hpp +++ b/src/mbgl/gl/segment.hpp @@ -1,12 +1,16 @@ #pragma once +#include <mbgl/gl/context.hpp> +#include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/util/optional.hpp> #include <cstddef> +#include <vector> namespace mbgl { namespace gl { +template <class Attributes> class Segment { public: Segment(std::size_t vertexOffset_, @@ -24,13 +28,38 @@ public: std::size_t vertexLength; std::size_t indexLength; + void bind(Context& context, + BufferID indexBuffer_, + const typename Attributes::Locations& attributeLocations, + const typename Attributes::Bindings& attributeBindings_) const { + if (!vao) { + vao = context.createVertexArray(); + context.vertexBuffer.setDirty(); + } + + context.vertexArrayObject = *vao; + + if (indexBuffer != indexBuffer_) { + indexBuffer = indexBuffer_; + context.elementBuffer.setDirty(); + context.elementBuffer = indexBuffer_; + } + + Attributes::bind(context, + attributeLocations, + variableBindings, + attributeBindings_, + vertexOffset); + } + private: - friend class Context; mutable optional<UniqueVertexArray> vao; + mutable optional<BufferID> indexBuffer; + mutable typename Attributes::VariableBindings variableBindings; }; template <class Attributes> -class SegmentVector : public std::vector<Segment> { +class SegmentVector : public std::vector<Segment<Attributes>> { public: SegmentVector() = default; }; |