From 6df6c10e1af827d06a387e7422176dd310cf83be Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 7 Oct 2016 09:57:01 +0200 Subject: Fix enums in QSGGeometry Minor fixes based on comments from the 5.8 API changes review: Revert to using Qt-style enum values (POSITION -> PositionAttribute). Use ByteType, FloatType, etc. instead of TypeByte, TypeFloat, ... Add comments about magic GL values. Add missing docs for Attribute::createWithAttributeType(). Change-Id: I1b8242efd3936f000ce8df6c11ff9ab7affb5713 Reviewed-by: Gunnar Sletta Reviewed-by: Shawn Rutledge --- src/quick/scenegraph/coreapi/qsggeometry.cpp | 73 ++++++++++------- src/quick/scenegraph/coreapi/qsggeometry.h | 117 ++++++++++++++------------- src/quick/scenegraph/coreapi/qsgnode.cpp | 2 +- 3 files changed, 106 insertions(+), 86 deletions(-) (limited to 'src/quick/scenegraph/coreapi') diff --git a/src/quick/scenegraph/coreapi/qsggeometry.cpp b/src/quick/scenegraph/coreapi/qsggeometry.cpp index 239557d527..b43a2bc2ba 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.cpp +++ b/src/quick/scenegraph/coreapi/qsggeometry.cpp @@ -54,18 +54,18 @@ QT_BEGIN_NAMESPACE QSGGeometry::Attribute QSGGeometry::Attribute::create(int attributeIndex, int tupleSize, int primitiveType, bool isPrimitive) { - Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, UNKNOWN, 0 }; + Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, UnknownAttribute, 0 }; return a; } -QSGGeometry::Attribute QSGGeometry::Attribute::createWithSemantic(int pos, int tupleSize, int type, Semantic semantic) +QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType) { Attribute a; a.position = pos; a.tupleSize = tupleSize; - a.type = type; - a.isVertexCoordinate = semantic == POSITION; - a.semantic = semantic; + a.type = primitiveType; + a.isVertexCoordinate = attributeType == PositionAttribute; + a.attributeType = attributeType; a.reserved = 0; return a; } @@ -78,7 +78,7 @@ QSGGeometry::Attribute QSGGeometry::Attribute::createWithSemantic(int pos, int t const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D() { static Attribute data[] = { - Attribute::createWithSemantic(0, 2, TypeFloat, Attribute::POSITION) + Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute) }; static AttributeSet attrs = { 1, sizeof(float) * 2, data }; return attrs; @@ -91,8 +91,8 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D() const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D() { static Attribute data[] = { - Attribute::createWithSemantic(0, 2, TypeFloat, Attribute::POSITION), - Attribute::createWithSemantic(1, 2, TypeFloat, Attribute::TEXCOORD) + Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute), + Attribute::createWithAttributeType(1, 2, FloatType, TexCoordAttribute) }; static AttributeSet attrs = { 2, sizeof(float) * 4, data }; return attrs; @@ -105,8 +105,8 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D( const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D() { static Attribute data[] = { - Attribute::createWithSemantic(0, 2, TypeFloat, Attribute::POSITION), - Attribute::createWithSemantic(1, 4, TypeUnsignedByte, Attribute::COLOR) + Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute), + Attribute::createWithAttributeType(1, 4, UnsignedByteType, ColorAttribute) }; static AttributeSet attrs = { 2, 2 * sizeof(float) + 4 * sizeof(char), data }; return attrs; @@ -134,12 +134,31 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D() \fn QSGGeometry::Attribute QSGGeometry::Attribute::create(int pos, int tupleSize, int primitiveType, bool isPosition) Creates a new QSGGeometry::Attribute for attribute register \a pos with \a - tupleSize. The \a primitiveType can be any of the supported OpenGL types, - such as \c GL_FLOAT or \c GL_UNSIGNED_BYTE. + tupleSize. The \a primitiveType can be any of the supported types from + QSGGeometry::Type, such as QSGGeometry::FloatType or + QSGGeometry::UnsignedByteType. - If the attribute describes the position for the vertex, the \a isPosition hint - should be set to \c true. The scene graph renderer may use this information - to perform optimizations. + If the attribute describes the position for the vertex, the \a isPosition + hint should be set to \c true. The scene graph renderer may use this + information to perform optimizations. + + \note Scene graph backends for APIs other than OpenGL may require an + accurate description of attributes' usage, and therefore it is recommended + to use createWithAttributeType() instead. + + Use the create function to construct the attribute, rather than an + initialization list, to ensure that all fields are initialized. + */ + +/*! + \fn QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType) + + Creates a new QSGGeometry::Attribute for attribute register \a pos with \a + tupleSize. The \a primitiveType can be any of the supported types from + QSGGeometry::Type, such as QSGGeometry::FloatType or + QSGGeometry::UnsignedByteType. + + \a attributeType describes the intended use of the attribute. Use the create function to construct the attribute, rather than an initialization list, to ensure that all fields are initialized. @@ -430,9 +449,9 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes, "GL_UNSIGNED_INT is not supported, geometry will not render" ); #endif - if (indexType != TypeUnsignedByte - && indexType != TypeUnsignedShort - && indexType != TypeUnsignedInt) { + if (indexType != UnsignedByteType + && indexType != UnsignedShortType + && indexType != UnsignedIntType) { qFatal("QSGGeometry: Unsupported index type, %x.\n", indexType); } @@ -549,13 +568,13 @@ const void *QSGGeometry::indexData() const GL_UNSIGNED_BYTE, etc. QSGGeometry provies its own type in order to be able to provide the same API with non-OpenGL backends as well. - \value TypeByte - \value TypeUnsignedByte - \value TypeShort - \value TypeUnsignedShort - \value TypeInt - \value TypeUnsignedInt - \value TypeFloat + \value ByteType + \value UnsignedByteType + \value ShortType + \value UnsignedShortType + \value IntType + \value UnsignedIntType + \value FloatType */ /*! @@ -653,8 +672,8 @@ void QSGGeometry::allocate(int vertexCount, int indexCount) m_index_data_offset = -1; m_owns_data = false; } else { - Q_ASSERT(m_index_type == TypeUnsignedInt || m_index_type == TypeUnsignedShort); - int indexByteSize = indexCount * (m_index_type == TypeUnsignedShort ? sizeof(quint16) : sizeof(quint32)); + Q_ASSERT(m_index_type == UnsignedIntType || m_index_type == UnsignedShortType); + int indexByteSize = indexCount * (m_index_type == UnsignedShortType ? sizeof(quint16) : sizeof(quint32)); m_data = (void *) malloc(vertexByteSize + indexByteSize); m_index_data_offset = vertexByteSize; m_owns_data = true; diff --git a/src/quick/scenegraph/coreapi/qsggeometry.h b/src/quick/scenegraph/coreapi/qsggeometry.h index ae7b2f494c..7a916610e3 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.h +++ b/src/quick/scenegraph/coreapi/qsggeometry.h @@ -51,30 +51,60 @@ class QSGGeometryData; class Q_QUICK_EXPORT QSGGeometry { public: + enum AttributeType { + UnknownAttribute, + PositionAttribute, + ColorAttribute, + TexCoordAttribute, + TexCoord1Attribute, + TexCoord2Attribute + }; + + enum DataPattern { + AlwaysUploadPattern = 0, + StreamPattern = 1, + DynamicPattern = 2, + StaticPattern = 3 + }; + + // Equivalents to GL_* drawing modes. + // Keep in sync with GL headers. + enum DrawingMode { + DrawPoints = 0x0000, + DrawLines = 0x0001, + DrawLineLoop = 0x0002, + DrawLineStrip = 0x0003, + DrawTriangles = 0x0004, + DrawTriangleStrip = 0x0005, + DrawTriangleFan = 0x0006 + }; + + // Equivalents to GL_BYTE and similar type constants. + // Keep in sync with GL headers. + enum Type { + ByteType = 0x1400, + UnsignedByteType = 0x1401, + ShortType = 0x1402, + UnsignedShortType = 0x1403, + IntType = 0x1404, + UnsignedIntType = 0x1405, + FloatType = 0x1406 + }; struct Q_QUICK_EXPORT Attribute { - enum Semantic { - UNKNOWN, - POSITION, - COLOR, - TEXCOORD, - TEXCOORD1, - TEXCOORD2 - }; - int position; int tupleSize; int type; uint isVertexCoordinate : 1; - Semantic semantic : 4; + AttributeType attributeType : 4; uint reserved : 27; static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition = false); - static Attribute createWithSemantic(int pos, int tupleSize, int type, Semantic semantic); + static Attribute createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType); }; struct AttributeSet { @@ -109,39 +139,10 @@ public: static const AttributeSet &defaultAttributes_TexturedPoint2D(); static const AttributeSet &defaultAttributes_ColoredPoint2D(); - enum DataPattern { - AlwaysUploadPattern = 0, - StreamPattern = 1, - DynamicPattern = 2, - StaticPattern = 3 - }; - - // Equivalents to GL_* drawing modes. - enum DrawingMode { - DrawPoints = 0x0000, - DrawLines = 0x0001, - DrawLineLoop = 0x0002, - DrawLineStrip = 0x0003, - DrawTriangles = 0x0004, - DrawTriangleStrip = 0x0005, - DrawTriangleFan = 0x0006 - }; - - // Equivalents to GL_BYTE and similar type constants. - enum Type { - TypeByte = 0x1400, - TypeUnsignedByte = 0x1401, - TypeShort = 0x1402, - TypeUnsignedShort = 0x1403, - TypeInt = 0x1404, - TypeUnsignedInt = 0x1405, - TypeFloat = 0x1406 - }; - QSGGeometry(const QSGGeometry::AttributeSet &attribs, int vertexCount, int indexCount = 0, - int indexType = TypeUnsignedShort); + int indexType = UnsignedShortType); virtual ~QSGGeometry(); // must use unsigned int to be compatible with the old GLenum to keep BC @@ -223,25 +224,25 @@ private: inline uint *QSGGeometry::indexDataAsUInt() { - Q_ASSERT(m_index_type == TypeUnsignedInt); + Q_ASSERT(m_index_type == UnsignedIntType); return static_cast(indexData()); } inline quint16 *QSGGeometry::indexDataAsUShort() { - Q_ASSERT(m_index_type == TypeUnsignedShort); + Q_ASSERT(m_index_type == UnsignedShortType); return static_cast(indexData()); } inline const uint *QSGGeometry::indexDataAsUInt() const { - Q_ASSERT(m_index_type == TypeUnsignedInt); + Q_ASSERT(m_index_type == UnsignedIntType); return static_cast(indexData()); } inline const quint16 *QSGGeometry::indexDataAsUShort() const { - Q_ASSERT(m_index_type == TypeUnsignedShort); + Q_ASSERT(m_index_type == UnsignedShortType); return static_cast(indexData()); } @@ -250,7 +251,7 @@ inline QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() Q_ASSERT(m_attributes.count == 1); Q_ASSERT(m_attributes.stride == 2 * sizeof(float)); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[0].position == 0); return static_cast(m_data); } @@ -261,10 +262,10 @@ inline QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() Q_ASSERT(m_attributes.stride == 4 * sizeof(float)); Q_ASSERT(m_attributes.attributes[0].position == 0); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[1].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[1].type == FloatType); return static_cast(m_data); } @@ -274,10 +275,10 @@ inline QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char)); Q_ASSERT(m_attributes.attributes[0].position == 0); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); - Q_ASSERT(m_attributes.attributes[1].type == TypeUnsignedByte); + Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType); return static_cast(m_data); } @@ -286,7 +287,7 @@ inline const QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() const Q_ASSERT(m_attributes.count == 1); Q_ASSERT(m_attributes.stride == 2 * sizeof(float)); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[0].position == 0); return static_cast(m_data); } @@ -297,10 +298,10 @@ inline const QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoin Q_ASSERT(m_attributes.stride == 4 * sizeof(float)); Q_ASSERT(m_attributes.attributes[0].position == 0); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[1].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[1].type == FloatType); return static_cast(m_data); } @@ -310,18 +311,18 @@ inline const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2 Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char)); Q_ASSERT(m_attributes.attributes[0].position == 0); Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); + Q_ASSERT(m_attributes.attributes[0].type == FloatType); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); - Q_ASSERT(m_attributes.attributes[1].type == TypeUnsignedByte); + Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType); return static_cast(m_data); } int QSGGeometry::sizeOfIndex() const { - if (m_index_type == TypeUnsignedShort) return 2; - else if (m_index_type == TypeUnsignedByte) return 1; - else if (m_index_type == TypeUnsignedInt) return 4; + if (m_index_type == UnsignedShortType) return 2; + else if (m_index_type == UnsignedByteType) return 1; + else if (m_index_type == UnsignedIntType) return 4; return 0; } diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp index 2211f88973..a1e1ef8c27 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.cpp +++ b/src/quick/scenegraph/coreapi/qsgnode.cpp @@ -1490,7 +1490,7 @@ QDebug operator<<(QDebug d, const QSGGeometryNode *n) d << "#V:" << g->vertexCount() << "#I:" << g->indexCount(); - if (g->attributeCount() > 0 && g->attributes()->type == QSGGeometry::TypeFloat) { + if (g->attributeCount() > 0 && g->attributes()->type == QSGGeometry::FloatType) { float x1 = 1e10, x2 = -1e10, y1=1e10, y2=-1e10; int stride = g->sizeOfVertex(); for (int i = 0; i < g->vertexCount(); ++i) { -- cgit v1.2.3