14QSGGeometry::Attribute QSGGeometry::Attribute::create(
int attributeIndex,
int tupleSize,
int primitiveType,
bool isPrimitive)
16 Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, UnknownAttribute, 0 };
20QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(
int pos,
int tupleSize,
int primitiveType, AttributeType attributeType)
24 a.tupleSize = tupleSize;
25 a.type = primitiveType;
26 a.isVertexCoordinate = attributeType == PositionAttribute;
27 a.attributeType = attributeType;
37const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
39 static Attribute data[] = {
40 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute)
42 static AttributeSet attrs = { 1,
sizeof(
float) * 2, data };
50const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
52 static Attribute data[] = {
53 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
54 Attribute::createWithAttributeType(1, 2, FloatType, TexCoordAttribute)
56 static AttributeSet attrs = { 2,
sizeof(
float) * 4, data };
64const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
66 static Attribute data[] = {
67 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
68 Attribute::createWithAttributeType(1, 4, UnsignedByteType, ColorAttribute)
70 static AttributeSet attrs = { 2, 2 *
sizeof(
float) + 4 *
sizeof(
char), data };
389QSGGeometry::QSGGeometry(
const QSGGeometry::AttributeSet &attributes,
393 : m_drawing_mode(DrawTriangleStrip)
396 , m_index_type(indexType)
397 , m_attributes(attributes)
399 , m_index_data_offset(-1)
400 , m_server_data(
nullptr)
402 , m_index_usage_pattern(AlwaysUploadPattern)
403 , m_vertex_usage_pattern(AlwaysUploadPattern)
406 Q_UNUSED(m_reserved_bits);
407 Q_ASSERT(m_attributes.count > 0);
408 Q_ASSERT(m_attributes.stride > 0);
409 if (indexType != UnsignedByteType
410 && indexType != UnsignedShortType
411 && indexType != UnsignedIntType) {
412 qFatal(
"QSGGeometry: Unsupported index type, %x.\n", indexType);
417 allocate(vertexCount, indexCount);
673void QSGGeometry::allocate(
int vertexCount,
int indexCount)
675 if (vertexCount == m_vertex_count && indexCount == m_index_count)
678 m_vertex_count = vertexCount;
679 m_index_count = indexCount;
681 bool canUsePrealloc = m_index_count <= 0;
682 int vertexByteSize = m_attributes.stride * m_vertex_count;
687 if (canUsePrealloc && vertexByteSize <= (
int)
sizeof(m_prealloc)) {
690 m_data = (
void *) &m_prealloc[0];
691 m_index_data_offset = -1;
694 Q_ASSERT(m_index_type == UnsignedIntType || m_index_type == UnsignedShortType);
695 int indexByteSize = indexCount * (m_index_type == UnsignedShortType ?
sizeof(quint16) :
sizeof(quint32));
696 m_data = (
void *) malloc(vertexByteSize + indexByteSize);
698 m_index_data_offset = vertexByteSize;
707 markIndexDataDirty();
708 markVertexDataDirty();
743void QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g,
const QRectF &rect,
const QRectF &textureRect)
745 TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
746 v[0].x = rect.left();
748 v[0].tx = textureRect.left();
749 v[0].ty = textureRect.top();
751 v[1].x = rect.left();
752 v[1].y = rect.bottom();
753 v[1].tx = textureRect.left();
754 v[1].ty = textureRect.bottom();
756 v[2].x = rect.right();
758 v[2].tx = textureRect.right();
759 v[2].ty = textureRect.top();
761 v[3].x = rect.right();
762 v[3].y = rect.bottom();
763 v[3].tx = textureRect.right();
764 v[3].ty = textureRect.bottom();