[Interest] Antialiasing possible on QSGGeometry?

Sletta Gunnar Gunnar.Sletta at digia.com
Tue Jun 11 08:52:08 CEST 2013


On Jun 10, 2013, at 8:59 PM, Mark <markg85 at gmail.com> wrote:

> Ahh oke, so i can't do a multisampling mode per geometrynode.. That
> kinda sucks because a grid looks a bit blurred when multisampling is
> running on everything.

blurring occurs when you place pixels outside the pixel boundary. If you target your pixels to be 1px wide and position them at the right position, they will not be antialiased..

There are two pitfalls here though..

- If you use anchors.centerIn and your parent has an odd width/height, the item will be positioned at an 0.5 pixel offset and stuff will be smudged.

- If you use GL_LINE, be cautious about where you position your lines. You can look at a single-width line as the rasterization of a that expands lineWidth/2 to each side of the line. If you draw a line from (0, 0) - (100, 0) width lineWidth = 1 it will be two pixels tall and have 50% coverage. If you draw it at (0, 0.5) - (100, 0.5) however, it will be solid. (These coordinates assumes that you use the default projection matrix set by QQuickWindow which scales the coordinate system to the pixelsize of the window).

QPainter will do the exact same when antialiasing is enabled, btw :)


> Damn, OpenGL is way more difficult then
> QPainter!

Can't argue with that :)

> And also way more inaccurate.

it really isn't, but it does take a lot more effort :)

cheers,
Gunnar

> 
> On Mon, Jun 10, 2013 at 9:56 AM, Sletta Gunnar <Gunnar.Sletta at digia.com> wrote:
>> Multisampling is a property of the OpenGL context of the window and it must be set before it is created, that is before the QQuickView is shown the very first time. Once the OpenGL context is created, you can't change it.
>> 
>> On Jun 7, 2013, at 9:32 PM, Mark <markg85 at gmail.com> wrote:
>> 
>>> Hi Gunnar,
>>> 
>>> That's an interesting solution!
>>> 
>>> But how do i get a QQuickView from within a custom component that
>>> inherits from QQuickItem?
>>> My component is meant to be a QML Plugin, not a standalone QML application.
>>> 
>>> Cheers,
>>> Mark
>>> 
>>> On Fri, Jun 7, 2013 at 8:12 AM, Sletta Gunnar <Gunnar.Sletta at digia.com> wrote:
>>>> You need to set the surface format of your QQuickView.
>>>> 
>>>> QQuickView view;
>>>> QSurfaceFormat format = view.format();
>>>> format.setSamples(16);
>>>> view.setFormat(format);
>>>> view.show();
>>>> 
>>>> If your graphics hardware supports multisample antialiasing, you will now have antialiased geometry.
>>>> 
>>>> As the scene graph might require depth/stencil buffer for its renderer, it is a bit important that you inherit the original surface format from the view instead of creating a new one from scratch.
>>>> 
>>>> qmlscene supports this out of the box by passing --multisample as a command line option.
>>>> 
>>>> cheers,
>>>> Gunnar
>>>> 
>>>> On Jun 7, 2013, at 12:12 AM, Mark <markg85 at gmail.com> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> Another day, another question :)
>>>>> Don't worry, i plan on making a big blog about everything. This
>>>>> information won't get lost.
>>>>> 
>>>>> So today i'm trying to draw a custom shape by setting vertices. More
>>>>> specifically a GL_QUAD_STRIP.
>>>>> 
>>>>> It looks like this (obviously just testing data)
>>>>>  QSGGeometry *geometry = new
>>>>> QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 8);
>>>>>  geometry->setDrawingMode(GL_QUAD_STRIP);
>>>>>  geometry->vertexDataAsPoint2D()[0].set(0, 100);
>>>>>  geometry->vertexDataAsPoint2D()[1].set(0, height());
>>>>>  geometry->vertexDataAsPoint2D()[2].set(width() / 4, 80);
>>>>>  geometry->vertexDataAsPoint2D()[3].set(width() / 4, height());
>>>>>  geometry->vertexDataAsPoint2D()[4].set(width() / 2, 110);
>>>>>  geometry->vertexDataAsPoint2D()[5].set(width() / 2, height());
>>>>>  geometry->vertexDataAsPoint2D()[6].set(width(), 150);
>>>>>  geometry->vertexDataAsPoint2D()[7].set(width(), height());
>>>>> 
>>>>>  QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
>>>>>  material->setColor(QColor(255, 0, 0, 128));
>>>>> 
>>>>>  QSGGeometryNode *n = new QSGGeometryNode;
>>>>>  n->setGeometry(geometry);
>>>>>  n->setFlag(QSGNode::OwnsGeometry);
>>>>>  n->setMaterial(material);
>>>>>  n->setFlag(QSGNode::OwnsMaterial);
>>>>> 
>>>>> So roughly the same as the example [1] only with a quad strip.
>>>>> However, this ends up looking a bit aliased.. So the question is: How
>>>>> do i get this anti-aliased?
>>>>> 
>>>>> I did read something about multisampling and setting the number of
>>>>> samples, but i can't find such a function in any of the used classes..
>>>>> 
>>>>> Kind regards,
>>>>> Mark
>>>>> 
>>>>> [1] http://qt-project.org/doc/qt-5.0/qtquick/qsggeometrynode.html
>>>>> _______________________________________________
>>>>> Interest mailing list
>>>>> Interest at qt-project.org
>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>> 
>> 




More information about the Interest mailing list