"QGLShaderProgram: shader programs are not supported" with OpenGL 3.2 in 5.0.1



  • I am trying to write an OpenGL 3.2 program using QT. Here is my journey:

    • Using Mac OS X Mountain Lion on a brand new MacBook Pro with latest graphics card
    • Using Qt 4.8, I could not instantiate an OpenGL context past 2.1
      ** Seems that several others have the same problem, the only workaround I could find was this hack: http://qt-project.org/forums/viewthread/8047
    • Using Qt 5.0.1, I can now instantiate an OpenGL 3.2 context. But, when I try to compile my shaders, I get "QGLShaderProgram: shader programs are not supported". I get this error whether I use QGLShaderProgram or QOpenGLShaderProgram.
      ** It seems that this is related to a bug in how Qt identifies which OpenGL features are available when using the core profile: http://qt-project.org/forums/viewthread/4856
      ** This forum posting implies that a fix was committed, but it seems that it never made it into 5.0?

    I'm using this as my format:
    @
    QGLFormat format;
    format.setVersion(3, 2);
    format.setProfile(QGLFormat::OpenGLContextProfile::CoreProfile);
    @

    Because the bug in identifying features is due to the CoreProfile, it seems that I should be able to fix it by switching to CompatibilityProfile. Indeeed, if I switch to CompatibilityProfile, it fixes the "shader programs are not supported" bug. But, it exposes a new bug - my OpenGL context is now 2.1 instead of 3.2, and my GLSL 1.5 shaders won't compile in a 2.1 context.

    Any imminent fixes / suggested workarounds? Thanks!



  • I'm having the same problem. I've been using a patched version of 4.8 to force it to use a 3.2 Core Profile context on Lion (works great). I was really hoping this would have been resolved in 5 so I could use a stock version of Qt on the Mac. I guess it is in the sense that it does get the correct context but now it thinks it doesn't have support for shaders.



  • How have you patched your 4.8? I can use the little core_profile_attributes.mm trick to make my 4.8 create an OpenGL 3.2 QGLContext, but I still get the "shader programs are not supported". I am using 4.8.3, which (as best I can tell) includes the patch to correctly determine what extensions are available (I can see the stuff that ZapB mentions in the previous thread).

    I went into qglextensions.cpp, qt_resolve_glsl_extensions(). I commented out this bit on lines 267-8.

    @
    if (!(QGLExtensions::glExtensions() & QGLExtensions::FragmentShader))
    return false;
    @

    and now I'm getting a memory access fault as soon as my program tries to create any sort of shader. This makes me think that the ctx->getProcAddress() calls are failing, which I presume means that the QGLContext that I made with this stuff

    @
    struct Core3_2_context : public QGLContext {
    Core3_2_context(const QGLFormat& format, QPaintDevice* device) : QGLContext(format,device) {}
    Core3_2_context(const QGLFormat& format) : QGLContext(format) {}

    virtual void* chooseMacVisual(GDHandle handle) {
        return select_3_2_mac_visual(handle);
    }
    

    };
    @

    isn't actually working...



  • I think I may actually have patched a version of 4.7 now that I'm looking at it. It's a version I cloned from the git repository well over a year ago. I just ended up forcing it to use a 3.2 context in qgl_mac.mm (set NSOpenGLProfileVersion3_2Core in the attribs[]), nothing special for the shaders. I tried applying the same modification to the latest 4.8.4 and it didn't even give me a 3.2 context (no crash though). All my attempts to modify 5.0.1 (similar to what you did above) have failed and it just crashes when it tries to create the shader.

    I may spend some time tomorrow adding some logging to the 5.0.1 source to see exactly where it's failing.



  • For 5.0.1 I got it working with minimal changes. I modified QGLExtensions::currentContextExtensions() in "qgl.cpp":

    @
    #if defined(QT_OPENGL_ES_2) || defined(Q_OS_MAC)
    glExtensions |= FramebufferObject;
    glExtensions |= GenerateMipmap;
    glExtensions |= FragmentShader;
    #endif
    @

    I just added the "defined(Q_OS_MAC)" and that did the trick. 3.2 with shaders, VAO, VBO, etc.



  • Awesome! Your easy little patch fixes 4.8.3 as well.

    However, it seems that QPainter doesn't work with OpenGL 3.2 Core Profile (I get lots of errors about shader compilation failures). I'm going to just disable overdrawing for now and continue.

    This tiny little fix would save anyone doing OpenGL 3.2 on Mac a ton of time, it would be awesome if it made it into the standard release!



  • Huh, guess I spoke too soon. Do you actually have a working application PixelDelirium?

    I can use Glew and raw OpenGL calls to draw some geometry on a QGLWidget.

    I can also use the QGLShaderProgram class and compile a shader without getting any errors. But when I use QGLBuffer and QGLShaderProgram, I can't get any geometry to render (neither 4.8.3 nor 5.0.1). The very same code and shaders worked under 2.1 (modified slightly for GLSL 1.5 vs 1.2, of course).



  • Yes, everything is working as expected. I'm using vertex, fragment and geometry shaders with VBOs. You aren't using any fixed pipeline calls, are you? They aren't available using the 3.2 core profile.



  • Huh. Nope, nothing fixed-function... Guess I'll keep digging!



  • Also, be sure to call glGetError() often, even after making any calls to QGL* functions, just in case. I've noticed (at least in 4.x) that they don't always handle/report errors.



  • I pretty much just had the exact same experience as nedtwigg. I have OS X Mountain Lion with a new card and a copy of Zap Brannigan's "Core Tutorial":http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt was not working properly. I pulled the #version lines down to #version 150 and dropped the use of layout() in simple.frag, but I had the 2.1 context issue with qt-4.8.2, then the "QGLShaderProgram: shader programs are not supported" issue with qt-5.0.1 and qt-5.0.2.

    I got a copy of the source and put in PixelDelirium's fix to qgl.cpp QGLExtensions::currentContextExtensions() described above, and the "shader programs are not supported" issue went away, but the triangle didn't show up. Because I am an idiot, rather than reading the tutorial and noticing that he tells you this, I instead brought out the GL profiler and compared what it was calling line by line with a working code until I noticed it wasn't instantiating a VAO. If you add these lines before you start building any QGLBuffer objects, the red triangle shows up as promised:

    @
    uint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    @

    It seems like hard coding that all OS X machines have support for shaders is probably not a real fix to this issue though. Isn't that what the qgl.cpp fix is doing?



  • Actually, I like this fix much better. If you take an unmodified qt-5.0.2 and the ZapB example, but instead of using QGLBuffer and QGLShaderProgram, use QOpenGLBuffer and QOpenGLShaderProgram, then it figures out that you've got shaders. It seems like this might be a better solution anyway since the "qt5 docs":http://qt-project.org/doc/qt-5.0/qtdoc/classes.html don't include QGLBuffer/QGLShaderProgram anymore. I still have to use the extra VAO lines mentioned above to get the red triangle, though.


Log in to reply
 

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