summaryrefslogtreecommitdiff
path: root/src/render/io
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-01-13 16:48:52 +0000
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-01-13 17:00:26 +0000
commitfc6ffba424bf279cd5e37bec76a7d9589254aac7 (patch)
tree7767777ae5f74cc32207d47e13da7705ba447cf3 /src/render/io
parent43d7e7cb6e02fe0c0743d2441a7d2726ed9260b4 (diff)
downloadqt3d-fc6ffba424bf279cd5e37bec76a7d9589254aac7.tar.gz
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 <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/objloader.cpp14
1 files changed, 7 insertions, 7 deletions
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 <Qt3DRender/qattribute.h>
#include <Qt3DRender/qbuffer.h>
+#include <algorithm>
+
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<quint16*>(indexBytes.data());
- for (int i=0; i<m_indices.size(); ++i)
- *usptr++ = static_cast<quint16>(m_indices.at(i));
+ quint16 *usptr = reinterpret_cast<quint16 *>(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<const char*>(m_indices.data()), indexBytes.size());
+ memcpy(indexBytes.data(), reinterpret_cast<const char *>(m_indices.constData()), indexBytes.size());
}
QBuffer *indexBuffer(new QBuffer(QBuffer::IndexBuffer));