Added QSGGeometry::Attribute::isPosition to give a hint about vertex data
authorGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 5 Sep 2011 05:50:58 +0000 (07:50 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Wed, 7 Sep 2011 07:00:27 +0000 (09:00 +0200)
Also added a QSGGeomtry::sizeOfIndex() function for convenience

Change-Id: If1f13afd4c1c5295dcfb00254144ef6b8b8b7878
Reviewed-on: http://codereview.qt.nokia.com/4307
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/declarative/items/qsgspriteimage.cpp
src/declarative/particles/qsgcustomparticle.cpp
src/declarative/particles/qsgimageparticle.cpp
src/declarative/scenegraph/coreapi/qsggeometry.cpp
src/declarative/scenegraph/coreapi/qsggeometry.h

index afa80e4..9a43b71 100644 (file)
@@ -225,8 +225,8 @@ void QSGSpriteImage::createEngine()
 }
 
 static QSGGeometry::Attribute SpriteImage_Attributes[] = {
-    { 0, 2, GL_FLOAT },            // tex
-    { 1, 4, GL_FLOAT }             // animData
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT),         // tex
+    QSGGeometry::Attribute::create(1, 4, GL_FLOAT)          // animData
 };
 
 static QSGGeometry::AttributeSet SpriteImage_AttributeSet =
index 373d050..eb6f45e 100644 (file)
@@ -83,11 +83,11 @@ static const char qt_particles_default_fragment_code[] =//TODO: Default frag req
         "}";
 
 static QSGGeometry::Attribute PlainParticle_Attributes[] = {
-    { 0, 2, GL_FLOAT },             // Position
-    { 1, 2, GL_FLOAT },             // TexCoord
-    { 2, 4, GL_FLOAT },             // Data
-    { 3, 4, GL_FLOAT },             // Vectors
-    { 4, 1, GL_FLOAT }              // r
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),       // Position
+    QSGGeometry::Attribute::create(1, 2, GL_FLOAT),             // TexCoord
+    QSGGeometry::Attribute::create(2, 4, GL_FLOAT),             // Data
+    QSGGeometry::Attribute::create(3, 4, GL_FLOAT),             // Vectors
+    QSGGeometry::Attribute::create(4, 1, GL_FLOAT)              // r
 };
 
 static QSGGeometry::AttributeSet PlainParticle_AttributeSet =
index 1e410ad..89e9a7d 100644 (file)
@@ -783,9 +783,9 @@ void QSGImageParticle::createEngine()
 }
 
 static QSGGeometry::Attribute SimpleParticle_Attributes[] = {
-    { 0, 2, GL_FLOAT },             // Position
-    { 1, 4, GL_FLOAT },             // Data
-    { 2, 4, GL_FLOAT }             // Vectors
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),             // Position
+    QSGGeometry::Attribute::create(1, 4, GL_FLOAT),             // Data
+    QSGGeometry::Attribute::create(2, 4, GL_FLOAT)             // Vectors
 };
 
 static QSGGeometry::AttributeSet SimpleParticle_AttributeSet =
@@ -796,10 +796,10 @@ static QSGGeometry::AttributeSet SimpleParticle_AttributeSet =
 };
 
 static QSGGeometry::Attribute ColoredParticle_Attributes[] = {
-    { 0, 2, GL_FLOAT },             // Position
-    { 1, 4, GL_FLOAT },             // Data
-    { 2, 4, GL_FLOAT },             // Vectors
-    { 3, 4, GL_UNSIGNED_BYTE },     // Colors
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),             // Position
+    QSGGeometry::Attribute::create(1, 4, GL_FLOAT),             // Data
+    QSGGeometry::Attribute::create(2, 4, GL_FLOAT),             // Vectors
+    QSGGeometry::Attribute::create(3, 4, GL_UNSIGNED_BYTE),     // Colors
 };
 
 static QSGGeometry::AttributeSet ColoredParticle_AttributeSet =
@@ -810,13 +810,13 @@ static QSGGeometry::AttributeSet ColoredParticle_AttributeSet =
 };
 
 static QSGGeometry::Attribute DeformableParticle_Attributes[] = {
-    { 0, 2, GL_FLOAT },             // Position
-    { 1, 2, GL_FLOAT },             // TexCoord
-    { 2, 4, GL_FLOAT },             // Data
-    { 3, 4, GL_FLOAT },             // Vectors
-    { 4, 4, GL_UNSIGNED_BYTE },     // Colors
-    { 5, 4, GL_FLOAT },             // DeformationVectors
-    { 6, 3, GL_FLOAT },             // Rotation
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),             // Position
+    QSGGeometry::Attribute::create(1, 2, GL_FLOAT),             // TexCoord
+    QSGGeometry::Attribute::create(2, 4, GL_FLOAT),             // Data
+    QSGGeometry::Attribute::create(3, 4, GL_FLOAT),             // Vectors
+    QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE),     // Colors
+    QSGGeometry::Attribute::create(5, 4, GL_FLOAT),             // DeformationVectors
+    QSGGeometry::Attribute::create(6, 3, GL_FLOAT),             // Rotation
 };
 
 static QSGGeometry::AttributeSet DeformableParticle_AttributeSet =
@@ -827,14 +827,14 @@ static QSGGeometry::AttributeSet DeformableParticle_AttributeSet =
 };
 
 static QSGGeometry::Attribute SpriteParticle_Attributes[] = {
-    { 0, 2, GL_FLOAT },             // Position
-    { 1, 2, GL_FLOAT },             // TexCoord
-    { 2, 4, GL_FLOAT },             // Data
-    { 3, 4, GL_FLOAT },             // Vectors
-    { 4, 4, GL_UNSIGNED_BYTE },     // Colors
-    { 5, 4, GL_FLOAT },             // DeformationVectors
-    { 6, 3, GL_FLOAT },             // Rotation
-    { 7, 4, GL_FLOAT }              // Anim Data
+    QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),             // Position
+    QSGGeometry::Attribute::create(1, 2, GL_FLOAT),             // TexCoord
+    QSGGeometry::Attribute::create(2, 4, GL_FLOAT),             // Data
+    QSGGeometry::Attribute::create(3, 4, GL_FLOAT),             // Vectors
+    QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE),     // Colors
+    QSGGeometry::Attribute::create(5, 4, GL_FLOAT),             // DeformationVectors
+    QSGGeometry::Attribute::create(6, 3, GL_FLOAT),             // Rotation
+    QSGGeometry::Attribute::create(7, 4, GL_FLOAT)              // Anim Data
 };
 
 static QSGGeometry::AttributeSet SpriteParticle_AttributeSet =
index 6b622af..0b17501 100644 (file)
 QT_BEGIN_NAMESPACE
 
 
+QSGGeometry::Attribute QSGGeometry::Attribute::create(int attributeIndex, int tupleSize, int primitiveType, bool isPrimitive)
+{
+    Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, 0 };
+    return a;
+}
+
+
 /*!
     Convenience function which returns attributes to be used for 2D solid
     color drawing.
@@ -53,7 +60,7 @@ QT_BEGIN_NAMESPACE
 const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
 {
     static Attribute data[] = {
-        { 0, 2, GL_FLOAT }
+        QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true)
     };
     static AttributeSet attrs = { 1, sizeof(float) * 2, data };
     return attrs;
@@ -66,8 +73,8 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
 const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
 {
     static Attribute data[] = {
-        { 0, 2, GL_FLOAT },
-        { 1, 2, GL_FLOAT }
+        QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),
+        QSGGeometry::Attribute::create(1, 2, GL_FLOAT)
     };
     static AttributeSet attrs = { 2, sizeof(float) * 4, data };
     return attrs;
@@ -80,8 +87,8 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D(
 const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
 {
     static Attribute data[] = {
-        { 0, 2, GL_FLOAT },
-        { 1, 4, GL_UNSIGNED_BYTE }
+        QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),
+        QSGGeometry::Attribute::create(1, 4, GL_UNSIGNED_BYTE)
     };
     static AttributeSet attrs = { 2, 2 * sizeof(float) + 4 * sizeof(char), data };
     return attrs;
@@ -131,11 +138,33 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
     Q_ASSERT(m_attributes.count > 0);
     Q_ASSERT(m_attributes.stride > 0);
 
+    if (indexType != GL_UNSIGNED_BYTE
+        && indexType != GL_UNSIGNED_SHORT
+#ifndef QT_OPENGL_ES
+        && indexType != GL_UNSIGNED_INT
+#endif
+            ) {
+        qFatal("QSGGeometry: Unsupported index type, %x.%s\n",
+               indexType,
+               indexType == GL_UNSIGNED_INT ? " GL_UNSIGNED_INT is not supported on OpenGL ES." : "");
+    }
+
+
     // Because allocate reads m_vertex_count, m_index_count and m_owns_data, these
     // need to be set before calling allocate...
     allocate(vertexCount, indexCount);
 }
 
+/*!
+    \fn int QSGGeometry::sizeOfIndexType() const
+
+    Returns the byte size of the index type.
+
+    This value is either 1 when index type is GL_UNSIGNED_BYTE or 2 when
+    index type is GL_UNSIGNED_SHORT. For Desktop OpenGL, GL_UNSIGNED_INT
+    with the value 4 is also supported.
+ */
+
 QSGGeometry::~QSGGeometry()
 {
     if (m_owns_data)
index 107cabc..57d66eb 100644 (file)
@@ -56,11 +56,17 @@ class QSGGeometryData;
 class Q_DECLARATIVE_EXPORT QSGGeometry
 {
 public:
+
     struct Attribute
     {
         int position;
         int tupleSize;
         int type;
+
+        uint isVertexCoordinate : 1;
+        uint migrateYourCodeToUseTheCreateFunction: 31; // ### Remove before release
+
+        static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition = false);
     };
 
     struct AttributeSet {
@@ -133,6 +139,8 @@ public:
     inline uint *indexDataAsUInt();
     inline quint16 *indexDataAsUShort();
 
+    inline int sizeOfIndex() const;
+
     const void *indexData() const;
     inline const uint *indexDataAsUInt() const;
     inline const quint16 *indexDataAsUShort() const;
@@ -272,6 +280,16 @@ inline const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2
     return (const ColoredPoint2D *) m_data;
 }
 
+int QSGGeometry::sizeOfIndex() const
+{
+    if (m_index_type == GL_UNSIGNED_SHORT) return 2;
+    else if (m_index_type == GL_UNSIGNED_BYTE) return 1;
+#ifndef QT_OPENGL_ES
+    else if (m_index_type == GL_UNSIGNED_INT) return 4;
+#endif
+    return 0;
+}
+
 QT_END_NAMESPACE
 
 QT_END_HEADER