summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-07-02 11:21:15 +0200
committerSean Harmer <sean.harmer@kdab.com>2014-07-05 16:03:12 +0200
commita20f272b2fe5179d95e397afc6aa3ed80afb7188 (patch)
tree7f9af56369176cb4eecd9acf073baf7479a1f0ef /src
parent0bb42c0ae5d47911334c03e29ef9918966d462f8 (diff)
Refactoring of MeshData, Buffer, Mesh and Attribute
They are now subclasses of the abstracts defined in the previous path. QAbstractMesh's source property was transferred to QMesh, this will allow to have ShapeMeshes subclass QAbstractMesh directly and not have a useless source property. MeshData, Buffer and Attribute moved to their own files and properly d-pointered. Change-Id: I6d09b00a17045826e16503f5fb2d8f8eb0f2abf2 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/core-components/qabstractmesh.cpp21
-rw-r--r--src/core/core-components/qabstractmesh.h10
-rw-r--r--src/core/core-components/qabstractmesh_p.h1
-rw-r--r--src/render/backend/jobs/loadmeshdatajob.cpp5
-rw-r--r--src/render/backend/qgraphicscontext.cpp6
-rw-r--r--src/render/backend/qgraphicscontext.h2
-rw-r--r--src/render/backend/renderer.cpp10
-rw-r--r--src/render/frontend/qabstractshapemesh.cpp2
-rw-r--r--src/render/frontend/qabstractshapemesh.h4
-rw-r--r--src/render/frontend/qitemmodelbuffer.cpp1
-rw-r--r--src/render/frontend/qitemmodelbuffer.h2
-rw-r--r--src/render/frontend/qmesh.cpp22
-rw-r--r--src/render/frontend/qmesh.h13
-rw-r--r--src/render/frontend/qmesh_p.h2
-rw-r--r--src/render/frontend/qspheremesh.cpp14
-rw-r--r--src/render/frontend/qspheremesh.h2
-rw-r--r--src/render/frontend/qtorusmesh.cpp16
-rw-r--r--src/render/frontend/qtorusmesh.h4
-rw-r--r--src/render/io/assimpparser.cpp20
-rw-r--r--src/render/io/gltfparser.cpp2
-rw-r--r--src/render/io/gltfparser.h4
-rw-r--r--src/render/io/meshdata.cpp385
-rw-r--r--src/render/io/meshdata.h125
-rw-r--r--src/render/io/meshdata_p.h67
-rw-r--r--src/render/io/objloader.cpp12
-rw-r--r--src/render/io/qattribute.cpp209
-rw-r--r--src/render/io/qattribute.h76
-rw-r--r--src/render/io/qattribute_p.h66
-rw-r--r--src/render/io/qbuffer.cpp205
-rw-r--r--src/render/io/qbuffer.h88
-rw-r--r--src/render/io/qbuffer_p.h69
-rw-r--r--src/render/io/render-io.pri11
32 files changed, 911 insertions, 565 deletions
diff --git a/src/core/core-components/qabstractmesh.cpp b/src/core/core-components/qabstractmesh.cpp
index 63be40a94..63c740749 100644
--- a/src/core/core-components/qabstractmesh.cpp
+++ b/src/core/core-components/qabstractmesh.cpp
@@ -77,27 +77,6 @@ QAbstractMesh::QAbstractMesh(QAbstractMeshPrivate &dd, Node *parent)
}
/*!
- * Sets the \a source of the mesh
- */
-void QAbstractMesh::setSource(const QString &source)
-{
- Q_D(QAbstractMesh);
- if (d->m_source != source) {
- d->m_source = source;
- emit sourceChanged();
- }
-}
-
-/*!
- * Returns the source of a mesh.
- */
-QString QAbstractMesh::source() const
-{
- Q_D(const QAbstractMesh);
- return d->m_source;
-}
-
-/*!
* Returns a QUuid uniquely identifying the mesh.
*/
const QUuid QAbstractMesh::uuid() const
diff --git a/src/core/core-components/qabstractmesh.h b/src/core/core-components/qabstractmesh.h
index c42946f56..ad5a3fe47 100644
--- a/src/core/core-components/qabstractmesh.h
+++ b/src/core/core-components/qabstractmesh.h
@@ -50,20 +50,22 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
class QAbstractMeshPrivate;
+class QAbstractMeshData;
+
+typedef QSharedPointer<QAbstractMeshData> QAbstractMeshDataPtr;
class QT3DCORESHARED_EXPORT QAbstractMesh : public Component
{
Q_OBJECT
- Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
public:
QAbstractMesh(Node *parent = 0);
- virtual void setSource(const QString &source);
- QString source() const;
-
const QUuid uuid() const;
+ virtual QAbstractMeshDataPtr data() = 0;
+ virtual void setData(QAbstractMeshDataPtr data) = 0;
+
Q_SIGNALS:
void sourceChanged();
diff --git a/src/core/core-components/qabstractmesh_p.h b/src/core/core-components/qabstractmesh_p.h
index e30ae222f..75f04839e 100644
--- a/src/core/core-components/qabstractmesh_p.h
+++ b/src/core/core-components/qabstractmesh_p.h
@@ -61,7 +61,6 @@ public:
Q_DECLARE_PUBLIC(QAbstractMesh)
- QString m_source;
const QUuid m_uuid;
};
diff --git a/src/render/backend/jobs/loadmeshdatajob.cpp b/src/render/backend/jobs/loadmeshdatajob.cpp
index 7275a8119..a042ce90d 100644
--- a/src/render/backend/jobs/loadmeshdatajob.cpp
+++ b/src/render/backend/jobs/loadmeshdatajob.cpp
@@ -46,6 +46,7 @@
#include <qmesh.h>
#include <renderer.h>
#include <meshdatamanager.h>
+#include <qattribute.h>
#include <QThread>
#include "renderlogging.h"
@@ -74,7 +75,7 @@ void LoadMeshDataJob::run()
qCDebug(Jobs) << Q_FUNC_INFO << "Mesh has raw data";
MeshData *meshData = m_renderer->meshDataManager()->getOrCreateResource(m_meshSource->uuid());
MeshDataManager::WriteLocker(m_renderer->meshDataManager());
- *meshData = *(m_meshSource->data().data());
+ *meshData = *(m_meshSource->data().staticCast<MeshData>().data());
}
}
else {
@@ -86,7 +87,7 @@ void LoadMeshDataJob::run()
MeshData *meshData = m_renderer->meshDataManager()->getOrCreateResource(m_meshSource->uuid());
MeshDataManager::WriteLocker(m_renderer->meshDataManager());
*meshData = *loader.mesh();
- AttributePtr attr = meshData->attributeByName(QStringLiteral("position"));
+ AttributePtr attr = meshData->attributeByName(QStringLiteral("position")).staticCast<Attribute>();
if (!attr) {
qCWarning(Jobs) << Q_FUNC_INFO << "unknown attribute: position";
return;
diff --git a/src/render/backend/qgraphicscontext.cpp b/src/render/backend/qgraphicscontext.cpp
index 15a80d225..5b60322c6 100644
--- a/src/render/backend/qgraphicscontext.cpp
+++ b/src/render/backend/qgraphicscontext.cpp
@@ -507,7 +507,7 @@ void QGraphicsContext::setUniforms(const QUniformPack &uniforms)
void QGraphicsContext::specifyAttribute(QString nm, AttributePtr attr)
{
- QOpenGLBuffer buf = glBufferFor(attr->buffer());
+ QOpenGLBuffer buf = glBufferFor(attr->buffer().staticCast<Buffer>());
buf.bind();
QOpenGLShaderProgram* prog = activeShader();
@@ -533,12 +533,12 @@ void QGraphicsContext::specifyAttribute(QString nm, AttributePtr attr)
void QGraphicsContext::specifyIndices(AttributePtr attr)
{
- if (attr->buffer()->type() != QOpenGLBuffer::IndexBuffer) {
+ if (attr->buffer().staticCast<Buffer>()->type() != QOpenGLBuffer::IndexBuffer) {
qCWarning(Backend) << Q_FUNC_INFO << "provided buffer is not correct type";
return;
}
- QOpenGLBuffer buf = glBufferFor(attr->buffer());
+ QOpenGLBuffer buf = glBufferFor(attr->buffer().staticCast<Buffer>());
if (!buf.bind())
qCWarning(Backend) << Q_FUNC_INFO << "binding index buffer failed";
diff --git a/src/render/backend/qgraphicscontext.h b/src/render/backend/qgraphicscontext.h
index 241d32d5f..a355517d8 100644
--- a/src/render/backend/qgraphicscontext.h
+++ b/src/render/backend/qgraphicscontext.h
@@ -51,6 +51,8 @@
#include <Qt3DRenderer/quniformvalue.h>
#include <Qt3DRenderer/rendercamera.h>
#include <Qt3DRenderer/meshdata.h>
+#include <Qt3DRenderer/qattribute.h>
+#include <Qt3DRenderer/qbuffer.h>
QT_BEGIN_NAMESPACE
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index c7f06aef9..c93822560 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -518,7 +518,7 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
// Manager should have a VAO Manager that are indexed by MeshData and Shader
// RenderCommand should have a handle to the corresponding VAO for the Mesh and Shader
- bool drawIndexed = !meshData->indexAttr().isNull();
+ bool drawIndexed = !meshData->indexAttribute().isNull();
//// Initialize GL
if (!vao->isCreated()) {
@@ -531,14 +531,14 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
// TO DO : Do that in a better / nicer way
Q_FOREACH (QString nm, meshData->attributeNames()) {
- AttributePtr attr(meshData->attributeByName(nm));
+ AttributePtr attr(meshData->attributeByName(nm).staticCast<Attribute>());
if (command->m_parameterAttributeToShaderNames.contains(nm))
m_graphicsContext->specifyAttribute(command->m_parameterAttributeToShaderNames[nm], attr);
else
qCWarning(Render::Rendering) << "Couldn't find a Parameter attribute named " << nm;
}
if (drawIndexed)
- m_graphicsContext->specifyIndices(meshData->indexAttr());
+ m_graphicsContext->specifyIndices(meshData->indexAttribute().staticCast<Attribute>());
vao->release();
}
@@ -558,13 +558,13 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
vao->bind();
GLint primType = meshData->primitiveType();
GLint primCount = meshData->primitiveCount();
- GLint indexType = drawIndexed ? meshData->indexAttr()->type() : 0;
+ GLint indexType = drawIndexed ? meshData->indexAttribute()->type() : 0;
if (drawIndexed)
m_graphicsContext->drawElements(primType,
primCount,
indexType,
- reinterpret_cast<void*>(meshData->indexAttr()->byteOffset()));
+ reinterpret_cast<void*>(meshData->indexAttribute()->byteOffset()));
else
m_graphicsContext->drawArrays(primType, 0, primCount);
diff --git a/src/render/frontend/qabstractshapemesh.cpp b/src/render/frontend/qabstractshapemesh.cpp
index c6698eedf..5066c89c8 100644
--- a/src/render/frontend/qabstractshapemesh.cpp
+++ b/src/render/frontend/qabstractshapemesh.cpp
@@ -65,7 +65,7 @@ QAbstractShapeMesh::QAbstractShapeMesh(QAbstractShapeMeshPrivate &dd, Node *pare
{
}
-MeshDataPtr QAbstractShapeMesh::data()
+QAbstractMeshDataPtr QAbstractShapeMesh::data()
{
Q_D(const QAbstractShapeMesh);
if (!d->m_loaded) {
diff --git a/src/render/frontend/qabstractshapemesh.h b/src/render/frontend/qabstractshapemesh.h
index 8a85b3a65..915daf337 100644
--- a/src/render/frontend/qabstractshapemesh.h
+++ b/src/render/frontend/qabstractshapemesh.h
@@ -61,8 +61,8 @@ class QT3DRENDERERSHARED_EXPORT QAbstractShapeMesh : public QMesh
public:
explicit QAbstractShapeMesh(Node *parent = 0);
- virtual MeshDataPtr data() Q_DECL_OVERRIDE;
- virtual MeshDataPtr buildMeshdata() const = 0;
+ virtual QAbstractMeshDataPtr data() Q_DECL_OVERRIDE;
+ virtual QAbstractMeshDataPtr buildMeshdata() const = 0;
protected:
Q_DECLARE_PRIVATE(QAbstractShapeMesh)
diff --git a/src/render/frontend/qitemmodelbuffer.cpp b/src/render/frontend/qitemmodelbuffer.cpp
index d52a912a8..0b9ad3f37 100644
--- a/src/render/frontend/qitemmodelbuffer.cpp
+++ b/src/render/frontend/qitemmodelbuffer.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qitemmodelbuffer.h"
-
#include <QDebug>
#include <QColor>
diff --git a/src/render/frontend/qitemmodelbuffer.h b/src/render/frontend/qitemmodelbuffer.h
index cd147b2fe..d71cad09b 100644
--- a/src/render/frontend/qitemmodelbuffer.h
+++ b/src/render/frontend/qitemmodelbuffer.h
@@ -46,6 +46,8 @@
#include <Qt3DRenderer/qt3drenderer_global.h>
#include <Qt3DRenderer/meshdata.h>
+#include <Qt3DRenderer/qbuffer.h>
+#include <Qt3DRenderer/qattribute.h>
#include <QAbstractItemModel>
#include <QMap>
diff --git a/src/render/frontend/qmesh.cpp b/src/render/frontend/qmesh.cpp
index e91ded59d..fcf33ecdf 100644
--- a/src/render/frontend/qmesh.cpp
+++ b/src/render/frontend/qmesh.cpp
@@ -56,7 +56,6 @@ namespace Qt3D {
QMeshPrivate::QMeshPrivate(QMesh *qq)
: QAbstractMeshPrivate(qq)
- , m_sourceDirty(false)
{}
QMesh::QMesh(Node *parent)
@@ -72,28 +71,33 @@ QMesh::QMesh(QMeshPrivate &dd, Node *parent)
void QMesh::setSource( const QString& source )
{
Q_D(QMesh);
- if (QAbstractMesh::source() == source)
+ if (d->m_source == source)
return;
- QAbstractMesh::setSource(source);
- d->m_sourceDirty = true;
-
+ d->m_source = source;
+ emit sourceChanged();
// Let aspects know about the change
QScenePropertyChangePtr e(new QScenePropertyChange(ComponentUpdated, this));
e->m_propertyName = QByteArrayLiteral("source");
- e->m_value = QAbstractMesh::source();
+ e->m_value = d->m_source;
notifyObservers(e);
}
-MeshDataPtr QMesh::data()
+QString QMesh::source() const
+{
+ Q_D(const QMesh);
+ return d->m_source;
+}
+
+QAbstractMeshDataPtr QMesh::data()
{
Q_D(const QMesh);
return d->m_data;
}
-void QMesh::setData(MeshDataPtr data)
+void QMesh::setData(QAbstractMeshDataPtr data)
{
Q_D(QMesh);
- d->m_data = data;
+ d->m_data = data.staticCast<MeshData>();
}
} // namespace Qt3D
diff --git a/src/render/frontend/qmesh.h b/src/render/frontend/qmesh.h
index ae52a64c7..a28152aa0 100644
--- a/src/render/frontend/qmesh.h
+++ b/src/render/frontend/qmesh.h
@@ -51,7 +51,9 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
class QMeshPrivate;
+class QAbstractMeshData;
+typedef QSharedPointer<QAbstractMeshData> QAbstractMeshDataPtr;
/**
* @brief Simple static mesh
*
@@ -59,16 +61,21 @@ class QMeshPrivate;
class QT3DRENDERERSHARED_EXPORT QMesh : public QAbstractMesh
{
Q_OBJECT
+ Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
public:
explicit QMesh(Node *parent = 0);
- void setSource(const QString &source) Q_DECL_OVERRIDE;
+ void setSource(const QString &source);
+ QString source() const;
// Not const because subclasses may want to perform
// more than just returning a MeshData straight away
- virtual MeshDataPtr data();
- void setData(MeshDataPtr d);
+ virtual QAbstractMeshDataPtr data() Q_DECL_OVERRIDE;
+ void setData(QAbstractMeshDataPtr d) Q_DECL_OVERRIDE;
+
+Q_SIGNALS:
+ void sourceChanged();
protected:
Q_DECLARE_PRIVATE(QMesh)
diff --git a/src/render/frontend/qmesh_p.h b/src/render/frontend/qmesh_p.h
index 75c7d3cf3..c6c6c1989 100644
--- a/src/render/frontend/qmesh_p.h
+++ b/src/render/frontend/qmesh_p.h
@@ -60,7 +60,7 @@ public:
Q_DECLARE_PUBLIC(QMesh)
MeshDataPtr m_data;
- bool m_sourceDirty;
+ QString m_source;
};
} // Qt3D
diff --git a/src/render/frontend/qspheremesh.cpp b/src/render/frontend/qspheremesh.cpp
index 3a2dea36d..9c6a69b46 100644
--- a/src/render/frontend/qspheremesh.cpp
+++ b/src/render/frontend/qspheremesh.cpp
@@ -43,6 +43,8 @@
#include "qspheremesh.h"
#include "renderlogging.h"
#include "qabstractshapemesh_p.h"
+#include "qbuffer.h"
+#include "qattribute.h"
#include <cmath>
@@ -132,7 +134,7 @@ float QSphereMesh::radius() const
return d->m_radius;
}
-MeshDataPtr QSphereMesh::buildMeshdata() const
+QAbstractMeshDataPtr QSphereMesh::buildMeshdata() const
{
Q_D(const QSphereMesh);
return createSphereMesh(d->m_radius, d->m_rings, d->m_slices, d->m_generateTangents);
@@ -196,17 +198,17 @@ MeshDataPtr QSphereMesh::createSphereMesh(double radius, int rings, int slices,
buf->setUsage(QOpenGLBuffer::StaticDraw);
buf->setData(bufferBytes);
- mesh->addAttribute(QStringLiteral("position"), new Attribute(buf, GL_FLOAT_VEC3, nVerts, 0, stride));
+ mesh->addAttribute(QStringLiteral("position"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, nVerts, 0, stride)));
quint32 offset = sizeof(float) * 3;
- mesh->addAttribute(QStringLiteral("texcoord"), new Attribute(buf, GL_FLOAT_VEC2, nVerts, offset, stride));
+ mesh->addAttribute(QStringLiteral("texcoord"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC2, nVerts, offset, stride)));
offset += sizeof(float) * 2;
- mesh->addAttribute(QStringLiteral("normal"), new Attribute(buf, GL_FLOAT_VEC3, nVerts, offset, stride));
+ mesh->addAttribute(QStringLiteral("normal"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, nVerts, offset, stride)));
offset += sizeof(float) * 3;
if (hasTangents) {
- mesh->addAttribute(QStringLiteral("tangent"), new Attribute(buf, GL_FLOAT_VEC4, nVerts, offset, stride));
+ mesh->addAttribute(QStringLiteral("tangent"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC4, nVerts, offset, stride)));
offset += sizeof(float) * 4;
}
@@ -262,7 +264,7 @@ MeshDataPtr QSphereMesh::createSphereMesh(double radius, int rings, int slices,
BufferPtr indexBuffer(new Buffer(QOpenGLBuffer::IndexBuffer));
indexBuffer->setUsage(QOpenGLBuffer::StaticDraw);
indexBuffer->setData(indexBytes);
- mesh->setIndexAttr(AttributePtr(new Attribute(indexBuffer, GL_UNSIGNED_SHORT, indices, 0, 0)));
+ mesh->setIndexAttribute(AttributePtr(new Attribute(indexBuffer, GL_UNSIGNED_SHORT, indices, 0, 0)));
mesh->computeBoundsFromAttribute(QStringLiteral("position"));
qCDebug(Render::Frontend) << "computed sphere bounds is:" << mesh->boundingBox();
diff --git a/src/render/frontend/qspheremesh.h b/src/render/frontend/qspheremesh.h
index 479416936..c981ee586 100644
--- a/src/render/frontend/qspheremesh.h
+++ b/src/render/frontend/qspheremesh.h
@@ -73,7 +73,7 @@ public:
float radius() const;
bool generateTangents() const;
- MeshDataPtr buildMeshdata() const Q_DECL_OVERRIDE;
+ QAbstractMeshDataPtr buildMeshdata() const Q_DECL_OVERRIDE;
Q_SIGNALS:
diff --git a/src/render/frontend/qtorusmesh.cpp b/src/render/frontend/qtorusmesh.cpp
index caf57764e..1de0f1729 100644
--- a/src/render/frontend/qtorusmesh.cpp
+++ b/src/render/frontend/qtorusmesh.cpp
@@ -42,6 +42,8 @@
#define _USE_MATH_DEFINES // For MSVC
#include "qtorusmesh.h"
#include "qabstractshapemesh_p.h"
+#include "qbuffer.h"
+#include "qattribute.h"
#include <cmath>
@@ -131,16 +133,16 @@ float QTorusMesh::minorRadius() const
return d->m_minorRadius;
}
-MeshDataPtr QTorusMesh::buildMeshdata() const
+QAbstractMeshDataPtr QTorusMesh::buildMeshdata() const
{
Q_D(const QTorusMesh);
return createTorusMesh(d->m_radius, d->m_minorRadius, d->m_rings, d->m_slices);
}
-MeshDataPtr QTorusMesh::createTorusMesh(double radius, double minorRadius,
+QAbstractMeshDataPtr QTorusMesh::createTorusMesh(double radius, double minorRadius,
int rings, int sides)
{
- MeshDataPtr mesh(new MeshData(GL_TRIANGLES));
+ QAbstractMeshDataPtr mesh(new MeshData(GL_TRIANGLES));
int nVerts = sides * ( rings + 1 );
QByteArray bufferBytes;
@@ -187,13 +189,13 @@ MeshDataPtr QTorusMesh::createTorusMesh(double radius, double minorRadius,
buf->setUsage(QOpenGLBuffer::StaticDraw);
buf->setData(bufferBytes);
- mesh->addAttribute(QStringLiteral("position"), new Attribute(buf, GL_FLOAT_VEC3, nVerts, 0, stride));
+ mesh->addAttribute(QStringLiteral("position"), QAbstractAttributePtr(new Attribute(buf, GL_FLOAT_VEC3, nVerts, 0, stride)));
quint32 offset = sizeof(float) * 3;
- mesh->addAttribute(QStringLiteral("texcoord"), new Attribute(buf, GL_FLOAT_VEC2, nVerts, offset, stride));
+ mesh->addAttribute(QStringLiteral("texcoord"), QAbstractAttributePtr(new Attribute(buf, GL_FLOAT_VEC2, nVerts, offset, stride)));
offset += sizeof(float) * 2;
- mesh->addAttribute(QStringLiteral("normal"), new Attribute(buf, GL_FLOAT_VEC3, nVerts, offset, stride));
+ mesh->addAttribute(QStringLiteral("normal"), QAbstractAttributePtr(new Attribute(buf, GL_FLOAT_VEC3, nVerts, offset, stride)));
offset += sizeof(float) * 3;
QByteArray indexBytes;
@@ -222,7 +224,7 @@ MeshDataPtr QTorusMesh::createTorusMesh(double radius, double minorRadius,
BufferPtr indexBuffer(new Buffer(QOpenGLBuffer::IndexBuffer));
indexBuffer->setUsage(QOpenGLBuffer::StaticDraw);
indexBuffer->setData(indexBytes);
- mesh->setIndexAttr(AttributePtr(new Attribute(indexBuffer, GL_UNSIGNED_SHORT, indices, 0, 0)));
+ mesh->setIndexAttribute(AttributePtr(new Attribute(indexBuffer, GL_UNSIGNED_SHORT, indices, 0, 0)));
mesh->computeBoundsFromAttribute(QStringLiteral("position"));
diff --git a/src/render/frontend/qtorusmesh.h b/src/render/frontend/qtorusmesh.h
index a6953afdf..7908fee37 100644
--- a/src/render/frontend/qtorusmesh.h
+++ b/src/render/frontend/qtorusmesh.h
@@ -72,7 +72,7 @@ public:
float radius() const;
float minorRadius() const;
- MeshDataPtr buildMeshdata() const Q_DECL_OVERRIDE;
+ QAbstractMeshDataPtr buildMeshdata() const Q_DECL_OVERRIDE;
Q_SIGNALS:
@@ -84,7 +84,7 @@ Q_SIGNALS:
private:
Q_DECLARE_PRIVATE(QTorusMesh)
- static MeshDataPtr createTorusMesh(double radius, double minorRadius, int rings, int sides);
+ static QAbstractMeshDataPtr createTorusMesh(double radius, double minorRadius, int rings, int sides);
};
} // Qt3D
diff --git a/src/render/io/assimpparser.cpp b/src/render/io/assimpparser.cpp
index 49a1a79fb..8f8f3b10a 100644
--- a/src/render/io/assimpparser.cpp
+++ b/src/render/io/assimpparser.cpp
@@ -53,6 +53,8 @@
#include <qmaterial.h>
#include <texture.h>
#include "renderlogging.h"
+#include "qbuffer.h"
+#include "qattribute.h"
QT_BEGIN_NAMESPACE
@@ -476,31 +478,31 @@ void AssimpParser::loadMesh(uint meshIndex)
// Add vertex attributes to the mesh with the right array
meshData->addAttribute(VERTICES_ATTRIBUTE_NAME,
- new Attribute(vbuffer,
+ AttributePtr(new Attribute(vbuffer,
GL_FLOAT_VEC3,
mesh->mNumVertices,
0,
- chunkSize * sizeof(float)));
+ chunkSize * sizeof(float))));
meshData->addAttribute(NORMAL_ATTRIBUTE_NAME,
- new Attribute(vbuffer,
+ AttributePtr(new Attribute(vbuffer,
GL_FLOAT_VEC3,
mesh->mNumVertices,
3 * sizeof(float),
- chunkSize * sizeof(float)));
+ chunkSize * sizeof(float))));
if (hasTangent)
meshData->addAttribute(TANGENT_ATTRIBUTE_NAME,
- new Attribute(vbuffer,
+ AttributePtr(new Attribute(vbuffer,
GL_FLOAT_VEC3,
mesh->mNumVertices,
6 * sizeof(float),
- chunkSize * sizeof(float)));
+ chunkSize * sizeof(float))));
if (hasTexture)
meshData->addAttribute(TEXTCOORD_ATTRIBUTE_NAME,
- new Attribute(vbuffer,
+ AttributePtr(new Attribute(vbuffer,
GL_FLOAT_VEC2,
mesh->mNumVertices,
(hasTangent ? 9 : 6) * sizeof(float),
- chunkSize * sizeof(float)));
+ chunkSize * sizeof(float))));
GLuint indiceType;
QByteArray ibufferContent;
uint indices = mesh->mNumFaces * 3;
@@ -532,7 +534,7 @@ void AssimpParser::loadMesh(uint meshIndex)
ibuffer->setData(ibufferContent);
// Add indices attributes
- meshData->setIndexAttr(AttributePtr(new Attribute(ibuffer, indiceType, indices, 0, 0)));
+ meshData->setIndexAttribute(AttributePtr(new Attribute(ibuffer, indiceType, indices, 0, 0)));
meshData->computeBoundsFromAttribute(VERTICES_ATTRIBUTE_NAME);
diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp
index acfb04bf5..b4a32addd 100644
--- a/src/render/io/gltfparser.cpp
+++ b/src/render/io/gltfparser.cpp
@@ -676,7 +676,7 @@ void GLTFParser::processJSONMesh( QString id, QJsonObject jsonObj )
if (!m_attributeDict.contains(k)) {
qCWarning(Render::Io) << "unknown index accessor:" << k << "on mesh" << id;
} else {
- md->setIndexAttr(m_attributeDict[k]);
+ md->setIndexAttribute(m_attributeDict[k]);
// m_attributeDict[k]->dump(100);
}
} // of has indices
diff --git a/src/render/io/gltfparser.h b/src/render/io/gltfparser.h
index a6e9c1994..7182c2e48 100644
--- a/src/render/io/gltfparser.h
+++ b/src/render/io/gltfparser.h
@@ -43,10 +43,10 @@
#define GLTFPARSER_H
#include <Qt3DRenderer/meshdata.h>
-
+#include <Qt3DRenderer/qattribute.h>
#include <Qt3DCore/entity.h>
#include <Qt3DRenderer/qtechnique.h>
-
+#include <Qt3DRenderer/qbuffer.h>
#include <QJsonDocument>
#include <QMultiHash>
#include <QImage>
diff --git a/src/render/io/meshdata.cpp b/src/render/io/meshdata.cpp
index 5f2927d23..5f75a1844 100644
--- a/src/render/io/meshdata.cpp
+++ b/src/render/io/meshdata.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "meshdata.h"
+#include "meshdata_p.h"
#include <QSet>
#include "renderlogging.h"
@@ -49,389 +50,41 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
-GLint elementType(GLint type)
+MeshDataPrivate::MeshDataPrivate(MeshData *qq)
+ : QAbstractMeshDataPrivate(qq)
+ , m_primitiveType(0)
{
- switch (type) {
- case GL_FLOAT:
- case GL_FLOAT_VEC2:
- case GL_FLOAT_VEC3:
- case GL_FLOAT_VEC4:
- return GL_FLOAT;
-
- case GL_DOUBLE:
-#ifdef GL_DOUBLE_VEC3 // For compiling on pre GL 4.1 systems
- case GL_DOUBLE_VEC2:
- case GL_DOUBLE_VEC3:
- case GL_DOUBLE_VEC4:
-#endif
- return GL_DOUBLE;
-
- default:
- qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
- }
-
- return GL_INVALID_VALUE;
-}
-
-GLint tupleSizeFromType(GLint type)
-{
- switch (type) {
- case GL_FLOAT:
- case GL_DOUBLE:
- case GL_UNSIGNED_BYTE:
- case GL_UNSIGNED_INT:
- break; // fall through
-
- case GL_FLOAT_VEC2:
-#ifdef GL_DOUBLE_VEC2 // For compiling on pre GL 4.1 systems.
- case GL_DOUBLE_VEC2:
-#endif
- return 2;
-
- case GL_FLOAT_VEC3:
-#ifdef GL_DOUBLE_VEC3 // For compiling on pre GL 4.1 systems.
- case GL_DOUBLE_VEC3:
-#endif
- return 3;
-
- case GL_FLOAT_VEC4:
-#ifdef GL_DOUBLE_VEC4 // For compiling on pre GL 4.1 systems.
- case GL_DOUBLE_VEC4:
-#endif
- return 4;
-
- default:
- qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
- }
-
- return 1;
-}
-
-GLuint byteSizeFromType(GLint type)
-{
- switch (type) {
- case GL_FLOAT: return sizeof(float);
- case GL_DOUBLE: return sizeof(double);
- case GL_UNSIGNED_BYTE: return sizeof(unsigned char);
- case GL_UNSIGNED_INT: return sizeof(GLuint);
-
- case GL_FLOAT_VEC2: return sizeof(float) * 2;
- case GL_FLOAT_VEC3: return sizeof(float) * 3;
- case GL_FLOAT_VEC4: return sizeof(float) * 4;
-#ifdef GL_DOUBLE_VEC3 // Required to compile on pre GL 4.1 systems
- case GL_DOUBLE_VEC2: return sizeof(double) * 2;
- case GL_DOUBLE_VEC3: return sizeof(double) * 3;
- case GL_DOUBLE_VEC4: return sizeof(double) * 4;
-#endif
- default:
- qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
- }
-
- return 0;
}
MeshData::MeshData()
- : m_primitiveType(0)
-{
-}
-
-MeshData::MeshData(int primitiveType) :
- m_primitiveType(primitiveType)
-{
- Q_ASSERT((m_primitiveType == GL_TRIANGLES) ||
- (m_primitiveType == GL_LINES) ||
- (m_primitiveType == GL_POINTS));
-}
-
-void MeshData::addAttribute(QString name, AttributePtr attr)
-{
- Q_ASSERT(!m_attributes.contains(name));
- m_attributes[name] = attr;
-}
-
-void MeshData::addAttribute(QString name, Attribute *attr)
-{
- Q_ASSERT(!m_attributes.contains(name));
- m_attributes[name] = AttributePtr(attr);
-}
-
-void MeshData::setIndexAttr(AttributePtr indexAttr)
+ : QAbstractMeshData(*new MeshDataPrivate(this))
{
- m_indexAttr = indexAttr;
}
-void MeshData::setIndexData(BufferPtr buf, int type, int count, int offset)
+MeshData::MeshData(MeshDataPrivate &dd)
+ : QAbstractMeshData(dd)
{
- m_indexAttr = AttributePtr(new Attribute(buf, type, count, offset));
}
-GLint MeshData::primitiveType() const
+MeshData::MeshData(int primitiveType)
+ : QAbstractMeshData(*new MeshDataPrivate(this))
{
- return m_primitiveType;
-}
-
-GLsizei MeshData::primitiveCount() const
-{
- if (m_indexAttr) {
- return 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 m_attributes.first()->count();
- }
-}
-
-QStringList MeshData::attributeNames() const
-{
- return m_attributes.keys();
-}
-
-AttributePtr MeshData::attributeByName(QString nm) const
-{
- return m_attributes.value(nm);
-}
-
-AttributePtr MeshData::indexAttr() const
-{
- return m_indexAttr;
-}
-
-QList<BufferPtr> MeshData::buffers() const
-{
- QSet<BufferPtr> r;
- if (m_indexAttr)
- r.insert(m_indexAttr->buffer());
-
- foreach (AttributePtr v, m_attributes.values())
- r.insert(v->buffer());
-
- return r.toList();
-}
-
-void MeshData::setBoundingBox(const AxisAlignedBoundingBox &bbox)
-{
- m_box = bbox;
-}
-
-void MeshData::computeBoundsFromAttribute(QString name)
-{
- AttributePtr attr = attributeByName(name);
- if (!attr) {
- qWarning() << Q_FUNC_INFO << "unknoen attribute:" << name;
- return;
- }
-
- m_box.clear();
- m_box.update(attr->asVector3D());
-}
-
-Attribute::Attribute(BufferPtr buf, int type, int count, int offset, int stride) :
- m_buffer(buf),
- m_type(type),
- m_count(count),
- m_stride(stride),
- m_offset(offset),
- m_divisor(0)
-{
-
+ setPrimitiveType(primitiveType);
}
-void Attribute::setDivisor(unsigned int divisor)
+void MeshData::setPrimitiveType(int primitiveType)
{
- m_divisor = divisor;
-}
-
-BufferPtr Attribute::buffer() const
-{
- return m_buffer;
-}
-
-QVector<QVector3D> Attribute::asVector3D() const
-{
- const QByteArray buffer = m_buffer->data();
- const char *rawBuffer = buffer.constData();
- rawBuffer += m_offset;
- const float* fptr;
- int stride;
-
- switch (type()) {
- case GL_FLOAT_VEC2:
- stride = sizeof(float) * 2; break;
-
- case GL_FLOAT_VEC3:
- stride = sizeof(float) * 3; break;
-
- case GL_FLOAT_VEC4:
- stride = sizeof(float) * 4; break;
-
- default:
- qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << QString::number(type(), 16) << "to QVector3D";
- return QVector<QVector3D>();
- }
-
- if (m_stride != 0)
- stride = m_stride;
- QVector<QVector3D> result;
- result.resize(m_count);
-
- for (int c=0; c<m_count; ++c) {
- QVector3D v;
- fptr = reinterpret_cast<const float*>(rawBuffer);
-
- switch (type()) {
- case GL_FLOAT_VEC2:
- v.setX(fptr[0]);
- v.setY(fptr[1]);
- v.setZ(0.0f);
- break;
-
- case GL_FLOAT_VEC3:
- case GL_FLOAT_VEC4:
- v.setX(fptr[0]);
- v.setY(fptr[1]);
- v.setZ(fptr[2]);
- break;
-
- default:
- break; // should never happen, we check types above
- }
-
- result[c] = v;
- rawBuffer += stride;
- }
-
- return result;
-}
-
-QVector<QVector2D> Attribute::asVector2D() const
-{
- char* rawBuffer = m_buffer->data().data();
- rawBuffer += m_offset;
- float* fptr;
- int stride;
-
- switch (type()) {
- case GL_FLOAT_VEC2:
- stride = sizeof(float) * 2; break;
-
- case GL_FLOAT_VEC3:
- stride = sizeof(float) * 3; break;
-
- case GL_FLOAT_VEC4:
- stride = sizeof(float) * 4; break;
-
- default:
- qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << QString::number(type(), 16) << "to QVector2D";
- return QVector<QVector2D>();
- }
-
- if (m_stride != 0)
- stride = m_stride;
-
- QVector<QVector2D> result;
- result.resize(m_count);
-
- for (int c=0; c<m_count; ++c) {
- QVector2D v;
- fptr = reinterpret_cast<float*>(rawBuffer);
- v.setX(fptr[0]);
- v.setY(fptr[1]);
- result[c] = v;
- rawBuffer += stride;
- }
-
- return result;
-}
-
-void Attribute::dump(int count)
-{
- char* rawBuffer = m_buffer->data().data();
- rawBuffer += m_offset;
-
- float* fptr;
- quint16* usptr;
-
- int stride = m_stride;
-
- for (int c=0; c<count; ++c) {
- switch (type()) {
- case GL_UNSIGNED_SHORT:
- if (!stride) stride = sizeof(quint16);
- usptr = reinterpret_cast<quint16*>(rawBuffer);
- qCDebug(Render::Io) << c << ":u16:" << usptr[0];
- break;
- case GL_UNSIGNED_INT:
- if (!stride) stride = sizeof(quint32);
- qCDebug(Render::Io) << c << ":u32:" << reinterpret_cast<quint32*>(rawBuffer)[0];
- break;
- case GL_FLOAT_VEC2:
- if (!stride) stride = sizeof(float) * 2;
- fptr = reinterpret_cast<float*>(rawBuffer);
- qCDebug(Render::Io) << c << ":vec2:"<< fptr[0] << fptr[0];
- break;
-
- case GL_FLOAT_VEC3:
- if (!stride) stride = sizeof(float) * 3;
- fptr = reinterpret_cast<float*>(rawBuffer);
- qCDebug(Render::Io) << c << ":vec3:" << fptr[0] << fptr[0] << fptr[2];
- break;
-
- default: qCDebug(Render::Io) << Q_FUNC_INFO << "unspported type:" << QString::number(type(), 16);
- }
-
-
- }
-}
-
-Buffer::Buffer(QOpenGLBuffer::Type ty) :
- m_type(ty),
- m_usage(QOpenGLBuffer::StaticDraw)
-{
-}
-
-void Buffer::setUsage(QOpenGLBuffer::UsagePattern usage)
-{
- m_usage = usage;
-}
-
-void Buffer::setData(QByteArray bytes)
-{
- m_clientSideBytes = bytes;
- // mark as dirty for dynamic / stream data
- // if static, check this is the first and only set.
-}
-
-QByteArray Buffer::data() const
-{
- return m_clientSideBytes;
-}
-
-QOpenGLBuffer Buffer::createGL() const
-{
- QOpenGLBuffer b(m_type);
- b.setUsagePattern(m_usage);
- if (!b.create())
- qCWarning(Render::Io) << Q_FUNC_INFO << "buffer creation failed";
-
- if (!b.bind())
- qCWarning(Render::Io) << Q_FUNC_INFO << "buffer binding failed";
-
- b.allocate(m_clientSideBytes.count());
- b.release();
- return b;
+ Q_D(MeshData);
+ Q_ASSERT((d->m_primitiveType == GL_TRIANGLES) ||
+ (d->m_primitiveType == GL_LINES) ||
+ (d->m_primitiveType == GL_POINTS));
+ d->m_primitiveType = primitiveType;
}
-void Buffer::upload(QOpenGLBuffer b)
+int MeshData::primitiveType() const
{
- if (!b.bind())
- qCWarning(Render::Io) << Q_FUNC_INFO << "buffer bind failed";
- b.allocate(NULL, m_clientSideBytes.count()); // orphan the buffer
- b.allocate(m_clientSideBytes.data(),
- m_clientSideBytes.count());
- b.release();
- qCDebug(Render::Io) << "uploaded buffer size=" << m_clientSideBytes.count();
+ Q_D(const MeshData);
+ return d->m_primitiveType;
}
} // of namespace
diff --git a/src/render/io/meshdata.h b/src/render/io/meshdata.h
index 3b881e4f8..ff9a06ba1 100644
--- a/src/render/io/meshdata.h
+++ b/src/render/io/meshdata.h
@@ -39,135 +39,38 @@
**
****************************************************************************/
-#ifndef MESHDATA_H
-#define MESHDATA_H
+#ifndef QT3D_MESHDATA_H
+#define QT3D_MESHDATA_H
#include <QSharedPointer>
-#include <QList>
-#include <QMap>
-#include <QOpenGLBuffer>
-#include <QVector2D>
-
-#include <Qt3DCore/axisalignedboundingbox.h>
+#include <Qt3DCore/qabstractmeshdata.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
QT_BEGIN_NAMESPACE
namespace Qt3D {
-GLint elementType(GLint type);
-GLint tupleSizeFromType(GLint type);
-GLuint byteSizeFromType(GLint type);
-
-class Buffer
-{
-public:
- Buffer(QOpenGLBuffer::Type ty);
-
- void setUsage(QOpenGLBuffer::UsagePattern usage);
-
- void setData(QByteArray bytes);
- QByteArray data() const;
-
- QOpenGLBuffer::Type type() const
- { return m_type; }
-
- void bind();
-
- QOpenGLBuffer createGL() const;
- void upload(QOpenGLBuffer b);
-
- // make a QObject and signal when contents change?
- // GraphicsContext could listen, orphan the QOpenGLBuffer and hence
- // reupload next time it's need
-private:
- const QOpenGLBuffer::Type m_type;
- QOpenGLBuffer::UsagePattern m_usage;
- QByteArray m_clientSideBytes;
-};
-
-typedef QSharedPointer<Buffer> BufferPtr;
-
-class Attribute
-{
-public:
- Attribute(BufferPtr buf, int type, int count, int offset=0, int stride = 0);
-
- void setDivisor(unsigned int divisor);
-
- unsigned int divisor() const
- { return m_divisor; }
-
- BufferPtr buffer() const;
-
- int type() const
- { return m_type; }
-
- unsigned int count() const
- { return m_count; }
-
- unsigned int byteStride() const
- { return m_stride; }
-
- unsigned int byteOffset() const
- { return m_offset; }
-
- QVector<QVector3D> asVector3D() const;
- QVector<QVector2D> asVector2D() const;
-
- void dump(int count);
-private:
- BufferPtr m_buffer;
- int m_type, m_count;
- unsigned int m_stride, m_offset; // both in bytes
- // AxisAlignedBoundBox m_range;
- unsigned int m_divisor;
-};
-
-typedef QSharedPointer<Attribute> AttributePtr;
-
/**
* @brief The MeshData class is shared by all instances of a RenderMesh,
* and holds the actual client (CPU)-side buffers representing mesh attributes
* and indices.
*/
-class MeshData
+
+class MeshDataPrivate;
+
+class QT3DRENDERERSHARED_EXPORT MeshData : public QAbstractMeshData
{
public:
MeshData();
explicit MeshData(int primitiveType);
- void addAttribute(QString name, AttributePtr attr);
-
- // permit inline 'new' call, will take ownership
- void addAttribute(QString name, Attribute* attr);
-
- void setIndexAttr(AttributePtr indexAttr);
- void setIndexData(BufferPtr buf, int type, int count, int offset = 0);
-
- GLint primitiveType() const;
- GLsizei primitiveCount() const;
-
- QStringList attributeNames() const;
- AttributePtr attributeByName(QString nm) const;
-
- AttributePtr indexAttr() const;
-
- QList<BufferPtr> buffers() const;
-
- // specify the bounding box explicitly
- void setBoundingBox(const AxisAlignedBoundingBox& bbox);
-
- void computeBoundsFromAttribute(QString name);
-
- AxisAlignedBoundingBox boundingBox() const
- { return m_box; }
-private:
- QMap<QString, AttributePtr> m_attributes;
+ void setPrimitiveType(int primitiveType) Q_DECL_OVERRIDE;
+ int primitiveType() const Q_DECL_OVERRIDE;
- int m_primitiveType;
- AttributePtr m_indexAttr;
+protected:
+ Q_DECLARE_PRIVATE(MeshData)
+ MeshData(MeshDataPrivate &dd);
- AxisAlignedBoundingBox m_box;
};
typedef QSharedPointer<MeshData> MeshDataPtr;
@@ -176,4 +79,4 @@ typedef QSharedPointer<MeshData> MeshDataPtr;
QT_END_NAMESPACE
-#endif // MESHDATA_H
+#endif // QT3D_MESHDATA_H
diff --git a/src/render/io/meshdata_p.h b/src/render/io/meshdata_p.h
new file mode 100644
index 000000000..ef3d89735
--- /dev/null
+++ b/src/render/io/meshdata_p.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_MESHDATA_P_H
+#define QT3D_MESHDATA_P_H
+
+#include <private/qabstractmeshdata_p.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class MeshData;
+
+class QT3DRENDERERSHARED_EXPORT MeshDataPrivate : public QAbstractMeshDataPrivate
+{
+public:
+ MeshDataPrivate(MeshData *qq);
+
+ Q_DECLARE_PUBLIC(MeshData)
+ int m_primitiveType;
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_MESHDATA_P_H
diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp
index 518cf7684..46b13f355 100644
--- a/src/render/io/objloader.cpp
+++ b/src/render/io/objloader.cpp
@@ -42,6 +42,8 @@
#include "objloader.h"
#include "qmesh.h"
+#include "qbuffer.h"
+#include "qattribute.h"
#include <Qt3DCore/axisalignedboundingbox.h>
#include "renderlogging.h"
@@ -252,21 +254,21 @@ MeshData *ObjLoader::mesh() const
buf->setData(bufferBytes);
- mesh->addAttribute(QStringLiteral("position"), new Attribute(buf, GL_FLOAT_VEC3, count, 0, stride));
+ mesh->addAttribute(QStringLiteral("position"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, 0, stride)));
quint32 offset = sizeof(float) * 3;
if (hasTextureCoordinates()) {
- mesh->addAttribute(QStringLiteral("texcoord"), new Attribute(buf, GL_FLOAT_VEC2, count, offset, stride));
+ mesh->addAttribute(QStringLiteral("texcoord"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC2, count, offset, stride)));
offset += sizeof(float) * 2;
}
if (hasNormals()) {
- mesh->addAttribute(QStringLiteral("normal"), new Attribute(buf, GL_FLOAT_VEC3, count, offset, stride));
+ mesh->addAttribute(QStringLiteral("normal"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, offset, stride)));
offset += sizeof(float) * 3;
}
if (hasTangents()) {
- mesh->addAttribute(QStringLiteral("tangent"), new Attribute(buf, GL_FLOAT_VEC4, count, offset, stride));
+ mesh->addAttribute(QStringLiteral("tangent"), AttributePtr(new Attribute(buf, GL_FLOAT_VEC4, count, offset, stride)));
offset += sizeof(float) * 4;
}
@@ -290,7 +292,7 @@ MeshData *ObjLoader::mesh() const
BufferPtr indexBuffer(new Buffer(QOpenGLBuffer::IndexBuffer));
indexBuffer->setUsage(QOpenGLBuffer::StaticDraw);
indexBuffer->setData(indexBytes);
- mesh->setIndexAttr(AttributePtr(new Attribute(indexBuffer, ty, m_indices.size(), 0, 0)));
+ mesh->setIndexAttribute(AttributePtr(new Attribute(indexBuffer, ty, m_indices.size(), 0, 0)));
mesh->computeBoundsFromAttribute(QStringLiteral("position"));
qCDebug(Render::Io) << "computed bounds is:" << mesh->boundingBox();
diff --git a/src/render/io/qattribute.cpp b/src/render/io/qattribute.cpp
new file mode 100644
index 000000000..cfa08aa7a
--- /dev/null
+++ b/src/render/io/qattribute.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qattribute.h"
+#include "qattribute_p.h"
+#include <QVector3D>
+#include <QVector2D>
+#include <QVector>
+#include <Qt3DCore/qabstractbuffer.h>
+#include "renderlogging.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+AttributePrivate::AttributePrivate(Attribute *qq)
+ : QAbstractAttributePrivate(qq)
+{
+}
+
+Attribute::Attribute(QAbstractBufferPtr buf, int type, int count, int offset, int stride)
+ : QAbstractAttribute(*new AttributePrivate(this), buf, type, count, offset, stride)
+{
+}
+
+Attribute::Attribute(AttributePrivate &dd, QAbstractBufferPtr buf, int type, int count, int offset, int stride)
+ : QAbstractAttribute(dd, buf, type, count, offset, stride)
+{
+}
+
+QVector<QVector3D> Attribute::asVector3D() const
+{
+ Q_D(const Attribute);
+ const QByteArray buffer = d->m_buffer->data();
+ const char *rawBuffer = buffer.constData();
+ rawBuffer += d->m_offset;
+ const float* fptr;
+ int stride;
+
+ switch (type()) {
+ case GL_FLOAT_VEC2:
+ stride = sizeof(float) * 2; break;
+
+ case GL_FLOAT_VEC3:
+ stride = sizeof(float) * 3; break;
+
+ case GL_FLOAT_VEC4:
+ stride = sizeof(float) * 4; break;
+
+ default:
+ qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << QString::number(type(), 16) << "to QVector3D";
+ return QVector<QVector3D>();
+ }
+
+ if (d->m_stride != 0)
+ stride = d->m_stride;
+ QVector<QVector3D> result;
+ result.resize(d->m_count);
+
+ for (uint c=0; c < d->m_count; ++c) {
+ QVector3D v;
+ fptr = reinterpret_cast<const float*>(rawBuffer);
+
+ switch (type()) {
+ case GL_FLOAT_VEC2:
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ v.setZ(0.0f);
+ break;
+
+ case GL_FLOAT_VEC3:
+ case GL_FLOAT_VEC4:
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ v.setZ(fptr[2]);
+ break;
+
+ default:
+ break; // should never happen, we check types above
+ }
+
+ result[c] = v;
+ rawBuffer += stride;
+ }
+
+ return result;
+}
+
+QVector<QVector2D> Attribute::asVector2D() const
+{
+ Q_D(const Attribute);
+ char* rawBuffer = d->m_buffer->data().data();
+ rawBuffer += d->m_offset;
+ float* fptr;
+ int stride;
+
+ switch (type()) {
+ case GL_FLOAT_VEC2:
+ stride = sizeof(float) * 2; break;
+
+ case GL_FLOAT_VEC3:
+ stride = sizeof(float) * 3; break;
+
+ case GL_FLOAT_VEC4:
+ stride = sizeof(float) * 4; break;
+
+ default:
+ qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << QString::number(type(), 16) << "to QVector2D";
+ return QVector<QVector2D>();
+ }
+
+ if (d->m_stride != 0)
+ stride = d->m_stride;
+
+ QVector<QVector2D> result;
+ result.resize(d->m_count);
+
+ for (uint c=0; c < d->m_count; ++c) {
+ QVector2D v;
+ fptr = reinterpret_cast<float*>(rawBuffer);
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ result[c] = v;
+ rawBuffer += stride;
+ }
+
+ return result;
+}
+
+void Attribute::dump(int count)
+{
+ Q_D(const Attribute);
+ char* rawBuffer = d->m_buffer->data().data();
+ rawBuffer += d->m_offset;
+
+ float* fptr;
+ quint16* usptr;
+
+ int stride = d->m_stride;
+
+ for (int c=0; c<count; ++c) {
+ switch (type()) {
+ case GL_UNSIGNED_SHORT:
+ if (!stride) stride = sizeof(quint16);
+ usptr = reinterpret_cast<quint16*>(rawBuffer);
+ qCDebug(Render::Io) << c << ":u16:" << usptr[0];
+ break;
+ case GL_UNSIGNED_INT:
+ if (!stride) stride = sizeof(quint32);
+ qCDebug(Render::Io) << c << ":u32:" << reinterpret_cast<quint32*>(rawBuffer)[0];
+ break;
+ case GL_FLOAT_VEC2:
+ if (!stride) stride = sizeof(float) * 2;
+ fptr = reinterpret_cast<float*>(rawBuffer);
+ qCDebug(Render::Io) << c << ":vec2:"<< fptr[0] << fptr[0];
+ break;
+
+ case GL_FLOAT_VEC3:
+ if (!stride) stride = sizeof(float) * 3;
+ fptr = reinterpret_cast<float*>(rawBuffer);
+ qCDebug(Render::Io) << c << ":vec3:" << fptr[0] << fptr[0] << fptr[2];
+ break;
+
+ default: qCDebug(Render::Io) << Q_FUNC_INFO << "unspported type:" << QString::number(type(), 16);
+ }
+ }
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/render/io/qattribute.h b/src/render/io/qattribute.h
new file mode 100644
index 000000000..001b9f267
--- /dev/null
+++ b/src/render/io/qattribute.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QATTRIBUTE_H
+#define QT3D_QATTRIBUTE_H
+
+#include <Qt3DCore/qabstractattribute.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+#include <QOpenGLBuffer>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class AttributePrivate;
+
+class QT3DRENDERERSHARED_EXPORT Attribute : public QAbstractAttribute
+{
+public:
+ Attribute(QAbstractBufferPtr buf, int type, int count, int offset=0, int stride = 0);
+
+ QVector<QVector3D> asVector3D() const Q_DECL_OVERRIDE;
+ QVector<QVector2D> asVector2D() const Q_DECL_OVERRIDE;
+
+ void dump(int count) Q_DECL_OVERRIDE;
+
+protected:
+ Q_DECLARE_PRIVATE(Attribute)
+ Attribute(AttributePrivate &dd, QAbstractBufferPtr buf, int type, int count, int offset=0, int stride = 0);
+};
+
+typedef QSharedPointer<Attribute> AttributePtr;
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QATTRIBUTE_H
diff --git a/src/render/io/qattribute_p.h b/src/render/io/qattribute_p.h
new file mode 100644
index 000000000..e7aa85bfe
--- /dev/null
+++ b/src/render/io/qattribute_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QATTRIBUTE_P_H
+#define QT3D_QATTRIBUTE_P_H
+
+#include <private/qabstractattribute_p.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class Attribute;
+
+class QT3DRENDERERSHARED_EXPORT AttributePrivate : public QAbstractAttributePrivate
+{
+public:
+ AttributePrivate(Attribute *qq);
+
+ Q_DECLARE_PUBLIC(Attribute)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QATTRIBUTE_P_H
diff --git a/src/render/io/qbuffer.cpp b/src/render/io/qbuffer.cpp
new file mode 100644
index 000000000..be27356b4
--- /dev/null
+++ b/src/render/io/qbuffer.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbuffer.h"
+#include "qbuffer_p.h"
+#include "renderlogging.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+GLint elementType(GLint type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ case GL_FLOAT_VEC2:
+ case GL_FLOAT_VEC3:
+ case GL_FLOAT_VEC4:
+ return GL_FLOAT;
+
+ case GL_DOUBLE:
+#ifdef GL_DOUBLE_VEC3 // For compiling on pre GL 4.1 systems
+ case GL_DOUBLE_VEC2:
+ case GL_DOUBLE_VEC3:
+ case GL_DOUBLE_VEC4:
+#endif
+ return GL_DOUBLE;
+
+ default:
+ qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
+ }
+
+ return GL_INVALID_VALUE;
+}
+
+GLint tupleSizeFromType(GLint type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ case GL_DOUBLE:
+ case GL_UNSIGNED_BYTE:
+ case GL_UNSIGNED_INT:
+ break; // fall through
+
+ case GL_FLOAT_VEC2:
+#ifdef GL_DOUBLE_VEC2 // For compiling on pre GL 4.1 systems.
+ case GL_DOUBLE_VEC2:
+#endif
+ return 2;
+
+ case GL_FLOAT_VEC3:
+#ifdef GL_DOUBLE_VEC3 // For compiling on pre GL 4.1 systems.
+ case GL_DOUBLE_VEC3:
+#endif
+ return 3;
+
+ case GL_FLOAT_VEC4:
+#ifdef GL_DOUBLE_VEC4 // For compiling on pre GL 4.1 systems.
+ case GL_DOUBLE_VEC4:
+#endif
+ return 4;
+
+ default:
+ qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
+ }
+
+ return 1;
+}
+
+GLuint byteSizeFromType(GLint type)
+{
+ switch (type) {
+ case GL_FLOAT: return sizeof(float);
+ case GL_DOUBLE: return sizeof(double);
+ case GL_UNSIGNED_BYTE: return sizeof(unsigned char);
+ case GL_UNSIGNED_INT: return sizeof(GLuint);
+
+ case GL_FLOAT_VEC2: return sizeof(float) * 2;
+ case GL_FLOAT_VEC3: return sizeof(float) * 3;
+ case GL_FLOAT_VEC4: return sizeof(float) * 4;
+#ifdef GL_DOUBLE_VEC3 // Required to compile on pre GL 4.1 systems
+ case GL_DOUBLE_VEC2: return sizeof(double) * 2;
+ case GL_DOUBLE_VEC3: return sizeof(double) * 3;
+ case GL_DOUBLE_VEC4: return sizeof(double) * 4;
+#endif
+ default:
+ qWarning() << Q_FUNC_INFO << "unsupported:" << QString::number(type, 16);
+ }
+
+ return 0;
+}
+
+BufferPrivate::BufferPrivate(Buffer *qq)
+ : QAbstractBufferPrivate(qq)
+{
+}
+
+Buffer::Buffer(QOpenGLBuffer::Type ty)
+ : QAbstractBuffer(*new BufferPrivate(this))
+{
+ Q_D(Buffer);
+ d->m_type = ty;
+ d->m_usage = QOpenGLBuffer::StaticDraw;
+}
+
+
+Buffer::Buffer(BufferPrivate &dd, QOpenGLBuffer::Type ty)
+ : QAbstractBuffer(dd)
+{
+ Q_D(Buffer);
+ d->m_type = ty;
+ d->m_usage = QOpenGLBuffer::StaticDraw;
+}
+
+void Buffer::setUsage(QOpenGLBuffer::UsagePattern usage)
+{
+ Q_D(Buffer);
+ d->m_usage = usage;
+}
+
+QOpenGLBuffer::Type Buffer::type() const
+{
+ Q_D(const Buffer);
+ return d->m_type;
+}
+
+void Buffer::bind()
+{
+
+}
+
+void Buffer::create()
+{
+ // TO DO -> Wrap createGL in here
+}
+
+QOpenGLBuffer Buffer::createGL() const
+{
+ Q_D(const Buffer);
+ QOpenGLBuffer b(d->m_type);
+ b.setUsagePattern(d->m_usage);
+ if (!b.create())
+ qCWarning(Render::Io) << Q_FUNC_INFO << "buffer creation failed";
+
+ if (!b.bind())
+ qCWarning(Render::Io) << Q_FUNC_INFO << "buffer binding failed";
+
+ b.allocate(d->m_data.count());
+ b.release();
+ return b;
+}
+
+void Buffer::upload(QOpenGLBuffer b)
+{
+ Q_D(Buffer);
+ if (!b.bind())
+ qCWarning(Render::Io) << Q_FUNC_INFO << "buffer bind failed";
+ b.allocate(NULL, d->m_data.count()); // orphan the buffer
+ b.allocate(d->m_data.data(),
+ d->m_data.count());
+ b.release();
+ qCDebug(Render::Io) << "uploaded buffer size=" << d->m_data.count();
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/render/io/qbuffer.h b/src/render/io/qbuffer.h
new file mode 100644
index 000000000..483855b6f
--- /dev/null
+++ b/src/render/io/qbuffer.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QBUFFER_H
+#define QT3D_QBUFFER_H
+
+#include <Qt3DCore/qabstractbuffer.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+#include <QSharedPointer>
+#include <QOpenGLBuffer>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+GLint elementType(GLint type);
+GLint tupleSizeFromType(GLint type);
+GLuint byteSizeFromType(GLint type);
+
+class BufferPrivate;
+
+class QT3DRENDERERSHARED_EXPORT Buffer : public QAbstractBuffer
+{
+public:
+ explicit Buffer(QOpenGLBuffer::Type ty);
+
+ void setUsage(QOpenGLBuffer::UsagePattern usage);
+ QOpenGLBuffer::Type type() const;
+
+ void bind() Q_DECL_OVERRIDE;
+ void create() Q_DECL_OVERRIDE;
+
+ QOpenGLBuffer createGL() const;
+ void upload(QOpenGLBuffer b);
+
+ // make a QObject and signal when contents change?
+ // GraphicsContext could listen, orphan the QOpenGLBuffer and hence
+ // reupload next time it's need
+protected:
+ Q_DECLARE_PRIVATE(Buffer)
+ Buffer(BufferPrivate &dd, QOpenGLBuffer::Type ty);
+};
+
+typedef QSharedPointer<Buffer> BufferPtr;
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QBUFFER_H
diff --git a/src/render/io/qbuffer_p.h b/src/render/io/qbuffer_p.h
new file mode 100644
index 000000000..348459a23
--- /dev/null
+++ b/src/render/io/qbuffer_p.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QBUFFER_P_H
+#define QT3D_QBUFFER_P_H
+
+#include <private/qabstractbuffer_p.h>
+#include <Qt3DRenderer/qt3drenderer_global.h>
+#include <QOpenGLBuffer>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class Buffer;
+
+class QT3DRENDERERSHARED_EXPORT BufferPrivate : public QAbstractBufferPrivate
+{
+public:
+ BufferPrivate(Buffer *qq);
+
+ Q_DECLARE_PUBLIC(Buffer)
+ QOpenGLBuffer::Type m_type;
+ QOpenGLBuffer::UsagePattern m_usage;
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QBUFFER_P_H
diff --git a/src/render/io/render-io.pri b/src/render/io/render-io.pri
index ad12b7803..7cb391944 100644
--- a/src/render/io/render-io.pri
+++ b/src/render/io/render-io.pri
@@ -7,7 +7,12 @@ HEADERS += \
$$PWD/texturedata.h \
$$PWD/assimpparser.h \
$$PWD/assimphelpers.h \
- $$PWD/abstractsceneparser.h
+ $$PWD/abstractsceneparser.h \
+ $$PWD/qattribute.h \
+ $$PWD/qattribute_p.h \
+ $$PWD/qbuffer.h \
+ $$PWD/qbuffer_p.h \
+ $$PWD/meshdata_p.h
SOURCES += \
$$PWD/meshdata.cpp \
@@ -16,4 +21,6 @@ SOURCES += \
$$PWD/texturedata.cpp \
$$PWD/assimpparser.cpp \
$$PWD/assimphelpers.cpp \
- $$PWD/abstractsceneparser.cpp
+ $$PWD/abstractsceneparser.cpp \
+ $$PWD/qattribute.cpp \
+ $$PWD/qbuffer.cpp