[Qt-qml] Problems with QML with OpenGL viewport

230 views
Skip to first unread message

Andrea Bernabei

unread,
Jan 15, 2012, 5:24:35 AM1/15/12
to qt-...@qt.nokia.com
hi guys :)

I’m writing a 3d model viewer, so basically I want to pass my glview
to QML to use it as an element and add the rest of the UI with QML…

My current problem is that only the element which represents my glview
(a custom QDeclarativeItem with reimplemented paint() with OpenGLES
2.0 calls) is shown, the rest (2 toolbars and some more) is all black.

But when I hit the buttons on the (black) toolbar (or scroll a
listview) those elements are shown, flickering with black, as if they
were trying to get the top view but the black layer was trying to
cover them again.

I have tried changing the setViewportUpdateMode, and that doesn’t help
(I have tried all values)…unless I set it to FullViewportUpdate, in
which case the UI is always repainted and FPS goes from 36 (with the
3D model viewer and all the rest under the black layer) to 22!!

So what I’d like to accomplish is: get what is inside my custom QML
element (QDeclarativeItem) repainted (i.e. the 3D Model), without
repainting the rest of the elements of the UI (toolbars, etc) because
that is useless and eats a lot of FPS…but without painting black over
all the UI elements (as it currently does)!

can you guys help me out? :)

Here’s the setup of my app

    QApplication::setGraphicsSystem("opengl");
    Q_INIT_RESOURCE(common);
    qmlRegisterType<modelviewer>("Test", 1, 0, "Viewer");
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);

    QGLWidget* renderer = new QGLWidget();

    //if setAutoFillBackground is true I get the 3D model painted, and
the rest is all WHITE, if it is false, the 3D Model is painted, and
the rest is all BLACK
    renderer->setAutoFillBackground(false);
    viewer->setViewport(renderer);

    viewer->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->setAttribute(Qt::WA_NoSystemBackground);
    viewer->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->viewport()->setAttribute(Qt::WA_NoSystemBackground);

    viewer->setMainQmlFile(QLatin1String("qml/main2.qml"));


Thanks in advance to anyone who will try to help me :)
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Alan Alpert

unread,
Jan 15, 2012, 9:24:49 PM1/15/12
to qt-...@qt.nokia.com, ext Andrea Bernabei

I don't know much about mixing opengl rendering with graphics view rendering,
but I do know it has already been done by one project.

QtQuick3D provides QML elements that can render your 3D model without even
having to use C++! See http://doc.qt.nokia.com/qt-quick3d-snapshot/qml-
mesh.html

If QtQuick3D still doesn't do what you want, its docs will probably help you
anyway. Implementing a custom QtQuick3D Item that paints in OpenGL should be a
lot better documented than doing the same with a 2D QtQuick Item. They've
probably even considered the repainting aspects, since they also have a scene
tree like GraphicsView does.

Source (For Qt4.x, For Qt5.x see codereview.qt-project.org):
http://qt.gitorious.org/qt-labs/qt3d
The Qt3D mailing list:
http://lists.trolltech.com/mailman/listinfo/qt-3d

--
Alan Alpert
Senior Engineer
Nokia, Qt Development Frameworks

Adriano Rezende

unread,
Feb 4, 2012, 8:44:15 AM2/4/12
to Andrea Bernabei, qt-...@qt.nokia.com
On Sun, Jan 15, 2012 at 8:24 AM, Andrea Bernabei <and.be...@gmail.com> wrote:

I have tried changing the setViewportUpdateMode, and that doesn’t help
(I have tried all values)…unless I set it to FullViewportUpdate, in
which case the UI is always repainted and FPS goes from 36 (with the
3D model viewer and all the rest under the black layer) to 22!!
 
When you set the viewport to use OpenGL you cannot use partial updates, since opengl just operates with full updates. But as suggested the best approach for you is to use Qml3D project, which I think already handles this integration probably rendering to a frame buffer object.

Br,
Adriano
Reply all
Reply to author
Forward
0 new messages