QOpenGLTexture::allocateStorage causes GL_INVALID_VALUE error



  • Posting in this subforum as I think the error is not caused by my usage of Qt Quick.

    I've distilled this to trivial Qt code in which the only interesting thing is several lines in synchronize() handling a texture. I get a GL_INVALID_VALUE from the allocateStorage line. Anyone knows why? I suspect it's probably due to the parameters I pass to this function.

    My code:

    main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQuickFramebufferObject>
    #include <QOpenGLFramebufferObject>
    #include <QOpenGLFunctions>
    #include <QOpenGLTexture>
    
    class MyItem : public QQuickFramebufferObject {
        Q_OBJECT
    
    public:
        Renderer* createRenderer() const;
    };
    
    class MyItemRenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions {
    public:
        MyItemRenderer() {
            initializeOpenGLFunctions();
        }
    
        void render() {
        }
    
        QOpenGLFramebufferObject* createFramebufferObject(const QSize &size) {
            QOpenGLFramebufferObjectFormat format;
            format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
            return new QOpenGLFramebufferObject(size, format);
        }
    
    protected:
        void synchronize(QQuickFramebufferObject* qqfbo) {
            Q_UNUSED(qqfbo)
    
            QOpenGLTexture tex(QOpenGLTexture::Target2D);
            tex.setSize(100, 100);
            tex.allocateStorage(QOpenGLTexture::BGRA, QOpenGLTexture::Int8);
    
            qDebug() << "starting loop";
            GLenum err;
            while ((err = glGetError()) != GL_NO_ERROR) {
                qDebug("\tgl error: 0x%x", err, 0, 16);
            }
        }
    };
    
    QQuickFramebufferObject::Renderer* MyItem::createRenderer() const {
        return new MyItemRenderer();
    }
    
    int main(int argc, char **argv) {
        QGuiApplication app(argc, argv);
    
        qmlRegisterType<MyItem>("MyItem", 1, 0, "MyItem");
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    
    #include "main.moc"
    

    main.qml

    import QtQuick 2.0
    import MyItem 1.0
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 400
        height: 400
    
        MyItem {
            anchors.fill: parent
        }
    }


  • I found a solution and posted it on StackOverflow


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.