devstone
devstone

Reputation: 21

why QQuickFramebufferObject::createRenderer not called?

I use Qt's official fboitem example, but it can't render properly. createRenderer should be called automatically inside the framework, and the log is printed and found that it is not called, so no rendering is performed.

But why isn't it called automatically?

Check out the Qt official mention that it is only called when the current program uses OpenGL rendering, but how to set the program to support OpenGL rendering? https://doc.qt.io/qt-6/qquickframebufferobject.html

this is simple code


class FboInSGRenderer : public QQuickFramebufferObject
{
    Q_OBJECT
    QML_NAMED_ELEMENT(Renderer)
public:
    Renderer *createRenderer() const;
};

class LogoInFboRenderer : public QQuickFramebufferObject::Renderer
{
public:
    LogoInFboRenderer()
    {
        logo.initialize();
    }

    void render() override {
        logo.render();
        update();
    }

    QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override {
        QOpenGLFramebufferObjectFormat format;
        format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
        format.setSamples(4);
        return new QOpenGLFramebufferObject(size, format);
    }

    LogoRenderer logo;
};

QQuickFramebufferObject::Renderer *FboInSGRenderer::createRenderer() const
{
    qDebug() << "#createRenderer call......";
    return new LogoInFboRenderer();
}

int main(int argc, char **argv)
{
    QGuiApplication app(argc, argv);

    QQuickView view;
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml"));
    view.show();

    return app.exec();
}

run result

So where am I going wrong?

My development environment:

Qt 5.15.2 MinGW64
Windows 10 Pro
Processor: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz 2.30 GHz
Graphics Card: NVIDIA GeForce MX330

Upvotes: 0

Views: 609

Answers (2)

pixelgrease
pixelgrease

Reputation: 2118

In Qt 6, at least in Qt 6.7, it may be necessary to add the following call to main.cpp before loading QML:

QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

QQmlApplicationEngine engine;

There is a call to isOpenGL() inside QQuickFramebufferObject::updatePaintNode() which if returns false prevents calling createRenderer().

Upvotes: 1

devstone
devstone

Reputation: 21

The problem is solved

My local registry was modified by some software

QMLSCENE_DEVICE =softwarecontext

So, just delete this and restart the computer and it will be ok

Upvotes: 1

Related Questions