summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-08-04 12:40:59 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-08-07 14:31:54 +0000
commit975624820bbb086f0d7957236128ddb043e792d0 (patch)
tree542c17edee5cb5238704e7aa6c083f15045a6149 /examples
parent4bbe0ad81a06fb42f3aab592e5645e546bfb90db (diff)
QAbstractAttribute: Type abstracted with an enum
Also added a dataSize property to know the number of components per vertice (1 - 4) Change-Id: Iaa7cee2a53958ed2ec2f603f3ffc7971c027991d Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qt3d/custom-mesh-cpp/main.cpp41
-rw-r--r--examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp2
2 files changed, 25 insertions, 18 deletions
diff --git a/examples/qt3d/custom-mesh-cpp/main.cpp b/examples/qt3d/custom-mesh-cpp/main.cpp
index 4d4e58761..6ef760b83 100644
--- a/examples/qt3d/custom-mesh-cpp/main.cpp
+++ b/examples/qt3d/custom-mesh-cpp/main.cpp
@@ -49,10 +49,11 @@
#include <Qt3DInput/QInputAspect>
+#include <Qt3DRenderer/QStateSet>
#include <Qt3DRenderer/QRenderAspect>
#include <Qt3DRenderer/QFrameGraph>
#include <Qt3DRenderer/QForwardRenderer>
-#include <Qt3DRenderer/QPhongMaterial>
+#include <Qt3DRenderer/QPerVertexColorMaterial>
#include <Qt3DRenderer/QGeometryRenderer>
#include <Qt3DRenderer/QGeometry>
@@ -97,7 +98,7 @@ int main(int argc, char* argv[])
frameGraph->setActiveFrameGraph(forwardRenderer);
// Material
- Qt3D::QMaterial *material = new Qt3D::QPhongMaterial(rootEntity);
+ Qt3D::QMaterial *material = new Qt3D::QPerVertexColorMaterial(rootEntity);
// Torus
Qt3D::QEntity *customMeshEntity = new Qt3D::QEntity(rootEntity);
@@ -105,12 +106,8 @@ int main(int argc, char* argv[])
// Transform
Qt3D::QTransform *transform = new Qt3D::QTransform;
Qt3D::QScaleTransform *scaleTransform = new Qt3D::QScaleTransform;
- scaleTransform->setScale3D(QVector3D(1.5, 1, 0.5));
- Qt3D::QRotateTransform *rotateTransform = new Qt3D::QRotateTransform;
- rotateTransform->setAxis(QVector3D(1, 0, 0));
- rotateTransform->setAngleDeg(45);
+ scaleTransform->setScale(8.0f);
transform->addTransform(scaleTransform);
- transform->addTransform(rotateTransform);
// Custom Mesh (TetraHedron)
Qt3D::QGeometryRenderer *customMeshRenderer = new Qt3D::QGeometryRenderer;
@@ -202,44 +199,54 @@ int main(int argc, char* argv[])
Qt3D::QAttribute *positionAttribute = new Qt3D::QAttribute();
positionAttribute->setAttributeType(Qt3D::QAttribute::VertexAttribute);
positionAttribute->setBuffer(vertexDataBuffer);
- positionAttribute->setType(GL_FLOAT_VEC3);
+ positionAttribute->setDataType(Qt3D::QAttribute::Float);
+ positionAttribute->setDataSize(3);
positionAttribute->setByteOffset(0);
positionAttribute->setByteStride(9 * sizeof(float));
positionAttribute->setCount(4);
- positionAttribute->setName(Qt3D::QMeshData::defaultPositionAttributeName());
+ positionAttribute->setName(Qt3D::QAttribute::defaultPositionAttributeName());
Qt3D::QAttribute *normalAttribute = new Qt3D::QAttribute();
normalAttribute->setAttributeType(Qt3D::QAttribute::VertexAttribute);
normalAttribute->setBuffer(vertexDataBuffer);
- normalAttribute->setType(GL_FLOAT_VEC3);
+ normalAttribute->setDataType(Qt3D::QAttribute::Float);
+ normalAttribute->setDataSize(3);
normalAttribute->setByteOffset(3 * sizeof(float));
normalAttribute->setByteStride(9 * sizeof(float));
normalAttribute->setCount(4);
- normalAttribute->setName(Qt3D::QMeshData::defaultNormalAttributeName());
+ normalAttribute->setName(Qt3D::QAttribute::defaultNormalAttributeName());
Qt3D::QAttribute *colorAttribute = new Qt3D::QAttribute();
colorAttribute->setAttributeType(Qt3D::QAttribute::VertexAttribute);
colorAttribute->setBuffer(vertexDataBuffer);
- colorAttribute->setType(GL_FLOAT_VEC3);
+ colorAttribute->setDataType(Qt3D::QAttribute::Float);
+ colorAttribute->setDataSize(3);
colorAttribute->setByteOffset(6 * sizeof(float));
colorAttribute->setByteStride(9 * sizeof(float));
colorAttribute->setCount(4);
- colorAttribute->setName(Qt3D::QMeshData::defaultColorAttributeName());
+ colorAttribute->setName(Qt3D::QAttribute::defaultColorAttributeName());
Qt3D::QAttribute *indexAttribute = new Qt3D::QAttribute();
indexAttribute->setAttributeType(Qt3D::QAttribute::IndexAttribute);
indexAttribute->setBuffer(indexDataBuffer);
- colorAttribute->setType(GL_UNSIGNED_SHORT);
- colorAttribute->setByteOffset(0);
- colorAttribute->setByteStride(0);
- colorAttribute->setCount(12);
+ indexAttribute->setDataType(Qt3D::QAttribute::UnsignedShort);
+ indexAttribute->setDataSize(1);
+ indexAttribute->setByteOffset(0);
+ indexAttribute->setByteStride(0);
+ indexAttribute->setCount(12);
customGeometry->addAttribute(positionAttribute);
customGeometry->addAttribute(normalAttribute);
customGeometry->addAttribute(colorAttribute);
customGeometry->addAttribute(indexAttribute);
+ customMeshRenderer->setInstanceCount(1);
+ customMeshRenderer->setBaseVertex(0);
+ customMeshRenderer->setBaseInstance(0);
+ customMeshRenderer->setPrimitiveType(Qt3D::QGeometryRenderer::Triangles);
customMeshRenderer->setGeometry(customGeometry);
+ // 4 faces of 3 points
+ customMeshRenderer->setPrimitiveCount(12);
customMeshEntity->addComponent(customMeshRenderer);
customMeshEntity->addComponent(transform);
diff --git a/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp b/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp
index c582ee2ec..5d8237753 100644
--- a/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp
+++ b/examples/qt3d/tessellation-modes/tessellatedquadmesh.cpp
@@ -76,7 +76,7 @@ public:
Qt3D::QMeshDataPtr mesh(new Qt3D::QMeshData(Qt3D::QMeshData::Patches));
mesh->addAttribute(Qt3D::QMeshData::defaultPositionAttributeName(),
- new Qt3D::QAttribute(vertexBuffer, GL_FLOAT_VEC3, nVerts));
+ new Qt3D::QAttribute(vertexBuffer, Qt3D::QAttribute::Float, 3, nVerts));
mesh->setVerticesPerPatch(4);
return mesh;
}