#include "qsggeometry.h"
#include "qsggeometry_p.h"
+#include <qopenglcontext.h>
+#include <qopenglfunctions.h>
+#include <private/qopenglextensions_p.h>
+
QT_BEGIN_NAMESPACE
Q_ASSERT(m_attributes.count > 0);
Q_ASSERT(m_attributes.stride > 0);
+ Q_ASSERT_X(indexType != GL_UNSIGNED_INT
+ || static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions())
+ ->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint),
+ "QSGGeometry::QSGGeometry",
+ "GL_UNSIGNED_INT is not supported, geometry will not render"
+ );
+
if (indexType != GL_UNSIGNED_BYTE
&& indexType != GL_UNSIGNED_SHORT
-#ifndef QT_OPENGL_ES
- && indexType != GL_UNSIGNED_INT
-#endif
- ) {
- qFatal("QSGGeometry: Unsupported index type, %x.%s\n",
- indexType,
- indexType == GL_UNSIGNED_INT ? " GL_UNSIGNED_INT is not supported on OpenGL ES." : "");
+ && indexType != GL_UNSIGNED_INT) {
+ qFatal("QSGGeometry: Unsupported index type, %x.\n", indexType);
}
}
/*!
- \fn int QSGGeometry::sizeOfIndexType() const
+ \fn int QSGGeometry::sizeOfVertex() const
+
+ Returns the size in bytes of one vertex.
+
+ This value comes from the attributes.
+ */
+
+/*!
+ \fn int QSGGeometry::sizeOfIndex() const
Returns the byte size of the index type.
inline int attributeCount() const { return m_attributes.count; }
inline const Attribute *attributes() const { return m_attributes.attributes; }
- inline int stride() const { return m_attributes.stride; }
+ inline int sizeOfVertex() const { return m_attributes.stride; }
static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
{
if (m_index_type == GL_UNSIGNED_SHORT) return 2;
else if (m_index_type == GL_UNSIGNED_BYTE) return 1;
-#ifndef QT_OPENGL_ES
else if (m_index_type == GL_UNSIGNED_INT) return 4;
-#endif
return 0;
}
if (g->attributeCount() > 0 && g->attributes()->type == GL_FLOAT) {
float x1 = 1e10, x2 = -1e10, y1=1e10, y2=-1e10;
- int stride = g->stride();
+ int stride = g->sizeOfVertex();
for (int i = 0; i < g->vertexCount(); ++i) {
float x = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[0];
float y = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[1];
const QSGGeometry *g = clip->geometry();
Q_ASSERT(g->attributeCount() > 0);
const QSGGeometry::Attribute *a = g->attributes();
- glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, g->stride(), g->vertexData());
+ glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, g->sizeOfVertex(), g->vertexData());
m_clip_program.setUniformValue(m_clip_matrix_id, m);
if (g->indexCount()) {
static bool use_vbo = !QGuiApplication::arguments().contains(QLatin1String("--no-vbo"));
const void *vertexData;
- int vertexByteSize = g->vertexCount() * g->stride();
+ int vertexByteSize = g->vertexCount() * g->sizeOfVertex();
if (use_vbo && g->vertexDataPattern() != QSGGeometry::AlwaysUploadPattern && vertexByteSize > 1024) {
// The base pointer for a VBO is 0
#else
GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
#endif
- glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->stride(), (char *) vertexData + offset);
+ glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->sizeOfVertex(), (char *) vertexData + offset);
offset += a.tupleSize * size_of_type(a.type);
}
if (updateData) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
- g->indexCount() * (g->indexType() == GL_UNSIGNED_SHORT ? 2 : 4),
+ g->indexCount() * g->sizeOfIndex(),
g->indexData(),
qt_drawTypeForPattern(g->indexDataPattern()));
QSGGeometryData::clearDirtyIndexData(g);
Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT);
geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
QVector4D *vp = (QVector4D *)geometry->vertexDataAsTexturedPoint2D();
- Q_ASSERT(geometry->stride() == sizeof(QVector4D));
+ Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D));
ushort *ip = geometry->indexDataAsUShort();
QPointF position(p.x(), p.y() - m_font.ascent());
QSGGeometry *fill = geometry();
// Check that the vertex type matches the material.
- Q_ASSERT(m_material_type != TypeFlat || fill->stride() == sizeof(Vertex));
- Q_ASSERT(m_material_type != TypeVertexGradient || fill->stride() == sizeof(ColorVertex));
+ Q_ASSERT(m_material_type != TypeFlat || fill->sizeOfVertex() == sizeof(Vertex));
+ Q_ASSERT(m_material_type != TypeVertexGradient || fill->sizeOfVertex() == sizeof(ColorVertex));
QSGGeometry *borderGeometry = 0;
if (m_border) {
borderGeometry = border()->geometry();
- Q_ASSERT(borderGeometry->stride() == sizeof(Vertex));
+ Q_ASSERT(borderGeometry->sizeOfVertex() == sizeof(Vertex));
}
int fillVertexCount = 0;
QSGGeometry geometry(QSGGeometry::defaultAttributes_Point2D(), 4, 0);
QCOMPARE(geometry.attributeCount(), 1);
- QCOMPARE(geometry.stride(), (int) sizeof(float) * 2);
+ QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 2);
QCOMPARE(geometry.vertexCount(), 4);
QCOMPARE(geometry.indexCount(), 0);
QVERIFY(geometry.indexData() == 0);
QSGGeometry geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4, 0);
QCOMPARE(geometry.attributeCount(), 2);
- QCOMPARE(geometry.stride(), (int) sizeof(float) * 4);
+ QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 4);
QCOMPARE(geometry.vertexCount(), 4);
QCOMPARE(geometry.indexCount(), 0);
QVERIFY(geometry.indexData() == 0);