opengl-4qt5.3

Serious rendering issues with OpenGL 4.1 and Qt 5


I've seen some promising references to being able to run Qt5 on modern OpenGL. I'm using the following code to set my QQuickView to OpenGL 4.1 Core (the latest supported on OSX 10.9 with my MacBook).

QSurfaceFormat sf = g_mainView->format();
sf.setProfile(QSurfaceFormat::CoreProfile);
sf.setVersion(4, 1);
g_mainView->setFormat(sf);

Major issues. First, the app crashes entirely when trying to render text. If I happen to only have images, rectangles, etc in my QML, I get a ton of fragment shader errors.

QOpenGLShader::compile(Fragment): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:5: 'varying' : syntax error syntax error

*** Problematic Fragment shader source code ***
#define lowp
#define mediump
#define highp

            varying highp vec2 qt_TexCoord0;
            uniform highp float qt_Opacity;
            uniform lowp sampler2D source;
            uniform lowp sampler2D maskSource;
            void main(void) {
                gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity;
            }


***
QQuickCustomMaterialShader: Shader compilation failed:
"ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:5: 'varying' : syntax error syntax error
"

Is Qt5.3 not ready for modern OpenGL yet? Or am I simply setting it up incorrectly? I want to embed my own OpenGL graphics windows using OpenGL 4, so my assumption is that I need that app running under GL 4 as well. Is there another way?


Solution

  • I Added some comments to your bug report and voted it up. It is indeed a Qt bug, as stated here: https://www.opengl.org/wiki/Core_Language_%28GLSL%29#Version the first preprocessor directive should be #version, but Qt adds defines for lowp, mediump and highp on its own breaking this requirement. Nvidia drivers lets you get away with it, but Intel's does not (I do not know about ATI's), so perhaps the developers in charge did not test on different enough hardware configurations.

    As it is, there is no easy workaround, you could change the Qt code not to add those defines (which is a distribution nightmare), or not use the QOpenGLShader class, which means house keeping the raw OpenGL objects yourself.