diff options
author | Paul Lemire <paul.lemire350@gmail.com> | 2015-08-10 14:49:23 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-08-11 17:29:18 +0000 |
commit | dfe50678f651f4effd677e4fc9d7b518a5975329 (patch) | |
tree | 509f9d0a126e285abcecf7f68deedf6ab439bbd7 /examples/qt3d/tessellation-modes | |
parent | 5156abc0fc3b390ae48f063dcc91b5c1187ff887 (diff) |
TessellatedQuadMesh converted to QGeometryRenderer
Change-Id: I72adb8b1221a06857d738ec19e6fd32e2c7886af
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/tessellation-modes')
-rw-r--r-- | examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp | 63 | ||||
-rw-r--r-- | examples/qt3d/tessellation-modes/tessellatedquadmesh.h | 9 |
2 files changed, 32 insertions, 40 deletions
diff --git a/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp b/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp index 5d8237753..22762a24c 100644 --- a/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp +++ b/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp @@ -38,24 +38,16 @@ #include <Qt3DRenderer/qattribute.h> #include <Qt3DRenderer/qbuffer.h> -#include <Qt3DRenderer/qmeshdata.h> +#include <Qt3DRenderer/qgeometry.h> -TessellatedQuadMesh::TessellatedQuadMesh(Qt3D::QNode *parent) - : Qt3D::QAbstractMesh(parent) -{ -} - -TessellatedQuadMesh::~TessellatedQuadMesh() -{ - QNode::cleanup(); -} - -class TessellatedQuadMeshFunctor : public Qt3D::QAbstractMeshFunctor +class TessellatedGeometry : public Qt3D::QGeometry { + Q_OBJECT public: - TessellatedQuadMeshFunctor() {} - - Qt3D::QMeshDataPtr operator ()() Q_DECL_OVERRIDE + TessellatedGeometry(Qt3D::QNode *parent = Q_NULLPTR) + : Qt3D::QGeometry(parent) + , m_positionAttribute(new Qt3D::QAttribute(this)) + , m_vertexBuffer(new Qt3D::QBuffer(Qt3D::QBuffer::VertexBuffer, this)) { const float positionData[] = { -0.8f, -0.8f, 0.0f, @@ -70,29 +62,34 @@ public: positionBytes.resize(size); memcpy(positionBytes.data(), positionData, size); - Qt3D::QBuffer *vertexBuffer(new Qt3D::QBuffer(Qt3D::QBuffer::VertexBuffer)); - vertexBuffer->setUsage(Qt3D::QBuffer::StaticDraw); - vertexBuffer->setData(positionBytes); + m_vertexBuffer->setData(positionBytes); - Qt3D::QMeshDataPtr mesh(new Qt3D::QMeshData(Qt3D::QMeshData::Patches)); - mesh->addAttribute(Qt3D::QMeshData::defaultPositionAttributeName(), - new Qt3D::QAttribute(vertexBuffer, Qt3D::QAttribute::Float, 3, nVerts)); - mesh->setVerticesPerPatch(4); - return mesh; - } + m_positionAttribute->setName(Qt3D::QAttribute::defaultPositionAttributeName()); + m_positionAttribute->setDataType(Qt3D::QAttribute::Float); + m_positionAttribute->setDataSize(3); + m_positionAttribute->setCount(nVerts); + m_positionAttribute->setByteStride(3 * sizeof(float)); + m_positionAttribute->setBuffer(m_vertexBuffer); - bool operator ==(const Qt3D::QAbstractMeshFunctor &other) const - { - const TessellatedQuadMeshFunctor *otherFunctor = functor_cast<TessellatedQuadMeshFunctor>(&other); - if (otherFunctor != Q_NULLPTR) - return true; - return false; + setVerticesPerPatch(4); + addAttribute(m_positionAttribute); } - QT3D_FUNCTOR(TessellatedQuadMeshFunctor) +private: + Qt3D::QAttribute *m_positionAttribute; + Qt3D::QBuffer *m_vertexBuffer; }; -Qt3D::QAbstractMeshFunctorPtr TessellatedQuadMesh::meshFunctor() const +TessellatedQuadMesh::TessellatedQuadMesh(Qt3D::QNode *parent) + : Qt3D::QGeometryRenderer(parent) { - return Qt3D::QAbstractMeshFunctorPtr(new TessellatedQuadMeshFunctor); + setPrimitiveType(Qt3D::QGeometryRenderer::Patches); + setGeometry(new TessellatedGeometry(this)); } + +TessellatedQuadMesh::~TessellatedQuadMesh() +{ + QNode::cleanup(); +} + +#include "tessellatedquadmesh.moc" diff --git a/examples/qt3d/tessellation-modes/tessellatedquadmesh.h b/examples/qt3d/tessellation-modes/tessellatedquadmesh.h index 0bb6459ef..6c4992183 100644 --- a/examples/qt3d/tessellation-modes/tessellatedquadmesh.h +++ b/examples/qt3d/tessellation-modes/tessellatedquadmesh.h @@ -37,19 +37,14 @@ #ifndef TESSELLATEDQUAD_H #define TESSELLATEDQUAD_H -#include <Qt3DRenderer/qabstractmesh.h> +#include <Qt3DRenderer/qgeometryrenderer.h> -class TessellatedQuadMesh : public Qt3D::QAbstractMesh +class TessellatedQuadMesh : public Qt3D::QGeometryRenderer { Q_OBJECT public: explicit TessellatedQuadMesh(Qt3D::QNode *parent = 0); ~TessellatedQuadMesh(); - - Qt3D::QAbstractMeshFunctorPtr meshFunctor() const Q_DECL_OVERRIDE; - -private: - QT3D_CLONEABLE(TessellatedQuadMesh) }; #endif // TESSELLATEDQUAD_H |