Unsolved QPainterPath Performance
-
Now I use QpainterPath to draw a mesh in QImage, like this:
Code:
QBrush* bs = new QBrush(*(pInfo->pImg)); bs->setStyle(Qt::TexturePattern); pait->setBrush(*bs); pait->setBrushOrigin(pInfo->rect.x(), pInfo->rect.y()); QPainterPath path; for (int i = pInfo->degree_start; i <= pInfo->degree_end; i += 2) { if (i > pInfo->pList->length - 4) { continue; } path.moveTo(QPointF(pInfo->pList->vtx[i].x, pInfo->pList->vtx[i].y)); path.lineTo(QPointF(pInfo->pList->vtx[i + 1].x, pInfo->pList->vtx[i + 1].y)); path.lineTo(QPointF(pInfo->pList->vtx[i + 3].x, pInfo->pList->vtx[i + 3].y)); path.lineTo(QPointF(pInfo->pList->vtx[i + 2].x, pInfo->pList->vtx[i + 2].y)); path.lineTo(QPointF(pInfo->pList->vtx[i].x, pInfo->pList->vtx[i].y)); } pait->fillPath(path, *bs); delete bs;
But I found when the points more than 1000, the drawing is very very slow. It need more than 20 seconds. My CPU is i5-9400F 2.9G. How to optimize it?
-
Maybe move the render to the opengl api and ditch QPainterPath altogether? It is reasonable that QPainterPath is for small discrete objects and not for complex meshes of many primitives. Alternately split it into multiple QPainterPaths and test. I'm not sure how easy it is to map an opengl render to QImage though.
-
@Kent-Dorfman So do I, I want to know how to use opengl in QPainterPath.