Qt 4.8
qsggeometry.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QML Shaders plugin of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSGGEOMETRY_H
43 #define QSGGEOMETRY_H
44 
45 #include <QtOpenGL/qgl.h>
46 
48 
50 
52 {
53 public:
54  struct Attribute
55  {
56  int position;
57  int tupleSize;
58  int type;
59  };
60 
61  struct AttributeSet {
62  int count;
63  int stride;
65  };
66 
67  struct Point2D { float x, y; };
68  struct TexturedPoint2D { float x, y; float tx, ty; };
69  struct ColoredPoint2D { float x, y; unsigned char r, g, b, a; };
70 
74 
76  int vertexCount,
77  int indexCount = 0,
79  ~QSGGeometry();
80 
81  void setDrawingMode(GLenum mode);
82  inline GLenum drawingMode() const { return m_drawing_mode; }
83 
84  void allocate(int vertexCount, int indexCount = 0);
85 
86  int vertexCount() const { return m_vertex_count; }
87 
88  void *vertexData() { return m_data; }
89  inline Point2D *vertexDataAsPoint2D();
92 
93  inline const void *vertexData() const { return m_data; }
94  inline const Point2D *vertexDataAsPoint2D() const;
95  inline const TexturedPoint2D *vertexDataAsTexturedPoint2D() const;
96  inline const ColoredPoint2D *vertexDataAsColoredPoint2D() const;
97 
98  inline int indexType() const { return m_index_type; }
99 
100  int indexCount() const { return m_index_count; }
101 
102  void *indexData();
103  inline uint *indexDataAsUInt();
104  inline quint16 *indexDataAsUShort();
105 
106  const void *indexData() const;
107  inline const uint *indexDataAsUInt() const;
108  inline const quint16 *indexDataAsUShort() const;
109 
110  inline int attributeCount() const { return m_attributes.count; }
111  inline const Attribute *attributes() const { return m_attributes.attributes; }
112  inline int stride() const { return m_attributes.stride; }
113 
114  static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
115  static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
116 
117 private:
123  void *m_data;
125 
127 
130 
131  float m_prealloc[16];
132 };
133 
135 {
137  return (uint *) indexData();
138 }
139 
141 {
143  return (quint16 *) indexData();
144 }
145 
146 inline const uint *QSGGeometry::indexDataAsUInt() const
147 {
149  return (uint *) indexData();
150 }
151 
153 {
155  return (quint16 *) indexData();
156 }
157 
159 {
161  Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
165  return (Point2D *) m_data;
166 }
167 
169 {
171  Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
178  return (TexturedPoint2D *) m_data;
179 }
180 
182 {
184  Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
191  return (ColoredPoint2D *) m_data;
192 }
193 
195 {
197  Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
201  return (const Point2D *) m_data;
202 }
203 
205 {
207  Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
214  return (const TexturedPoint2D *) m_data;
215 }
216 
218 {
220  Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
227  return (const ColoredPoint2D *) m_data;
228 }
229 
231 
233 
234 #endif // QSGGEOMETRY_H
GLenum drawingMode() const
Definition: qsggeometry.h:82
void * vertexData()
Definition: qsggeometry.h:88
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Definition: qsggeometry.h:168
#define GL_UNSIGNED_INT
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const AttributeSet & defaultAttributes_TexturedPoint2D()
Definition: qsggeometry.cpp:57
int indexType() const
Definition: qsggeometry.h:98
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
int m_drawing_mode
Definition: qsggeometry.h:118
static const AttributeSet & defaultAttributes_Point2D()
Definition: qsggeometry.cpp:47
void * indexData()
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
void * m_reserved_pointer
Definition: qsggeometry.h:126
long ASN1_INTEGER_get ASN1_INTEGER * a
QSGGeometry(const QSGGeometry::AttributeSet &attribs, int vertexCount, int indexCount=0, int indexType=GL_UNSIGNED_SHORT)
Definition: qsggeometry.cpp:80
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int stride() const
Definition: qsggeometry.h:112
int m_vertex_count
Definition: qsggeometry.h:119
uint m_owns_data
Definition: qsggeometry.h:128
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static const AttributeSet & defaultAttributes_ColoredPoint2D()
Definition: qsggeometry.cpp:68
ColoredPoint2D * vertexDataAsColoredPoint2D()
Definition: qsggeometry.h:181
float m_prealloc[16]
Definition: qsggeometry.h:131
void * m_data
Definition: qsggeometry.h:123
#define GL_UNSIGNED_SHORT
unsigned short quint16
Definition: qglobal.h:936
unsigned int uint
Definition: qglobal.h:996
#define GL_FLOAT
uint m_reserved_bits
Definition: qsggeometry.h:129
static void updateRectGeometry(QSGGeometry *g, const QRectF &rect)
void setDrawingMode(GLenum mode)
quint16 * indexDataAsUShort()
Definition: qsggeometry.h:140
unsigned int GLenum
Definition: main.cpp:50
Point2D * vertexDataAsPoint2D()
Definition: qsggeometry.h:158
#define GL_UNSIGNED_BYTE
int m_index_count
Definition: qsggeometry.h:120
const Attribute * attributes
Definition: qsggeometry.h:64
int m_index_data_offset
Definition: qsggeometry.h:124
const void * vertexData() const
Definition: qsggeometry.h:93
const Attribute * attributes() const
Definition: qsggeometry.h:111
int indexCount() const
Definition: qsggeometry.h:100
#define QT_END_HEADER
Definition: qglobal.h:137
void allocate(int vertexCount, int indexCount=0)
uint * indexDataAsUInt()
Definition: qsggeometry.h:134
int attributeCount() const
Definition: qsggeometry.h:110
int vertexCount() const
Definition: qsggeometry.h:86
int m_index_type
Definition: qsggeometry.h:121