Select to view content in your preferred language

Direct QPainter based rendering and Antialiasing

2529
6
07-18-2018 09:08 PM
GabeLevy
Emerging Contributor

Hi,

I've been experimenting with ArcGISRuntime::MapGraphicsView, specifically I was to draw directly on top of the rendered map. I can successfully draw either by overriding MapGraphicsView::drawForeground(...) which receives QPainter* as its first parameter, or I also managed to do it via QGraphicsScene by retrieving the instance of it in the constructor of my MapGraphicsView derived subclass and then added to it my own QGraphicsObject based instance with its own rendering routine.

Both approaches function as expected with one exception - I'm unable to make the rendering of lines and ellipses to be anti-aliased. I have been using Scene item based rendering in my other projects and always managed to get the QPainter to draw the primitives anti-aliased by setting the QPainter::setRenderHint(QPainter::Antialiasing).

Since I can make the anti-aliasing work on other non-Esri types of projects, my guess is that the ArcGIS MapGraphicsView keeps tight control of the QPainter's rendering setting so even if I set the anti-aliasing inside the paint() function (on QGraphicsObject, or MapGraphicsView::drawForeground), it wont respect that flag.

Can you please help and clarify what I'm missing here and how can I make the direct painting look properly aliased?

Thank you in advance.

Kind regards

Gabe

0 Kudos
6 Replies
MichaelTims
Occasional Contributor

Hi Gabe,

I'm wondering if setting setRenderHint(QPainter::Antialiasing) on the MapGraphicsView in your application makes any difference?

Thanks.

-Michael

0 Kudos
GabeLevy
Emerging Contributor

Hello Michael,

I just tried it and unfortunately it makes not difference

The vector map that I downloaded under my ESRI dev account is properly anti-aliased and has always been when running my test app.

Only my direct drawings remain un-antialiased.

0 Kudos
MichaelTims
Occasional Contributor

Hi Gabe,

Thanks for trying that.  Bummer that it didn't do the trick.  I will try to repro on my end so I can do some troubleshooting.  We have seen problems in the past with OpenGL states being left dirty and the QPainter system not resetting the default state back properly for what the items require while painting.  It could be something like that going on since you've mentioned that you see the correct behavior when not consuming the ArcGIS Qt view.  I'll keep you posted.

-Michael

0 Kudos
GabeLevy
Emerging Contributor

Thanks Michael, I hope you'll be able to find the cause of this.

If you need any more info, please let me know.

Looking forward to your findings.

Gabe

0 Kudos
MichaelTims
Occasional Contributor

Hi Gabe,

I can work around the problem by specifying the number of samples to be used for multisampling.

This can be done in a couple ways:

1) In main.cpp before the QApplication is instantiated.

QSurfaceFormat fmt;
fmt.setSamples(8);
QSurfaceFormat::setDefaultFormat(fmt);

2) On the QGraphicsView's viewport directly.

In subclassed MapGraphicsView constructor:

auto openGlWidget = static_cast<QOpenGLWidget*>(viewport());
auto format = openGlWidget->format();
format.setSamples(8);
openGlWidget->setFormat(format);

However what I still need to find out is whether the MapGraphicsView should be setting up the number of samples by default.  I should have that information soon.

Thanks.

-Michael

GabeLevy
Emerging Contributor

Thanks, Michael.

The workaround indeed works - much appreciated.

Unless there is some valid reason for not making it default, I believe it would be more intuitive to make it so.

Thanks for finding the workaround and the code snippets.

Gabe

0 Kudos