简体   繁体   English

为 Qt5 指定 OpenGL 桌面而不是 ES

[英]Specifying OpenGL Desktop instead of ES for Qt5

I am finally trying to wrap my head around shaders, using a tutorial I found.我终于尝试使用我找到的教程围绕着色器。 I decided to start with Qt5 (Windows) since I'm familiar with it and can focus on learning GLSL itself to start with.我决定从 Qt5 (Windows) 开始,因为我熟悉它并且可以专注于学习 GLSL 本身。 The only difference between what I'm doing and the tutorial is that I'm working with a QOpenGLWidget rather than a QOpenGLWindow (I just have a form with one widget on it, nothing special).我正在做的事情和教程之间的唯一区别是我正在使用QOpenGLWidget而不是QOpenGLWindow (我只有一个带有一个小部件的表单,没什么特别的)。

To get started with a fragment shader, in Qt I added a new desktop (not ES) fragment shader to my project, and Qt generates the following shader:为了开始使用片段着色器,在 Qt 中,我在我的项目中添加了一个新的桌面(不是 ES)片段着色器,Qt 生成以下着色器:

uniform sampler2D qt_Texture0;
varying vec4 qt_TexCoord0;

void main(void)
{
    gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);
}

However, when compiling this shader, it generates this error:但是,在编译此着色器时,会生成此错误:

QOpenGLShader::compile(Fragment): ERROR: 0:2: '' : No precision specified for (float)

I did a little bit of searching around and found this answer which states:我做了一些搜索并找到了这个答案,其中指出:

No default precision exists for fp types in fragment shaders in OpenGL ES 2.0. OpenGL ES 2.0 中片段着色器中的 fp 类型不存在默认精度。

From this, my conclusion is that my application is using OpenGL ES and not Desktop (otherwise it wouldn't expect a precision to be defined).由此,我的结论是我的应用程序使用的是 OpenGL ES 而不是桌面(否则它不会期望定义精度)。

The GL version string I'm seeing is OpenGL ES 2.0 (ANGLE 2.1.0.8613f4946861) .我看到的 GL 版本字符串是OpenGL ES 2.0 (ANGLE 2.1.0.8613f4946861) Fwiw, in Qt4 on this same machine, the version string is 3.0.0 - Build 9.17.10.4229 . Fwiw,在同一台机器上的 Qt4 中,版本字符串是3.0.0 - Build 9.17.10.4229

Assuming my conclusion is correct, my question is: How can I configure the application to use regular OpenGL instead of OpenGL ES?假设我的结论是正确的,我的问题是:如何将应用程序配置为使用常规 OpenGL 而不是 OpenGL ES?


The suggestion in the comments to set the surface format's renderable type to OpenGL seemed promising, but it isn't working.将表面格式的可渲染类型设置为OpenGL的评论中的建议似乎很有希望,但它不起作用。 For example, if I change it in the widget's constructor:例如,如果我在小部件的构造函数中更改它:

View::View (QWidget *parent) :
    QOpenGLWidget(parent),
    ...
{

    QSurfaceFormat f = format();
    qDebug() << "type was" << f.renderableType();

    f.setRenderableType(QSurfaceFormat::OpenGL);
    qDebug() << "type set to" << f.renderableType();

    setFormat(f);
    qDebug() << "type is now" << format().renderableType();

}

void View::initializeGL () {

    qDebug() << __FUNCTION__ << "type is now" << this->format().renderableType();
    ...

}

The issue persists and the output is (0 = default, 1 = OpenGL , 2 = OpenGLES ):问题仍然存在,输出为(0 = 默认,1 = OpenGL ,2 = OpenGLES ):

type was 0
type set to 1
type is now 1
initializeGL type is now 2

So it appears to be being forced back to OpenGLES at some point between the constructor and initializeGL .因此,它似乎在构造函数和initializeGL之间的某个时刻被迫返回OpenGLES

I observed similar behavior when setting the default surface format before constructing any GUI objects (and before constructing the QApplication ) as well.在构建任何 GUI 对象之前(以及在构建QApplication之前)设置默认表面格式时,我也观察到了类似的行为。

Qt5 on Windows will use ANGLE as a fallback (emulating OpenGL ES 2.0 with Direct3D) if either the video card is blacklisted (in ANGLE configuration at the time Qt was compiled) or the video driver does not support modern OpenGL (ie if you have only the stock driver provided by Microsoft).如果视频卡被列入黑名单(在 Qt 编译时的 ANGLE 配置中)或视频驱动程序不支持现代 OpenGL(即,如果您只有Microsoft 提供的库存驱动程序)。

You can force the application to use OpenGL instead of angle by adding:您可以通过添加以下内容来强制应用程序使用 OpenGL 而不是角度:

QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);

in your main.cpp file or by setting the environment variable QT_OPENGL to "desktop" (without quotes).在 main.cpp 文件中或通过将环境变量QT_OPENGL设置为“桌面”(不带引号)。 You can find more details here: http://doc.qt.io/qt-5/windows-requirements.html您可以在此处找到更多详细信息: http : //doc.qt.io/qt-5/windows-requirements.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM