summaryrefslogtreecommitdiffstats
path: root/src/render/io
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2015-01-23 16:22:00 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-08-07 00:11:31 +0000
commitc2f6f37699296557c5d79ae750e0ce91647de2ee (patch)
tree6c140186656c46d5e8584d48772f70e78d04806c /src/render/io
parentce69c98f6954ef2c8806bc44a457a58e4202d751 (diff)
New Buffer API Frontend Classes
- Switch QAbstractAttribute and QAbstractBuffer to QNode subclasses - Get rid of all shared pointer when dealing with these (needed to expose to QML and use the QObject ownership) - Introduce QGeometryRender, QGeometry, QAttributeProvider, QAttributeAggregator. A QMesh component now is: a QGeometryRenderer which specifies its QGeometry. The QGeometry refererences n attributes. Each attribute references a QAbstractBuffer. Change-Id: I49a10c11a605e5fe7c180af86a404f622e763f48 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/gltfparser.cpp12
-rw-r--r--src/render/io/gltfparser_p.h4
-rw-r--r--src/render/io/objloader.cpp18
-rw-r--r--src/render/io/qattribute.cpp132
-rw-r--r--src/render/io/qattribute.h28
-rw-r--r--src/render/io/qattribute_p.h6
-rw-r--r--src/render/io/qbuffer.cpp75
-rw-r--r--src/render/io/qbuffer.h55
-rw-r--r--src/render/io/qbuffer_p.h11
-rw-r--r--src/render/io/qmeshdata.cpp38
-rw-r--r--src/render/io/qmeshdata.h13
-rw-r--r--src/render/io/qmeshdata_p.h5
12 files changed, 282 insertions, 115 deletions
diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp
index 0cff55016..1baaf1712 100644
--- a/src/render/io/gltfparser.cpp
+++ b/src/render/io/gltfparser.cpp
@@ -625,11 +625,11 @@ void GLTFParser::processJSONBufferView( QString id, const QJsonObject& json )
}
int target = json.value(KEY_TARGET).toInt();
- QOpenGLBuffer::Type ty(QOpenGLBuffer::VertexBuffer);
+ QBuffer::BufferType ty(QBuffer::VertexBuffer);
switch (target) {
- case GL_ARRAY_BUFFER: ty = QOpenGLBuffer::VertexBuffer; break;
- case GL_ELEMENT_ARRAY_BUFFER: ty = QOpenGLBuffer::IndexBuffer; break;
+ case GL_ARRAY_BUFFER: ty = QBuffer::VertexBuffer; break;
+ case GL_ELEMENT_ARRAY_BUFFER: ty = QBuffer::IndexBuffer; break;
default:
qWarning() << Q_FUNC_INFO << "buffer" << id << "unsupported target:" << target;
return;
@@ -654,7 +654,7 @@ void GLTFParser::processJSONBufferView( QString id, const QJsonObject& json )
}
delete f;
- BufferPtr b(new Buffer(ty));
+ QBuffer *b(new QBuffer(ty));
b->setData(bytes);
m_buffers[id] = b;
}
@@ -667,7 +667,7 @@ void GLTFParser::processJSONAccessor( QString id, const QJsonObject& json )
return;
}
- BufferPtr buf = m_buffers.value(bvName);
+ QBuffer *buf = m_buffers.value(bvName);
int offset = 0, stride = 0;
int type = json.value(KEY_TYPE).toInt();
int count = json.value(KEY_COUNT).toInt();
@@ -677,7 +677,7 @@ void GLTFParser::processJSONAccessor( QString id, const QJsonObject& json )
if ( json.contains(KEY_BYTE_STRIDE))
stride = json.value(KEY_BYTE_STRIDE).toInt();
- AttributePtr attr( new Attribute( buf, type, count, offset, stride ) );
+ QAttribute *attr( new QAttribute( buf, type, count, offset, stride ) );
m_attributeDict[id] = attr;
}
diff --git a/src/render/io/gltfparser_p.h b/src/render/io/gltfparser_p.h
index d18e4483e..0ca5edc28 100644
--- a/src/render/io/gltfparser_p.h
+++ b/src/render/io/gltfparser_p.h
@@ -114,7 +114,7 @@ private:
// so record the association here for when we instantiate meshes
QMap<QMeshData*, QString> m_meshMaterialDict;
- QMap<QString, AttributePtr> m_attributeDict;
+ QMap<QString, QAttribute *> m_attributeDict;
class BufferData
{
@@ -131,7 +131,7 @@ private:
QMap<QString, QMaterial*> m_materialCache;
QMap<QString, BufferData> m_bufferDatas;
- QMap<QString, BufferPtr> m_buffers;
+ QMap<QString, QBuffer*> m_buffers;
QMap<QString, QString> m_shaderPaths;
QMap<QString, QShaderProgram*> m_programs;
diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp
index 5bde449d8..7cd0dce69 100644
--- a/src/render/io/objloader.cpp
+++ b/src/render/io/objloader.cpp
@@ -244,26 +244,26 @@ QMeshData *ObjLoader::mesh() const
}
} // of buffer filling loop
- BufferPtr buf(new Buffer(QOpenGLBuffer::VertexBuffer));
- buf->setUsage(QOpenGLBuffer::StaticDraw);
+ QBuffer *buf(new QBuffer(QBuffer::VertexBuffer));
+ buf->setUsage(QBuffer::StaticDraw);
buf->setData(bufferBytes);
- mesh->addAttribute(QMeshData::defaultPositionAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, 0, stride)));
+ mesh->addAttribute(QMeshData::defaultPositionAttributeName(), new QAttribute(buf, GL_FLOAT_VEC3, count, 0, stride));
quint32 offset = sizeof(float) * 3;
if (hasTextureCoordinates()) {
- mesh->addAttribute(QMeshData::defaultTextureCoordinateAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC2, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultTextureCoordinateAttributeName(), new QAttribute(buf, GL_FLOAT_VEC2, count, offset, stride));
offset += sizeof(float) * 2;
}
if (hasNormals()) {
- mesh->addAttribute(QMeshData::defaultNormalAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC3, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultNormalAttributeName(), new QAttribute(buf, GL_FLOAT_VEC3, count, offset, stride));
offset += sizeof(float) * 3;
}
if (hasTangents()) {
- mesh->addAttribute(QMeshData::defaultTangentAttributeName(), AttributePtr(new Attribute(buf, GL_FLOAT_VEC4, count, offset, stride)));
+ mesh->addAttribute(QMeshData::defaultTangentAttributeName(), new QAttribute(buf, GL_FLOAT_VEC4, count, offset, stride));
offset += sizeof(float) * 4;
}
@@ -284,10 +284,10 @@ QMeshData *ObjLoader::mesh() const
memcpy(indexBytes.data(), reinterpret_cast<const char*>(m_indices.data()), indexBytes.size());
}
- BufferPtr indexBuffer(new Buffer(QOpenGLBuffer::IndexBuffer));
- indexBuffer->setUsage(QOpenGLBuffer::StaticDraw);
+ QBuffer *indexBuffer(new QBuffer(QBuffer::IndexBuffer));
+ indexBuffer->setUsage(QBuffer::StaticDraw);
indexBuffer->setData(indexBytes);
- mesh->setIndexAttribute(AttributePtr(new Attribute(indexBuffer, ty, m_indices.size(), 0, 0)));
+ mesh->setIndexAttribute(new QAttribute(indexBuffer, ty, m_indices.size(), 0, 0));
mesh->computeBoundsFromAttribute(QMeshData::defaultPositionAttributeName());
qCDebug(Render::Io) << "computed bounds is:" << mesh->boundingBox();
diff --git a/src/render/io/qattribute.cpp b/src/render/io/qattribute.cpp
index 9087c2d64..814ec0aa8 100644
--- a/src/render/io/qattribute.cpp
+++ b/src/render/io/qattribute.cpp
@@ -36,10 +36,11 @@
#include "qattribute.h"
#include "qattribute_p.h"
+#include <QVector4D>
#include <QVector3D>
#include <QVector2D>
#include <QVector>
-#include <Qt3DCore/qabstractbuffer.h>
+#include <Qt3DRenderer/qbuffer.h>
#include <Qt3DRenderer/private/renderlogging_p.h>
QT_BEGIN_NAMESPACE
@@ -50,28 +51,105 @@ namespace Qt3D {
class Qt3D::AttributePrivate
\internal
*/
-AttributePrivate::AttributePrivate()
+QAttributePrivate::QAttributePrivate()
: QAbstractAttributePrivate()
{
}
-Attribute::Attribute(QAbstractBufferPtr buf, int type, int count, int offset, int stride)
- : QAbstractAttribute(*new AttributePrivate, buf, type, count, offset, stride)
+QAttribute::QAttribute(QNode *parent)
+ : QAbstractAttribute(*new QAttributePrivate(), parent)
{
}
-/*! \internal */
-Attribute::Attribute(AttributePrivate &dd, QAbstractBufferPtr buf, int type, int count, int offset, int stride)
- : QAbstractAttribute(dd, buf, type, count, offset, stride)
+QAttribute::QAttribute(QBuffer *buf, int type, int count, int offset, int stride)
+ : QAbstractAttribute(*new QAttributePrivate(), buf, QString(), type, count, offset, stride)
{
}
-QVector<QVector3D> Attribute::asVector3D() const
+QAttribute::QAttribute(QBuffer *buf, const QString &name, int type, int count, int offset, int stride)
+ : QAbstractAttribute(*new QAttributePrivate(), buf, name, type, count, offset, stride)
{
- Q_D(const Attribute);
+}
+
+QAttribute::~QAttribute()
+{
+ QAbstractAttribute::cleanup();
+}
+
+void QAttribute::copy(const QNode *ref)
+{
+ QAbstractAttribute::copy(ref);
+}
+
+QVector<QVector4D> QAttribute::asVector4D() const
+{
+ Q_D(const QAttribute);
const QByteArray buffer = d->m_buffer->data();
const char *rawBuffer = buffer.constData();
- rawBuffer += d->m_offset;
+ rawBuffer += d->m_byteOffset;
+ 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<QVector4D>();
+ }
+
+ if (d->m_byteStride != 0)
+ stride = d->m_byteStride;
+ QVector<QVector4D> result;
+ result.resize(d->m_count);
+
+ for (uint c = 0; c < d->m_count; ++c) {
+ QVector4D v;
+ fptr = reinterpret_cast<const float*>(rawBuffer);
+
+ switch (type()) {
+ case GL_FLOAT_VEC2:
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ break;
+
+ case GL_FLOAT_VEC3:
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ v.setZ(fptr[2]);
+ break;
+
+ case GL_FLOAT_VEC4:
+ v.setX(fptr[0]);
+ v.setY(fptr[1]);
+ v.setZ(fptr[2]);
+ v.setW(fptr[3]);
+ break;
+
+ default:
+ break; // should never happen, we check types above
+ }
+
+ result[c] = v;
+ rawBuffer += stride;
+ }
+
+ return result;
+}
+
+QVector<QVector3D> QAttribute::asVector3D() const
+{
+ Q_D(const QAttribute);
+ const QByteArray buffer = d->m_buffer->data();
+ const char *rawBuffer = buffer.constData();
+ rawBuffer += d->m_byteOffset;
const float* fptr;
int stride;
@@ -90,12 +168,12 @@ QVector<QVector3D> Attribute::asVector3D() const
return QVector<QVector3D>();
}
- if (d->m_stride != 0)
- stride = d->m_stride;
+ if (d->m_byteStride != 0)
+ stride = d->m_byteStride;
QVector<QVector3D> result;
result.resize(d->m_count);
- for (uint c=0; c < d->m_count; ++c) {
+ for (uint c = 0; c < d->m_count; ++c) {
QVector3D v;
fptr = reinterpret_cast<const float*>(rawBuffer);
@@ -103,7 +181,6 @@ QVector<QVector3D> Attribute::asVector3D() const
case GL_FLOAT_VEC2:
v.setX(fptr[0]);
v.setY(fptr[1]);
- v.setZ(0.0f);
break;
case GL_FLOAT_VEC3:
@@ -124,11 +201,11 @@ QVector<QVector3D> Attribute::asVector3D() const
return result;
}
-QVector<QVector2D> Attribute::asVector2D() const
+QVector<QVector2D> QAttribute::asVector2D() const
{
- Q_D(const Attribute);
+ Q_D(const QAttribute);
char* rawBuffer = d->m_buffer->data().data();
- rawBuffer += d->m_offset;
+ rawBuffer += d->m_byteOffset;
float* fptr;
int stride;
@@ -147,13 +224,13 @@ QVector<QVector2D> Attribute::asVector2D() const
return QVector<QVector2D>();
}
- if (d->m_stride != 0)
- stride = d->m_stride;
+ if (d->m_byteStride != 0)
+ stride = d->m_byteStride;
QVector<QVector2D> result;
result.resize(d->m_count);
- for (uint c=0; c < d->m_count; ++c) {
+ for (uint c = 0; c < d->m_count; ++c) {
QVector2D v;
fptr = reinterpret_cast<float*>(rawBuffer);
v.setX(fptr[0]);
@@ -165,16 +242,16 @@ QVector<QVector2D> Attribute::asVector2D() const
return result;
}
-void Attribute::dump(int count)
+void QAttribute::dump(int count)
{
- Q_D(const Attribute);
- const char* rawBuffer = d->m_buffer->data().constData();
- rawBuffer += d->m_offset;
+ Q_D(const QAttribute);
+ const char* rawBuffer = d->m_buffer->data().data();
+ rawBuffer += d->m_byteOffset;
const float* fptr;
const quint16* usptr;
- int stride = d->m_stride;
+ int stride = d->m_byteStride;
for (int c=0; c<count; ++c) {
switch (type()) {
@@ -208,6 +285,11 @@ void Attribute::dump(int count)
}
}
+QBuffer *QAttribute::buffer() const
+{
+ return static_cast<QBuffer *>(QAbstractAttribute::buffer());
+}
+
} // Qt3D
QT_END_NAMESPACE
diff --git a/src/render/io/qattribute.h b/src/render/io/qattribute.h
index 29c8228a2..6d312dd30 100644
--- a/src/render/io/qattribute.h
+++ b/src/render/io/qattribute.h
@@ -39,33 +39,43 @@
#include <Qt3DCore/qabstractattribute.h>
#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <QOpenGLBuffer>
+#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
namespace Qt3D {
-class AttributePrivate;
+class QAttributePrivate;
+class QBuffer;
-class QT3DRENDERERSHARED_EXPORT Attribute : public QAbstractAttribute
+class QT3DRENDERERSHARED_EXPORT QAttribute : public QAbstractAttribute
{
+ Q_OBJECT
+
public:
- Attribute(QAbstractBufferPtr buf, int type, int count, int offset=0, int stride = 0);
+ explicit QAttribute(QNode *parent = 0);
+ QAttribute(QBuffer *buf, int type, int count, int offset=0, int stride = 0);
+ QAttribute(QBuffer *buf, const QString &name, int type, int count, int offset=0, int stride = 0);
+ ~QAttribute();
+ QVector<QVector4D> asVector4D() const Q_DECL_OVERRIDE;
QVector<QVector3D> asVector3D() const Q_DECL_OVERRIDE;
QVector<QVector2D> asVector2D() const Q_DECL_OVERRIDE;
void dump(int count) Q_DECL_OVERRIDE;
+ QBuffer *buffer() const;
+
protected:
- Q_DECLARE_PRIVATE(Attribute)
- Attribute(AttributePrivate &dd, QAbstractBufferPtr buf, int type, int count, int offset=0, int stride = 0);
-};
+ void copy(const QNode *ref) Q_DECL_OVERRIDE;
-typedef QSharedPointer<Attribute> AttributePtr;
+private:
+ QT3D_CLONEABLE(QAttribute)
+ Q_DECLARE_PRIVATE(QAttribute)
+};
} // Qt3D
QT_END_NAMESPACE
-#endif // QATTRIBUTE_H
+#endif // QT3D_QATTRIBUTE_H
diff --git a/src/render/io/qattribute_p.h b/src/render/io/qattribute_p.h
index 82b2278d6..bd660b1eb 100644
--- a/src/render/io/qattribute_p.h
+++ b/src/render/io/qattribute_p.h
@@ -44,12 +44,12 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
-class Attribute;
+class QAttribute;
-class QT3DRENDERERSHARED_EXPORT AttributePrivate : public QAbstractAttributePrivate
+class QT3DRENDERERSHARED_EXPORT QAttributePrivate : public QAbstractAttributePrivate
{
public:
- AttributePrivate();
+ QAttributePrivate();
};
} // Qt3D
diff --git a/src/render/io/qbuffer.cpp b/src/render/io/qbuffer.cpp
index 54ab6d75d..e9ab21c96 100644
--- a/src/render/io/qbuffer.cpp
+++ b/src/render/io/qbuffer.cpp
@@ -46,55 +46,86 @@ namespace Qt3D {
\class Qt3D::BufferPrivate
\internal
*/
-BufferPrivate::BufferPrivate()
+QBufferPrivate::QBufferPrivate()
: QAbstractBufferPrivate()
+ , m_usage(QBuffer::StaticDraw)
{
}
-Buffer::Buffer(QOpenGLBuffer::Type ty)
- : QAbstractBuffer(*new BufferPrivate)
+
+QBuffer::QBuffer(QBuffer::BufferType ty, QNode *parent)
+ : QAbstractBuffer(*new QBufferPrivate(), parent)
{
- Q_D(Buffer);
+ Q_D(QBuffer);
d->m_type = ty;
- d->m_usage = QOpenGLBuffer::StaticDraw;
+}
+
+QBuffer::~QBuffer()
+{
+ QAbstractBuffer::cleanup();
}
/*! \internal */
-Buffer::Buffer(BufferPrivate &dd, QOpenGLBuffer::Type ty)
- : QAbstractBuffer(dd)
+QBuffer::QBuffer(QBufferPrivate &dd, QBuffer::BufferType ty, QNode *parent)
+ : QAbstractBuffer(dd, parent)
{
- Q_D(Buffer);
+ Q_D(QBuffer);
d->m_type = ty;
- d->m_usage = QOpenGLBuffer::StaticDraw;
}
-void Buffer::setUsage(QOpenGLBuffer::UsagePattern usage)
+void QBuffer::copy(const QNode *ref)
+{
+ QAbstractBuffer::copy(ref);
+ const QBuffer *buffer = static_cast<const QBuffer *>(ref);
+ d_func()->m_type = buffer->d_func()->m_type;
+ d_func()->m_usage = buffer->d_func()->m_usage;
+}
+
+QBuffer::UsageType QBuffer::usage() const
{
- Q_D(Buffer);
- d->m_usage = usage;
+ Q_D(const QBuffer);
+ return d->m_usage;
}
-QOpenGLBuffer::Type Buffer::type() const
+void QBuffer::setUsage(QBuffer::UsageType usage)
{
- Q_D(const Buffer);
+ Q_D(QBuffer);
+ if (usage != d->m_usage) {
+ d->m_usage = usage;
+ emit usageChanged();
+ }
+}
+
+QBuffer::BufferType QBuffer::type() const
+{
+ Q_D(const QBuffer);
return d->m_type;
}
-void Buffer::bind()
+void QBuffer::setType(QBuffer::BufferType type)
+{
+ Q_D(QBuffer);
+ if (type != d->m_type) {
+ d->m_type = type;
+ emit typeChanged();
+ }
+}
+
+void QBuffer::bind()
{
}
-void Buffer::create()
+void QBuffer::create()
{
// TO DO -> Wrap createGL in here
}
-QOpenGLBuffer Buffer::createGL() const
+QOpenGLBuffer QBuffer::createGL() const
{
- Q_D(const Buffer);
- QOpenGLBuffer b(d->m_type);
- b.setUsagePattern(d->m_usage);
+ Q_D(const QBuffer);
+ QOpenGLBuffer b(static_cast<QOpenGLBuffer::Type>(d->m_type));
+ b.setUsagePattern(static_cast<QOpenGLBuffer::UsagePattern>(d->m_usage));
if (!b.create())
qCWarning(Render::Io) << Q_FUNC_INFO << "buffer creation failed";
@@ -106,9 +137,9 @@ QOpenGLBuffer Buffer::createGL() const
return b;
}
-void Buffer::upload(QOpenGLBuffer b)
+void QBuffer::upload(QOpenGLBuffer b)
{
- Q_D(Buffer);
+ Q_D(QBuffer);
if (!b.bind())
qCWarning(Render::Io) << Q_FUNC_INFO << "buffer bind failed";
b.allocate(NULL, d->m_data.count()); // orphan the buffer
diff --git a/src/render/io/qbuffer.h b/src/render/io/qbuffer.h
index 429f0fb3d..a5e1ceedc 100644
--- a/src/render/io/qbuffer.h
+++ b/src/render/io/qbuffer.h
@@ -50,15 +50,46 @@ GLint elementType(GLint type);
GLint tupleSizeFromType(GLint type);
GLuint byteSizeFromType(GLint type);
-class BufferPrivate;
+class QBufferPrivate;
-class QT3DRENDERERSHARED_EXPORT Buffer : public QAbstractBuffer
+class QT3DRENDERERSHARED_EXPORT QBuffer : public QAbstractBuffer
{
+ Q_OBJECT
+ Q_PROPERTY(BufferType type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(UsageType usage READ usage WRITE setUsage NOTIFY usageChanged)
+
public:
- explicit Buffer(QOpenGLBuffer::Type ty);
+ enum BufferType
+ {
+ VertexBuffer = 0x8892, // GL_ARRAY_BUFFER
+ IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER
+ PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER
+ PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER
+ };
+ Q_ENUM(BufferType)
+
+ enum UsageType
+ {
+ StreamDraw = 0x88E0, // GL_STREAM_DRAW
+ StreamRead = 0x88E1, // GL_STREAM_READ
+ StreamCopy = 0x88E2, // GL_STREAM_COPY
+ StaticDraw = 0x88E4, // GL_STATIC_DRAW
+ StaticRead = 0x88E5, // GL_STATIC_READ
+ StaticCopy = 0x88E6, // GL_STATIC_COPY
+ DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW
+ DynamicRead = 0x88E9, // GL_DYNAMIC_READ
+ DynamicCopy = 0x88EA // GL_DYNAMIC_COPY
+ };
+ Q_ENUM(UsageType)
+
+ QBuffer(BufferType ty = QBuffer::VertexBuffer, QNode *parent = 0);
+ ~QBuffer();
+
+ void setUsage(UsageType usage);
+ UsageType usage() const;
- void setUsage(QOpenGLBuffer::UsagePattern usage);
- QOpenGLBuffer::Type type() const;
+ void setType(BufferType type);
+ BufferType type() const;
void bind() Q_DECL_OVERRIDE;
void create() Q_DECL_OVERRIDE;
@@ -70,11 +101,17 @@ public:
// 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);
-};
+ QBuffer(QBufferPrivate &dd, QBuffer::BufferType ty, QNode *parent = 0);
+ void copy(const QNode *ref) Q_DECL_OVERRIDE;
+
+Q_SIGNALS:
+ void typeChanged();
+ void usageChanged();
-typedef QSharedPointer<Buffer> BufferPtr;
+private:
+ Q_DECLARE_PRIVATE(QBuffer)
+ QT3D_CLONEABLE(QBuffer)
+};
} // Qt3D
diff --git a/src/render/io/qbuffer_p.h b/src/render/io/qbuffer_p.h
index c86bdcd5c..036a9e26d 100644
--- a/src/render/io/qbuffer_p.h
+++ b/src/render/io/qbuffer_p.h
@@ -38,6 +38,7 @@
#define QT3D_QBUFFER_P_H
#include <private/qabstractbuffer_p.h>
+#include <Qt3DRenderer/qbuffer.h>
#include <Qt3DRenderer/qt3drenderer_global.h>
#include <QOpenGLBuffer>
@@ -45,15 +46,13 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
-class Buffer;
-
-class QT3DRENDERERSHARED_EXPORT BufferPrivate : public QAbstractBufferPrivate
+class QT3DRENDERERSHARED_EXPORT QBufferPrivate : public QAbstractBufferPrivate
{
public:
- BufferPrivate();
+ QBufferPrivate();
- QOpenGLBuffer::Type m_type;
- QOpenGLBuffer::UsagePattern m_usage;
+ QBuffer::BufferType m_type;
+ QBuffer::UsageType m_usage;
};
} // Qt3D
diff --git a/src/render/io/qmeshdata.cpp b/src/render/io/qmeshdata.cpp
index ddb2b00d8..0a689257f 100644
--- a/src/render/io/qmeshdata.cpp
+++ b/src/render/io/qmeshdata.cpp
@@ -49,11 +49,18 @@ namespace Qt3D {
\internal
*/
QMeshDataPrivate::QMeshDataPrivate()
- : m_verticesPerPatch(0)
+ : m_indexAttr(Q_NULLPTR)
+ , m_verticesPerPatch(0)
, m_primitiveType(0)
{
}
+QMeshDataPrivate::~QMeshDataPrivate()
+{
+ delete m_indexAttr;
+ qDeleteAll(m_attributes);
+}
+
QMeshData::QMeshData(PrimitiveType primitiveType)
: d_ptr(new QMeshDataPrivate)
{
@@ -62,15 +69,18 @@ QMeshData::QMeshData(PrimitiveType primitiveType)
QMeshData::~QMeshData()
{
+// delete d_ptr;
}
+// TO DO: Be careful is QMeshData is copied to not leak memory
+
/*! \internal */
QMeshData::QMeshData(QMeshDataPrivate &dd)
: d_ptr(&dd)
{
}
-void QMeshData::addAttribute(const QString &name, const QAbstractAttributePtr &attr)
+void QMeshData::addAttribute(const QString &name, QAbstractAttribute *attr)
{
Q_D(QMeshData);
const int i = d->m_attributesNames.indexOf(name);
@@ -82,7 +92,7 @@ void QMeshData::addAttribute(const QString &name, const QAbstractAttributePtr &a
}
}
-void QMeshData::setIndexAttribute(const QAbstractAttributePtr &attr)
+void QMeshData::setIndexAttribute(QAbstractAttribute *attr)
{
Q_D(QMeshData);
d->m_indexAttr = attr;
@@ -94,17 +104,17 @@ QStringList QMeshData::attributeNames() const
return d->m_attributesNames;
}
-QAbstractAttributePtr QMeshData::attributeByName(const QString &name) const
+QAbstractAttribute *QMeshData::attributeByName(const QString &name) const
{
Q_D(const QMeshData);
const int i = d->m_attributesNames.indexOf(name);
if (i != -1)
return d->m_attributes[i];
else
- return QAbstractAttributePtr();
+ return Q_NULLPTR;
}
-QAbstractAttributePtr QMeshData::indexAttribute() const
+QAbstractAttribute *QMeshData::indexAttribute() const
{
Q_D(const QMeshData);
return d->m_indexAttr;
@@ -161,17 +171,17 @@ int QMeshData::primitiveCount() const
}
}
-QList<QAbstractBufferPtr> QMeshData::buffers() const
+QVector<QAbstractBuffer *> QMeshData::buffers() const
{
Q_D(const QMeshData);
- QSet<QAbstractBufferPtr> r;
+ QVector<QAbstractBuffer*> r;
+ r.reserve(d->m_attributes.count() + 1);
if (d->m_indexAttr)
- r.insert(d->m_indexAttr->buffer());
-
- Q_FOREACH (const QAbstractAttributePtr &v, d->m_attributes)
- r.insert(v->buffer());
+ r.push_back(d->m_indexAttr->buffer());
+ Q_FOREACH (QAbstractAttribute *attr, d->m_attributes)
+ r.push_back(attr->buffer());
- return r.toList();
+ return r;
}
void QMeshData::setBoundingBox(const QAxisAlignedBoundingBox &bbox)
@@ -183,7 +193,7 @@ void QMeshData::setBoundingBox(const QAxisAlignedBoundingBox &bbox)
void QMeshData::computeBoundsFromAttribute(const QString &name)
{
Q_D(QMeshData);
- QAbstractAttributePtr attr = attributeByName(name);
+ QAbstractAttribute *attr = attributeByName(name);
if (!attr) {
qWarning() << Q_FUNC_INFO << "unknown attribute:" << name;
return;
diff --git a/src/render/io/qmeshdata.h b/src/render/io/qmeshdata.h
index d60aa819b..23116ec7e 100644
--- a/src/render/io/qmeshdata.h
+++ b/src/render/io/qmeshdata.h
@@ -49,9 +49,6 @@ class QAbstractAttribute;
class QAbstractBuffer;
class QMeshDataPrivate;
-typedef QSharedPointer<QAbstractAttribute> QAbstractAttributePtr;
-typedef QSharedPointer<QAbstractBuffer> QAbstractBufferPtr;
-
class QT3DRENDERERSHARED_EXPORT QMeshData
{
public:
@@ -73,12 +70,12 @@ public:
explicit QMeshData(PrimitiveType primitiveType = Triangles);
virtual ~QMeshData();
- void addAttribute(const QString &name, const QAbstractAttributePtr &attr);
- void setIndexAttribute(const QAbstractAttributePtr &attr);
+ void addAttribute(const QString &name, QAbstractAttribute *attr);
+ void setIndexAttribute(QAbstractAttribute *attr);
QStringList attributeNames() const;
- QAbstractAttributePtr attributeByName(const QString &name) const;
- QAbstractAttributePtr indexAttribute() const;
+ QAbstractAttribute *attributeByName(const QString &name) const;
+ QAbstractAttribute *indexAttribute() const;
static QString defaultPositionAttributeName();
static QString defaultNormalAttributeName();
@@ -94,7 +91,7 @@ public:
int primitiveCount() const;
- QList<QAbstractBufferPtr> buffers() const;
+ QVector<QAbstractBuffer *> buffers() const;
void setBoundingBox(const QAxisAlignedBoundingBox &bbox);
void computeBoundsFromAttribute(const QString &name);
diff --git a/src/render/io/qmeshdata_p.h b/src/render/io/qmeshdata_p.h
index 19bb89963..c1722396d 100644
--- a/src/render/io/qmeshdata_p.h
+++ b/src/render/io/qmeshdata_p.h
@@ -56,10 +56,11 @@ class QMeshDataPrivate
{
public:
QMeshDataPrivate();
+ ~QMeshDataPrivate();
QStringList m_attributesNames;
- QVector<QAbstractAttributePtr> m_attributes;
- QAbstractAttributePtr m_indexAttr;
+ QVector<QAbstractAttribute *> m_attributes;
+ QAbstractAttribute *m_indexAttr;
QAxisAlignedBoundingBox m_bbox;
int m_verticesPerPatch;
int m_primitiveType;