diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-02 17:43:51 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-05 10:52:19 -0700 |
commit | e4310aa87489c2db52d7ff65f71e51cc6c9700b6 (patch) | |
tree | 438e67108779aac6f8787ef7b03644534955bf1f /src/mbgl/gl/attribute.hpp | |
parent | b9b8657d43aa1172e9ca6be162e915006806ee57 (diff) | |
download | qtlocation-mapboxgl-e4310aa87489c2db52d7ff65f71e51cc6c9700b6.tar.gz |
[core] Improve attribute binding API
Diffstat (limited to 'src/mbgl/gl/attribute.hpp')
-rw-r--r-- | src/mbgl/gl/attribute.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp new file mode 100644 index 0000000000..8bc474e967 --- /dev/null +++ b/src/mbgl/gl/attribute.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include <mbgl/gl/types.hpp> +#include <mbgl/gl/shader.hpp> + +#include <cstddef> +#include <limits> +#include <vector> + +namespace mbgl { +namespace gl { + +template <typename T, std::size_t N> +class Attribute { +public: + Attribute(const char* name, const Shader& shader) + : location(shader.getAttributeLocation(name)) {} + + AttributeLocation location; +}; + +class AttributeBinding { +public: + template <class Vertex, class T, std::size_t N, std::size_t O> + AttributeBinding(const T (Vertex::*)[N], const Attribute<T, N>& attribute, std::integral_constant<std::size_t, O>) + : location(attribute.location), + type(DataTypeOf<T>::value), + count(N), + offset(O) { + static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout"); + static_assert(O % 4 == 0, "vertex attribute must be optimally aligned"); + static_assert(1 <= N && N <= 4, "count must be 1, 2, 3, or 4"); + static_assert(sizeof(Vertex) <= std::numeric_limits<int32_t>::max(), "vertex type is too big"); + } + + AttributeLocation location; + DataType type; + uint8_t count; + std::size_t offset; +}; + +#define MBGL_MAKE_ATTRIBUTE_BINDING(Vertex, shader, name) \ + ::mbgl::gl::AttributeBinding(&Vertex::name, \ + shader.name, \ + std::integral_constant<std::size_t, offsetof(Vertex, name)>()) + +template <class Shader, class Vertex> struct AttributeBindings; + +} // namespace gl +} // namespace mbgl |