qsggeometry.sip 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // qsggeometry.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtQuick Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. class QSGGeometry /Supertype=PyQt6.sip.wrapper/
  22. {
  23. %TypeHeaderCode
  24. #include <qsggeometry.h>
  25. %End
  26. public:
  27. struct Attribute
  28. {
  29. %TypeHeaderCode
  30. #include <qsggeometry.h>
  31. %End
  32. int position;
  33. int tupleSize;
  34. int type;
  35. uint isVertexCoordinate;
  36. QSGGeometry::AttributeType attributeType;
  37. static QSGGeometry::Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition = false) /Factory/;
  38. static QSGGeometry::Attribute createWithAttributeType(int pos, int tupleSize, int primitiveType, QSGGeometry::AttributeType attributeType) /Factory/;
  39. };
  40. struct AttributeSet /NoDefaultCtors/
  41. {
  42. %TypeHeaderCode
  43. #include <qsggeometry.h>
  44. #include <QList>
  45. %End
  46. AttributeSet(SIP_PYOBJECT attributes /TypeHint="Iterable[QSGGeometry.Attribute]"/, int stride = 0);
  47. %MethodCode
  48. PyObject *iter = PyObject_GetIter(a0);
  49. if (!iter || PyUnicode_Check(a0))
  50. {
  51. Py_XDECREF(iter);
  52. PyErr_SetString(PyExc_TypeError, "iterable object expected");
  53. sipError = sipErrorContinue;
  54. }
  55. else
  56. {
  57. QList<QSGGeometry::Attribute> attrs;
  58. int stride = 0;
  59. for (Py_ssize_t i = 0; ; ++i)
  60. {
  61. PyErr_Clear();
  62. PyObject *itm = PyIter_Next(iter);
  63. if (!itm)
  64. {
  65. if (PyErr_Occurred())
  66. sipError = sipErrorFail;
  67. break;
  68. }
  69. int state, is_err = 0;
  70. QSGGeometry::Attribute *attr;
  71. attr = reinterpret_cast<QSGGeometry::Attribute *>(
  72. sipForceConvertToType(itm, sipType_QSGGeometry_Attribute, 0,
  73. SIP_NOT_NONE, &state, &is_err));
  74. if (is_err)
  75. {
  76. PyErr_Format(PyExc_TypeError,
  77. "index %zd has type '%s' but 'QSGGeometry.Attribute' is expected",
  78. i, sipPyTypeName(Py_TYPE(itm)));
  79. Py_DECREF(itm);
  80. sipError = sipErrorFail;
  81. break;
  82. }
  83. // Calculate the stride if there no explicit one.
  84. if (a1 <= 0)
  85. {
  86. int size;
  87. switch (attr->type)
  88. {
  89. case QSGGeometry::ByteType:
  90. size = sizeof (qint8);
  91. break;
  92. case QSGGeometry::DoubleType:
  93. size = sizeof (double);
  94. break;
  95. case QSGGeometry::FloatType:
  96. size = sizeof (float);
  97. break;
  98. case QSGGeometry::IntType:
  99. size = sizeof (qint32);
  100. break;
  101. default:
  102. size = 0;
  103. }
  104. if (!size)
  105. {
  106. PyErr_Format(PyExc_TypeError,
  107. "index %zd has an unsupported primitive type",
  108. i);
  109. sipReleaseType(attr, sipType_QSGGeometry_Attribute, state);
  110. Py_DECREF(itm);
  111. sipError = sipErrorFail;
  112. break;
  113. }
  114. stride += attr->tupleSize * size;
  115. }
  116. attrs.append(*attr);
  117. sipReleaseType(attr, sipType_QSGGeometry_Attribute, state);
  118. Py_DECREF(itm);
  119. }
  120. Py_DECREF(iter);
  121. if (sipError == sipErrorNone)
  122. {
  123. if (attrs.isEmpty())
  124. {
  125. PyErr_SetString(PyExc_TypeError, "no attributes defined");
  126. sipError = sipErrorFail;
  127. }
  128. else
  129. {
  130. PyObject *bytes = PyBytes_FromStringAndSize(
  131. reinterpret_cast<char *>(attrs.data()),
  132. sizeof (QSGGeometry::Attribute) * attrs.size());
  133. if (!bytes)
  134. {
  135. sipError = sipErrorFail;
  136. }
  137. else
  138. {
  139. sipCpp = new QSGGeometry::AttributeSet;
  140. sipCpp->count = attrs.size();
  141. sipCpp->stride = (a1 > 0 ? a1 : stride);
  142. sipCpp->attributes = reinterpret_cast<QSGGeometry::Attribute *>(
  143. PyBytes_AsString(bytes));
  144. sipSetUserObject(sipSelf, bytes);
  145. }
  146. }
  147. }
  148. }
  149. %End
  150. int count;
  151. int stride;
  152. const QSGGeometry::Attribute *attributes /TypeHint="PyQt6.sip.array[QSGGeometry.Attribute]"/ {
  153. %GetCode
  154. sipPy = sipConvertToTypedArray((void *)sipCpp->attributes,
  155. sipType_QSGGeometry_Attribute, "iiiI", sizeof (QSGGeometry::Attribute),
  156. sipCpp->count, SIP_READ_ONLY);
  157. %End
  158. %SetCode
  159. sipErr = 1;
  160. PyErr_SetString(PyExc_ValueError, "array is read-only");
  161. %End
  162. };
  163. };
  164. struct Point2D
  165. {
  166. %TypeHeaderCode
  167. #include <qsggeometry.h>
  168. %End
  169. float x;
  170. float y;
  171. void set(float nx, float ny);
  172. };
  173. struct TexturedPoint2D
  174. {
  175. %TypeHeaderCode
  176. #include <qsggeometry.h>
  177. %End
  178. float x;
  179. float y;
  180. float tx;
  181. float ty;
  182. void set(float nx, float ny, float ntx, float nty);
  183. };
  184. struct ColoredPoint2D
  185. {
  186. %TypeHeaderCode
  187. #include <qsggeometry.h>
  188. %End
  189. float x;
  190. float y;
  191. unsigned char r /PyInt/;
  192. unsigned char g /PyInt/;
  193. unsigned char b /PyInt/;
  194. unsigned char a /PyInt/;
  195. void set(float nx, float ny, uchar nr /PyInt/, uchar ng /PyInt/, uchar nb /PyInt/, uchar na /PyInt/);
  196. };
  197. static const QSGGeometry::AttributeSet &defaultAttributes_Point2D() /NoCopy/;
  198. static const QSGGeometry::AttributeSet &defaultAttributes_TexturedPoint2D() /NoCopy/;
  199. static const QSGGeometry::AttributeSet &defaultAttributes_ColoredPoint2D() /NoCopy/;
  200. enum DataPattern
  201. {
  202. AlwaysUploadPattern,
  203. StreamPattern,
  204. DynamicPattern,
  205. StaticPattern,
  206. };
  207. QSGGeometry(const QSGGeometry::AttributeSet &attribs /KeepReference/, int vertexCount, int indexCount = 0, int indexType = QSGGeometry::UnsignedShortType);
  208. virtual ~QSGGeometry();
  209. void setDrawingMode(unsigned int mode);
  210. unsigned int drawingMode() const;
  211. void allocate(int vertexCount, int indexCount = 0);
  212. int vertexCount() const;
  213. void *vertexData();
  214. int indexType() const;
  215. int indexCount() const;
  216. void *indexData();
  217. int attributeCount() const;
  218. SIP_PYOBJECT attributes() const /TypeHint="PyQt6.sip.array[QSGGeometry.Attribute]"/;
  219. %MethodCode
  220. sipRes = sipConvertToTypedArray((void *)sipCpp->attributes(),
  221. sipType_QSGGeometry_Attribute, "iiiI", sizeof (QSGGeometry::Attribute),
  222. sipCpp->attributeCount(), SIP_READ_ONLY);
  223. %End
  224. int sizeOfVertex() const;
  225. static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
  226. static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
  227. void setIndexDataPattern(QSGGeometry::DataPattern p);
  228. QSGGeometry::DataPattern indexDataPattern() const;
  229. void setVertexDataPattern(QSGGeometry::DataPattern p);
  230. QSGGeometry::DataPattern vertexDataPattern() const;
  231. void markIndexDataDirty();
  232. void markVertexDataDirty();
  233. float lineWidth() const;
  234. void setLineWidth(float w);
  235. SIP_PYOBJECT indexDataAsUInt() /TypeHint="PyQt6.sip.array[int]"/;
  236. %MethodCode
  237. sipRes = sipConvertToArray(sipCpp->indexDataAsUInt(), "I",
  238. sipCpp->indexCount(), 0);
  239. %End
  240. SIP_PYOBJECT indexDataAsUShort() /TypeHint="PyQt6.sip.array[int]"/;
  241. %MethodCode
  242. sipRes = sipConvertToArray(sipCpp->indexDataAsUShort(), "H",
  243. sipCpp->indexCount(), 0);
  244. %End
  245. SIP_PYOBJECT vertexDataAsPoint2D() /TypeHint="PyQt6.sip.array[QSGGeometry.Point2D]"/;
  246. %MethodCode
  247. sipRes = sipConvertToTypedArray(sipCpp->vertexDataAsPoint2D(),
  248. sipType_QSGGeometry_Point2D, "ff", sizeof (QSGGeometry::Point2D),
  249. sipCpp->vertexCount(), 0);
  250. %End
  251. SIP_PYOBJECT vertexDataAsTexturedPoint2D() /TypeHint="PyQt6.sip.array[QSGGeometry.TexturedPoint2D]"/;
  252. %MethodCode
  253. sipRes = sipConvertToTypedArray(sipCpp->vertexDataAsTexturedPoint2D(),
  254. sipType_QSGGeometry_TexturedPoint2D, "ffff",
  255. sizeof (QSGGeometry::TexturedPoint2D), sipCpp->vertexCount(), 0);
  256. %End
  257. SIP_PYOBJECT vertexDataAsColoredPoint2D() /TypeHint="PyQt6.sip.array[QSGGeometry.ColoredPoint2D]"/;
  258. %MethodCode
  259. sipRes = sipConvertToTypedArray(sipCpp->vertexDataAsColoredPoint2D(),
  260. sipType_QSGGeometry_ColoredPoint2D, "ffbbbb",
  261. sizeof (QSGGeometry::ColoredPoint2D), sipCpp->vertexCount(), 0);
  262. %End
  263. int sizeOfIndex() const;
  264. enum AttributeType
  265. {
  266. UnknownAttribute,
  267. PositionAttribute,
  268. ColorAttribute,
  269. TexCoordAttribute,
  270. TexCoord1Attribute,
  271. TexCoord2Attribute,
  272. };
  273. enum DrawingMode /BaseType=IntEnum/
  274. {
  275. DrawPoints,
  276. DrawLines,
  277. DrawLineLoop,
  278. DrawLineStrip,
  279. DrawTriangles,
  280. DrawTriangleStrip,
  281. DrawTriangleFan,
  282. };
  283. enum Type
  284. {
  285. ByteType,
  286. UnsignedByteType,
  287. ShortType,
  288. UnsignedShortType,
  289. IntType,
  290. UnsignedIntType,
  291. FloatType,
  292. Bytes2Type,
  293. Bytes3Type,
  294. Bytes4Type,
  295. DoubleType,
  296. };
  297. static void updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect);
  298. %If (Qt_6_10_0 -)
  299. void setVertexCount(int count);
  300. %End
  301. %If (Qt_6_10_0 -)
  302. void setIndexCount(int count);
  303. %End
  304. private:
  305. QSGGeometry(const QSGGeometry &);
  306. };