summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-03-05 18:35:56 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-03-05 18:35:56 +0100
commit422ed287303250aca31d792acc2b4201ad5d9e32 (patch)
treed27feb1d61b8851fe4132c12db53eeba83d7ee6b
parent1ca25a375b3d7794bf56b0a106adb1bd7108c9e3 (diff)
downloadqtlocation-mapboxgl-422ed287303250aca31d792acc2b4201ad5d9e32.tar.gz
[core] add data type to vertex attribute descriptors
-rw-r--r--src/mbgl/gfx/attribute.hpp72
-rw-r--r--src/mbgl/gl/attribute.hpp6
2 files changed, 39 insertions, 39 deletions
diff --git a/src/mbgl/gfx/attribute.hpp b/src/mbgl/gfx/attribute.hpp
index 2f33d3e484..5f4bbc5d31 100644
--- a/src/mbgl/gfx/attribute.hpp
+++ b/src/mbgl/gfx/attribute.hpp
@@ -23,35 +23,35 @@ namespace gfx {
namespace {
-template <typename, std::size_t> constexpr AttributeDataType AttributeDataTypeOf = AttributeDataType::Invalid;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int8_t, 1> = AttributeDataType::Byte;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int8_t, 2> = AttributeDataType::Byte2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int8_t, 3> = AttributeDataType::Byte3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int8_t, 4> = AttributeDataType::Byte4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint8_t, 1> = AttributeDataType::UByte;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint8_t, 2> = AttributeDataType::UByte2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint8_t, 3> = AttributeDataType::UByte3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint8_t, 4> = AttributeDataType::UByte4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int16_t, 1> = AttributeDataType::Short;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int16_t, 2> = AttributeDataType::Short2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int16_t, 3> = AttributeDataType::Short3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int16_t, 4> = AttributeDataType::Short4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint16_t, 1> = AttributeDataType::UShort;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint16_t, 2> = AttributeDataType::UShort2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint16_t, 3> = AttributeDataType::UShort3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint16_t, 4> = AttributeDataType::UShort4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int32_t, 1> = AttributeDataType::Int;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int32_t, 2> = AttributeDataType::Int2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int32_t, 3> = AttributeDataType::Int3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<int32_t, 4> = AttributeDataType::Int4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint32_t, 1> = AttributeDataType::UInt;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint32_t, 2> = AttributeDataType::UInt2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint32_t, 3> = AttributeDataType::UInt3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<uint32_t, 4> = AttributeDataType::UInt4;
-template <> constexpr AttributeDataType AttributeDataTypeOf<float, 1> = AttributeDataType::Float;
-template <> constexpr AttributeDataType AttributeDataTypeOf<float, 2> = AttributeDataType::Float2;
-template <> constexpr AttributeDataType AttributeDataTypeOf<float, 3> = AttributeDataType::Float3;
-template <> constexpr AttributeDataType AttributeDataTypeOf<float, 4> = AttributeDataType::Float4;
+template <typename, std::size_t> struct AttributeDataTypeOf;
+template <> struct AttributeDataTypeOf<int8_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::Byte> {};
+template <> struct AttributeDataTypeOf<int8_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::Byte2> {};
+template <> struct AttributeDataTypeOf<int8_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::Byte3> {};
+template <> struct AttributeDataTypeOf<int8_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::Byte4> {};
+template <> struct AttributeDataTypeOf<uint8_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::UByte> {};
+template <> struct AttributeDataTypeOf<uint8_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::UByte2> {};
+template <> struct AttributeDataTypeOf<uint8_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::UByte3> {};
+template <> struct AttributeDataTypeOf<uint8_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::UByte4> {};
+template <> struct AttributeDataTypeOf<int16_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::Short> {};
+template <> struct AttributeDataTypeOf<int16_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::Short2> {};
+template <> struct AttributeDataTypeOf<int16_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::Short3> {};
+template <> struct AttributeDataTypeOf<int16_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::Short4> {};
+template <> struct AttributeDataTypeOf<uint16_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::UShort> {};
+template <> struct AttributeDataTypeOf<uint16_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::UShort2> {};
+template <> struct AttributeDataTypeOf<uint16_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::UShort3> {};
+template <> struct AttributeDataTypeOf<uint16_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::UShort4> {};
+template <> struct AttributeDataTypeOf<int32_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::Int> {};
+template <> struct AttributeDataTypeOf<int32_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::Int2> {};
+template <> struct AttributeDataTypeOf<int32_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::Int3> {};
+template <> struct AttributeDataTypeOf<int32_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::Int4> {};
+template <> struct AttributeDataTypeOf<uint32_t, 1> : std::integral_constant<AttributeDataType, AttributeDataType::UInt> {};
+template <> struct AttributeDataTypeOf<uint32_t, 2> : std::integral_constant<AttributeDataType, AttributeDataType::UInt2> {};
+template <> struct AttributeDataTypeOf<uint32_t, 3> : std::integral_constant<AttributeDataType, AttributeDataType::UInt3> {};
+template <> struct AttributeDataTypeOf<uint32_t, 4> : std::integral_constant<AttributeDataType, AttributeDataType::UInt4> {};
+template <> struct AttributeDataTypeOf<float, 1> : std::integral_constant<AttributeDataType, AttributeDataType::Float> {};
+template <> struct AttributeDataTypeOf<float, 2> : std::integral_constant<AttributeDataType, AttributeDataType::Float2> {};
+template <> struct AttributeDataTypeOf<float, 3> : std::integral_constant<AttributeDataType, AttributeDataType::Float3> {};
+template <> struct AttributeDataTypeOf<float, 4> : std::integral_constant<AttributeDataType, AttributeDataType::Float4> {};
} // namespace
@@ -59,7 +59,7 @@ template <typename T, std::size_t N>
class AttributeType {
public:
using ElementType = T;
- static constexpr AttributeDataType DataType = AttributeDataTypeOf<T, N>;
+ static constexpr AttributeDataType DataType = AttributeDataTypeOf<T, N>::value;
static constexpr size_t Dimensions = N;
using Value = std::array<T, N>;
};
@@ -139,7 +139,7 @@ struct Descriptor<Vertex<A1>> {
using Type = Vertex<A1>;
static_assert(sizeof(Type) < 256, "vertex type must be smaller than 256 bytes");
static_assert(std::is_standard_layout<Type>::value, "vertex type must use standard layout");
- static constexpr const VertexDescriptor Data = { sizeof(Type), 1, {
+ static constexpr const VertexDescriptor data = { sizeof(Type), 1, {
{ A1::DataType, offsetof(Type, a1) },
}};
};
@@ -149,7 +149,7 @@ struct Descriptor<Vertex<A1, A2>> {
using Type = Vertex<A1, A2>;
static_assert(sizeof(Type) < 256, "vertex type must be smaller than 256 bytes");
static_assert(std::is_standard_layout<Type>::value, "vertex type must use standard layout");
- static constexpr const VertexDescriptor Data = { sizeof(Type), 2, {
+ static constexpr const VertexDescriptor data = { sizeof(Type), 2, {
{ A1::DataType, offsetof(Type, a1) },
{ A2::DataType, offsetof(Type, a2) },
}};
@@ -160,7 +160,7 @@ struct Descriptor<Vertex<A1, A2, A3>> {
using Type = Vertex<A1, A2, A3>;
static_assert(sizeof(Type) < 256, "vertex type must be smaller than 256 bytes");
static_assert(std::is_standard_layout<Type>::value, "vertex type must use standard layout");
- static constexpr const VertexDescriptor Data = { sizeof(Type), 3, {
+ static constexpr const VertexDescriptor data = { sizeof(Type), 3, {
{ A1::DataType, offsetof(Type, a1) },
{ A2::DataType, offsetof(Type, a2) },
{ A3::DataType, offsetof(Type, a3) },
@@ -172,7 +172,7 @@ struct Descriptor<Vertex<A1, A2, A3, A4>> {
using Type = Vertex<A1, A2, A3, A4>;
static_assert(sizeof(Type) < 256, "vertex type must be smaller than 256 bytes");
static_assert(std::is_standard_layout<Type>::value, "vertex type must use standard layout");
- static constexpr const VertexDescriptor Data = { sizeof(Type), 4, {
+ static constexpr const VertexDescriptor data = { sizeof(Type), 4, {
{ A1::DataType, offsetof(Type, a1) },
{ A2::DataType, offsetof(Type, a2) },
{ A3::DataType, offsetof(Type, a3) },
@@ -185,7 +185,7 @@ struct Descriptor<Vertex<A1, A2, A3, A4, A5>> {
using Type = Vertex<A1, A2, A3, A4, A5>;
static_assert(sizeof(Type) < 256, "vertex type must be smaller than 256 bytes");
static_assert(std::is_standard_layout<Type>::value, "vertex type must use standard layout");
- static constexpr const VertexDescriptor Data = { sizeof(Type), 5, {
+ static constexpr const VertexDescriptor data = { sizeof(Type), 5, {
{ A1::DataType, offsetof(Type, a1) },
{ A2::DataType, offsetof(Type, a2) },
{ A3::DataType, offsetof(Type, a3) },
@@ -205,7 +205,7 @@ template <class A>
using Vertex = typename detail::Vertex<A>::Type;
template <class V>
-constexpr const VertexDescriptor vertexDescriptor = detail::Descriptor<V>::Data;
+using VertexDescriptorOf = detail::Descriptor<V>;
} // namespace gfx
} // namespace mbgl
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index 33749d257f..53ba71a89f 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -41,10 +41,10 @@ using AttributeBindingArray = std::vector<optional<AttributeBinding>>;
*/
template <std::size_t I, typename Vertex>
AttributeBinding attributeBinding(const VertexBuffer<Vertex>& buffer) {
- static_assert(I < gfx::vertexDescriptor<Vertex>.count, "vertex attribute index out of range");
+ static_assert(I < gfx::VertexDescriptorOf<Vertex>::data.count, "vertex attribute index out of range");
return {
- gfx::vertexDescriptor<Vertex>.attributes[I],
- gfx::vertexDescriptor<Vertex>.stride,
+ gfx::VertexDescriptorOf<Vertex>::data.attributes[I],
+ gfx::VertexDescriptorOf<Vertex>::data.stride,
buffer.buffer,
0,
};