Serious rendering issues with OpenGL 4.1 and Qt 5

2019-02-26 15:00发布

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?

2条回答
Ridiculous、
2楼-- · 2019-02-26 15:05

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

查看更多
不美不萌又怎样
3楼-- · 2019-02-26 15:18

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.

查看更多
登录 后发表回答