| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/coreapi/qsggeometry.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the Qt scene graph research project. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #ifndef QSGGEOMETRY_H | - | ||||||
| 41 | #define QSGGEOMETRY_H | - | ||||||
| 42 | - | |||||||
| 43 | #include <QtQuick/qtquickglobal.h> | - | ||||||
| 44 | #include <QtGui/qopengl.h> | - | ||||||
| 45 | #include <QtCore/QRectF> | - | ||||||
| 46 | - | |||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||
| 48 | - | |||||||
| 49 | class QSGGeometryData; | - | ||||||
| 50 | - | |||||||
| 51 | class Q_QUICK_EXPORT QSGGeometry | - | ||||||
| 52 | { | - | ||||||
| 53 | public: | - | ||||||
| 54 | enum AttributeType { | - | ||||||
| 55 | UnknownAttribute, | - | ||||||
| 56 | PositionAttribute, | - | ||||||
| 57 | ColorAttribute, | - | ||||||
| 58 | TexCoordAttribute, | - | ||||||
| 59 | TexCoord1Attribute, | - | ||||||
| 60 | TexCoord2Attribute | - | ||||||
| 61 | }; | - | ||||||
| 62 | - | |||||||
| 63 | enum DataPattern { | - | ||||||
| 64 | AlwaysUploadPattern = 0, | - | ||||||
| 65 | StreamPattern = 1, | - | ||||||
| 66 | DynamicPattern = 2, | - | ||||||
| 67 | StaticPattern = 3 | - | ||||||
| 68 | }; | - | ||||||
| 69 | - | |||||||
| 70 | // Equivalents to GL_* drawing modes. | - | ||||||
| 71 | // Keep in sync with GL headers. | - | ||||||
| 72 | enum DrawingMode { | - | ||||||
| 73 | DrawPoints = 0x0000, | - | ||||||
| 74 | DrawLines = 0x0001, | - | ||||||
| 75 | DrawLineLoop = 0x0002, | - | ||||||
| 76 | DrawLineStrip = 0x0003, | - | ||||||
| 77 | DrawTriangles = 0x0004, | - | ||||||
| 78 | DrawTriangleStrip = 0x0005, | - | ||||||
| 79 | DrawTriangleFan = 0x0006 | - | ||||||
| 80 | }; | - | ||||||
| 81 | - | |||||||
| 82 | // Equivalents to GL_BYTE and similar type constants. | - | ||||||
| 83 | // Keep in sync with GL headers. | - | ||||||
| 84 | enum Type { | - | ||||||
| 85 | ByteType = 0x1400, | - | ||||||
| 86 | UnsignedByteType = 0x1401, | - | ||||||
| 87 | ShortType = 0x1402, | - | ||||||
| 88 | UnsignedShortType = 0x1403, | - | ||||||
| 89 | IntType = 0x1404, | - | ||||||
| 90 | UnsignedIntType = 0x1405, | - | ||||||
| 91 | FloatType = 0x1406 | - | ||||||
| 92 | }; | - | ||||||
| 93 | - | |||||||
| 94 | struct Q_QUICK_EXPORT Attribute | - | ||||||
| 95 | { | - | ||||||
| 96 | int position; | - | ||||||
| 97 | int tupleSize; | - | ||||||
| 98 | int type; | - | ||||||
| 99 | - | |||||||
| 100 | uint isVertexCoordinate : 1; | - | ||||||
| 101 | - | |||||||
| 102 | AttributeType attributeType : 4; | - | ||||||
| 103 | - | |||||||
| 104 | uint reserved : 27; | - | ||||||
| 105 | - | |||||||
| 106 | static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition = false); | - | ||||||
| 107 | static Attribute createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType); | - | ||||||
| 108 | }; | - | ||||||
| 109 | - | |||||||
| 110 | struct AttributeSet { | - | ||||||
| 111 | int count; | - | ||||||
| 112 | int stride; | - | ||||||
| 113 | const Attribute *attributes; | - | ||||||
| 114 | }; | - | ||||||
| 115 | - | |||||||
| 116 | struct Point2D { | - | ||||||
| 117 | float x, y; | - | ||||||
| 118 | void set(float nx, float ny) { | - | ||||||
| 119 | x = nx; y = ny; | - | ||||||
| 120 | } executed 140 times by 1 test: end of blockExecuted by:
| 140 | ||||||
| 121 | }; | - | ||||||
| 122 | struct TexturedPoint2D { | - | ||||||
| 123 | float x, y; | - | ||||||
| 124 | float tx, ty; | - | ||||||
| 125 | void set(float nx, float ny, float ntx, float nty) { | - | ||||||
| 126 | x = nx; y = ny; tx = ntx; ty = nty; | - | ||||||
| 127 | } executed 4993244 times by 26 tests: end of blockExecuted by:
| 4993244 | ||||||
| 128 | }; | - | ||||||
| 129 | struct ColoredPoint2D { | - | ||||||
| 130 | float x, y; | - | ||||||
| 131 | unsigned char r, g, b, a; | - | ||||||
| 132 | void set(float nx, float ny, uchar nr, uchar ng, uchar nb, uchar na) { | - | ||||||
| 133 | x = nx; y = ny; | - | ||||||
| 134 | r = nr; g = ng, b = nb; a = na; | - | ||||||
| 135 | } never executed: end of block | 0 | ||||||
| 136 | }; | - | ||||||
| 137 | - | |||||||
| 138 | static const AttributeSet &defaultAttributes_Point2D(); | - | ||||||
| 139 | static const AttributeSet &defaultAttributes_TexturedPoint2D(); | - | ||||||
| 140 | static const AttributeSet &defaultAttributes_ColoredPoint2D(); | - | ||||||
| 141 | - | |||||||
| 142 | QSGGeometry(const QSGGeometry::AttributeSet &attribs, | - | ||||||
| 143 | int vertexCount, | - | ||||||
| 144 | int indexCount = 0, | - | ||||||
| 145 | int indexType = UnsignedShortType); | - | ||||||
| 146 | virtual ~QSGGeometry(); | - | ||||||
| 147 | - | |||||||
| 148 | // must use unsigned int to be compatible with the old GLenum to keep BC | - | ||||||
| 149 | void setDrawingMode(unsigned int mode); | - | ||||||
| 150 | inline unsigned int drawingMode() const { return m_drawing_mode; } executed 14752889 times by 71 tests: return m_drawing_mode;Executed by:
| 14752889 | ||||||
| 151 | - | |||||||
| 152 | void allocate(int vertexCount, int indexCount = 0); | - | ||||||
| 153 | - | |||||||
| 154 | int vertexCount() const { return m_vertex_count; } executed 20091437 times by 72 tests: return m_vertex_count;Executed by:
| 20091437 | ||||||
| 155 | - | |||||||
| 156 | void *vertexData() { return m_data; } executed 3034806 times by 72 tests: return m_data;Executed by:
| 3034806 | ||||||
| 157 | inline Point2D *vertexDataAsPoint2D(); | - | ||||||
| 158 | inline TexturedPoint2D *vertexDataAsTexturedPoint2D(); | - | ||||||
| 159 | inline ColoredPoint2D *vertexDataAsColoredPoint2D(); | - | ||||||
| 160 | - | |||||||
| 161 | inline const void *vertexData() const { return m_data; } executed 16 times by 1 test: return m_data;Executed by:
| 16 | ||||||
| 162 | inline const Point2D *vertexDataAsPoint2D() const; | - | ||||||
| 163 | inline const TexturedPoint2D *vertexDataAsTexturedPoint2D() const; | - | ||||||
| 164 | inline const ColoredPoint2D *vertexDataAsColoredPoint2D() const; | - | ||||||
| 165 | - | |||||||
| 166 | inline int indexType() const { return m_index_type; } executed 324916 times by 71 tests: return m_index_type;Executed by:
| 324916 | ||||||
| 167 | - | |||||||
| 168 | int indexCount() const { return m_index_count; } executed 2884301 times by 72 tests: return m_index_count;Executed by:
| 2884301 | ||||||
| 169 | - | |||||||
| 170 | void *indexData(); | - | ||||||
| 171 | inline uint *indexDataAsUInt(); | - | ||||||
| 172 | inline quint16 *indexDataAsUShort(); | - | ||||||
| 173 | - | |||||||
| 174 | inline int sizeOfIndex() const; | - | ||||||
| 175 | - | |||||||
| 176 | const void *indexData() const; | - | ||||||
| 177 | inline const uint *indexDataAsUInt() const; | - | ||||||
| 178 | inline const quint16 *indexDataAsUShort() const; | - | ||||||
| 179 | - | |||||||
| 180 | inline int attributeCount() const { return m_attributes.count; } executed 534272 times by 72 tests: return m_attributes.count;Executed by:
| 534272 | ||||||
| 181 | inline const Attribute *attributes() const { return m_attributes.attributes; } executed 6866604 times by 71 tests: return m_attributes.attributes;Executed by:
| 6866604 | ||||||
| 182 | inline int sizeOfVertex() const { return m_attributes.stride; } executed 13134025 times by 72 tests: return m_attributes.stride;Executed by:
| 13134025 | ||||||
| 183 | - | |||||||
| 184 | static void updateRectGeometry(QSGGeometry *g, const QRectF &rect); | - | ||||||
| 185 | static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect); | - | ||||||
| 186 | static void updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect); | - | ||||||
| 187 | - | |||||||
| 188 | void setIndexDataPattern(DataPattern p); | - | ||||||
| 189 | DataPattern indexDataPattern() const { return DataPattern(m_index_usage_pattern); } never executed: return DataPattern(m_index_usage_pattern); | 0 | ||||||
| 190 | - | |||||||
| 191 | void setVertexDataPattern(DataPattern p); | - | ||||||
| 192 | DataPattern vertexDataPattern() const { return DataPattern(m_vertex_usage_pattern); } never executed: return DataPattern(m_vertex_usage_pattern); | 0 | ||||||
| 193 | - | |||||||
| 194 | void markIndexDataDirty(); | - | ||||||
| 195 | void markVertexDataDirty(); | - | ||||||
| 196 | - | |||||||
| 197 | float lineWidth() const; | - | ||||||
| 198 | void setLineWidth(float w); | - | ||||||
| 199 | - | |||||||
| 200 | private: | - | ||||||
| 201 | friend class QSGGeometryData; | - | ||||||
| 202 | - | |||||||
| 203 | int m_drawing_mode; | - | ||||||
| 204 | int m_vertex_count; | - | ||||||
| 205 | int m_index_count; | - | ||||||
| 206 | int m_index_type; | - | ||||||
| 207 | const AttributeSet &m_attributes; | - | ||||||
| 208 | void *m_data; | - | ||||||
| 209 | int m_index_data_offset; | - | ||||||
| 210 | - | |||||||
| 211 | QSGGeometryData *m_server_data; | - | ||||||
| 212 | - | |||||||
| 213 | uint m_owns_data : 1; | - | ||||||
| 214 | uint m_index_usage_pattern : 2; | - | ||||||
| 215 | uint m_vertex_usage_pattern : 2; | - | ||||||
| 216 | uint m_dirty_index_data : 1; | - | ||||||
| 217 | uint m_dirty_vertex_data : 1; | - | ||||||
| 218 | uint m_reserved_bits : 25; | - | ||||||
| 219 | - | |||||||
| 220 | float m_prealloc[16]; | - | ||||||
| 221 | - | |||||||
| 222 | float m_line_width; | - | ||||||
| 223 | }; | - | ||||||
| 224 | - | |||||||
| 225 | inline uint *QSGGeometry::indexDataAsUInt() | - | ||||||
| 226 | { | - | ||||||
| 227 | Q_ASSERT(m_index_type == UnsignedIntType); | - | ||||||
| 228 | return static_cast<uint *>(indexData()); never executed: return static_cast<uint *>(indexData()); | 0 | ||||||
| 229 | } | - | ||||||
| 230 | - | |||||||
| 231 | inline quint16 *QSGGeometry::indexDataAsUShort() | - | ||||||
| 232 | { | - | ||||||
| 233 | Q_ASSERT(m_index_type == UnsignedShortType); | - | ||||||
| 234 | return static_cast<quint16 *>(indexData()); executed 1104054 times by 69 tests: return static_cast<quint16 *>(indexData());Executed by:
| 1104054 | ||||||
| 235 | } | - | ||||||
| 236 | - | |||||||
| 237 | inline const uint *QSGGeometry::indexDataAsUInt() const | - | ||||||
| 238 | { | - | ||||||
| 239 | Q_ASSERT(m_index_type == UnsignedIntType); | - | ||||||
| 240 | return static_cast<const uint *>(indexData()); never executed: return static_cast<const uint *>(indexData()); | 0 | ||||||
| 241 | } | - | ||||||
| 242 | - | |||||||
| 243 | inline const quint16 *QSGGeometry::indexDataAsUShort() const | - | ||||||
| 244 | { | - | ||||||
| 245 | Q_ASSERT(m_index_type == UnsignedShortType); | - | ||||||
| 246 | return static_cast<const quint16 *>(indexData()); never executed: return static_cast<const quint16 *>(indexData()); | 0 | ||||||
| 247 | } | - | ||||||
| 248 | - | |||||||
| 249 | inline QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() | - | ||||||
| 250 | { | - | ||||||
| 251 | Q_ASSERT(m_attributes.count == 1); | - | ||||||
| 252 | Q_ASSERT(m_attributes.stride == 2 * sizeof(float)); | - | ||||||
| 253 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 254 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 255 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 256 | return static_cast<Point2D *>(m_data); executed 400650 times by 14 tests: return static_cast<Point2D *>(m_data);Executed by:
| 400650 | ||||||
| 257 | } | - | ||||||
| 258 | - | |||||||
| 259 | inline QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() | - | ||||||
| 260 | { | - | ||||||
| 261 | Q_ASSERT(m_attributes.count == 2); | - | ||||||
| 262 | Q_ASSERT(m_attributes.stride == 4 * sizeof(float)); | - | ||||||
| 263 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 264 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 265 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 266 | Q_ASSERT(m_attributes.attributes[1].position == 1); | - | ||||||
| 267 | Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); | - | ||||||
| 268 | Q_ASSERT(m_attributes.attributes[1].type == FloatType); | - | ||||||
| 269 | return static_cast<TexturedPoint2D *>(m_data); executed 246356 times by 36 tests: return static_cast<TexturedPoint2D *>(m_data);Executed by:
| 246356 | ||||||
| 270 | } | - | ||||||
| 271 | - | |||||||
| 272 | inline QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() | - | ||||||
| 273 | { | - | ||||||
| 274 | Q_ASSERT(m_attributes.count == 2); | - | ||||||
| 275 | Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char)); | - | ||||||
| 276 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 277 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 278 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 279 | Q_ASSERT(m_attributes.attributes[1].position == 1); | - | ||||||
| 280 | Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); | - | ||||||
| 281 | Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType); | - | ||||||
| 282 | return static_cast<ColoredPoint2D *>(m_data); never executed: return static_cast<ColoredPoint2D *>(m_data); | 0 | ||||||
| 283 | } | - | ||||||
| 284 | - | |||||||
| 285 | inline const QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() const | - | ||||||
| 286 | { | - | ||||||
| 287 | Q_ASSERT(m_attributes.count == 1); | - | ||||||
| 288 | Q_ASSERT(m_attributes.stride == 2 * sizeof(float)); | - | ||||||
| 289 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 290 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 291 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 292 | return static_cast<const Point2D *>(m_data); executed 98 times by 1 test: return static_cast<const Point2D *>(m_data);Executed by:
| 98 | ||||||
| 293 | } | - | ||||||
| 294 | - | |||||||
| 295 | inline const QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() const | - | ||||||
| 296 | { | - | ||||||
| 297 | Q_ASSERT(m_attributes.count == 2); | - | ||||||
| 298 | Q_ASSERT(m_attributes.stride == 4 * sizeof(float)); | - | ||||||
| 299 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 300 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 301 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 302 | Q_ASSERT(m_attributes.attributes[1].position == 1); | - | ||||||
| 303 | Q_ASSERT(m_attributes.attributes[1].tupleSize == 2); | - | ||||||
| 304 | Q_ASSERT(m_attributes.attributes[1].type == FloatType); | - | ||||||
| 305 | return static_cast<const TexturedPoint2D *>(m_data); never executed: return static_cast<const TexturedPoint2D *>(m_data); | 0 | ||||||
| 306 | } | - | ||||||
| 307 | - | |||||||
| 308 | inline const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() const | - | ||||||
| 309 | { | - | ||||||
| 310 | Q_ASSERT(m_attributes.count == 2); | - | ||||||
| 311 | Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char)); | - | ||||||
| 312 | Q_ASSERT(m_attributes.attributes[0].position == 0); | - | ||||||
| 313 | Q_ASSERT(m_attributes.attributes[0].tupleSize == 2); | - | ||||||
| 314 | Q_ASSERT(m_attributes.attributes[0].type == FloatType); | - | ||||||
| 315 | Q_ASSERT(m_attributes.attributes[1].position == 1); | - | ||||||
| 316 | Q_ASSERT(m_attributes.attributes[1].tupleSize == 4); | - | ||||||
| 317 | Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType); | - | ||||||
| 318 | return static_cast<const ColoredPoint2D *>(m_data); never executed: return static_cast<const ColoredPoint2D *>(m_data); | 0 | ||||||
| 319 | } | - | ||||||
| 320 | - | |||||||
| 321 | int QSGGeometry::sizeOfIndex() const | - | ||||||
| 322 | { | - | ||||||
| 323 | if (m_index_type == UnsignedShortType) return 2; executed 14504 times by 29 tests: return 2;Executed by:
| 120-14504 | ||||||
| 324 | else if (m_index_type == UnsignedByteType) return 1; never executed: return 1;
| 0-120 | ||||||
| 325 | else if (m_index_type == UnsignedIntType) return 4; executed 120 times by 1 test: return 4;Executed by:
| 0-120 | ||||||
| 326 | return 0; never executed: return 0; | 0 | ||||||
| 327 | } | - | ||||||
| 328 | - | |||||||
| 329 | QT_END_NAMESPACE | - | ||||||
| 330 | - | |||||||
| 331 | #endif // QSGGEOMETRY_H | - | ||||||
| Source code | Switch to Preprocessed file |