15QSGGeometry::Attribute QSGGeometry::Attribute::create(
int attributeIndex,
int tupleSize,
int primitiveType,
bool isPrimitive)
17 Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, UnknownAttribute, 0 };
21QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(
int pos,
int tupleSize,
int primitiveType, AttributeType attributeType)
25 a.tupleSize = tupleSize;
26 a.type = primitiveType;
27 a.isVertexCoordinate = attributeType == PositionAttribute;
28 a.attributeType = attributeType;
38const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
40 static Attribute data[] = {
41 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute)
43 static AttributeSet attrs = { 1,
sizeof(
float) * 2, data };
51const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
53 static Attribute data[] = {
54 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
55 Attribute::createWithAttributeType(1, 2, FloatType, TexCoordAttribute)
57 static AttributeSet attrs = { 2,
sizeof(
float) * 4, data };
65const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
67 static Attribute data[] = {
68 Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
69 Attribute::createWithAttributeType(1, 4, UnsignedByteType, ColorAttribute)
71 static AttributeSet attrs = { 2, 2 *
sizeof(
float) + 4 *
sizeof(
char), data };
390QSGGeometry::QSGGeometry(
const QSGGeometry::AttributeSet &attributes,
394 : m_drawing_mode(DrawTriangleStrip)
397 , m_index_type(indexType)
398 , m_attributes(attributes)
400 , m_index_data_offset(-1)
401 , m_server_data(
nullptr)
403 , m_index_usage_pattern(AlwaysUploadPattern)
404 , m_vertex_usage_pattern(AlwaysUploadPattern)
407 Q_UNUSED(m_reserved_bits);
408 Q_ASSERT(m_attributes.count > 0);
409 Q_ASSERT(m_attributes.stride > 0);
410 if (indexType != UnsignedByteType
411 && indexType != UnsignedShortType
412 && indexType != UnsignedIntType) {
413 qFatal(
"QSGGeometry: Unsupported index type, %x.\n", indexType);
418 allocate(vertexCount, indexCount);
674void QSGGeometry::allocate(
int vertexCount,
int indexCount)
676 if (vertexCount == m_vertex_count && indexCount == m_index_count)
679 m_vertex_count = vertexCount;
680 m_index_count = indexCount;
682 bool canUsePrealloc = m_index_count <= 0;
683 int vertexByteSize = m_attributes.stride * m_vertex_count;
688 if (canUsePrealloc && vertexByteSize <= (
int)
sizeof(m_prealloc)) {
691 m_data = (
void *) &m_prealloc[0];
692 m_index_data_offset = -1;
695 Q_ASSERT(m_index_type == UnsignedIntType || m_index_type == UnsignedShortType);
696 int indexByteSize = indexCount * (m_index_type == UnsignedShortType ?
sizeof(quint16) :
sizeof(quint32));
697 m_data = (
void *) malloc(vertexByteSize + indexByteSize);
699 m_index_data_offset = vertexByteSize;
708 markIndexDataDirty();
709 markVertexDataDirty();
744void QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g,
const QRectF &rect,
const QRectF &textureRect)
746 TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
747 v[0].x = rect.left();
749 v[0].tx = textureRect.left();
750 v[0].ty = textureRect.top();
752 v[1].x = rect.left();
753 v[1].y = rect.bottom();
754 v[1].tx = textureRect.left();
755 v[1].ty = textureRect.bottom();
757 v[2].x = rect.right();
759 v[2].tx = textureRect.right();
760 v[2].ty = textureRect.top();
762 v[3].x = rect.right();
763 v[3].y = rect.bottom();
764 v[3].tx = textureRect.right();
765 v[3].ty = textureRect.bottom();