diff options
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsggeometry.h')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsggeometry.h | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/src/quick/scenegraph/coreapi/qsggeometry.h b/src/quick/scenegraph/coreapi/qsggeometry.h index 5773b6abd1..ae7b2f494c 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.h +++ b/src/quick/scenegraph/coreapi/qsggeometry.h @@ -54,15 +54,27 @@ public: struct Q_QUICK_EXPORT Attribute { + enum Semantic { + UNKNOWN, + POSITION, + COLOR, + TEXCOORD, + TEXCOORD1, + TEXCOORD2 + }; + int position; int tupleSize; int type; uint isVertexCoordinate : 1; - uint reserved : 31; + Semantic semantic : 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); }; struct AttributeSet { @@ -104,14 +116,37 @@ public: 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 = GL_UNSIGNED_SHORT); + int indexType = TypeUnsignedShort); virtual ~QSGGeometry(); - void setDrawingMode(GLenum mode); - inline GLenum drawingMode() const { return m_drawing_mode; } + // must use unsigned int to be compatible with the old GLenum to keep BC + void setDrawingMode(unsigned int mode); + inline unsigned int drawingMode() const { return m_drawing_mode; } void allocate(int vertexCount, int indexCount = 0); @@ -147,6 +182,7 @@ public: static void updateRectGeometry(QSGGeometry *g, const QRectF &rect); static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect); + static void updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect); void setIndexDataPattern(DataPattern p); DataPattern indexDataPattern() const { return DataPattern(m_index_usage_pattern); } @@ -187,25 +223,25 @@ private: inline uint *QSGGeometry::indexDataAsUInt() { - Q_ASSERT(m_index_type == GL_UNSIGNED_INT); + Q_ASSERT(m_index_type == TypeUnsignedInt); return static_cast<uint *>(indexData()); } inline quint16 *QSGGeometry::indexDataAsUShort() { - Q_ASSERT(m_index_type == GL_UNSIGNED_SHORT); + Q_ASSERT(m_index_type == TypeUnsignedShort); return static_cast<quint16 *>(indexData()); } inline const uint *QSGGeometry::indexDataAsUInt() const { - Q_ASSERT(m_index_type == GL_UNSIGNED_INT); + Q_ASSERT(m_index_type == TypeUnsignedInt); return static_cast<const uint *>(indexData()); } inline const quint16 *QSGGeometry::indexDataAsUShort() const { - Q_ASSERT(m_index_type == GL_UNSIGNED_SHORT); + Q_ASSERT(m_index_type == TypeUnsignedShort); return static_cast<const quint16 *>(indexData()); } @@ -214,7 +250,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[0].position == 0); return static_cast<Point2D *>(m_data); } @@ -225,10 +261,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[1].type == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[1].type == TypeFloat); return static_cast<TexturedPoint2D *>(m_data); } @@ -238,10 +274,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); - Q_ASSERT(m_attributes.attributes[1].type == GL_UNSIGNED_BYTE); + Q_ASSERT(m_attributes.attributes[1].type == TypeUnsignedByte); return static_cast<ColoredPoint2D *>(m_data); } @@ -250,7 +286,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[0].position == 0); return static_cast<const Point2D *>(m_data); } @@ -261,10 +297,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); - Q_ASSERT(m_attributes.attributes[1].type == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[1].type == TypeFloat); return static_cast<const TexturedPoint2D *>(m_data); } @@ -274,18 +310,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 == GL_FLOAT); + Q_ASSERT(m_attributes.attributes[0].type == TypeFloat); Q_ASSERT(m_attributes.attributes[1].position == 1); Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); - Q_ASSERT(m_attributes.attributes[1].type == GL_UNSIGNED_BYTE); + Q_ASSERT(m_attributes.attributes[1].type == TypeUnsignedByte); return static_cast<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; - else if (m_index_type == GL_UNSIGNED_INT) return 4; + if (m_index_type == TypeUnsignedShort) return 2; + else if (m_index_type == TypeUnsignedByte) return 1; + else if (m_index_type == TypeUnsignedInt) return 4; return 0; } |