Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSGGeometry / scenegraph: how to reuse data from QSGGeometry



  • Hi,

    I am using scenegraph to generate a chart and so each x ms I get a new data sample from the input module. Now I regenerate the data constantly using a for loop:
    @
    QSGGeometry* geometryNewLine = mNodeNewLine->geometry();
    geometryNewLine->allocate(mLoopVertices->newLineVertices.count());
    QSGGeometry::ColoredPoint2D *verticesNewLine = geometryNewLine->vertexDataAsColoredPoint2D();

        for (int i=0; i<mLoopVertices->newLineVertices.count(); i++)
        {
            color = mLoopVertices->newLineVertices.at(i).second ? colorInspiration : colorExpiration;
            verticesNewLine[i].set(//adapt vertice
                                   mLoopVertices->newLineVertices.at(i).first.x, mLoopVertices->newLineVertices.at(i).first.y,
                                   //adapt color
                                   color.red(), color.green(), color.blue(), color.alpha()
                                   );
        }
    

    @
    But this is taking quite some time and performance of course ... now I do not seem to see in the documentation a method for updating this with one new sample at the time? Do I always need to copy everything?

    A immediate easy update could be using a QVector in code outside of the updatePaintNode and then get the data as an array out of it and doing a memcopy or some sort (std::copy).

    Still I wonder if there is not an easier way of updating part of the data through QSGGeometry instead of always copying everything,

    thanks in advance,

    kind regards,

    Tim

    [edit, code tags added, koahnig]



  • Please check out the "code wrapping section":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 in the forum help. This helps to make your code more readable in the forum.


Log in to reply