[Interest] QPainter questions
maitai
maitai at virtual-winds.org
Sun May 14 20:06:42 CEST 2017
Hello all,
I am using QPainter (Qt 5.8) to render quite complex QImages, meaning
many calls to drawPath, drawPolygons and drawPolyLines;
I have noticed that a very costly operation is drawPolylines. It gets
much better if I use drawLines, but the result is ugly due to non-joined
lines and (as it seems) no antialising. It is also much faster if I just
set antialiasing off, but again with poor image quality in the end.
Several questions here:
1) Is there something I can do to improve things with drawPolylines,
even at a small cost in quality?
2) I tried to render on an openGL surface (QOffscreenSurface) instead of
QImage, not changing anything else in my program, i.e. still calling
QPainter::drawPolyLines and such, and converting back to a QImage in the
end. The result is that it works, but it is actually slower than regular
paintEngine... I was hoping for a big gain in speed especially
concerning antialising, but it is actually the opposite (1000ms with
openGL versus 800ms using QImage directly).
3) I also have to draw some other QImages in the final image with
QPainter::drawImage(). It works but the alpha channel of these images
appear in black when using the openGL version. I have tried a lot to
play with openGL options and format but no way so far.
What I am doing basically is:
#ifndef USE_S57_OPENGL
snapPix = QImage(myProj.getW(), myProj.getH(),
QImage::Format_ARGB32_Premultiplied);
snapPix.fill(Qt::transparent);
QPainter pnt(&snapPix);
#else
QSurfaceFormat format;
format.setMajorVersion(4);
format.setMinorVersion(3);
QOpenGLContext context;
//context.setFormat(format); //for some reason that does not work
context.create();
QOffscreenSurface surface;
surface.setFormat(format);
surface.create();
context.makeCurrent(&surface);
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setSamples(16); //or 4, does not make any difference
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
QOpenGLFramebufferObject fbo(myProj.getW(), myProj.getH(),
fboFormat);
fbo.bind();
QOpenGLPaintDevice device(QSize(myProj.getW(), myProj.getH()));
QPainter pnt(&device);
#endif
pnt.setRenderHint(QPainter::Antialiasing);
pnt.setRenderHint(QPainter::SmoothPixmapTransform);
(..... all the painting you can imagine ...)
pnt.end()
#ifdef USE_S57_OPENGL
fbo.release();
snapPix = fbo.toImage();
#endif
Thanks in advance for any advice. I am not an expert in openGL, needless
to say..
Philippe Lelong
More information about the Interest
mailing list