3

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?

Evan
  • 2,441
  • 23
  • 36
  • This same code base compiles on Linux. Tested the same Surface Format code there. It bombs using the core profile, but works using compatibility. I thought Qt 5.2 and higher was supposed to work with core. See Sean's comments in this video https://www.youtube.com/watch?v=YqlaKY0a1hg. What do I need to do? Mac does not provide a compatibility profile with modern gl. – Evan Sep 16 '14 at 23:09
  • this problem still exists in the 5.4, not on windows, as on windows it return the compatibility profile. – emailhy Nov 05 '14 at 14:38
  • I'm still having rendering problems with QGraphicalEffects on my Mac and Linux boxes. I opened a bug about it: https://bugreports.qt-project.org/browse/QTBUG-42107 I am able to use the controls that crashed in 5.3, though. I'm on the beta published a few weeks ago. – Evan Nov 05 '14 at 18:23

2 Answers2

6

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.

1

I disagree with it being a bug in Qt. As stated in the link you pasted: "If a #version​ directive does not appear at the top, then it assumes 1.10, which is almost certainly not what you want."

That is what Qt wants, and that is what a OpenGL4 context should provide/allow as well. It's a bug in the Intel drivers: When you want a >2.0 context, the implicit fallback to version GLSL1.10 doesn't work with Intel drivers