From fc6ffba424bf279cd5e37bec76a7d9589254aac7 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 13 Jan 2017 16:48:52 +0000 Subject: ObjLoader: actually check for the indices' values The decision whether we can use ushort instead of uint for the entries in the index buffer depends on the value of each entry, not on how many entries (indices) we have. Clean up the related code. Task-number: QTBUG-44089 Change-Id: Id8e1cb422c1bd3a84f8964864a41cc4784edce61 Reviewed-by: Sean Harmer --- src/render/io/objloader.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/render/io') diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp index 686a9d5f0..aaecac9e8 100644 --- a/src/render/io/objloader.cpp +++ b/src/render/io/objloader.cpp @@ -56,6 +56,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE namespace Qt3DRender { @@ -405,19 +407,17 @@ QGeometry *ObjLoader::geometry() const QByteArray indexBytes; QAttribute::VertexBaseType ty; - if (m_indices.size() < 65536) { + if (std::all_of(m_indices.cbegin(), m_indices.cend(), [](unsigned int index) { return index < 65536; })) { // we can use USHORT ty = QAttribute::UnsignedShort; indexBytes.resize(m_indices.size() * sizeof(quint16)); - quint16* usptr = reinterpret_cast(indexBytes.data()); - for (int i=0; i(m_indices.at(i)); + quint16 *usptr = reinterpret_cast(indexBytes.data()); + std::copy(m_indices.cbegin(), m_indices.cend(), usptr); } else { - // use UINT - no conversion needed, but let's ensure int is 32-bit! + // use UINT ty = QAttribute::UnsignedInt; - Q_ASSERT(sizeof(int) == sizeof(quint32)); indexBytes.resize(m_indices.size() * sizeof(quint32)); - memcpy(indexBytes.data(), reinterpret_cast(m_indices.data()), indexBytes.size()); + memcpy(indexBytes.data(), reinterpret_cast(m_indices.constData()), indexBytes.size()); } QBuffer *indexBuffer(new QBuffer(QBuffer::IndexBuffer)); -- cgit v1.2.3