summaryrefslogtreecommitdiffstats
path: root/src/render/io
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-10-20 08:44:50 +0200
committerPaul Lemire <paul.lemire@kdab.com>2014-10-22 10:45:16 +0200
commit5d31b5f774475f87a00447c4eac6eb96e9651675 (patch)
treee0206fbc355033b2d41a2ef423feb5c8fc488e8e /src/render/io
parent0c8a6df93997e7aba0c8269ce986bd8fe4168d5b (diff)
QAbstractMeshData merged with QMeshData and moved to Renderer
That implied moving QAbstractMesh to Renderer as well. Change-Id: I9013bf0458b849f7805d214a70580a80e86d8c84 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/gltfparser.cpp6
-rw-r--r--src/render/io/gltfparser_p.h2
-rw-r--r--src/render/io/objloader.cpp10
-rw-r--r--src/render/io/qmeshdata.cpp114
-rw-r--r--src/render/io/qmeshdata.h53
-rw-r--r--src/render/io/qmeshdata_p.h22
-rw-r--r--src/render/io/render-io.pri8
7 files changed, 173 insertions, 42 deletions
diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp
index c78e844e7..f41a5ed23 100644
--- a/src/render/io/gltfparser.cpp
+++ b/src/render/io/gltfparser.cpp
@@ -74,7 +74,7 @@
// need to move these to somewhere common?
#include <Qt3DRenderer/private/renderstate_p.h>
#include <Qt3DRenderer/private/blendstate_p.h>
-#include <Qt3DCore/private/qabstractmesh_p.h>
+#include <private/qabstractmesh_p.h>
QT_BEGIN_NAMESPACE
@@ -215,7 +215,7 @@ private:
{
public:
explicit GLTFParserMeshFunctor(QMeshDataPtr meshData);
- QAbstractMeshDataPtr operator ()() Q_DECL_OVERRIDE;
+ QMeshDataPtr operator ()() Q_DECL_OVERRIDE;
bool operator ==(const QAbstractMeshFunctor &other) const Q_DECL_OVERRIDE;
private:
@@ -1041,7 +1041,7 @@ GLTFParserMesh::GLTFParserMeshFunctor::GLTFParserMeshFunctor(QMeshDataPtr meshDa
{
}
-QAbstractMeshDataPtr GLTFParserMesh::GLTFParserMeshFunctor::operator ()()
+QMeshDataPtr GLTFParserMesh::GLTFParserMeshFunctor::operator ()()
{
return m_meshData;
}
diff --git a/src/render/io/gltfparser_p.h b/src/render/io/gltfparser_p.h
index ffbb18930..10d8bfab7 100644
--- a/src/render/io/gltfparser_p.h
+++ b/src/render/io/gltfparser_p.h
@@ -50,7 +50,7 @@
#include <Qt3DRenderer/qbuffer.h>
#include <QJsonDocument>
#include <QMultiHash>
-#include <Qt3DCore/qabstractmesh.h>
+#include <Qt3DRenderer/qabstractmesh.h>
#include <QImage>
#include <Qt3DRenderer/private/abstractsceneparser_p.h>
diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp
index 9956bb9af..4afadfae3 100644
--- a/src/render/io/objloader.cpp
+++ b/src/render/io/objloader.cpp
@@ -254,21 +254,21 @@ QMeshData *ObjLoader::mesh() const
buf->setData(bufferBytes);
- mesh->addAttribute(QAbstractMeshData::defaultPositionAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, 0, stride)));
+ mesh->addAttribute(QMeshData::defaultPositionAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, 0, stride)));
quint32 offset = sizeof(float) * 3;
if (hasTextureCoordinates()) {
- mesh->addAttribute(QAbstractMeshData::defaultTextureCoordinateAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC2, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultTextureCoordinateAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC2, count, offset, stride)));
offset += sizeof(float) * 2;
}
if (hasNormals()) {
- mesh->addAttribute(QAbstractMeshData::defaultNormalAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultNormalAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, offset, stride)));
offset += sizeof(float) * 3;
}
if (hasTangents()) {
- mesh->addAttribute(QAbstractMeshData::defaultTangentAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC4, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultTangentAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC4, count, offset, stride)));
offset += sizeof(float) * 4;
}
@@ -294,7 +294,7 @@ QMeshData *ObjLoader::mesh() const
indexBuffer->setData(indexBytes);
mesh->setIndexAttribute(AttributePtr(new Attribute(indexBuffer, ty, m_indices.size(), 0, 0)));
- mesh->computeBoundsFromAttribute(QAbstractMeshData::defaultPositionAttributeName());
+ mesh->computeBoundsFromAttribute(QMeshData::defaultPositionAttributeName());
qCDebug(Render::Io) << "computed bounds is:" << mesh->boundingBox();
return mesh;
diff --git a/src/render/io/qmeshdata.cpp b/src/render/io/qmeshdata.cpp
index 00c7c3a05..3cc848c64 100644
--- a/src/render/io/qmeshdata.cpp
+++ b/src/render/io/qmeshdata.cpp
@@ -41,9 +41,8 @@
#include "qmeshdata.h"
#include "qmeshdata_p.h"
-
-#include <QSet>
-#include "renderlogging.h"
+#include <Qt3DCore/qabstractattribute.h>
+#include <Qt3DCore/qabstractbuffer.h>
#include <QOpenGLVertexArrayObject>
QT_BEGIN_NAMESPACE
@@ -51,25 +50,118 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
QMeshDataPrivate::QMeshDataPrivate(QMeshData *qq)
- : QAbstractMeshDataPrivate(qq)
+ : q_ptr(qq)
+ , m_verticesPerPatch(0)
, m_primitiveType(0)
{
}
-QMeshData::QMeshData()
- : QAbstractMeshData(*new QMeshDataPrivate(this))
+QMeshData::QMeshData(int primitiveType)
+ : d_ptr(new QMeshDataPrivate(this))
+{
+ setPrimitiveType(primitiveType);
+}
+
+QMeshData::~QMeshData()
{
}
QMeshData::QMeshData(QMeshDataPrivate &dd)
- : QAbstractMeshData(dd)
+ : d_ptr(&dd)
{
}
-QMeshData::QMeshData(int primitiveType)
- : QAbstractMeshData(*new QMeshDataPrivate(this))
+void QMeshData::addAttribute(const QString &name, QAbstractAttributePtr attr)
{
- setPrimitiveType(primitiveType);
+ Q_D(QMeshData);
+ d->m_attributes.insert(name, attr);
+}
+
+void QMeshData::setIndexAttribute(QAbstractAttributePtr attr)
+{
+ Q_D(QMeshData);
+ d->m_indexAttr = attr;
+}
+
+QStringList QMeshData::attributeNames() const
+{
+ Q_D(const QMeshData);
+ return d->m_attributes.keys();
+}
+
+QAbstractAttributePtr QMeshData::attributeByName(QString name) const
+{
+ Q_D(const QMeshData);
+ return d->m_attributes.value(name);
+}
+
+QAbstractAttributePtr QMeshData::indexAttribute() const
+{
+ Q_D(const QMeshData);
+ return d->m_indexAttr;
+}
+
+void QMeshData::setVerticesPerPatch(int verticesPerPatch)
+{
+ Q_D(QMeshData);
+ d->m_verticesPerPatch = verticesPerPatch;
+}
+
+int QMeshData::verticesPerPatch() const
+{
+ Q_D(const QMeshData);
+ return d->m_verticesPerPatch;
+}
+
+int QMeshData::primitiveCount() const
+{
+ Q_D(const QMeshData);
+ if (d->m_indexAttr) {
+ return d->m_indexAttr->count();
+ } else {
+ // assume all attribute arrays have the same size
+ // will break with instanced drawing, but probably per-instance
+ // arrays aren't coming from this code-path.
+ // Maybe.
+ return d->m_attributes.first()->count();
+ }
+}
+
+QList<QAbstractBufferPtr> QMeshData::buffers() const
+{
+ Q_D(const QMeshData);
+ QSet<QAbstractBufferPtr> r;
+ if (d->m_indexAttr)
+ r.insert(d->m_indexAttr->buffer());
+
+ Q_FOREACH (QAbstractAttributePtr v, d->m_attributes.values())
+ r.insert(v->buffer());
+
+ return r.toList();
+}
+
+void QMeshData::setBoundingBox(const AxisAlignedBoundingBox &bbox)
+{
+ Q_D(QMeshData);
+ d->m_bbox = bbox;
+}
+
+void QMeshData::computeBoundsFromAttribute(const QString &name)
+{
+ Q_D(QMeshData);
+ QAbstractAttributePtr attr = attributeByName(name);
+ if (!attr) {
+ qWarning() << Q_FUNC_INFO << "unknoen attribute:" << name;
+ return;
+ }
+ d->m_bbox.clear();
+ d->m_bbox.update(attr->asVector3D());
+}
+
+AxisAlignedBoundingBox QMeshData::boundingBox() const
+{
+ Q_D(const QMeshData);
+ return d->m_bbox;
}
void QMeshData::setPrimitiveType(int primitiveType)
@@ -88,6 +180,6 @@ int QMeshData::primitiveType() const
return d->m_primitiveType;
}
-} // of namespace
+} // Qt3D
QT_END_NAMESPACE
diff --git a/src/render/io/qmeshdata.h b/src/render/io/qmeshdata.h
index 043ff7ba1..0165c3ac3 100644
--- a/src/render/io/qmeshdata.h
+++ b/src/render/io/qmeshdata.h
@@ -42,39 +42,64 @@
#ifndef QT3D_QMESHDATA_H
#define QT3D_QMESHDATA_H
-#include <QSharedPointer>
-#include <Qt3DCore/qabstractmeshdata.h>
#include <Qt3DRenderer/qt3drenderer_global.h>
+#include <Qt3DCore/axisalignedboundingbox.h>
+#include <QSharedPointer>
QT_BEGIN_NAMESPACE
namespace Qt3D {
-/**
- * @brief The QMeshData class is shared by all instances of a RenderMesh,
- * and holds the actual client (CPU)-side buffers representing mesh attributes
- * and indices.
- */
-
+class QAbstractAttribute;
+class QAbstractBuffer;
class QMeshDataPrivate;
-class QT3DRENDERERSHARED_EXPORT QMeshData : public QAbstractMeshData
+typedef QSharedPointer<QAbstractAttribute> QAbstractAttributePtr;
+typedef QSharedPointer<QAbstractBuffer> QAbstractBufferPtr;
+
+class QT3DRENDERERSHARED_EXPORT QMeshData
{
public:
- QMeshData();
- explicit QMeshData(int primitiveType);
+ explicit QMeshData(int primitiveType = 0);
+ virtual ~QMeshData();
+
+ void addAttribute(const QString& name, QAbstractAttributePtr attr);
+ void setIndexAttribute(QAbstractAttributePtr attr);
+
+ QStringList attributeNames() const;
+ QAbstractAttributePtr attributeByName(QString name) const;
+ QAbstractAttributePtr indexAttribute() const;
+
+ static const QString defaultPositionAttributeName() { return QStringLiteral("vertexPosition"); }
+ static const QString defaultNormalAttributeName() { return QStringLiteral("vertexNormal"); }
+ static const QString defaultColorAttributeName() { return QStringLiteral("vertexColor"); }
+ static const QString defaultTextureCoordinateAttributeName() { return QStringLiteral("vertexTexCoord"); }
+ static const QString defaultTangentAttributeName() { return QStringLiteral("vertexTangent"); }
+
+ void setPrimitiveType(int primitiveType);
+ int primitiveType() const;
+
+ void setVerticesPerPatch(int verticesPerPatch);
+ int verticesPerPatch() const;
+
+ int primitiveCount() const;
+
+ QList<QAbstractBufferPtr> buffers() const;
+
+ void setBoundingBox(const AxisAlignedBoundingBox &bbox);
+ void computeBoundsFromAttribute(const QString &name);
- void setPrimitiveType(int primitiveType) Q_DECL_OVERRIDE;
- int primitiveType() const Q_DECL_OVERRIDE;
+ AxisAlignedBoundingBox boundingBox() const;
protected:
Q_DECLARE_PRIVATE(QMeshData)
+ QMeshDataPrivate *d_ptr;
QMeshData(QMeshDataPrivate &dd);
};
typedef QSharedPointer<QMeshData> QMeshDataPtr;
-}
+} // Qt3D
QT_END_NAMESPACE
diff --git a/src/render/io/qmeshdata_p.h b/src/render/io/qmeshdata_p.h
index 9776e2719..774626754 100644
--- a/src/render/io/qmeshdata_p.h
+++ b/src/render/io/qmeshdata_p.h
@@ -42,20 +42,34 @@
#ifndef QT3D_QMESHDATA_P_H
#define QT3D_QMESHDATA_P_H
-#include <private/qabstractmeshdata_p.h>
-#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <Qt3DRenderer/qmeshdata.h>
+#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/axisalignedboundingbox.h>
+
+#include <QMap>
+#include <QSharedPointer>
QT_BEGIN_NAMESPACE
namespace Qt3D {
-class QT3DRENDERERSHARED_EXPORT QMeshDataPrivate : public QAbstractMeshDataPrivate
+class QMeshData;
+class QAbstractAttribute;
+class QAbstractBuffer;
+
+typedef QSharedPointer<QAbstractAttribute> QAbstractAttributePtr;
+
+class QT3DCORESHARED_EXPORT QMeshDataPrivate
{
public:
QMeshDataPrivate(QMeshData *qq);
Q_DECLARE_PUBLIC(QMeshData)
+ QMeshData *q_ptr;
+
+ QMap<QString, QAbstractAttributePtr> m_attributes;
+ QAbstractAttributePtr m_indexAttr;
+ AxisAlignedBoundingBox m_bbox;
+ int m_verticesPerPatch;
int m_primitiveType;
};
diff --git a/src/render/io/render-io.pri b/src/render/io/render-io.pri
index 5f8e6df09..f4fa77de5 100644
--- a/src/render/io/render-io.pri
+++ b/src/render/io/render-io.pri
@@ -1,7 +1,6 @@
INCLUDEPATH += $$PWD
HEADERS += \
- $$PWD/qmeshdata.h \
$$PWD/gltfparser_p.h \
$$PWD/objloader_p.h \
$$PWD/texturedata.h \
@@ -10,13 +9,14 @@ HEADERS += \
$$PWD/qattribute_p.h \
$$PWD/qbuffer.h \
$$PWD/qbuffer_p.h \
- $$PWD/qmeshdata_p.h
+ $$PWD/qmeshdata_p.h \
+ $$PWD/qmeshdata.h
SOURCES += \
- $$PWD/qmeshdata.cpp \
$$PWD/gltfparser.cpp \
$$PWD/objloader.cpp \
$$PWD/texturedata.cpp \
$$PWD/abstractsceneparser.cpp \
$$PWD/qattribute.cpp \
- $$PWD/qbuffer.cpp
+ $$PWD/qbuffer.cpp \
+ $$PWD/qmeshdata.cpp