本文整理汇总了C++中QSGNode::appendChildNode方法的典型用法代码示例。如果您正苦于以下问题:C++ QSGNode::appendChildNode方法的具体用法?C++ QSGNode::appendChildNode怎么用?C++ QSGNode::appendChildNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSGNode
的用法示例。
在下文中一共展示了QSGNode::appendChildNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QSGNode *Renderer::paintNode(const QRectF& viewport) const {
if (m_tiles.isEmpty()) {
return 0;
}
QSGNode *parentNode = new QSGNode;
for (const Tile& tile : m_tiles) {
if (tile.visible) {
QRectF rect = m_view->tileRect(tile);
QSGSimpleTextureNode *node = new SimpleTextureNode;
node->setFlag(QSGNode::OwnedByParent, true);
node->setTexture(m_view->window()->createTextureFromImage(tile.image));
node->setRect(rect);
node->setFiltering(QSGTexture::Nearest);
// node->setOwnsTexture(true); // TODO: Qt 5.4
qreal dx1 = rect.left() < viewport.left() ? viewport.left() - rect.left() : 0.0f;
qreal dy1 = 0.0f;
qreal dx2 = rect.right() > viewport.right() ? viewport.right() - rect.right() : 0.0f;
qreal dy2 = rect.bottom() > viewport.bottom() ? viewport.bottom() - rect.bottom() : 0.0f;
if (dx1 != 0.0f || dx2 != 0.0f || dy2 != 0.0f) {
QSGClipNode *clip = new QSGClipNode;
clip->setIsRectangular(true);
clip->setClipRect(rect.adjusted(dx1, dy1, dx2, dy2));
parentNode->appendChildNode(clip);
clip->appendChildNode(node);
// qDebug() << "Clipping";
} else {
parentNode->appendChildNode(node);
}
}
}
return parentNode;
}
示例2: updatePaintNode
QSGNode* AudioBarSpectrumItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) {
if (!m_analyzer) return oldNode;
if (!isVisible()) return oldNode;
const std::vector<double>& points = m_analyzer->getSimplifiedSpectrum();
const double gain = m_agcEnabled ? m_analyzer->getAgcValue() : m_manualGain;
const int pointCount = points.size();
if (pointCount < 2) return oldNode;
// -------------------- Prepare QSG Nodes:
QSGNode* parentNode = nullptr;
if (oldNode) {
parentNode = static_cast<QSGNode*>(oldNode);
} else {
parentNode = new QSGNode;
}
// adapt child count:
int childCount = parentNode->childCount();
if (childCount != 2) {
parentNode->removeAllChildNodes();
QSGGeometryNode* node = new QSGGeometryNode;
QSGGeometry* geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
QSGFlatColorMaterial* material = new QSGFlatColorMaterial;
material->setColor("#fff");
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
parentNode->appendChildNode(node);
// Attention: TODO: colors are swapped!
node = new QSGGeometryNode;
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
material = new QSGFlatColorMaterial;
material->setColor(m_color);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
parentNode->appendChildNode(node);
}
QSGGeometryNode* const qsgNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(0));
QSGGeometryNode* const qsgNodeOutline = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(1));
if (!qsgNode || !qsgNodeOutline) {
qCritical() << "[SpectrumItem] Could not get QSG Node.";
return nullptr;
}
QSGGeometry* const geometry = qsgNode->geometry();
QSGGeometry* const geometryOutline = qsgNodeOutline->geometry();
if (!geometry || !geometryOutline) {
qCritical() << "[SpectrumItem] Could not get QSG Geometry.";
return nullptr;
}
const int verticesCount = pointCount * 7;
const int outlineVerticesCount = pointCount * 7;
geometry->allocate(verticesCount);
geometryOutline->allocate(outlineVerticesCount);
QSGGeometry::Point2D* const vertices = geometry->vertexDataAsPoint2D();
QSGGeometry::Point2D* const verticesOutline = geometryOutline->vertexDataAsPoint2D();
if (! vertices || !verticesOutline) {
qCritical() << "[SpectrumItem] Could not get QSG vertices.";
return nullptr;
}
const double itemWidth = width();
const double itemHeight = height();
const double barWidth = (itemWidth / pointCount) * 0.4;
const double spaceWidth = (itemWidth / pointCount) * 0.6;
const double endLineHeight = itemHeight / 100.0;
// draw spectrum:
for (int i = 0; i < pointCount; ++i) {
const float x = itemWidth * (i / float(pointCount));
const float y = itemHeight * (1 - points[i] * gain);
vertices[i*7].set(x, itemHeight);
vertices[i*7+1].set(x, y);
vertices[i*7+2].set(x + barWidth, itemHeight);
vertices[i*7+3].set(x + barWidth, y);
vertices[i*7+4].set(x + barWidth, itemHeight);
vertices[i*7+5].set(x + barWidth, itemHeight);
vertices[i*7+6].set(x + barWidth + spaceWidth, itemHeight);
const float y2 = qMin(itemHeight, itemHeight * (1 - points[i] * gain) + endLineHeight);
verticesOutline[i*7].set(x, itemHeight);
verticesOutline[i*7+1].set(x, y2);
verticesOutline[i*7+2].set(x + barWidth, itemHeight);
verticesOutline[i*7+3].set(x + barWidth, y2);
verticesOutline[i*7+4].set(x + barWidth, itemHeight);
verticesOutline[i*7+5].set(x + barWidth, itemHeight);
verticesOutline[i*7+6].set(x + barWidth + spaceWidth, itemHeight);
}
//.........这里部分代码省略.........
示例3: grab
void SSGQuickLayer::grab()
{
if (!m_item || m_size.isNull()) {
delete m_fbo;
delete m_secondaryFbo;
m_fbo = m_secondaryFbo = 0;
m_depthStencilBuffer.clear();
m_dirtyTexture = false;
return;
}
QSGNode *root = m_item;
while (root->firstChild() && root->type() != QSGNode::RootNodeType)
root = root->firstChild();
if (root->type() != QSGNode::RootNodeType)
return;
if (!m_renderer) {
m_renderer = m_context->createRenderer();
connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture()));
}
m_renderer->setDevicePixelRatio(m_device_pixel_ratio);
m_renderer->setRootNode(static_cast<QSGRootNode *>(root));
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
bool deleteFboLater = false;
if (!m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format
|| (!m_fbo->format().mipmap() && m_mipmap))
{
if (!m_multisamplingChecked) {
if (m_context->openglContext()->format().samples() <= 1) {
m_multisampling = false;
} else {
const QSet<QByteArray> extensions = m_context->openglContext()->extensions();
m_multisampling = extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_multisample"))
&& extensions.contains(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
}
m_multisamplingChecked = true;
}
if (m_multisampling) {
// Don't delete the FBO right away in case it is used recursively.
deleteFboLater = true;
delete m_secondaryFbo;
QOpenGLFramebufferObjectFormat format;
format.setInternalTextureFormat(m_format);
format.setSamples(m_context->openglContext()->format().samples());
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
QOpenGLFramebufferObjectFormat format;
format.setInternalTextureFormat(m_format);
format.setMipmap(m_mipmap);
if (m_recursive) {
deleteFboLater = true;
delete m_secondaryFbo;
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
delete m_fbo;
delete m_secondaryFbo;
m_fbo = new QOpenGLFramebufferObject(m_size, format);
m_secondaryFbo = 0;
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_fbo);
}
}
}
if (m_recursive && !m_secondaryFbo) {
// m_fbo already created, m_recursive was just set.
Q_ASSERT(m_fbo);
Q_ASSERT(!m_multisampling);
m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format());
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
}
// Render texture.
root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update.
m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update.
#ifdef QSG_DEBUG_FBO_OVERLAY
if (qmlFboOverlay()) {
if (!m_debugOverlay)
m_debugOverlay = new QSGSimpleRectNode();
m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height()));
m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40));
root->appendChildNode(m_debugOverlay);
}
#endif
m_dirtyTexture = false;
m_renderer->setDeviceRect(m_size);
m_renderer->setViewportRect(m_size);
QRectF mirrored(m_mirrorHorizontal ? m_rect.right() : m_rect.left(),
//.........这里部分代码省略.........
示例4: updatePaintNode
QSGNode* NodeConnectionLines::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) {
if (!m_nodeObject) return nullptr;
const QVector<QPointer<NodeBase>>& connectedNodes = m_nodeObject->getConnectedNodes();
int connectionCount = connectedNodes.size();
// -------------------- Prepare QSG Nodes:
QSGNode* parentNode = oldNode;
if (!oldNode) {
parentNode = new QSGNode();
} else {
// update color in case it changed:
// FIXME: is there a more efficient way to do this?
for (int i=0; i<parentNode->childCount(); ++i) {
QSGGeometryNode* childNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!childNode) continue;
QSGFlatColorMaterial* material = static_cast<QSGFlatColorMaterial*>(childNode->material());
if (!material) continue;
material->setColor(m_color);
}
}
// adapt child count:
int childCount = parentNode->childCount();
if (childCount < connectionCount) {
for (int i=0; i<(connectionCount - childCount); ++i) {
QSGGeometryNode* node = new QSGGeometryNode;
QSGGeometry* geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
QSGFlatColorMaterial* material = new QSGFlatColorMaterial;
material->setColor(m_color);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
parentNode->appendChildNode(node);
}
} else if (childCount > connectionCount) {
for (int i=0; i<(childCount - connectionCount); ++i) {
parentNode->removeChildNode(parentNode->childAtIndex(0));
}
}
Q_ASSERT(parentNode->childCount() == connectionCount);
// calculate common start point:
const QPointF p0(width(), height() / 2);
double widthOffset = m_lineWidth / 2;
//const QPointF posInScene = mapToScene(QPointF(0, 0));
for (int i=0; i<connectionCount; ++i) {
NodeBase* otherNode = connectedNodes[i];
if (!otherNode) continue;
QQuickItem* otherGuiItem = otherNode->getGuiItem();
if (!otherGuiItem) continue;
const QPointF p3 = mapFromItem(otherGuiItem, QPointF(-otherGuiItem->width() / 2, otherGuiItem->height() / 2));
int handleLength = std::max(50, std::min(int(p3.x() - p0.x()), 80));
const QPointF p1(p0.x() + handleLength, p0.y());
const QPointF p2(p3.x() - handleLength, p3.y());
// calculate reasonable segment count:
int segmentCount = qMax(16.0, qMin(qAbs(p3.y() - p0.y()) / 25, 50.0));
int verticesCount = segmentCount * 2;
QSGGeometryNode* qsgNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!qsgNode) continue;
QSGGeometry* geometry = qsgNode->geometry();
if (!geometry) continue;
geometry->allocate(verticesCount);
QSGGeometry::Point2D* vertices = geometry->vertexDataAsPoint2D();
// triangulate cubic bezier curve:
for (int i = 0; i < segmentCount; ++i) {
// t is the position on the line:
const qreal t = i / qreal(segmentCount - 1);
// pos is the point on the curve at "t":
const QPointF pos = calculateBezierPoint(t, p0, p1, p2, p3);
// normal is the normal vector at that point
const QPointF normal = normalFromTangent(calculateBezierTangent(t, p0, p1, p2, p3));
// first is a point offsetted in the normal direction by lineWidth / 2 from pos
const QPointF first = pos - normal * widthOffset;
// ssecond is a point offsetted in the negative normal direction by lineWidth / 2 from pos
const QPointF second = pos + normal * widthOffset;
// add first and second as vertices to this geometry:
vertices[i*2].set(first.x(), first.y());
vertices[i*2+1].set(second.x(), second.y());
}
// tell Scene Graph that this items needs to be drawn:
qsgNode->markDirty(QSGNode::DirtyGeometry);
}
return parentNode;
}