OpenGL (QGLWindow) functionality in QDeclarativeView
-
Hi,
I am working on a project for Sailfish OS (Qt 4.8) app.
I need to integrate openGL into QML using a QDeclarativeView.
Seen and tried the examples as shown in the Qt Forums.
They all:
set a QGLWidget as the viewport of the QDeclarativeView;
Use a QDeclarativeItem and re-implement the paint function with:
beginNativePainting() etc.;
qmlRegisterType is used to bind the QDeclarativeItem class to a QML type.This looks nice (as in the examples) if you have some simple fixed pipeline rendering, but I need to use a lot of extra openGL functionality (like setAttribute, QGLShaderProgram, compileSourceCode, etc.).
This is all neatly implemented in QGLWidget, but not in QDeclarativeItem which is now responsible for the openGL rendering/painting.
So, is there a way have the QGLWidget available / accessible in QML?
Thanks. -
This may not be the answer you're looking for, but the kind of things you're trying to do is possible with little effort with QtQuick 2 (Qt5). With QtQuick2 your more or less directly manipulate OpenGL data in custom Qml items.
Using Qt 4.8, i'm not sure how you could do that without creating your own QPainter+QGLWidget+QDeclarativeView+QDeclarativeItem to support custom advanced painting commands. And very likely need to modify private implementation of those classes too.
-
I have now made a MyDeclarativeView class derived from QDeclarativeView.
Next I have added my QGLWindow as a child Widget to MyDeclarativeView.
Further MyDeclarativeView sets a QGraphicsScene (setScene) to which I add QML items (addItem).
Seems to work, but I am not sure if this is all sound.... -
(I guess you meant QDeclarative(View))
Yes you can implement it manually that way. I'm not sure if making the QGLWindow a child of your view will render it or not. If not, you may want to make it a sibling of your View.
I'm very curious about it if you succeed, interesting problem.
-
QDeclarative(View) corrected. Sorry.
Yes it works as desktop app.
Only had to:
@view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);@
(view = MyDeclarativeView object).Now try it on Sailfish...
I'll report back. -
Does not crash on Sailfish, but QGLWindow stays black...
Possibly a openGL issue with the simulator.
And had to comment out:
#ifdef HAS_BOOSTER
view = MDeclarativeCache::qDeclarativeView();
#else...
because I have my own QDeclarativeView derived class.
I'll ask about it on the Sailfish list. -
Just found out that signals in QML (to c++) don't work.
Changed QDeclarativeView->setScene etc. to QDeclarativeView->setSource
Now it works.
QGLWindow overlaps qml page.