rename QSGGeometry::stride() to sizeOfVertex for symetry with index
authorGunnar Sletta <gunnar.sletta@nokia.com>
Thu, 8 Sep 2011 13:15:57 +0000 (15:15 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Thu, 8 Sep 2011 13:45:49 +0000 (15:45 +0200)
Also support GL_UNSIGNED_INT as index type when supported by GL

Change-Id: I0988e102c8a04ce6cd02fb02528204ba810f853a
Reviewed-on: http://codereview.qt-project.org/4453
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/declarative/scenegraph/coreapi/qsggeometry.cpp
src/declarative/scenegraph/coreapi/qsggeometry.h
src/declarative/scenegraph/coreapi/qsgnode.cpp
src/declarative/scenegraph/coreapi/qsgrenderer.cpp
src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp
src/declarative/scenegraph/qsgdefaultrectanglenode.cpp
tests/auto/declarative/geometry/tst_geometry.cpp

index 0b17501..8661c9a 100644 (file)
 #include "qsggeometry.h"
 #include "qsggeometry_p.h"
 
+#include <qopenglcontext.h>
+#include <qopenglfunctions.h>
+#include <private/qopenglextensions_p.h>
+
 QT_BEGIN_NAMESPACE
 
 
@@ -138,15 +142,17 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
     Q_ASSERT(m_attributes.count > 0);
     Q_ASSERT(m_attributes.stride > 0);
 
+    Q_ASSERT_X(indexType != GL_UNSIGNED_INT
+               || static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions())
+                  ->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint),
+               "QSGGeometry::QSGGeometry",
+               "GL_UNSIGNED_INT is not supported, geometry will not render"
+               );
+
     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." : "");
+        && indexType != GL_UNSIGNED_INT) {
+        qFatal("QSGGeometry: Unsupported index type, %x.\n", indexType);
     }
 
 
@@ -156,7 +162,15 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
 }
 
 /*!
-    \fn int QSGGeometry::sizeOfIndexType() const
+    \fn int QSGGeometry::sizeOfVertex() const
+
+    Returns the size in bytes of one vertex.
+
+    This value comes from the attributes.
+ */
+
+/*!
+    \fn int QSGGeometry::sizeOfIndex() const
 
     Returns the byte size of the index type.
 
index 57d66eb..d7b343c 100644 (file)
@@ -147,7 +147,7 @@ public:
 
     inline int attributeCount() const { return m_attributes.count; }
     inline const Attribute *attributes() const { return m_attributes.attributes; }
-    inline int stride() const { return m_attributes.stride; }
+    inline int sizeOfVertex() const { return m_attributes.stride; }
 
     static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
     static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
@@ -284,9 +284,7 @@ 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;
 }
 
index fac44da..083b073 100644 (file)
@@ -1102,7 +1102,7 @@ QDebug operator<<(QDebug d, const QSGGeometryNode *n)
 
          if (g->attributeCount() > 0 && g->attributes()->type == GL_FLOAT) {
              float x1 = 1e10, x2 = -1e10, y1=1e10, y2=-1e10;
-             int stride = g->stride();
+             int stride = g->sizeOfVertex();
              for (int i = 0; i < g->vertexCount(); ++i) {
                  float x = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[0];
                  float y = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[1];
index 508c8ee..b81df00 100644 (file)
@@ -502,7 +502,7 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
             const QSGGeometry *g = clip->geometry();
             Q_ASSERT(g->attributeCount() > 0);
             const QSGGeometry::Attribute *a = g->attributes();
-            glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, g->stride(), g->vertexData());
+            glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, g->sizeOfVertex(), g->vertexData());
 
             m_clip_program.setUniformValue(m_clip_matrix_id, m);
             if (g->indexCount()) {
@@ -616,7 +616,7 @@ void QSGRenderer::draw(const QSGMaterialShader *shader, const QSGGeometry *g)
     static bool use_vbo = !QGuiApplication::arguments().contains(QLatin1String("--no-vbo"));
 
     const void *vertexData;
-    int vertexByteSize = g->vertexCount() * g->stride();
+    int vertexByteSize = g->vertexCount() * g->sizeOfVertex();
     if (use_vbo && g->vertexDataPattern() != QSGGeometry::AlwaysUploadPattern && vertexByteSize > 1024) {
 
         // The base pointer for a VBO is 0
@@ -661,7 +661,7 @@ void QSGRenderer::draw(const QSGMaterialShader *shader, const QSGGeometry *g)
 #else
         GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
 #endif
-        glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->stride(), (char *) vertexData + offset);
+        glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->sizeOfVertex(), (char *) vertexData + offset);
         offset += a.tupleSize * size_of_type(a.type);
     }
 
@@ -684,7 +684,7 @@ void QSGRenderer::draw(const QSGMaterialShader *shader, const QSGGeometry *g)
 
         if (updateData) {
             glBufferData(GL_ELEMENT_ARRAY_BUFFER,
-                         g->indexCount() * (g->indexType() == GL_UNSIGNED_SHORT ? 2 : 4),
+                         g->indexCount() * g->sizeOfIndex(),
                          g->indexData(),
                          qt_drawTypeForPattern(g->indexDataPattern()));
             QSGGeometryData::clearDirtyIndexData(g);
index 1e56b94..e34a4e0 100644 (file)
@@ -200,7 +200,7 @@ void QSGTextMaskMaterial::populate(const QPointF &p,
     Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT);
     geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
     QVector4D *vp = (QVector4D *)geometry->vertexDataAsTexturedPoint2D();
-    Q_ASSERT(geometry->stride() == sizeof(QVector4D));
+    Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D));
     ushort *ip = geometry->indexDataAsUShort();
 
     QPointF position(p.x(), p.y() - m_font.ascent());
index 4a742ef..b49966b 100644 (file)
@@ -248,13 +248,13 @@ void QSGDefaultRectangleNode::updateGeometry()
     QSGGeometry *fill = geometry();
 
     // Check that the vertex type matches the material.
-    Q_ASSERT(m_material_type != TypeFlat || fill->stride() == sizeof(Vertex));
-    Q_ASSERT(m_material_type != TypeVertexGradient || fill->stride() == sizeof(ColorVertex));
+    Q_ASSERT(m_material_type != TypeFlat || fill->sizeOfVertex() == sizeof(Vertex));
+    Q_ASSERT(m_material_type != TypeVertexGradient || fill->sizeOfVertex() == sizeof(ColorVertex));
 
     QSGGeometry *borderGeometry = 0;
     if (m_border) {
         borderGeometry = border()->geometry();
-        Q_ASSERT(borderGeometry->stride() == sizeof(Vertex));
+        Q_ASSERT(borderGeometry->sizeOfVertex() == sizeof(Vertex));
     }
 
     int fillVertexCount = 0;
index b62104d..2915902 100644 (file)
@@ -63,7 +63,7 @@ void GeometryTest::testPoint2D()
     QSGGeometry geometry(QSGGeometry::defaultAttributes_Point2D(), 4, 0);
 
     QCOMPARE(geometry.attributeCount(), 1);
-    QCOMPARE(geometry.stride(), (int) sizeof(float) * 2);
+    QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 2);
     QCOMPARE(geometry.vertexCount(), 4);
     QCOMPARE(geometry.indexCount(), 0);
     QVERIFY(geometry.indexData() == 0);
@@ -96,7 +96,7 @@ void GeometryTest::testTexturedPoint2D()
     QSGGeometry geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4, 0);
 
     QCOMPARE(geometry.attributeCount(), 2);
-    QCOMPARE(geometry.stride(), (int) sizeof(float) * 4);
+    QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 4);
     QCOMPARE(geometry.vertexCount(), 4);
     QCOMPARE(geometry.indexCount(), 0);
     QVERIFY(geometry.indexData() == 0);