diff --git a/src/Magnum/MeshTools/Combine.cpp b/src/Magnum/MeshTools/Combine.cpp index f66a00181..87f46fc99 100644 --- a/src/Magnum/MeshTools/Combine.cpp +++ b/src/Magnum/MeshTools/Combine.cpp @@ -83,8 +83,8 @@ Trade::MeshData combineIndexedImplementation(const MeshPrimitive primitive, Cont duplicateInto(indices, src, dst); vertexOffset += src.size()[1]; attributeData[attributeOffset++] = Trade::MeshAttributeData{ - mesh.attributeName(i), mesh.attributeFormat(i), - mesh.attributeArraySize(i), dst}; + mesh.attributeName(i), mesh.attributeFormat(i), dst, + mesh.attributeArraySize(i)}; } indexOffset += indexSize; diff --git a/src/Magnum/MeshTools/CompressIndices.cpp b/src/Magnum/MeshTools/CompressIndices.cpp index 5061d628c..575d9a778 100644 --- a/src/Magnum/MeshTools/CompressIndices.cpp +++ b/src/Magnum/MeshTools/CompressIndices.cpp @@ -155,8 +155,9 @@ Trade::MeshData compressIndices(Trade::MeshData&& data, MeshIndexType atLeast) { for(UnsignedInt i = 0, max = attributeData.size(); i != max; ++i) { const UnsignedInt stride = data.attributeStride(i); attributeData[i] = Trade::MeshAttributeData{data.attributeName(i), - data.attributeFormat(i), data.attributeArraySize(i), - Containers::StridedArrayView1D{vertexData, vertexData.data() + data.attributeOffset(i) + offset*stride, newVertexCount, stride}}; + data.attributeFormat(i), + Containers::StridedArrayView1D{vertexData, vertexData.data() + data.attributeOffset(i) + offset*stride, newVertexCount, stride}, + data.attributeArraySize(i)}; } Trade::MeshIndexData indices{result.second, result.first}; diff --git a/src/Magnum/MeshTools/Concatenate.cpp b/src/Magnum/MeshTools/Concatenate.cpp index f1e207ef8..210325cac 100644 --- a/src/Magnum/MeshTools/Concatenate.cpp +++ b/src/Magnum/MeshTools/Concatenate.cpp @@ -72,10 +72,11 @@ Trade::MeshData concatenate(Containers::Array&& indexData, const UnsignedI absolute, referencing the vertex data array */ for(Trade::MeshAttributeData& attribute: attributeData) { attribute = Trade::MeshAttributeData{ - attribute.name(), attribute.format(), attribute.arraySize(), + attribute.name(), attribute.format(), Containers::StridedArrayView1D{vertexData, vertexData + attribute.offset(vertexData), - vertexCount, attribute.stride()}}; + vertexCount, attribute.stride()}, + attribute.arraySize()}; } /* Only list primitives are supported currently */ diff --git a/src/Magnum/MeshTools/GenerateIndices.cpp b/src/Magnum/MeshTools/GenerateIndices.cpp index ce8be55b9..343d490b3 100644 --- a/src/Magnum/MeshTools/GenerateIndices.cpp +++ b/src/Magnum/MeshTools/GenerateIndices.cpp @@ -190,8 +190,9 @@ Trade::MeshData generateIndices(Trade::MeshData&& data) { Containers::Array attributeData{data.attributeCount()}; for(UnsignedInt i = 0, max = attributeData.size(); i != max; ++i) { attributeData[i] = Trade::MeshAttributeData{data.attributeName(i), - data.attributeFormat(i), data.attributeArraySize(i), - Containers::StridedArrayView1D{vertexData, vertexData.data() + data.attributeOffset(i), vertexCount, data.attributeStride(i)}}; + data.attributeFormat(i), + Containers::StridedArrayView1D{vertexData, vertexData.data() + data.attributeOffset(i), vertexCount, data.attributeStride(i)}, + data.attributeArraySize(i)}; } /* Generate the index array */ diff --git a/src/Magnum/MeshTools/Interleave.cpp b/src/Magnum/MeshTools/Interleave.cpp index 4acb73726..b98c589fb 100644 --- a/src/Magnum/MeshTools/Interleave.cpp +++ b/src/Magnum/MeshTools/Interleave.cpp @@ -222,10 +222,11 @@ Trade::MeshData interleavedLayout(Trade::MeshData&& data, const UnsignedInt vert absolute, referencing the above-allocated data array */ for(Trade::MeshAttributeData& attribute: attributeData) { attribute = Trade::MeshAttributeData{ - attribute.name(), attribute.format(), attribute.arraySize(), + attribute.name(), attribute.format(), Containers::StridedArrayView1D{vertexData, vertexData + attribute.offset(vertexData), - vertexCount, attribute.stride()}}; + vertexCount, attribute.stride()}, + attribute.arraySize()}; } return Trade::MeshData{data.primitive(), std::move(vertexData), std::move(attributeData)}; diff --git a/src/Magnum/MeshTools/RemoveDuplicates.cpp b/src/Magnum/MeshTools/RemoveDuplicates.cpp index 3b224f80a..9e4fcc443 100644 --- a/src/Magnum/MeshTools/RemoveDuplicates.cpp +++ b/src/Magnum/MeshTools/RemoveDuplicates.cpp @@ -446,11 +446,11 @@ Trade::MeshData removeDuplicates(Trade::MeshData&& data) { for(UnsignedInt i = 0; i != ownedInterleaved.attributeCount(); ++i) attributeData[i] = Trade::MeshAttributeData{ownedInterleaved.attributeName(i), ownedInterleaved.attributeFormat(i), - ownedInterleaved.attributeArraySize(i), Containers::StridedArrayView1D{uniqueVertexData, uniqueVertexData.data() + ownedInterleaved.attributeOffset(i), uniqueVertexCount, - ownedInterleaved.attributeStride(i)}}; + ownedInterleaved.attributeStride(i)}, + ownedInterleaved.attributeArraySize(i)}; Trade::MeshIndexData indices{indexType, indexData}; return Trade::MeshData{ownedInterleaved.primitive(), diff --git a/src/Magnum/MeshTools/Test/CombineTest.cpp b/src/Magnum/MeshTools/Test/CombineTest.cpp index baed2f953..d1920ede3 100644 --- a/src/Magnum/MeshTools/Test/CombineTest.cpp +++ b/src/Magnum/MeshTools/Test/CombineTest.cpp @@ -98,9 +98,9 @@ void CombineTest::combineIndexedAttributes() { Trade::MeshData b{MeshPrimitive::LineLoop, {}, indicesB, Trade::MeshIndexData{indicesB}, {}, dataB, {Trade::MeshAttributeData{ + Trade::meshAttributeCustom(17), VertexFormat::Byte, /* Array attribute to verify it's correctly propagated */ - Trade::meshAttributeCustom(17), VertexFormat::Byte, 2, - Containers::arrayView(dataB)}}}; + Containers::arrayView(dataB), 2}}}; Trade::MeshData c{MeshPrimitive::LineLoop, {}, indicesC, Trade::MeshIndexData{indicesC}, {}, dataC, {Trade::MeshAttributeData{ diff --git a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp index afa442933..bf84b9d3f 100644 --- a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp @@ -274,7 +274,7 @@ template void CompressIndicesTest::compressMeshData() { {}, Containers::arrayView(&vertexData, 1), { Trade::MeshAttributeData{Trade::meshAttributeCustom(42), /* Array attribute to verify it's correctly propagated */ - VertexFormat::Float, 2, Containers::arrayView(vertexData.data)}, + VertexFormat::Float, Containers::arrayView(vertexData.data), 2}, Trade::MeshAttributeData{Trade::MeshAttribute::Normal, Containers::arrayView(vertexData.normals)} }}; CORRADE_COMPARE(data.vertexCount(), 103); diff --git a/src/Magnum/MeshTools/Test/ConcatenateTest.cpp b/src/Magnum/MeshTools/Test/ConcatenateTest.cpp index 06288e28e..0490a30ec 100644 --- a/src/Magnum/MeshTools/Test/ConcatenateTest.cpp +++ b/src/Magnum/MeshTools/Test/ConcatenateTest.cpp @@ -102,9 +102,9 @@ void ConcatenateTest::concatenate() { &vertexDataA[0].position, 2, sizeof(VertexDataA))}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Short, 2, + VertexFormat::Short, Containers::stridedArrayView(vertexDataA, - &vertexDataA[0].data, 2, sizeof(VertexDataA))} + &vertexDataA[0].data, 2, sizeof(VertexDataA)), 2} }}; /* Second is indexed, has only one texture coordinate of the two, an extra @@ -128,9 +128,9 @@ void ConcatenateTest::concatenate() { &vertexDataB[0].color, 4, sizeof(VertexDataB))}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Short, 2, + VertexFormat::Short, Containers::stridedArrayView(vertexDataB, - &vertexDataB[0].data, 4, sizeof(VertexDataB))}, + &vertexDataB[0].data, 4, sizeof(VertexDataB)), 2}, Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates, Containers::stridedArrayView(vertexDataB, &vertexDataB[0].texcoords1, 4, sizeof(VertexDataB))} @@ -628,13 +628,13 @@ void ConcatenateTest::concatenateInconsistentAttributeArraySize() { Trade::MeshAttributeData{Trade::MeshAttribute::Position, VertexFormat::Vector3, nullptr}, Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::ByteNormalized, 5, nullptr} + VertexFormat::ByteNormalized, nullptr, 5} }}; Trade::MeshData b{MeshPrimitive::Lines, nullptr, { Trade::MeshAttributeData{Trade::MeshAttribute::Position, VertexFormat::Vector3, nullptr}, Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::ByteNormalized, 4, nullptr} + VertexFormat::ByteNormalized, nullptr, 4} }}; std::ostringstream out; diff --git a/src/Magnum/MeshTools/Test/DuplicateTest.cpp b/src/Magnum/MeshTools/Test/DuplicateTest.cpp index bed42e88d..8e7abba22 100644 --- a/src/Magnum/MeshTools/Test/DuplicateTest.cpp +++ b/src/Magnum/MeshTools/Test/DuplicateTest.cpp @@ -291,7 +291,7 @@ template void DuplicateTest::duplicateMeshData() { Containers::arrayView(vertexData.positions)}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Float, 3, Containers::arrayView(vertexData.extra)} + VertexFormat::Float, Containers::arrayView(vertexData.extra), 3} }}; Trade::MeshData duplicated = MeshTools::duplicate(data); @@ -341,7 +341,7 @@ void DuplicateTest::duplicateMeshDataExtra() { Trade::MeshAttributeData{4}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Float, 3, Containers::arrayView(extra)} + VertexFormat::Float, Containers::arrayView(extra), 3} }); CORRADE_VERIFY(MeshTools::isInterleaved(duplicated)); CORRADE_COMPARE(duplicated.primitive(), MeshPrimitive::Lines); diff --git a/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp b/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp index 1e9cbc760..23b274f19 100644 --- a/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp +++ b/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp @@ -406,9 +406,9 @@ void GenerateIndicesTest::generateIndicesMeshData() { &vertexData[0].position, 5, sizeof(Vertex))}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Short, 2, + VertexFormat::Short, Containers::stridedArrayView(vertexData, - &vertexData[0].data, 5, sizeof(Vertex))}, + &vertexData[0].data, 5, sizeof(Vertex)), 2}, Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates, Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates, 5, sizeof(Vertex))} diff --git a/src/Magnum/MeshTools/Test/InterleaveTest.cpp b/src/Magnum/MeshTools/Test/InterleaveTest.cpp index 8729aa82a..f11d1eb29 100644 --- a/src/Magnum/MeshTools/Test/InterleaveTest.cpp +++ b/src/Magnum/MeshTools/Test/InterleaveTest.cpp @@ -484,9 +484,9 @@ void InterleaveTest::interleavedDataArrayAttributes() { Trade::MeshData data{MeshPrimitive::Triangles, std::move(vertexData), { Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Float, 3, normals}, + VertexFormat::Float, normals, 3}, Trade::MeshAttributeData{Trade::meshAttributeCustom(43), - VertexFormat::Float, 2, positions} + VertexFormat::Float, positions, 2} }}; CORRADE_VERIFY(MeshTools::isInterleaved(data)); @@ -652,7 +652,7 @@ void InterleaveTest::interleavedLayout() { Containers::arrayCast(vertexData.slice(3*8, 3*20))}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::Short, 2, Containers::StridedArrayView2D{vertexData.suffix(3*20), {3, 4}}} + VertexFormat::Short, Containers::StridedArrayView2D{vertexData.suffix(3*20), {3, 4}}, 2} }; Trade::MeshIndexData indices{Containers::arrayCast(indexData)}; @@ -702,7 +702,7 @@ void InterleaveTest::interleavedLayoutExtra() { Trade::MeshAttributeData{1}, /* Array attribute to verify it's correctly propagated */ Trade::MeshAttributeData{Trade::meshAttributeCustom(15), - VertexFormat::UnsignedByte, 6, nullptr}, + VertexFormat::UnsignedByte, nullptr, 6}, Trade::MeshAttributeData{1}, Trade::MeshAttributeData{Trade::MeshAttribute::Color, VertexFormat::Vector3, nullptr}, diff --git a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp index 76c937a4b..8d75680f3 100644 --- a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp +++ b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp @@ -663,8 +663,8 @@ void RemoveDuplicatesTest::removeDuplicatesMeshData() { Trade::MeshAttributeData{Trade::MeshAttribute::Position, Containers::arrayView(vertexData->positions)}, Trade::MeshAttributeData{Trade::meshAttributeCustom(42), - VertexFormat::ShortNormalized, 2, - Containers::stridedArrayView(vertexData->data)}, + VertexFormat::ShortNormalized, + Containers::stridedArrayView(vertexData->data), 2}, }}; Trade::MeshData unique = MeshTools::removeDuplicates(mesh); diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index bfdd641d3..48744ef60 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -60,7 +60,7 @@ MeshIndexData::MeshIndexData(const Containers::StridedArrayView2D& d _data = data.asContiguous(); } -MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView1D& data) noexcept: MeshAttributeData{name, format, arraySize, data, nullptr} { +MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView1D& data, UnsignedShort arraySize) noexcept: MeshAttributeData{nullptr, name, format, data, arraySize} { /* Yes, this calls into a constexpr function defined in the header -- because I feel that makes more sense than duplicating the full assert logic */ @@ -69,7 +69,7 @@ MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexForma "Trade::MeshAttributeData: expected stride to be positive and enough to fit" << format << Debug::nospace << (arraySize ? Utility::format("[{}]", arraySize).data() : "") << Debug::nospace << ", got" << data.stride(), ); } -MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView2D& data) noexcept: MeshAttributeData{name, format, arraySize, Containers::StridedArrayView1D{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, nullptr} { +MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView2D& data, UnsignedShort arraySize) noexcept: MeshAttributeData{nullptr, name, format, Containers::StridedArrayView1D{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, arraySize} { /* Yes, this calls into a constexpr function defined in the header -- because I feel that makes more sense than duplicating the full assert logic */ diff --git a/src/Magnum/Trade/MeshData.h b/src/Magnum/Trade/MeshData.h index f25cd7e78..9e85c8e59 100644 --- a/src/Magnum/Trade/MeshData.h +++ b/src/Magnum/Trade/MeshData.h @@ -346,57 +346,31 @@ class MAGNUM_TRADE_EXPORT MeshAttributeData { * @param name Attribute name * @param format Vertex format * @param data Attribute data - * - * Expects that @p data stride is large enough to fit @p type and that - * @p type corresponds to @p name. - */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView1D& data) noexcept: MeshAttributeData{name, format, 0, data} {} - - /** - * @brief Type-erased constructor for an array attribute - * @param name Attribute name - * @param format Vertex format - * @param arraySize Array size - * @param data Attribute data + * @param arraySize Array size. Use @cpp 0 @ce for non-array + * attributes. * * Expects that @p data stride is large enough to fit all @p arraySize * items of @p type, @p type corresponds to @p name and @p arraySize is - * zero for builtin attributes. Passing @cpp 0 @ce to @p arraySize is - * equivalent to calling the above overload. + * zero for builtin attributes. */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView1D& data) noexcept; + explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView1D& data, UnsignedShort arraySize = 0) noexcept; /** * @brief Constructor * @param name Attribute name * @param format Vertex format * @param data Attribute data - * - * Expects that the second dimension of @p data is contiguous and its - * size matches @p type; and that @p type corresponds to @p name. - */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView2D& data) noexcept: MeshAttributeData{name, format, 0, data} {} - - /** @overload */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, std::nullptr_t) noexcept: MeshAttributeData{name, format, 0, nullptr, nullptr} {} - - /** - * @brief Construct an array attribute - * @param name Attribute name - * @param format Vertex format - * @param arraySize Array size - * @param data Attribute data + * @param arraySize Array size. Use @cpp 0 @ce for non-array + * attributes. * * Expects that the second dimension of @p data is contiguous and its * size matches @p type and @p arraSize, that @p type corresponds to - * @p name and @p arraySize is zero for builtin attributes. Passing - * @cpp 0 @ce to @p arraySize is equivalent to calling the above - * overload. + * @p name and @p arraySize is zero for builtin attributes. */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView2D& data) noexcept; + explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView2D& data, UnsignedShort arraySize = 0) noexcept; /** @overload */ - explicit MeshAttributeData(MeshAttribute name, VertexFormat format, UnsignedShort arraySize, std::nullptr_t) noexcept: MeshAttributeData{name, format, arraySize, nullptr, nullptr} {} + explicit MeshAttributeData(MeshAttribute name, VertexFormat format, std::nullptr_t, UnsignedShort arraySize = 0) noexcept: MeshAttributeData{nullptr, name, format, nullptr, arraySize} {} /** * @brief Constructor @@ -404,7 +378,7 @@ class MAGNUM_TRADE_EXPORT MeshAttributeData { * @param data Attribute data * * Detects @ref VertexFormat based on @p T and calls - * @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D&). + * @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D&, UnsignedShort). * For most types known by Magnum, the detected @ref VertexFormat is of * the same name as the type (so e.g. @ref Magnum::Vector3ui "Vector3ui" * gets recognized as @ref VertexFormat::Vector3ui), with the @@ -446,7 +420,7 @@ class MAGNUM_TRADE_EXPORT MeshAttributeData { * @param data Attribute data * * Detects @ref VertexFormat based on @p T and calls - * @ref MeshAttributeData(MeshAttribute, VertexFormat, UnsignedShort, const Containers::StridedArrayView1D&) + * @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D&, UnsignedShort) * with the second dimension size passed to @p arraySize. Expects that * the second dimension is contiguous. At the moment only custom * attributes can be arrays, which means this function can't be used @@ -478,7 +452,7 @@ class MAGNUM_TRADE_EXPORT MeshAttributeData { * * Note that due to the @cpp constexpr @ce nature of this constructor, * no @p format / @p arraySize checks against @p stride can be done. - * You're encouraged to use the @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D&) + * You're encouraged to use the @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D&, UnsignedShort) * constructor if you want additional safeguards. * @see @ref isOffsetOnly(), @ref arraySize(), * @ref data(Containers::ArrayView) const @@ -570,7 +544,8 @@ class MAGNUM_TRADE_EXPORT MeshAttributeData { private: friend MeshData; - constexpr explicit MeshAttributeData(MeshAttribute name, VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView1D& data, std::nullptr_t) noexcept; + /* nullptr first, to avoid accidental matches as much as possible */ + constexpr explicit MeshAttributeData(std::nullptr_t, MeshAttribute name, VertexFormat format, const Containers::StridedArrayView1D& data, UnsignedShort arraySize) noexcept; VertexFormat _format; MeshAttribute _name; @@ -2086,7 +2061,7 @@ namespace Implementation { #endif } -constexpr MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, const UnsignedShort arraySize, const Containers::StridedArrayView1D& data, std::nullptr_t) noexcept: +constexpr MeshAttributeData::MeshAttributeData(std::nullptr_t, const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView1D& data, const UnsignedShort arraySize) noexcept: _format{(CORRADE_CONSTEXPR_ASSERT(!arraySize || !isVertexFormatImplementationSpecific(format), "Trade::MeshAttributeData: array attributes can't have an implementation-specific format"), format)}, _name{(CORRADE_CONSTEXPR_ASSERT(Implementation::isVertexFormatCompatibleWithAttribute(name, format), @@ -2114,9 +2089,9 @@ constexpr MeshAttributeData::MeshAttributeData(const MeshAttribute name, const V "Trade::MeshAttributeData:" << name << "can't be an array attribute"), arraySize)}, _data{offset} {} -template constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView1D& data) noexcept: MeshAttributeData{name, Implementation::vertexFormatFor::type>(), 0, data, nullptr} {} +template constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView1D& data) noexcept: MeshAttributeData{nullptr, name, Implementation::vertexFormatFor::type>(), data, 0} {} -template constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView2D& data) noexcept: MeshAttributeData{name, Implementation::vertexFormatFor::type>(), UnsignedShort(data.size()[1]), Containers::StridedArrayView1D{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, (CORRADE_CONSTEXPR_ASSERT(data.stride()[1] == sizeof(T), "Trade::MeshAttributeData: second view dimension is not contiguous"), nullptr)} {} +template constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView2D& data) noexcept: MeshAttributeData{(CORRADE_CONSTEXPR_ASSERT(data.stride()[1] == sizeof(T), "Trade::MeshAttributeData: second view dimension is not contiguous"), nullptr), name, Implementation::vertexFormatFor::type>(), Containers::StridedArrayView1D{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, UnsignedShort(data.size()[1])} {} template Containers::ArrayView MeshData::indices() const { CORRADE_ASSERT(isIndexed(), diff --git a/src/Magnum/Trade/Test/MeshDataTest.cpp b/src/Magnum/Trade/Test/MeshDataTest.cpp index fdb60f9ae..3b2f08fa7 100644 --- a/src/Magnum/Trade/Test/MeshDataTest.cpp +++ b/src/Magnum/Trade/Test/MeshDataTest.cpp @@ -750,7 +750,7 @@ void MeshDataTest::constructAttributeWrongStride() { std::ostringstream out; Error redirectError{&out}; MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector3, Containers::arrayCast(positionData)}; - MeshAttributeData{meshAttributeCustom(1), VertexFormat::Float, 4, Containers::arrayCast(positionData)}; + MeshAttributeData{meshAttributeCustom(1), VertexFormat::Float, Containers::arrayCast(positionData), 4}; /* We need this one to be constexpr, which means there can't be a warning about stride not matching the size */ MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector3, 0, 3*sizeof(Vector3), 1}; @@ -831,7 +831,7 @@ void MeshDataTest::constructArrayAttributeNonContiguous() { void MeshDataTest::constructArrayAttribute2D() { char vertexData[3*4*sizeof(Vector2)]; - MeshAttributeData data{meshAttributeCustom(35), VertexFormat::Vector2, 4, Containers::StridedArrayView2D{vertexData, {3, 4*sizeof(Vector2)}}}; + MeshAttributeData data{meshAttributeCustom(35), VertexFormat::Vector2, Containers::StridedArrayView2D{vertexData, {3, 4*sizeof(Vector2)}}, 4}; CORRADE_VERIFY(!data.isOffsetOnly()); CORRADE_COMPARE(data.name(), meshAttributeCustom(35)); CORRADE_COMPARE(data.format(), VertexFormat::Vector2); @@ -850,9 +850,9 @@ void MeshDataTest::constructArrayAttribute2DWrongSize() { std::ostringstream out; Error redirectError{&out}; - MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, 3, + MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, Containers::StridedArrayView2D{vertexData, - {3, 4*sizeof(Vector2)}}}; + {3, 4*sizeof(Vector2)}}, 3}; CORRADE_COMPARE(out.str(), "Trade::MeshAttributeData: second view dimension size 32 doesn't match VertexFormat::Vector2 and array size 3\n"); } @@ -865,16 +865,16 @@ void MeshDataTest::constructArrayAttribute2DNonContiguous() { std::ostringstream out; Error redirectError{&out}; - MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, 2, + MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, Containers::StridedArrayView2D{vertexData, - {3, sizeof(Vector2)*4}}.every({1, 2})}; + {3, sizeof(Vector2)*4}}.every({1, 2}), 2}; CORRADE_COMPARE(out.str(), "Trade::MeshAttributeData: second view dimension is not contiguous\n"); } void MeshDataTest::constructArrayAttributeTypeErased() { Vector2 vertexData[3*4]; Containers::StridedArrayView1D attribute{vertexData, 3, 4*sizeof(Vector2)}; - MeshAttributeData data{meshAttributeCustom(35), VertexFormat::Vector2, 4, attribute}; + MeshAttributeData data{meshAttributeCustom(35), VertexFormat::Vector2, attribute, 4}; CORRADE_VERIFY(!data.isOffsetOnly()); CORRADE_COMPARE(data.name(), meshAttributeCustom(35)); CORRADE_COMPARE(data.format(), VertexFormat::Vector2); @@ -885,7 +885,7 @@ void MeshDataTest::constructArrayAttributeTypeErased() { } void MeshDataTest::constructArrayAttributeNullptr() { - MeshAttributeData positions{meshAttributeCustom(35), VertexFormat::Vector2, 4, nullptr}; + MeshAttributeData positions{meshAttributeCustom(35), VertexFormat::Vector2, nullptr, 4}; CORRADE_VERIFY(!positions.isOffsetOnly()); CORRADE_COMPARE(positions.arraySize(), 4); CORRADE_COMPARE(positions.name(), meshAttributeCustom(35)); @@ -923,20 +923,20 @@ void MeshDataTest::constructArrayAttributeNotAllowed() { auto positions2Dchar = Containers::arrayCast<2, const char>(positions2D); /* This is all fine */ - MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, 0, positions}; + MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, positions, 0}; MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, 0, 3, 6*sizeof(Vector2), 0}; - MeshAttributeData{meshAttributeCustom(35), vertexFormatWrap(0xdead), 0, positions}; + MeshAttributeData{meshAttributeCustom(35), vertexFormatWrap(0xdead), positions, 0}; MeshAttributeData{meshAttributeCustom(35), positions2D}; - MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, 3, positions2Dchar}; + MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, positions2Dchar, 3}; MeshAttributeData{meshAttributeCustom(35), VertexFormat::Vector2, 0, 3, 6*sizeof(Vector2), 3}; /* This is not */ std::ostringstream out; Error redirectError{&out}; - MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2b, 3, Containers::arrayView(positionData)}; - MeshAttributeData{meshAttributeCustom(35), vertexFormatWrap(0xdead), 3, Containers::arrayView(positionData)}; + MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2b, Containers::arrayView(positionData), 3}; + MeshAttributeData{meshAttributeCustom(35), vertexFormatWrap(0xdead), Containers::arrayView(positionData), 3}; MeshAttributeData{MeshAttribute::Position, positions2D}; - MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, 3, positions2Dchar}; + MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, positions2Dchar, 3}; MeshAttributeData{MeshAttribute::Position, VertexFormat::Vector2, 0, 3, 6*sizeof(Vector2), 3}; MeshAttributeData{meshAttributeCustom(35), vertexFormatWrap(0xdead), 0, 3, 6*sizeof(Vector2), 3}; CORRADE_COMPARE(out.str(),