Browse Source

Trade: unify array MeshAttributeData constructors.

The array size is always last, defaulting to 0. This makes it consistent
with the offset-only constructor and removes two unnecessary overloads.
It's a breaking change, but I don't think array attributes have many
users yet -- and  better to do this now than later. In any case, sorry
about breaking your code.
pull/454/head
Vladimír Vondruš 6 years ago
parent
commit
96f82ad124
  1. 4
      src/Magnum/MeshTools/Combine.cpp
  2. 5
      src/Magnum/MeshTools/CompressIndices.cpp
  3. 5
      src/Magnum/MeshTools/Concatenate.cpp
  4. 5
      src/Magnum/MeshTools/GenerateIndices.cpp
  5. 5
      src/Magnum/MeshTools/Interleave.cpp
  6. 4
      src/Magnum/MeshTools/RemoveDuplicates.cpp
  7. 4
      src/Magnum/MeshTools/Test/CombineTest.cpp
  8. 2
      src/Magnum/MeshTools/Test/CompressIndicesTest.cpp
  9. 12
      src/Magnum/MeshTools/Test/ConcatenateTest.cpp
  10. 4
      src/Magnum/MeshTools/Test/DuplicateTest.cpp
  11. 4
      src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp
  12. 8
      src/Magnum/MeshTools/Test/InterleaveTest.cpp
  13. 4
      src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp
  14. 4
      src/Magnum/Trade/MeshData.cpp
  15. 59
      src/Magnum/Trade/MeshData.h
  16. 28
      src/Magnum/Trade/Test/MeshDataTest.cpp

4
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;

5
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<const void>{vertexData, vertexData.data() + data.attributeOffset(i) + offset*stride, newVertexCount, stride}};
data.attributeFormat(i),
Containers::StridedArrayView1D<const void>{vertexData, vertexData.data() + data.attributeOffset(i) + offset*stride, newVertexCount, stride},
data.attributeArraySize(i)};
}
Trade::MeshIndexData indices{result.second, result.first};

5
src/Magnum/MeshTools/Concatenate.cpp

@ -72,10 +72,11 @@ Trade::MeshData concatenate(Containers::Array<char>&& 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<void>{vertexData,
vertexData + attribute.offset(vertexData),
vertexCount, attribute.stride()}};
vertexCount, attribute.stride()},
attribute.arraySize()};
}
/* Only list primitives are supported currently */

5
src/Magnum/MeshTools/GenerateIndices.cpp

@ -190,8 +190,9 @@ Trade::MeshData generateIndices(Trade::MeshData&& data) {
Containers::Array<Trade::MeshAttributeData> 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<const void>{vertexData, vertexData.data() + data.attributeOffset(i), vertexCount, data.attributeStride(i)}};
data.attributeFormat(i),
Containers::StridedArrayView1D<const void>{vertexData, vertexData.data() + data.attributeOffset(i), vertexCount, data.attributeStride(i)},
data.attributeArraySize(i)};
}
/* Generate the index array */

5
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<void>{vertexData,
vertexData + attribute.offset(vertexData),
vertexCount, attribute.stride()}};
vertexCount, attribute.stride()},
attribute.arraySize()};
}
return Trade::MeshData{data.primitive(), std::move(vertexData), std::move(attributeData)};

4
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<void>{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(),

4
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{

2
src/Magnum/MeshTools/Test/CompressIndicesTest.cpp

@ -274,7 +274,7 @@ template<class T> 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);

12
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;

4
src/Magnum/MeshTools/Test/DuplicateTest.cpp

@ -291,7 +291,7 @@ template<class T> 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);

4
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))}

8
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<Vector3>(vertexData.slice(3*8, 3*20))},
/* Array attribute to verify it's correctly propagated */
Trade::MeshAttributeData{Trade::meshAttributeCustom(42),
VertexFormat::Short, 2, Containers::StridedArrayView2D<char>{vertexData.suffix(3*20), {3, 4}}}
VertexFormat::Short, Containers::StridedArrayView2D<char>{vertexData.suffix(3*20), {3, 4}}, 2}
};
Trade::MeshIndexData indices{Containers::arrayCast<UnsignedShort>(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},

4
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);

4
src/Magnum/Trade/MeshData.cpp

@ -60,7 +60,7 @@ MeshIndexData::MeshIndexData(const Containers::StridedArrayView2D<const char>& d
_data = data.asContiguous();
}
MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, UnsignedShort arraySize, const Containers::StridedArrayView1D<const void>& data) noexcept: MeshAttributeData{name, format, arraySize, data, nullptr} {
MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView1D<const void>& 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<const char>& data) noexcept: MeshAttributeData{name, format, arraySize, Containers::StridedArrayView1D<const void>{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, nullptr} {
MeshAttributeData::MeshAttributeData(const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView2D<const char>& data, UnsignedShort arraySize) noexcept: MeshAttributeData{nullptr, name, format, Containers::StridedArrayView1D<const void>{{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 */

59
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<const void>& 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<const void>& data) noexcept;
explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView1D<const void>& 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<const char>& 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<const char>& data) noexcept;
explicit MeshAttributeData(MeshAttribute name, VertexFormat format, const Containers::StridedArrayView2D<const char>& 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<const void>&).
* @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D<const void>&, 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<const void>&)
* @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D<const void>&, 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<const void>&)
* You're encouraged to use the @ref MeshAttributeData(MeshAttribute, VertexFormat, const Containers::StridedArrayView1D<const void>&, UnsignedShort)
* constructor if you want additional safeguards.
* @see @ref isOffsetOnly(), @ref arraySize(),
* @ref data(Containers::ArrayView<const void>) 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<const void>& 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<const void>& 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<const void>& data, std::nullptr_t) noexcept:
constexpr MeshAttributeData::MeshAttributeData(std::nullptr_t, const MeshAttribute name, const VertexFormat format, const Containers::StridedArrayView1D<const void>& 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<class T> constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView1D<T>& data) noexcept: MeshAttributeData{name, Implementation::vertexFormatFor<typename std::remove_const<T>::type>(), 0, data, nullptr} {}
template<class T> constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView1D<T>& data) noexcept: MeshAttributeData{nullptr, name, Implementation::vertexFormatFor<typename std::remove_const<T>::type>(), data, 0} {}
template<class T> constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView2D<T>& data) noexcept: MeshAttributeData{name, Implementation::vertexFormatFor<typename std::remove_const<T>::type>(), UnsignedShort(data.size()[1]), Containers::StridedArrayView1D<const void>{{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<class T> constexpr MeshAttributeData::MeshAttributeData(MeshAttribute name, const Containers::StridedArrayView2D<T>& data) noexcept: MeshAttributeData{(CORRADE_CONSTEXPR_ASSERT(data.stride()[1] == sizeof(T), "Trade::MeshAttributeData: second view dimension is not contiguous"), nullptr), name, Implementation::vertexFormatFor<typename std::remove_const<T>::type>(), Containers::StridedArrayView1D<const void>{{data.data(), ~std::size_t{}}, data.size()[0], data.stride()[0]}, UnsignedShort(data.size()[1])} {}
template<class T> Containers::ArrayView<const T> MeshData::indices() const {
CORRADE_ASSERT(isIndexed(),

28
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<const char>(positionData)};
MeshAttributeData{meshAttributeCustom(1), VertexFormat::Float, 4, Containers::arrayCast<const Vector3>(positionData)};
MeshAttributeData{meshAttributeCustom(1), VertexFormat::Float, Containers::arrayCast<const Vector3>(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<char>{vertexData, {3, 4*sizeof(Vector2)}}};
MeshAttributeData data{meshAttributeCustom(35), VertexFormat::Vector2, Containers::StridedArrayView2D<char>{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<char>{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<char>{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<Vector2> 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(),

Loading…
Cancel
Save