On 14/01/2019 22:10, Jérôme Godbout wrote:
Hi,

I'm trying to enable the antialiasing inside my project that use QQmlApplicationEngine (currently under Linux). I have some QMl Shape that look ugly and the antialiasing doesn't seem to work at all. What is the proper way to enable the AA that is cross platform and will work on both QtCreator debug and release mode?

Note that debug/release mode has nothing to do with this...

Assuming that you're using the OpenGL backend:

I have try to enable the default surface at the very beginning of the main, after the application is created or even on the QWindow surface, but nothing seem to work:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSurfaceFormat>
#include <QQuickWindow>
#include <QOpenGLContext>

#define NB_AA_SAMPLE 8

void EnableAntialiasingOnEngine(QGuiApplication& app)
{
     QWindow* window = app.topLevelWindows().first();
     QSurfaceFormat surface_format; // = window->format();
     surface_format.setSamples(NB_AA_SAMPLE); // AA sampling
     window->setFormat(surface_format);
}

This is meaningless; you need to set the format on the window AND the context and you need to do so before they're created (in the sense of calling create() on them). In other words, this is incomplete and too late.

void EnableAA()
{
     QOpenGLContext ogl_context;
     QSurfaceFormat surface_format;
     surface_format.setSamples(NB_AA_SAMPLE);
     ogl_context.setFormat(surface_format);
     if(!ogl_context.create())
     {
         qWarning("Cannot create OpenGL context for AA.");
     }
}

This might be useful as a check that you CAN create an OpenGL context that supports MSAA. But note that the mere creation isn't enough, you need to get the format back from the created context (context.format()) and check *that*.


void EnableDefaultAA()
{
     QSurfaceFormat surface_format = QSurfaceFormat::defaultFormat();
     surface_format.setSamples(NB_AA_SAMPLE); // AA sampling
     QSurfaceFormat::setDefaultFormat(surface_format);
}

This is the correct way and should work, given you call this before creating QGuiApplication. If the result is still aliased, grab the root object, downcast it (it's going to be some QQuickWindow subclass), get its OpenGL context after it has been created (openglContext(), or connect to openglContextCreated()), and dump its format. Thus double checking that your implementation DOES support multisampling...

My 2 c,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to