From c2b488fa7a9cc10bfa6342bd415aaf58fe857c9a Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 8 Sep 2011 15:15:57 +0200 Subject: [PATCH] rename QSGGeometry::stride() to sizeOfVertex for symetry with index MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Samuel Rødal --- src/declarative/scenegraph/coreapi/qsggeometry.cpp | 30 ++++++++++++++++------ src/declarative/scenegraph/coreapi/qsggeometry.h | 4 +-- src/declarative/scenegraph/coreapi/qsgnode.cpp | 2 +- src/declarative/scenegraph/coreapi/qsgrenderer.cpp | 8 +++--- .../scenegraph/qsgdefaultglyphnode_p.cpp | 2 +- .../scenegraph/qsgdefaultrectanglenode.cpp | 6 ++--- tests/auto/declarative/geometry/tst_geometry.cpp | 4 +-- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/declarative/scenegraph/coreapi/qsggeometry.cpp b/src/declarative/scenegraph/coreapi/qsggeometry.cpp index 0b17501..8661c9a 100644 --- a/src/declarative/scenegraph/coreapi/qsggeometry.cpp +++ b/src/declarative/scenegraph/coreapi/qsggeometry.cpp @@ -42,6 +42,10 @@ #include "qsggeometry.h" #include "qsggeometry_p.h" +#include +#include +#include + 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(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. diff --git a/src/declarative/scenegraph/coreapi/qsggeometry.h b/src/declarative/scenegraph/coreapi/qsggeometry.h index 57d66eb..d7b343c 100644 --- a/src/declarative/scenegraph/coreapi/qsggeometry.h +++ b/src/declarative/scenegraph/coreapi/qsggeometry.h @@ -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; } diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp index fac44da..083b073 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.cpp +++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp @@ -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(g)->vertexData() + i * stride))[0]; float y = ((float *)((char *)const_cast(g)->vertexData() + i * stride))[1]; diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp index 508c8ee..b81df00 100644 --- a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp @@ -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); diff --git a/src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp b/src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp index 1e56b94..e34a4e0 100644 --- a/src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp @@ -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()); diff --git a/src/declarative/scenegraph/qsgdefaultrectanglenode.cpp b/src/declarative/scenegraph/qsgdefaultrectanglenode.cpp index 4a742ef..b49966b 100644 --- a/src/declarative/scenegraph/qsgdefaultrectanglenode.cpp +++ b/src/declarative/scenegraph/qsgdefaultrectanglenode.cpp @@ -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; diff --git a/tests/auto/declarative/geometry/tst_geometry.cpp b/tests/auto/declarative/geometry/tst_geometry.cpp index b62104d..2915902 100644 --- a/tests/auto/declarative/geometry/tst_geometry.cpp +++ b/tests/auto/declarative/geometry/tst_geometry.cpp @@ -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); -- 2.7.4