summaryrefslogtreecommitdiffstats
path: root/src/render/io/gltfparser.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-08-04 12:40:59 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-08-07 14:31:54 +0000
commit975624820bbb086f0d7957236128ddb043e792d0 (patch)
tree542c17edee5cb5238704e7aa6c083f15045a6149 /src/render/io/gltfparser.cpp
parent4bbe0ad81a06fb42f3aab592e5645e546bfb90db (diff)
QAbstractAttribute: Type abstracted with an enum
Also added a dataSize property to know the number of components per vertice (1 - 4) Change-Id: Iaa7cee2a53958ed2ec2f603f3ffc7971c027991d Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/io/gltfparser.cpp')
-rw-r--r--src/render/io/gltfparser.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp
index 1baaf1712..65c800fb0 100644
--- a/src/render/io/gltfparser.cpp
+++ b/src/render/io/gltfparser.cpp
@@ -199,6 +199,59 @@ const QString KEY_INTERNAL_FORMAT = QStringLiteral("internalFormat");
// return QParameter::Undefined;
//}
+QAbstractAttribute::DataType typeFromGLType(GLint dataType, uint &dataCount)
+{
+ switch (dataType) {
+
+ case GL_UNSIGNED_SHORT:
+ dataCount = 1;
+ return QAbstractAttribute::UnsignedShort;
+
+ case GL_UNSIGNED_BYTE:
+ dataCount = 1;
+ return QAbstractAttribute::UnsignedByte;
+
+ case GL_UNSIGNED_INT:
+ dataCount = 1;
+ return QAbstractAttribute::UnsignedInt;
+
+ case GL_SHORT:
+ dataCount = 1;
+ return QAbstractAttribute::Short;
+
+ case GL_BYTE:
+ dataCount = 1;
+ return QAbstractAttribute::Byte;
+
+ case GL_INT:
+ dataCount = 1;
+ return QAbstractAttribute::Int;
+
+ case GL_FLOAT:
+ dataCount = 1;
+ break;
+
+ case GL_FLOAT_VEC2:
+ dataCount = 2;
+ break;
+
+ case GL_FLOAT_VEC3:
+ dataCount = 3;
+ break;
+
+ case GL_FLOAT_VEC4:
+ dataCount = 4;
+ break;
+
+// TO DO: Handle doubles
+
+ default:
+ Q_UNREACHABLE();
+ }
+
+ return QAbstractAttribute::Float;
+}
+
} // of anonymous namespace
class GLTFParserMeshPrivate;
@@ -677,7 +730,10 @@ void GLTFParser::processJSONAccessor( QString id, const QJsonObject& json )
if ( json.contains(KEY_BYTE_STRIDE))
stride = json.value(KEY_BYTE_STRIDE).toInt();
- QAttribute *attr( new QAttribute( buf, type, count, offset, stride ) );
+ uint dataSize = 0;
+ QAttribute::DataType dataType = typeFromGLType(type, dataSize);
+
+ QAttribute *attr( new QAttribute( buf, dataType, dataSize, count, offset, stride ) );
m_attributeDict[id] = attr;
}