Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Minimal QQuickFramebufferObject code triggers error: "glLinkProgram - GL_INVALID_ENUM" in CodeXL

Minimal QQuickFramebufferObject code triggers error: "glLinkProgram - GL_INVALID_ENUM" in CodeXL

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
openglruntime error
1 Posts 1 Posters 628 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefan Monov76
    wrote on 4 Jan 2017, 18:17 last edited by
    #1

    I've cleaned up the Qt example "textureinsgnode" to produce something more minimal. But when I run the code in the CodeXL OpenGL debugger (with "Break on OpenGL error" enabled), it breaks in the QOpenGLShaderProgram::link function, with the message "glLinkProgram - GL_INVALID_ENUM". This confuses me, because glLinkProgram doesn't take any enums, only a program id.

    Why is this error happening?

    Note that the program works fine outside CodeXL.

    Platform note: This has been tested only on one PC, with the following specs:

    • OS: Ubuntu Linux 16.04
    • GPU: Mobile Intel(R) 4 Series Express Chipset Family

    My code

    As I said, I've based my testcase on the textureinsgnode sample app bundled with Qt. Since mine is a derived work, I have to first post the license terms here:

    /****************************************************************************
    **
    ** Copyright (C) 2015 The Qt Company Ltd.
    ** Contact: http://www.qt.io/licensing/
    **
    ** This file is part of the examples of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:BSD$
    ** You may use this file under the terms of the BSD license as follows:
    **
    ** "Redistribution and use in source and binary forms, with or without
    ** modification, are permitted provided that the following conditions are
    ** met:
    **   * Redistributions of source code must retain the above copyright
    **     notice, this list of conditions and the following disclaimer.
    **   * Redistributions in binary form must reproduce the above copyright
    **     notice, this list of conditions and the following disclaimer in
    **     the documentation and/or other materials provided with the
    **     distribution.
    **   * Neither the name of The Qt Company Ltd nor the names of its
    **     contributors may be used to endorse or promote products derived
    **     from this software without specific prior written permission.
    **
    **
    ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
    

    And now for the actual source.

    main.cpp: (trivial)

    #include <QGuiApplication>
    
    #include <QtQuick/QQuickView>
    
    #include "myitem.h"
    
    int main(int argc, char **argv)
    {
        QGuiApplication app(argc, argv);
    
        qmlRegisterType<MyItem>("MyItem", 1, 0, "MyItem");
    
        QQuickView view;
        view.setResizeMode(QQuickView::SizeRootObjectToView);
        view.setSource(QUrl("qrc:///main.qml"));
        view.show();
    
        return app.exec();
    }
    

    myitem.cpp:

    #include "myitem.h"
    #include "myitemglcode.h"
    
    #include <QtGui/QOpenGLFramebufferObject>
    
    class MyItemRenderer : public QQuickFramebufferObject::Renderer
    {
    public:
        MyItemRenderer()
        {
            glCode.initializeGL();
        }
    
        void render() {
            glCode.renderGL();
            update();
        }
    
        QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) {
            QOpenGLFramebufferObjectFormat format;
            format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
            return new QOpenGLFramebufferObject(size, format);
        }
    
        MyItemGLCode glCode;
    };
    
    QQuickFramebufferObject::Renderer *MyItem::createRenderer() const
    {
        return new MyItemRenderer();
    }
    

    myitem.h:

    #ifndef MYITEM2_H
    #define MYITEM2_H
    
    #include <QtQuick/QQuickFramebufferObject>
    
    class MyItem : public QQuickFramebufferObject
    {
        Q_OBJECT
    public:
        Renderer *createRenderer() const;
    };
    
    #endif
    

    myitemglcode.cpp:

    #include "myitemglcode.h"
    
    void MyItemGLCode::paintQtLogo()
    {
        program1.enableAttributeArray("vertex");
        program1.setAttributeArray("vertex", vertices.constData());
        glDrawArrays(GL_TRIANGLES, 0, vertices.size());
        program1.disableAttributeArray("vertex");
    }
    
    void MyItemGLCode::initializeGL()
    {
        initializeOpenGLFunctions();
    
        QOpenGLShader *vshader1 = new QOpenGLShader(QOpenGLShader::Vertex, &program1);
        const char *vsrc1 =
            "attribute highp vec4 vertex;\n"
            "uniform mediump mat4 matrix;\n"
            "varying mediump vec4 color;\n"
            "void main(void)\n"
            "{\n"
            "    gl_Position = matrix * vertex;\n"
            "}\n";
        vshader1->compileSourceCode(vsrc1);
    
        QOpenGLShader *fshader1 = new QOpenGLShader(QOpenGLShader::Fragment, &program1);
        const char *fsrc1 =
            "varying mediump vec4 color;\n"
            "void main(void)\n"
            "{\n"
            "    gl_FragColor = vec4(0.40, 1.0, 0.0, 1.0);\n"
            "}\n";
        fshader1->compileSourceCode(fsrc1);
    
        program1.addShader(vshader1);
        program1.addShader(fshader1);
        program1.link();
    
        m_fAngle = 0;
        createGeometry();
    }
    
    void MyItemGLCode::renderGL()
    {
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glDisable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
    
        QMatrix4x4 modelview;
        modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
        modelview.translate(0.0f, -0.2f, 0.0f);
    
        program1.bind();
        program1.setUniformValue("matrix", modelview);
        paintQtLogo();
        program1.release();
    
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_CULL_FACE);
    
        m_fAngle += 1.0f;
    }
    
    void MyItemGLCode::createGeometry()
    {
        vertices.clear();
    
        vertices << QVector3D(0, 0, 0.0f);
        vertices << QVector3D(1, 0, 0.0f);
        vertices << QVector3D(0, 1, 0.0f);
    }
    

    myitemglcode.h:

    #ifndef MYITEMGLCODE_H
    #define MYITEMGLCODE_H
    
    #include <QtGui/qvector3d.h>
    #include <QtGui/qmatrix4x4.h>
    #include <QtGui/qopenglshaderprogram.h>
    #include <QtGui/qopenglfunctions.h>
    
    #include <QVector>
    
    class MyItemGLCode : protected QOpenGLFunctions
    {
    public:
        void renderGL();
        void initializeGL();
    
    private:
        qreal   m_fAngle;
    
        QVector<QVector3D> vertices;
        QOpenGLShaderProgram program1;
    
        void paintQtLogo();
        void createGeometry();
    };
    #endif
    

    main.qml:

    import QtQuick 2.0
    
    import MyItem 1.0
    import QtQuick.Layouts 1.3
    
    Item {
        width: 400
        height: 400
        Image {
    
            source: "/bg.png"
            anchors.fill: parent
            fillMode: Image.Stretch
        }
    
        MyItem {
            anchors.fill: parent
        }
    }
    

    I think it may be a problem in the cheap Intel GPU/drivers I have, or maybe it's a bug in CodeXL.

    Note that the return value value of link() in my code is true, meaning "success".

    I've also uploaded the complete testcase project here, if you want to run it more easily. (the download button is at the top-right corner of that page).

    1 Reply Last reply
    0

    1/1

    4 Jan 2017, 18:17

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved