本文整理汇总了C++中QSGGeometry::vertexData方法的典型用法代码示例。如果您正苦于以下问题:C++ QSGGeometry::vertexData方法的具体用法?C++ QSGGeometry::vertexData怎么用?C++ QSGGeometry::vertexData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSGGeometry
的用法示例。
在下文中一共展示了QSGGeometry::vertexData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compareSelectionNode
void compareSelectionNode(QSGNode *node, const QRectF &rect, int selectionId)
{
QSGGeometryNode *geometryNode = static_cast<QSGGeometryNode *>(node);
QSGGeometry *geometry = geometryNode->geometry();
QCOMPARE(geometry->vertexCount(), 4);
QCOMPARE(geometry->drawingMode(), (GLenum)GL_TRIANGLE_STRIP);
OpaqueColoredPoint2DWithSize *data =
static_cast<OpaqueColoredPoint2DWithSize *>(geometry->vertexData());
float *lowerLeft = reinterpret_cast<float *>(data);
float *lowerRight = reinterpret_cast<float *>(++data);
float *upperLeft = reinterpret_cast<float *>(++data);
float *upperRight = reinterpret_cast<float *>(++data);
QCOMPARE(QRectF(QPointF(upperLeft[0], upperLeft[1]), QPointF(lowerRight[0], lowerRight[1])),
rect);
QCOMPARE(lowerRight[0], upperRight[0]);
QCOMPARE(lowerRight[1], lowerLeft[1]);
QCOMPARE(upperLeft[0], lowerLeft[0]);
QCOMPARE(upperLeft[1], upperRight[1]);
QCOMPARE(int(lowerLeft[4]), selectionId);
QCOMPARE(int(lowerRight[4]), selectionId);
QCOMPARE(int(upperLeft[4]), selectionId);
QCOMPARE(int(upperRight[4]), selectionId);
TimelineItemsMaterial *material = static_cast<TimelineItemsMaterial *>(
geometryNode->material());
QVERIFY(!(material->flags() & QSGMaterial::Blending));
}
示例2: allocate
void BindlingLoopsGeometry::allocate(QSGMaterial *material)
{
QSGGeometry *geometry = new QSGGeometry(BindlingLoopsGeometry::point2DWithOffset(),
usedVertices);
Q_ASSERT(geometry->vertexData());
geometry->setIndexDataPattern(QSGGeometry::StaticPattern);
geometry->setVertexDataPattern(QSGGeometry::StaticPattern);
node = new QSGGeometryNode;
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry, true);
node->setMaterial(material);
allocatedVertices = usedVertices;
usedVertices = 0;
}
示例3: sizeof
Point2DWithOffset *BindlingLoopsGeometry::vertexData()
{
QSGGeometry *geometry = node->geometry();
Q_ASSERT(geometry->attributeCount() == 2);
Q_ASSERT(geometry->sizeOfVertex() == sizeof(Point2DWithOffset));
const QSGGeometry::Attribute *attributes = geometry->attributes();
Q_ASSERT(attributes[0].position == 0);
Q_ASSERT(attributes[0].tupleSize == 2);
Q_ASSERT(attributes[0].type == GL_FLOAT);
Q_ASSERT(attributes[1].position == 1);
Q_ASSERT(attributes[1].tupleSize == 2);
Q_ASSERT(attributes[1].type == GL_FLOAT);
Q_UNUSED(attributes);
return static_cast<Point2DWithOffset *>(geometry->vertexData());
}
示例4: updateStrokeNode
void QQuickShapeGenericRenderer::updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node)
{
if (!node->m_strokeNode)
return;
if (!(d->effectiveDirty & (DirtyStrokeGeom | DirtyColor)))
return;
QQuickShapeGenericStrokeFillNode *n = node->m_strokeNode;
QSGGeometry *g = n->geometry();
if (d->strokeVertices.isEmpty()) {
if (g->vertexCount() || g->indexCount()) {
g->allocate(0, 0);
n->markDirty(QSGNode::DirtyGeometry);
}
return;
}
n->markDirty(QSGNode::DirtyGeometry);
// Async loading runs update once, bails out above, then updates again once
// ready. Set the material dirty then. This is in-line with fill where the
// first activateMaterial() achieves the same.
if (!g->vertexCount())
n->markDirty(QSGNode::DirtyMaterial);
if ((d->effectiveDirty & DirtyColor) && !(d->effectiveDirty & DirtyStrokeGeom)) {
ColoredVertex *vdst = reinterpret_cast<ColoredVertex *>(g->vertexData());
for (int i = 0; i < g->vertexCount(); ++i)
vdst[i].set(vdst[i].x, vdst[i].y, d->strokeColor);
return;
}
g->allocate(d->strokeVertices.count(), 0);
g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
}
示例5: QSGGeometry
QSGGeometryNode *createSelectionNode(QSGMaterial *material)
{
QSGGeometryNode *selectionNode = new QSGGeometryNode;
selectionNode->setMaterial(material);
selectionNode->setFlag(QSGNode::OwnsMaterial, false);
QSGGeometry *geometry = new QSGGeometry(OpaqueColoredPoint2DWithSize::attributes(), 4);
Q_ASSERT(geometry->vertexData());
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
OpaqueColoredPoint2DWithSize *v = OpaqueColoredPoint2DWithSize::fromVertexData(geometry);
for (int i = 0; i < 4; ++i)
v[i].set(0, 0, 0, 0, 0, 0, 0, 0, 0);
selectionNode->setGeometry(geometry);
selectionNode->setFlag(QSGNode::OwnsGeometry, true);
selectionNode->setFlag(QSGNode::OwnedByParent, false);
return selectionNode;
}
示例6: buildRenderList
void Renderer::buildRenderList(QSGNode *node, QSGClipNode *clip)
{
if (node->isSubtreeBlocked())
return;
if (node->type() == QSGNode::GeometryNodeType || node->type() == QSGNode::ClipNodeType) {
QSGBasicGeometryNode *gn = static_cast<QSGBasicGeometryNode *>(node);
QSGGeometry *g = gn->geometry();
Element e;
e.node = gn;
if (g->vertexCount() > 0) {
e.vboOffset = m_vboSize;
int vertexSize = g->sizeOfVertex() * g->vertexCount();
m_vboSize += vertexSize;
m_vboData.resize(m_vboSize);
memcpy(m_vboData.data() + e.vboOffset, g->vertexData(), vertexSize);
} else {
e.vboOffset = -1;
}
if (g->indexCount() > 0) {
e.iboOffset = m_iboSize;
int indexSize = g->sizeOfIndex() * g->indexCount();
m_iboSize += indexSize;
m_iboData.resize(m_iboSize);
memcpy(m_iboData.data() + e.iboOffset, g->indexData(), indexSize);
} else {
e.iboOffset = -1;
}
m_renderList.add(e);
static_cast<BasicGeometryNode_Accessor *>(node)->m_clip_list = clip;
if (node->type() == QSGNode::ClipNodeType)
clip = static_cast<QSGClipNode *>(node);
}
QSGNODE_TRAVERSE(node)
buildRenderList(child, clip);
}
示例7: updateGeometry
void QQuickDefaultClipNode::updateGeometry()
{
QSGGeometry *g = geometry();
if (qFuzzyIsNull(m_radius)) {
g->allocate(4);
QSGGeometry::updateRectGeometry(g, m_rect);
} else {
int vertexCount = 0;
// Radius should never exceeds half of the width or half of the height
qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius);
QRectF rect = m_rect;
rect.adjust(radius, radius, -radius, -radius);
int segments = qMin(30, qCeil(radius)); // Number of segments per corner.
g->allocate((segments + 1) * 2);
QVector2D *vertices = (QVector2D *)g->vertexData();
for (int part = 0; part < 2; ++part) {
for (int i = 0; i <= segments; ++i) {
//### Should change to calculate sin/cos only once.
qreal angle = qreal(0.5 * M_PI) * (part + i / qreal(segments));
qreal s = qFastSin(angle);
qreal c = qFastCos(angle);
qreal y = (part ? rect.bottom() : rect.top()) - radius * c; // current inner y-coordinate.
qreal lx = rect.left() - radius * s; // current inner left x-coordinate.
qreal rx = rect.right() + radius * s; // current inner right x-coordinate.
vertices[vertexCount++] = QVector2D(rx, y);
vertices[vertexCount++] = QVector2D(lx, y);
}
}
}
markDirty(DirtyGeometry);
setClipRect(m_rect);
}
示例8: QSGGeometry
QSGGeometry *NotesGeometry::createGeometry(QVector<int> &ids, const TimelineModel *model,
const TimelineRenderState *parentState, bool collapsed)
{
float rowHeight = TimelineModel::defaultRowHeight();
QSGGeometry *geometry = new QSGGeometry(point2DWithDistanceFromTop(),
ids.count() * 2);
geometry->setDrawingMode(GL_LINES);
geometry->setLineWidth(3);
Point2DWithDistanceFromTop *v =
static_cast<Point2DWithDistanceFromTop *>(geometry->vertexData());
for (int i = 0; i < ids.count(); ++i) {
int timelineIndex = ids[i];
float horizontalCenter = ((model->startTime(timelineIndex) +
model->endTime(timelineIndex)) / (qint64)2 -
parentState->start()) * parentState->scale();
float verticalStart = (collapsed ? (model->collapsedRow(timelineIndex) + 0.1) : 0.1) *
rowHeight;
float verticalEnd = verticalStart + 0.8 * rowHeight;
v[i * 2].set(horizontalCenter, verticalStart, 0);
v[i * 2 + 1].set(horizontalCenter, verticalEnd, 1);
}
return geometry;
}
示例9: QSGGeometry
void
QcLocationCircleNode::update(const QcLocationCircleData & location_circle_data)
{
// QSGGeometry * location_circle_geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 1);
// location_circle_geometry->setLineWidth(100); // point size, max is 255
// location_circle_geometry->setDrawingMode(GL_POINTS);
QSGGeometry * geometry = new QSGGeometry(LocationCirclePoint2D_AttributeSet, 4);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
m_geometry_node->setGeometry(geometry);
m_geometry_node->setFlag(QSGNode::OwnsGeometry);
LocationCirclePoint2D * vertices = static_cast<LocationCirclePoint2D *>(geometry->vertexData());
float x, y;
if (location_circle_data.visible()) {
QcVectorDouble screen_coordinate = m_viewport->coordinate_to_screen(location_circle_data.coordinate());
x = screen_coordinate.x();
y = screen_coordinate.y();
qInfo() << screen_coordinate;
} else {
x = .5 * m_viewport->width(); // Fixme: vector
y = .5 * m_viewport->height();
}
float accuracy_radius = m_viewport->to_px(location_circle_data.horizontal_precision());
constexpr float dot_radius_minimum = 10.;
constexpr float cone_scale_factor = 5.;
float dot_radius = qMax(accuracy_radius, dot_radius_minimum);
float radius = cone_scale_factor * dot_radius_minimum;
float margin = 10;
float size = radius + margin;
float angle = location_circle_data.bearing() + 90.; // North point to y
vertices[0].set(QcVectorDouble(x - size, y - size), QcVectorDouble(-size, -size), radius, dot_radius, accuracy_radius, angle);
vertices[1].set(QcVectorDouble(x - size, y + size), QcVectorDouble(-size, size), radius, dot_radius, accuracy_radius, angle);
vertices[2].set(QcVectorDouble(x + size, y - size), QcVectorDouble( size, -size), radius, dot_radius, accuracy_radius, angle);
vertices[3].set(QcVectorDouble(x + size, y + size), QcVectorDouble( size, size), radius, dot_radius, accuracy_radius, angle);
}
示例10: buildCustomNodes
QQuickShaderEffectNode* QQuickCustomParticle::buildCustomNodes()
{
if (QOpenGLContext::currentContext()->isOpenGLES() && m_count * 4 > 0xffff) {
printf("CustomParticle: Too many particles... \n");
return 0;
}
if (m_count <= 0) {
printf("CustomParticle: Too few particles... \n");
return 0;
}
if (m_groups.isEmpty())
return 0;
QQuickShaderEffectNode *rootNode = 0;
QQuickShaderEffectMaterial *material = new QQuickShaderEffectMaterial;
m_dirtyProgram = true;
foreach (const QString &str, m_groups){
int gIdx = m_system->groupIds[str];
int count = m_system->groupData[gIdx]->size();
QQuickShaderEffectNode* node = new QQuickShaderEffectNode();
m_nodes.insert(gIdx, node);
node->setMaterial(material);
//Create Particle Geometry
int vCount = count * 4;
int iCount = count * 6;
QSGGeometry *g = new QSGGeometry(PlainParticle_AttributeSet, vCount, iCount);
g->setDrawingMode(GL_TRIANGLES);
node->setGeometry(g);
node->setFlag(QSGNode::OwnsGeometry, true);
PlainVertex *vertices = (PlainVertex *) g->vertexData();
for (int p=0; p < count; ++p) {
commit(gIdx, p);
vertices[0].tx = 0;
vertices[0].ty = 0;
vertices[1].tx = 1;
vertices[1].ty = 0;
vertices[2].tx = 0;
vertices[2].ty = 1;
vertices[3].tx = 1;
vertices[3].ty = 1;
vertices += 4;
}
quint16 *indices = g->indexDataAsUShort();
for (int i=0; i < count; ++i) {
int o = i * 4;
indices[0] = o;
indices[1] = o + 1;
indices[2] = o + 2;
indices[3] = o + 1;
indices[4] = o + 3;
indices[5] = o + 2;
indices += 6;
}
}
示例11: updateGeometry
void QSGDefaultImageNode::updateGeometry()
{
Q_ASSERT(!m_targetRect.isEmpty());
const QSGTexture *t = m_material.texture();
if (!t) {
QSGGeometry *g = geometry();
g->allocate(4);
g->setDrawingMode(GL_TRIANGLE_STRIP);
memset(g->vertexData(), 0, g->sizeOfVertex() * 4);
} else {
QRectF sourceRect = t->normalizedTextureSubRect();
QRectF innerSourceRect(sourceRect.x() + m_innerSourceRect.x() * sourceRect.width(),
sourceRect.y() + m_innerSourceRect.y() * sourceRect.height(),
m_innerSourceRect.width() * sourceRect.width(),
m_innerSourceRect.height() * sourceRect.height());
bool hasMargins = m_targetRect != m_innerTargetRect;
int floorLeft = qFloor(m_subSourceRect.left());
int ceilRight = qCeil(m_subSourceRect.right());
int floorTop = qFloor(m_subSourceRect.top());
int ceilBottom = qCeil(m_subSourceRect.bottom());
int hTiles = ceilRight - floorLeft;
int vTiles = ceilBottom - floorTop;
bool hasTiles = hTiles != 1 || vTiles != 1;
bool fullTexture = innerSourceRect == QRectF(0, 0, 1, 1);
#ifdef QT_OPENGL_ES_2
QOpenGLContext *ctx = QOpenGLContext::currentContext();
bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat);
QSize size = t->textureSize();
bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
bool wrapSupported = npotSupported || !isNpot;
#else
bool wrapSupported = true;
#endif
// An image can be rendered as a single quad if:
// - There are no margins, and either:
// - the image isn't repeated
// - the source rectangle fills the entire texture so that texture wrapping can be used,
// and NPOT is supported
if (!hasMargins && (!hasTiles || (fullTexture && wrapSupported))) {
QRectF sr;
if (!fullTexture) {
sr = QRectF(innerSourceRect.x() + (m_subSourceRect.left() - floorLeft) * innerSourceRect.width(),
innerSourceRect.y() + (m_subSourceRect.top() - floorTop) * innerSourceRect.height(),
m_subSourceRect.width() * innerSourceRect.width(),
m_subSourceRect.height() * innerSourceRect.height());
} else {
sr = QRectF(m_subSourceRect.left() - floorLeft, m_subSourceRect.top() - floorTop,
m_subSourceRect.width(), m_subSourceRect.height());
}
if (m_mirror) {
qreal oldLeft = sr.left();
sr.setLeft(sr.right());
sr.setRight(oldLeft);
}
if (m_antialiasing) {
QSGGeometry *g = geometry();
Q_ASSERT(g != &m_geometry);
g->allocate(8, 14);
g->setDrawingMode(GL_TRIANGLE_STRIP);
SmoothVertex *vertices = reinterpret_cast<SmoothVertex *>(g->vertexData());
float delta = float(qAbs(m_targetRect.width()) < qAbs(m_targetRect.height())
? m_targetRect.width() : m_targetRect.height()) * 0.5f;
float sx = float(sr.width() / m_targetRect.width());
float sy = float(sr.height() / m_targetRect.height());
for (int d = -1; d <= 1; d += 2) {
for (int j = 0; j < 2; ++j) {
for (int i = 0; i < 2; ++i, ++vertices) {
vertices->x = m_targetRect.x() + i * m_targetRect.width();
vertices->y = m_targetRect.y() + j * m_targetRect.height();
vertices->u = sr.x() + i * sr.width();
vertices->v = sr.y() + j * sr.height();
vertices->dx = (i == 0 ? delta : -delta) * d;
vertices->dy = (j == 0 ? delta : -delta) * d;
vertices->du = (d < 0 ? 0 : vertices->dx * sx);
vertices->dv = (d < 0 ? 0 : vertices->dy * sy);
}
}
}
Q_ASSERT(vertices - g->vertexCount() == g->vertexData());
static const quint16 indices[] = {
0, 4, 1, 5, 3, 7, 2, 6, 0, 4,
4, 6, 5, 7
};
Q_ASSERT(g->sizeOfIndex() * g->indexCount() == sizeof(indices));
memcpy(g->indexDataAsUShort(), indices, sizeof(indices));
} else {
m_geometry.allocate(4);
m_geometry.setDrawingMode(GL_TRIANGLE_STRIP);
QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_targetRect, sr);
}
} else {
int hCells = hTiles;
int vCells = vTiles;
//.........这里部分代码省略.........
示例12: updateFillNode
void QQuickShapeGenericRenderer::updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node)
{
if (!node->m_fillNode)
return;
if (!(d->effectiveDirty & (DirtyFillGeom | DirtyColor | DirtyFillGradient)))
return;
// Make a copy of the data that will be accessed by the material on
// the render thread. This must be done even when we bail out below.
QQuickShapeGenericStrokeFillNode *n = node->m_fillNode;
updateShadowDataInNode(d, n);
QSGGeometry *g = n->geometry();
if (d->fillVertices.isEmpty()) {
if (g->vertexCount() || g->indexCount()) {
g->allocate(0, 0);
n->markDirty(QSGNode::DirtyGeometry);
}
return;
}
if (d->fillGradientActive) {
QQuickShapeGenericStrokeFillNode::Material gradMat;
switch (d->fillGradientActive) {
case LinearGradient:
gradMat = QQuickShapeGenericStrokeFillNode::MatLinearGradient;
break;
case RadialGradient:
gradMat = QQuickShapeGenericStrokeFillNode::MatRadialGradient;
break;
case ConicalGradient:
gradMat = QQuickShapeGenericStrokeFillNode::MatConicalGradient;
break;
default:
Q_UNREACHABLE();
}
n->activateMaterial(m_item->window(), gradMat);
if (d->effectiveDirty & DirtyFillGradient) {
// Gradients are implemented via a texture-based material.
n->markDirty(QSGNode::DirtyMaterial);
// stop here if only the gradient changed; no need to touch the geometry
if (!(d->effectiveDirty & DirtyFillGeom))
return;
}
} else {
n->activateMaterial(m_item->window(), QQuickShapeGenericStrokeFillNode::MatSolidColor);
// fast path for updating only color values when no change in vertex positions
if ((d->effectiveDirty & DirtyColor) && !(d->effectiveDirty & DirtyFillGeom)) {
ColoredVertex *vdst = reinterpret_cast<ColoredVertex *>(g->vertexData());
for (int i = 0; i < g->vertexCount(); ++i)
vdst[i].set(vdst[i].x, vdst[i].y, d->fillColor);
n->markDirty(QSGNode::DirtyGeometry);
return;
}
}
const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
? d->fillIndices.count() * 2 : d->fillIndices.count();
if (g->indexType() != d->indexType) {
g = new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
d->fillVertices.count(), indexCount, d->indexType);
n->setGeometry(g);
} else {
g->allocate(d->fillVertices.count(), indexCount);
}
g->setDrawingMode(QSGGeometry::DrawTriangles);
memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
n->markDirty(QSGNode::DirtyGeometry);
}