QUItCoding / qnanopainter

Library for implementing OpenGL accelerated Qt (Quick) C++ UI components.
http://quitcoding.com
Other
393 stars 77 forks source link

multiple quickwindow scenegraph couldn't render correct #80

Open msinamsh opened 5 months ago

msinamsh commented 5 months ago

@cinderblocks @jcelerier @jarkkokoivikko-code-q @NielsMayer i designed an app using scenegraph for rendering some 2d on qtquick and qml. My goal is render some 2d content on main window and another 2d content on a seprate window. I load my app from c++ with this code : ` QGuiApplication app(argc, argv); QQmlApplicationEngine engine;

if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)

ifndef QNANO_USE_RHI

QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

endif

endif

const QUrl url(u"qrc:/NoroView/Main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
    &app, []() { QCoreApplication::exit(-1); },
    Qt::QueuedConnection);

engine.load(url);

return app.exec();

`

and QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

is for set graphics api for using on scene graph and its ok. like this photo:

Screen Shot 2024-01-30 at 2 17 59 AM

Everything goes fine with just one window(main window) but when i open another seprate window to render second content on it using ApplicationWindow from qml texts on the main window get unreadable and content on the second window turn into mono color(just green) and the texts will get completely unreadable as you can see in below image

Screen Shot 2024-01-30 at 2 20 09 AM

and i think its because i cant use setgraphicsapi for second window that i opened from qml with ApplicationWindow

. and maybe its because i should render scenegraph with multithread according to this link: https://doc.qt.io/qt-6/qtquick-visualcanvas-scenegraph.html#what-if-there-is-no-or-more-than-one-window-visible

but i dont know how can i

msinamsh commented 5 months ago

@jcelerier @NielsMayer @jarkkokoivikko-code-q @gunrot @mariuszmaximus @BaCaRoZzo @kgron @jarkkokoivikko-code-q please help me i use qnanopainter and all thing is good but i just stoped my project because of this problem

QUItCoding commented 5 months ago

@msinamsh I tested this today and was able to reproduce the issue when RHI is not used (so it worked with QNANO_USE_RHI). I think the issue is not about setting the OpenGL for multiple windows, but sharing the same QNanoPainter instance. Added a new QNANO_ENABLE_PAINTER_SHARING define with the new commit https://github.com/QUItCoding/qnanopainter/commit/e46cfaf3b50beb775dcd5c6129a34808e6d34a69 . When I disable QNANO_ENABLE_PAINTER_SHARING, QNanoPainter works for me from multiple windows.

If someone has more time to debug this, why it happens, propose alternative fix with sharing enabled etc. please do 🙂

msinamsh commented 5 months ago

@QUItCoding oww thanks a lot sir you make my day. thank you very very much!

hartcw commented 4 months ago

In Qt, if you want to share OpenQL objects (textures etc) across multiple QOpenGLContexts, then you have to enable the Qt::AA_ShareOpenGLContexts attribute early when your app starts up.

QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);

For the QNanoWidget path, because each QNanoWidget gets its own QOpenGLContext instance, but the QNanoPainter is a global singleton, the app must enable this attribute if they use more than one QNanoWidget.

I'm not sure about the QNanoQuickItemPainter code paths, but maybe it is affected by the same issue?