Browse Source

Trade: const++

pull/537/head
Vladimír Vondruš 5 years ago
parent
commit
fe57f23e12
  1. 34
      src/Magnum/Trade/MeshData.cpp
  2. 8
      src/Magnum/Trade/MeshData.h

34
src/Magnum/Trade/MeshData.cpp

@ -264,39 +264,39 @@ Containers::StridedArrayView2D<char> MeshData::mutableIndices() {
out.size(), out.stride()}; out.size(), out.stride()};
} }
MeshAttributeData MeshData::attributeData(UnsignedInt id) const { MeshAttributeData MeshData::attributeData(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeData(): index" << id << "out of range for" << _attributes.size() << "attributes", MeshAttributeData{}); "Trade::MeshData::attributeData(): index" << id << "out of range for" << _attributes.size() << "attributes", MeshAttributeData{});
const MeshAttributeData& attribute = _attributes[id]; const MeshAttributeData& attribute = _attributes[id];
return MeshAttributeData{attribute._name, attribute._format, attributeDataViewInternal(attribute)}; return MeshAttributeData{attribute._name, attribute._format, attributeDataViewInternal(attribute)};
} }
MeshAttribute MeshData::attributeName(UnsignedInt id) const { MeshAttribute MeshData::attributeName(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeName(): index" << id << "out of range for" << _attributes.size() << "attributes", {}); "Trade::MeshData::attributeName(): index" << id << "out of range for" << _attributes.size() << "attributes", {});
return _attributes[id]._name; return _attributes[id]._name;
} }
VertexFormat MeshData::attributeFormat(UnsignedInt id) const { VertexFormat MeshData::attributeFormat(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeFormat(): index" << id << "out of range for" << _attributes.size() << "attributes", {}); "Trade::MeshData::attributeFormat(): index" << id << "out of range for" << _attributes.size() << "attributes", {});
return _attributes[id]._format; return _attributes[id]._format;
} }
std::size_t MeshData::attributeOffset(UnsignedInt id) const { std::size_t MeshData::attributeOffset(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeOffset(): index" << id << "out of range for" << _attributes.size() << "attributes", {}); "Trade::MeshData::attributeOffset(): index" << id << "out of range for" << _attributes.size() << "attributes", {});
return _attributes[id]._isOffsetOnly ? _attributes[id]._data.offset : return _attributes[id]._isOffsetOnly ? _attributes[id]._data.offset :
static_cast<const char*>(_attributes[id]._data.pointer) - _vertexData.data(); static_cast<const char*>(_attributes[id]._data.pointer) - _vertexData.data();
} }
UnsignedInt MeshData::attributeStride(UnsignedInt id) const { UnsignedInt MeshData::attributeStride(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeStride(): index" << id << "out of range for" << _attributes.size() << "attributes", {}); "Trade::MeshData::attributeStride(): index" << id << "out of range for" << _attributes.size() << "attributes", {});
return _attributes[id]._stride; return _attributes[id]._stride;
} }
UnsignedShort MeshData::attributeArraySize(UnsignedInt id) const { UnsignedShort MeshData::attributeArraySize(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attributeArraySize(): index" << id << "out of range for" << _attributes.size() << "attributes", {}); "Trade::MeshData::attributeArraySize(): index" << id << "out of range for" << _attributes.size() << "attributes", {});
return _attributes[id]._arraySize; return _attributes[id]._arraySize;
@ -322,31 +322,31 @@ UnsignedInt MeshData::attributeFor(const MeshAttribute name, UnsignedInt id) con
#endif #endif
} }
UnsignedInt MeshData::attributeId(const MeshAttribute name, UnsignedInt id) const { UnsignedInt MeshData::attributeId(const MeshAttribute name, const UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeId(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeId(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attributeId; return attributeId;
} }
VertexFormat MeshData::attributeFormat(MeshAttribute name, UnsignedInt id) const { VertexFormat MeshData::attributeFormat(const MeshAttribute name, const UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeFormat(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeFormat(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attributeFormat(attributeId); return attributeFormat(attributeId);
} }
std::size_t MeshData::attributeOffset(MeshAttribute name, UnsignedInt id) const { std::size_t MeshData::attributeOffset(const MeshAttribute name, const UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeOffset(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeOffset(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attributeOffset(attributeId); return attributeOffset(attributeId);
} }
UnsignedInt MeshData::attributeStride(MeshAttribute name, UnsignedInt id) const { UnsignedInt MeshData::attributeStride(const MeshAttribute name, const UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeStride(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeStride(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attributeStride(attributeId); return attributeStride(attributeId);
} }
UnsignedShort MeshData::attributeArraySize(MeshAttribute name, UnsignedInt id) const { UnsignedShort MeshData::attributeArraySize(const MeshAttribute name, const UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeArraySize(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attributeArraySize(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attributeArraySize(attributeId); return attributeArraySize(attributeId);
@ -364,7 +364,7 @@ Containers::StridedArrayView1D<const void> MeshData::attributeDataViewInternal(c
_vertexCount, attribute._stride}; _vertexCount, attribute._stride};
} }
Containers::StridedArrayView2D<const char> MeshData::attribute(UnsignedInt id) const { Containers::StridedArrayView2D<const char> MeshData::attribute(const UnsignedInt id) const {
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::attribute(): index" << id << "out of range for" << _attributes.size() << "attributes", nullptr); "Trade::MeshData::attribute(): index" << id << "out of range for" << _attributes.size() << "attributes", nullptr);
const MeshAttributeData& attribute = _attributes[id]; const MeshAttributeData& attribute = _attributes[id];
@ -376,14 +376,14 @@ Containers::StridedArrayView2D<const char> MeshData::attribute(UnsignedInt id) c
(attribute._arraySize ? attribute._arraySize : 1)); (attribute._arraySize ? attribute._arraySize : 1));
} }
Containers::StridedArrayView2D<char> MeshData::mutableAttribute(UnsignedInt id) { Containers::StridedArrayView2D<char> MeshData::mutableAttribute(const UnsignedInt id) {
CORRADE_ASSERT(_vertexDataFlags & DataFlag::Mutable, CORRADE_ASSERT(_vertexDataFlags & DataFlag::Mutable,
"Trade::MeshData::mutableAttribute(): vertex data not mutable", {}); "Trade::MeshData::mutableAttribute(): vertex data not mutable", {});
CORRADE_ASSERT(id < _attributes.size(), CORRADE_ASSERT(id < _attributes.size(),
"Trade::MeshData::mutableAttribute(): index" << id << "out of range for" << _attributes.size() << "attributes", nullptr); "Trade::MeshData::mutableAttribute(): index" << id << "out of range for" << _attributes.size() << "attributes", nullptr);
const MeshAttributeData& attribute = _attributes[id]; const MeshAttributeData& attribute = _attributes[id];
/* Build a 2D view using information about attribute type size */ /* Build a 2D view using information about attribute type size */
auto out = Containers::arrayCast<2, const char>( const auto out = Containers::arrayCast<2, const char>(
attributeDataViewInternal(attribute), attributeDataViewInternal(attribute),
isVertexFormatImplementationSpecific(attribute._format) ? isVertexFormatImplementationSpecific(attribute._format) ?
attribute._stride : vertexFormatSize(attribute._format)* attribute._stride : vertexFormatSize(attribute._format)*
@ -396,13 +396,13 @@ Containers::StridedArrayView2D<char> MeshData::mutableAttribute(UnsignedInt id)
out.size(), out.stride()}; out.size(), out.stride()};
} }
Containers::StridedArrayView2D<const char> MeshData::attribute(MeshAttribute name, UnsignedInt id) const { Containers::StridedArrayView2D<const char> MeshData::attribute(const MeshAttribute name, UnsignedInt id) const {
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attribute(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {}); CORRADE_ASSERT(attributeId != ~UnsignedInt{}, "Trade::MeshData::attribute(): index" << id << "out of range for" << attributeCount(name) << name << "attributes", {});
return attribute(attributeId); return attribute(attributeId);
} }
Containers::StridedArrayView2D<char> MeshData::mutableAttribute(MeshAttribute name, UnsignedInt id) { Containers::StridedArrayView2D<char> MeshData::mutableAttribute(const MeshAttribute name, UnsignedInt id) {
CORRADE_ASSERT(_vertexDataFlags & DataFlag::Mutable, CORRADE_ASSERT(_vertexDataFlags & DataFlag::Mutable,
"Trade::MeshData::mutableAttribute(): vertex data not mutable", {}); "Trade::MeshData::mutableAttribute(): vertex data not mutable", {});
const UnsignedInt attributeId = attributeFor(name, id); const UnsignedInt attributeId = attributeFor(name, id);
@ -414,7 +414,7 @@ void MeshData::indicesInto(const Containers::StridedArrayView1D<UnsignedInt> des
CORRADE_ASSERT(isIndexed(), CORRADE_ASSERT(isIndexed(),
"Trade::MeshData::indicesInto(): the mesh is not indexed", ); "Trade::MeshData::indicesInto(): the mesh is not indexed", );
CORRADE_ASSERT(destination.size() == indexCount(), "Trade::MeshData::indicesInto(): expected a view with" << indexCount() << "elements but got" << destination.size(), ); CORRADE_ASSERT(destination.size() == indexCount(), "Trade::MeshData::indicesInto(): expected a view with" << indexCount() << "elements but got" << destination.size(), );
auto destination1ui = Containers::arrayCast<2, UnsignedInt>(destination); const auto destination1ui = Containers::arrayCast<2, UnsignedInt>(destination);
if(_indexType == MeshIndexType::UnsignedInt) if(_indexType == MeshIndexType::UnsignedInt)
return Utility::copy(Containers::arrayView(reinterpret_cast<const UnsignedInt*>(_indices), _indexCount), destination); return Utility::copy(Containers::arrayView(reinterpret_cast<const UnsignedInt*>(_indices), _indexCount), destination);

8
src/Magnum/Trade/MeshData.h

@ -2195,7 +2195,7 @@ template<class T, class> Containers::StridedArrayView2D<typename std::remove_ext
return Containers::arrayCast<2, typename std::remove_extent<T>::type>(data); return Containers::arrayCast<2, typename std::remove_extent<T>::type>(data);
} }
template<class T, class> Containers::StridedArrayView1D<const T> MeshData::attribute(MeshAttribute name, UnsignedInt id) const { template<class T, class> Containers::StridedArrayView1D<const T> MeshData::attribute(const MeshAttribute name, const UnsignedInt id) const {
Containers::StridedArrayView2D<const char> data = attribute(name, id); Containers::StridedArrayView2D<const char> data = attribute(name, id);
#ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */ #ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */
if(!data.stride()[1]) return {}; if(!data.stride()[1]) return {};
@ -2206,7 +2206,7 @@ template<class T, class> Containers::StridedArrayView1D<const T> MeshData::attri
return Containers::arrayCast<1, const T>(data); return Containers::arrayCast<1, const T>(data);
} }
template<class T, class> Containers::StridedArrayView2D<const typename std::remove_extent<T>::type> MeshData::attribute(MeshAttribute name, UnsignedInt id) const { template<class T, class> Containers::StridedArrayView2D<const typename std::remove_extent<T>::type> MeshData::attribute(const MeshAttribute name, const UnsignedInt id) const {
Containers::StridedArrayView2D<const char> data = attribute(name, id); Containers::StridedArrayView2D<const char> data = attribute(name, id);
#ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */ #ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */
if(!data.stride()[1]) return {}; if(!data.stride()[1]) return {};
@ -2218,7 +2218,7 @@ template<class T, class> Containers::StridedArrayView2D<const typename std::remo
return Containers::arrayCast<2, const typename std::remove_extent<T>::type>(data); return Containers::arrayCast<2, const typename std::remove_extent<T>::type>(data);
} }
template<class T, class> Containers::StridedArrayView1D<T> MeshData::mutableAttribute(MeshAttribute name, UnsignedInt id) { template<class T, class> Containers::StridedArrayView1D<T> MeshData::mutableAttribute(const MeshAttribute name, const UnsignedInt id) {
Containers::StridedArrayView2D<char> data = mutableAttribute(name, id); Containers::StridedArrayView2D<char> data = mutableAttribute(name, id);
#ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */ #ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */
if(!data.stride()[1]) return {}; if(!data.stride()[1]) return {};
@ -2229,7 +2229,7 @@ template<class T, class> Containers::StridedArrayView1D<T> MeshData::mutableAttr
return Containers::arrayCast<1, T>(data); return Containers::arrayCast<1, T>(data);
} }
template<class T, class> Containers::StridedArrayView2D<typename std::remove_extent<T>::type> MeshData::mutableAttribute(MeshAttribute name, UnsignedInt id) { template<class T, class> Containers::StridedArrayView2D<typename std::remove_extent<T>::type> MeshData::mutableAttribute(const MeshAttribute name, const UnsignedInt id) {
Containers::StridedArrayView2D<char> data = mutableAttribute(name, id); Containers::StridedArrayView2D<char> data = mutableAttribute(name, id);
#ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */ #ifdef CORRADE_GRACEFUL_ASSERT /* Sigh. Brittle. Better idea? */
if(!data.stride()[1]) return {}; if(!data.stride()[1]) return {};

Loading…
Cancel
Save