Qt 4.8
Classes | Public Functions | Static Public Functions | Properties | List of all members
QSGGeometry Class Reference

#include <qsggeometry.h>

Classes

struct  Attribute
 
struct  AttributeSet
 
struct  ColoredPoint2D
 
struct  Point2D
 
struct  TexturedPoint2D
 

Public Functions

void allocate (int vertexCount, int indexCount=0)
 
int attributeCount () const
 
const Attributeattributes () const
 
GLenum drawingMode () const
 
int indexCount () const
 
void * indexData ()
 
const void * indexData () const
 
uintindexDataAsUInt ()
 
const uintindexDataAsUInt () const
 
quint16indexDataAsUShort ()
 
const quint16indexDataAsUShort () const
 
int indexType () const
 
 QSGGeometry (const QSGGeometry::AttributeSet &attribs, int vertexCount, int indexCount=0, int indexType=GL_UNSIGNED_SHORT)
 
void setDrawingMode (GLenum mode)
 
int stride () const
 
int vertexCount () const
 
void * vertexData ()
 
const void * vertexData () const
 
ColoredPoint2DvertexDataAsColoredPoint2D ()
 
const ColoredPoint2DvertexDataAsColoredPoint2D () const
 
Point2DvertexDataAsPoint2D ()
 
const Point2DvertexDataAsPoint2D () const
 
TexturedPoint2DvertexDataAsTexturedPoint2D ()
 
const TexturedPoint2DvertexDataAsTexturedPoint2D () const
 
 ~QSGGeometry ()
 

Static Public Functions

static const AttributeSetdefaultAttributes_ColoredPoint2D ()
 
static const AttributeSetdefaultAttributes_Point2D ()
 
static const AttributeSetdefaultAttributes_TexturedPoint2D ()
 
static void updateRectGeometry (QSGGeometry *g, const QRectF &rect)
 
static void updateTexturedRectGeometry (QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
 

Properties

const AttributeSetm_attributes
 
void * m_data
 
int m_drawing_mode
 
int m_index_count
 
int m_index_data_offset
 
int m_index_type
 
uint m_owns_data: 1
 
float m_prealloc [16]
 
uint m_reserved_bits: 31
 
void * m_reserved_pointer
 
int m_vertex_count
 

Detailed Description

Definition at line 51 of file qsggeometry.h.

Constructors and Destructors

◆ QSGGeometry()

QSGGeometry::QSGGeometry ( const QSGGeometry::AttributeSet attribs,
int  vertexCount,
int  indexCount = 0,
int  indexType = GL_UNSIGNED_SHORT 
)

Definition at line 80 of file qsggeometry.cpp.

85  , m_vertex_count(0)
86  , m_index_count(0)
89  , m_data(0)
91  , m_owns_data(false)
92 {
95 
96  // Because allocate reads m_vertex_count, m_index_count and m_owns_data, these
97  // need to be set before calling allocate...
99 }
int indexType() const
Definition: qsggeometry.h:98
int m_drawing_mode
Definition: qsggeometry.h:118
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int m_vertex_count
Definition: qsggeometry.h:119
uint m_owns_data
Definition: qsggeometry.h:128
#define GL_TRIANGLE_STRIP
void * m_data
Definition: qsggeometry.h:123
int m_index_count
Definition: qsggeometry.h:120
int m_index_data_offset
Definition: qsggeometry.h:124
const Attribute * attributes() const
Definition: qsggeometry.h:111
int indexCount() const
Definition: qsggeometry.h:100
void allocate(int vertexCount, int indexCount=0)
int vertexCount() const
Definition: qsggeometry.h:86
int m_index_type
Definition: qsggeometry.h:121

◆ ~QSGGeometry()

QSGGeometry::~QSGGeometry ( )

Definition at line 101 of file qsggeometry.cpp.

102 {
103  if (m_owns_data)
104  qFree(m_data);
105 }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
uint m_owns_data
Definition: qsggeometry.h:128
void * m_data
Definition: qsggeometry.h:123

Functions

◆ allocate()

void QSGGeometry::allocate ( int  vertexCount,
int  indexCount = 0 
)

Definition at line 126 of file qsggeometry.cpp.

Referenced by drawingMode(), QSGGeometry(), and ShaderEffectItem::updateGeometry().

127 {
129  return;
130 
133 
134  bool canUsePrealloc = m_index_count <= 0;
135  int vertexByteSize = m_attributes.stride * m_vertex_count;
136 
137  if (m_owns_data)
138  qFree(m_data);
139 
140  if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) {
141  m_data = (void *) &m_prealloc[0];
142  m_index_data_offset = -1;
143  m_owns_data = false;
144  } else {
146  int indexByteSize = indexCount * (m_index_type == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32));
147  m_data = (void *) qMalloc(vertexByteSize + indexByteSize);
148  m_index_data_offset = vertexByteSize;
149  m_owns_data = true;
150  }
151 
152 }
#define GL_UNSIGNED_INT
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int m_vertex_count
Definition: qsggeometry.h:119
uint m_owns_data
Definition: qsggeometry.h:128
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
int m_index_count
Definition: qsggeometry.h:120
unsigned int quint32
Definition: qglobal.h:938
int m_index_data_offset
Definition: qsggeometry.h:124
int indexCount() const
Definition: qsggeometry.h:100
int vertexCount() const
Definition: qsggeometry.h:86
int m_index_type
Definition: qsggeometry.h:121

◆ attributeCount()

int QSGGeometry::attributeCount ( ) const
inline

Definition at line 110 of file qsggeometry.h.

Referenced by ShaderEffectItem::bindGeometry().

110 { return m_attributes.count; }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122

◆ attributes()

const Attribute* QSGGeometry::attributes ( ) const
inline

Definition at line 111 of file qsggeometry.h.

Referenced by ShaderEffectItem::bindGeometry(), ShaderEffectItem::renderEffect(), and ShaderEffectItem::updateShaderProgram().

111 { return m_attributes.attributes; }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
const Attribute * attributes
Definition: qsggeometry.h:64

◆ defaultAttributes_ColoredPoint2D()

const QSGGeometry::AttributeSet & QSGGeometry::defaultAttributes_ColoredPoint2D ( )
static

Definition at line 68 of file qsggeometry.cpp.

69 {
70  static Attribute data[] = {
71  { 0, 2, GL_FLOAT },
72  { 1, 4, GL_UNSIGNED_BYTE }
73  };
74  static AttributeSet attrs = { 2, 2 * sizeof(float) + 4 * sizeof(char), data };
75  return attrs;
76 }
static const char * data(const QByteArray &arr)
#define GL_FLOAT
#define GL_UNSIGNED_BYTE

◆ defaultAttributes_Point2D()

const QSGGeometry::AttributeSet & QSGGeometry::defaultAttributes_Point2D ( )
static

Definition at line 47 of file qsggeometry.cpp.

48 {
49  static Attribute data[] = {
50  { 0, 2, GL_FLOAT }
51  };
52  static AttributeSet attrs = { 1, sizeof(float) * 2, data };
53  return attrs;
54 }
static const char * data(const QByteArray &arr)
#define GL_FLOAT

◆ defaultAttributes_TexturedPoint2D()

const QSGGeometry::AttributeSet & QSGGeometry::defaultAttributes_TexturedPoint2D ( )
static

Definition at line 57 of file qsggeometry.cpp.

58 {
59  static Attribute data[] = {
60  { 0, 2, GL_FLOAT },
61  { 1, 2, GL_FLOAT }
62  };
63  static AttributeSet attrs = { 2, sizeof(float) * 4, data };
64  return attrs;
65 }
static const char * data(const QByteArray &arr)
#define GL_FLOAT

◆ drawingMode()

GLenum QSGGeometry::drawingMode ( ) const
inline

Definition at line 82 of file qsggeometry.h.

Referenced by ShaderEffectItem::renderEffect().

82 { return m_drawing_mode; }
int m_drawing_mode
Definition: qsggeometry.h:118

◆ indexCount()

int QSGGeometry::indexCount ( ) const
inline

Definition at line 100 of file qsggeometry.h.

Referenced by allocate(), drawingMode(), and ShaderEffectItem::renderEffect().

100 { return m_index_count; }
int m_index_count
Definition: qsggeometry.h:120

◆ indexData() [1/2]

void * QSGGeometry::indexData ( )

Definition at line 107 of file qsggeometry.cpp.

Referenced by indexCount(), indexDataAsUInt(), indexDataAsUShort(), and ShaderEffectItem::renderEffect().

108 {
109  return m_index_data_offset < 0
110  ? 0
111  : ((char *) m_data + m_index_data_offset);
112 }
void * m_data
Definition: qsggeometry.h:123
int m_index_data_offset
Definition: qsggeometry.h:124

◆ indexData() [2/2]

const void * QSGGeometry::indexData ( ) const

Definition at line 114 of file qsggeometry.cpp.

115 {
116  return m_index_data_offset < 0
117  ? 0
118  : ((char *) m_data + m_index_data_offset);
119 }
void * m_data
Definition: qsggeometry.h:123
int m_index_data_offset
Definition: qsggeometry.h:124

◆ indexDataAsUInt() [1/2]

uint * QSGGeometry::indexDataAsUInt ( )
inline

Definition at line 134 of file qsggeometry.h.

Referenced by indexCount().

135 {
137  return (uint *) indexData();
138 }
#define GL_UNSIGNED_INT
void * indexData()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int uint
Definition: qglobal.h:996
int m_index_type
Definition: qsggeometry.h:121

◆ indexDataAsUInt() [2/2]

const uint * QSGGeometry::indexDataAsUInt ( ) const
inline

Definition at line 146 of file qsggeometry.h.

147 {
149  return (uint *) indexData();
150 }
#define GL_UNSIGNED_INT
void * indexData()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int uint
Definition: qglobal.h:996
int m_index_type
Definition: qsggeometry.h:121

◆ indexDataAsUShort() [1/2]

quint16 * QSGGeometry::indexDataAsUShort ( )
inline

Definition at line 140 of file qsggeometry.h.

Referenced by indexCount(), and ShaderEffectItem::updateGeometry().

141 {
143  return (quint16 *) indexData();
144 }
void * indexData()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define GL_UNSIGNED_SHORT
unsigned short quint16
Definition: qglobal.h:936
int m_index_type
Definition: qsggeometry.h:121

◆ indexDataAsUShort() [2/2]

const quint16 * QSGGeometry::indexDataAsUShort ( ) const
inline

Definition at line 152 of file qsggeometry.h.

153 {
155  return (quint16 *) indexData();
156 }
void * indexData()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define GL_UNSIGNED_SHORT
unsigned short quint16
Definition: qglobal.h:936
int m_index_type
Definition: qsggeometry.h:121

◆ indexType()

int QSGGeometry::indexType ( ) const
inline

Definition at line 98 of file qsggeometry.h.

Referenced by ShaderEffectItem::renderEffect().

98 { return m_index_type; }
int m_index_type
Definition: qsggeometry.h:121

◆ setDrawingMode()

void QSGGeometry::setDrawingMode ( GLenum  mode)

Definition at line 121 of file qsggeometry.cpp.

122 {
123  m_drawing_mode = mode;
124 }
int m_drawing_mode
Definition: qsggeometry.h:118

◆ stride()

int QSGGeometry::stride ( ) const
inline

Definition at line 112 of file qsggeometry.h.

Referenced by ShaderEffectItem::bindGeometry().

112 { return m_attributes.stride; }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122

◆ updateRectGeometry()

void QSGGeometry::updateRectGeometry ( QSGGeometry g,
const QRectF rect 
)
static

Definition at line 154 of file qsggeometry.cpp.

Referenced by stride().

155 {
156  Point2D *v = g->vertexDataAsPoint2D();
157  v[0].x = rect.left();
158  v[0].y = rect.top();
159 
160  v[1].x = rect.right();
161  v[1].y = rect.top();
162 
163  v[2].x = rect.left();
164  v[2].y = rect.bottom();
165 
166  v[3].x = rect.right();
167  v[3].y = rect.bottom();
168 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
Point2D * vertexDataAsPoint2D()
Definition: qsggeometry.h:158
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528

◆ updateTexturedRectGeometry()

void QSGGeometry::updateTexturedRectGeometry ( QSGGeometry g,
const QRectF rect,
const QRectF sourceRect 
)
static

Definition at line 170 of file qsggeometry.cpp.

Referenced by stride(), and ShaderEffectItem::updateGeometry().

171 {
172  TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
173  v[0].x = rect.left();
174  v[0].y = rect.top();
175  v[0].tx = textureRect.left();
176  v[0].ty = textureRect.top();
177 
178  v[1].x = rect.right();
179  v[1].y = rect.top();
180  v[1].tx = textureRect.right();
181  v[1].ty = textureRect.top();
182 
183  v[2].x = rect.left();
184  v[2].y = rect.bottom();
185  v[2].tx = textureRect.left();
186  v[2].ty = textureRect.bottom();
187 
188  v[3].x = rect.right();
189  v[3].y = rect.bottom();
190  v[3].tx = textureRect.right();
191  v[3].ty = textureRect.bottom();
192 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Definition: qsggeometry.h:168
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528

◆ vertexCount()

int QSGGeometry::vertexCount ( ) const
inline

Definition at line 86 of file qsggeometry.h.

Referenced by allocate(), ShaderEffectItem::renderEffect(), and ShaderEffectItem::updateGeometry().

86 { return m_vertex_count; }
int m_vertex_count
Definition: qsggeometry.h:119

◆ vertexData() [1/2]

void* QSGGeometry::vertexData ( )
inline

Definition at line 88 of file qsggeometry.h.

Referenced by ShaderEffectItem::bindGeometry().

88 { return m_data; }
void * m_data
Definition: qsggeometry.h:123

◆ vertexData() [2/2]

const void* QSGGeometry::vertexData ( ) const
inline

Definition at line 93 of file qsggeometry.h.

93 { return m_data; }
void * m_data
Definition: qsggeometry.h:123

◆ vertexDataAsColoredPoint2D() [1/2]

QSGGeometry::ColoredPoint2D * QSGGeometry::vertexDataAsColoredPoint2D ( )
inline

Definition at line 181 of file qsggeometry.h.

Referenced by vertexData().

182 {
184  Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
191  return (ColoredPoint2D *) m_data;
192 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
#define GL_UNSIGNED_BYTE
const Attribute * attributes
Definition: qsggeometry.h:64

◆ vertexDataAsColoredPoint2D() [2/2]

const QSGGeometry::ColoredPoint2D * QSGGeometry::vertexDataAsColoredPoint2D ( ) const
inline

Definition at line 217 of file qsggeometry.h.

218 {
220  Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
227  return (const ColoredPoint2D *) m_data;
228 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
#define GL_UNSIGNED_BYTE
const Attribute * attributes
Definition: qsggeometry.h:64

◆ vertexDataAsPoint2D() [1/2]

QSGGeometry::Point2D * QSGGeometry::vertexDataAsPoint2D ( )
inline

Definition at line 158 of file qsggeometry.h.

Referenced by updateRectGeometry(), and vertexData().

159 {
161  Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
165  return (Point2D *) m_data;
166 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
const Attribute * attributes
Definition: qsggeometry.h:64

◆ vertexDataAsPoint2D() [2/2]

const QSGGeometry::Point2D * QSGGeometry::vertexDataAsPoint2D ( ) const
inline

Definition at line 194 of file qsggeometry.h.

195 {
197  Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
201  return (const Point2D *) m_data;
202 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
const Attribute * attributes
Definition: qsggeometry.h:64

◆ vertexDataAsTexturedPoint2D() [1/2]

QSGGeometry::TexturedPoint2D * QSGGeometry::vertexDataAsTexturedPoint2D ( )
inline

Definition at line 168 of file qsggeometry.h.

Referenced by ShaderEffectItem::updateGeometry(), updateTexturedRectGeometry(), and vertexData().

169 {
171  Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
178  return (TexturedPoint2D *) m_data;
179 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
const Attribute * attributes
Definition: qsggeometry.h:64

◆ vertexDataAsTexturedPoint2D() [2/2]

const QSGGeometry::TexturedPoint2D * QSGGeometry::vertexDataAsTexturedPoint2D ( ) const
inline

Definition at line 204 of file qsggeometry.h.

205 {
207  Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
214  return (const TexturedPoint2D *) m_data;
215 }
const AttributeSet & m_attributes
Definition: qsggeometry.h:122
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void * m_data
Definition: qsggeometry.h:123
#define GL_FLOAT
const Attribute * attributes
Definition: qsggeometry.h:64

Properties

◆ m_attributes

const AttributeSet& QSGGeometry::m_attributes
private

◆ m_data

void* QSGGeometry::m_data
private

◆ m_drawing_mode

int QSGGeometry::m_drawing_mode
private

Definition at line 118 of file qsggeometry.h.

Referenced by drawingMode(), and setDrawingMode().

◆ m_index_count

int QSGGeometry::m_index_count
private

Definition at line 120 of file qsggeometry.h.

Referenced by allocate(), and indexCount().

◆ m_index_data_offset

int QSGGeometry::m_index_data_offset
private

Definition at line 124 of file qsggeometry.h.

Referenced by allocate(), and indexData().

◆ m_index_type

int QSGGeometry::m_index_type
private

Definition at line 121 of file qsggeometry.h.

Referenced by allocate(), indexDataAsUInt(), indexDataAsUShort(), and indexType().

◆ m_owns_data

uint QSGGeometry::m_owns_data
private

Definition at line 128 of file qsggeometry.h.

Referenced by allocate(), and ~QSGGeometry().

◆ m_prealloc

float QSGGeometry::m_prealloc[16]
private

Definition at line 131 of file qsggeometry.h.

Referenced by allocate().

◆ m_reserved_bits

uint QSGGeometry::m_reserved_bits
private

Definition at line 129 of file qsggeometry.h.

◆ m_reserved_pointer

void* QSGGeometry::m_reserved_pointer
private

Definition at line 126 of file qsggeometry.h.

◆ m_vertex_count

int QSGGeometry::m_vertex_count
private

Definition at line 119 of file qsggeometry.h.

Referenced by allocate(), and vertexCount().


The documentation for this class was generated from the following files: