diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/gl/attribute.hpp | 22 | ||||
-rw-r--r-- | src/mbgl/gl/context.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/gl/types.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/vertex_array.hpp | 17 |
4 files changed, 34 insertions, 12 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index 1f60c8c980..fa6c2ddeab 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -12,6 +12,7 @@ #include <functional> #include <string> #include <array> +#include <limits> namespace mbgl { namespace gl { @@ -30,12 +31,12 @@ template <> struct DataTypeOf<float> : std::integral_constant<DataType, DataT class AttributeBinding { public: DataType attributeType; - std::size_t attributeSize; - std::size_t attributeOffset; + uint8_t attributeSize; + uint32_t attributeOffset; BufferID vertexBuffer; - std::size_t vertexSize; - std::size_t vertexOffset; + uint32_t vertexSize; + uint32_t vertexOffset; friend bool operator==(const AttributeBinding& lhs, const AttributeBinding& rhs) { @@ -71,20 +72,25 @@ public: std::size_t attributeIndex, std::size_t attributeSize = N) { static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout"); + assert(attributeSize >= 1); + assert(attributeSize <= 4); + assert(Vertex::attributeOffsets[attributeIndex] <= std::numeric_limits<uint32_t>::max()); + static_assert(sizeof(Vertex) <= std::numeric_limits<uint32_t>::max(), "vertex too large"); return AttributeBinding { DataTypeOf<T>::value, - attributeSize, - Vertex::attributeOffsets[attributeIndex], + static_cast<uint8_t>(attributeSize), + static_cast<uint32_t>(Vertex::attributeOffsets[attributeIndex]), buffer.buffer, - sizeof(Vertex), + static_cast<uint32_t>(sizeof(Vertex)), 0, }; } static optional<Binding> offsetBinding(const optional<Binding>& binding, std::size_t vertexOffset) { + assert(vertexOffset <= std::numeric_limits<uint32_t>::max()); if (binding) { AttributeBinding result = *binding; - result.vertexOffset = vertexOffset; + result.vertexOffset = static_cast<uint32_t>(vertexOffset); return result; } else { return binding; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index f7d210d52e..35683cff89 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -285,11 +285,12 @@ VertexArray Context::createVertexArray() { if (supportsVertexArrays()) { VertexArrayID id = 0; MBGL_CHECK_ERROR(vertexArray->genVertexArrays(1, &id)); - return { std::make_unique<VertexArrayState>(UniqueVertexArray(std::move(id), { this }), *this) }; + UniqueVertexArray vao(std::move(id), { this }); + return { UniqueVertexArrayState(new VertexArrayState(std::move(vao), *this), VertexArrayStateDeleter { true })}; } else { // On GL implementations which do not support vertex arrays, attribute bindings are global state. // So return a VertexArray which shares our global state tracking and whose deleter is a no-op. - return { UniqueVertexArrayState(&globalVertexArrayState, [] (VertexArrayState*) {}) }; + return { UniqueVertexArrayState(&globalVertexArrayState, VertexArrayStateDeleter { false }) }; } } diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index 058bc226b8..452c882ac9 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -24,7 +24,7 @@ enum class ShaderType : uint32_t { Fragment = 0x8B30 }; -enum class DataType : uint32_t { +enum class DataType : uint16_t { Byte = 0x1400, UnsignedByte = 0x1401, Short = 0x1402, diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp index 9ccf48d9bd..46c67017bb 100644 --- a/src/mbgl/gl/vertex_array.hpp +++ b/src/mbgl/gl/vertex_array.hpp @@ -40,7 +40,22 @@ private: } }; -using UniqueVertexArrayState = std::unique_ptr<VertexArrayState, std::function<void (VertexArrayState*)>>; +class VertexArrayStateDeleter { +public: + VertexArrayStateDeleter(bool destroy_) + : destroy(destroy_) {} + + void operator()(VertexArrayState* ptr) const { + if (destroy) { + delete ptr; + } + } + +private: + bool destroy; +}; + +using UniqueVertexArrayState = std::unique_ptr<VertexArrayState, VertexArrayStateDeleter>; class VertexArray { public: |