[Interest] Custom QQuickItem with smooth painting

Gunnar Sletta gunnar at sletta.org
Wed Jan 28 07:51:25 CET 2015


Which platform / hardware is this?

If you run your code with QSG_INFO=1 in the environment, does it report how many samples it finds? (16 is usually the absolute max on desktop hardware, 8 on some. 4 is usually the cap on embedded).

If the hardware or GL stack doesn’t support multisampling, it should fall back to no multisampling, which should be the same as the default. It looks as if Qt thinks it is using multisampling while in fact there is none. 

cheers,
Gunnar

> On 28 Jan 2015, at 00:33, Ruslan Moukhlynin <ruslan at khvmntk.ru> wrote:
> 
> Thanks for the answer!
> 
> In my case setting samples makes the output even worse then without setting it. I've tried 16 and 255, nothing works.
> 
> Setting format.setSamples() removes any antialiasing at all.
> 
> Without format.setSamples() - http://pbrd.co/1EO9GRh <http://pbrd.co/1EO9GRh>
> 
> 
> With format.setSamples() - http://pbrd.co/1EO9KjX <http://pbrd.co/1EO9KjX>
> 
> The yellow star is my shape I want to paint with antialiasing. The rectangle is QML Rectangle with radius set.
> 
> 
> 
> 27.01.2015 17:22, Gunnar Sletta пишет:
>> You can either rely on multisample antialiasing by doing:
>> 
>> QQuickView view;
>> QSurfaceFormat format = view.requestedFormat();
>> format.setSamples(16); // set as high as possible, will be cut back to what is supported
>> view.setFormat(view);
>> 
>> view.setSource(“my.qml”);
>> 
>> view.show();
>> 
>> By requesting a multisampled OpenGL context, all primitives will be antialiased. Depending on your hardware, this might come at a performance cost though. 
>> 
>> If you don’t want to rely on multisampling, you need to create triangles along the edges of your line to “fake” an antialiased edge, like you already found out that the default rectangle implementation does. 
>> 
>> -
>> cheers,
>> Gunnar
>> 
>>> On 27 Jan 2015, at 02:49, Ruslan Moukhlynin <ruslan at khvmntk.ru <mailto:ruslan at khvmntk.ru>> wrote:
>>> 
>>> Hi all!
>>> In my app I use some custom QML element, for simplicity it just a line.
>>> 
>>> So I overrided QQuickItem::updatePaintNode and inside it I paint my element.
>>> 
>>> QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);
>>> geometry->setDrawingMode(GL_LINES);
>>> geometry->setLineWidth(3);
>>> geometry->vertexDataAsPoint2D()[0].set(0, 0);
>>> geometry->vertexDataAsPoint2D()[1].set(width(), height());
>>> 
>>> QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
>>> material->setColor(QColor(255, 0, 0));
>>> 
>>> QSGGeometryNode *node = new QSGGeometryNode;
>>> node->setGeometry(geometry);
>>> node->setFlag(QSGNode::OwnsGeometry);
>>> node->setMaterial(material);
>>> node->setFlag(QSGNode::OwnsMaterial);
>>> 
>>> But this line looks so ugly. There is no antialiasing at all here.
>>> Ok, I 've looked through QSGDefaultRectangleNode source from $QTDIR/Src/qtdeclarative/src/quick/scenegraph and tried to implement its QSGSmoothColorMaterial instead of QSGFlatColorMaterial but nothing works, I just get segmentation fault.
>>> I can't see call stack, just some assembler code so I cannot find the problem line in my code.
>>> 
>>> So my question is very simple - how can I paint smooth line in custom QQuickItem item? Any advice, example or suggestions will be greatly appreciated!
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150128/6380685a/attachment.html>


More information about the Interest mailing list