Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

qt5.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...