本文介绍了为Qt5指定OpenGL桌面而不是ES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最终尝试使用教程.我决定从Qt5(Windows)开始,因为我对此很熟悉,并且可以专注于学习GLSL本身.我正在做的事情和本教程之间的唯一区别是,我使用的是QOpenGLWidget而不是QOpenGLWindow(我只有一个带有一个小部件的表单,没什么特别的).

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. 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).

要开始使用片段着色器,在Qt中,我向项目添加了一个新的桌面(非ES)片段着色器,Qt生成了以下着色器:

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:

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:

据此,我的结论是我的应用程序使用的是OpenGL ES,而不是台式机(否则就不会期望定义精度).

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).

我看到的GL版本字符串是 OpenGL ES 2.0(ANGLE 2.1.0.8613f4946861).首先,在同一台计算机上的Qt4中,版本字符串为 3.0.0-Build 9.17.10.4229 .

The GL version string I'm seeing is 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.

假设我的结论是正确的,我的问题是:如何配置应用程序以使用常规OpenGL而不是OpenGL ES?

Assuming my conclusion is correct, my question is: How can I configure the application to use regular OpenGL instead of OpenGL ES?

注释中关于将表面格式的可渲染类型设置为OpenGL的建议似乎很有希望,但是没有用.例如,如果我在小部件的构造函数中更改它:

The suggestion in the comments to set the surface format's renderable type to OpenGL seemed promising, but it isn't working. 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();
    ...

}

问题仍然存在,输出为(0 =默认,1 = OpenGL,2 = OpenGLES):

The issue persists and the output is (0 = default, 1 = OpenGL, 2 = OpenGLES):

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

因此,它似乎在构造函数和initializeGL之间的某个时刻被迫退回到OpenGLES.

So it appears to be being forced back to OpenGLES at some point between the constructor and initializeGL.

在构造任何GUI对象之前(以及构造QApplication之前)设置默认表面格式时,我观察到类似的行为.

I observed similar behavior when setting the default surface format before constructing any GUI objects (and before constructing the QApplication) as well.

推荐答案

Windows上的Qt5将使用ANGLE作为后备(使用Direct3D模拟OpenGL ES 2.0).编译)或视频驱动程序不支持现代OpenGL(即,如果您只有Microsoft提供的常规驱动程序).

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 (i.e. if you have only the stock driver provided by Microsoft).

您可以通过添加以下内容来强制应用程序使用OpenGL而不是angle:

You can force the application to use OpenGL instead of angle by adding:

QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);

在main.cpp文件中,或者将环境变量 QT_OPENGL 设置为桌面"(不带引号).您可以在此处找到更多详细信息: http://doc.qt.io/qt -5/windows-requirements.html

in your main.cpp file or by setting the environment variable QT_OPENGL to "desktop" (without quotes). You can find more details here: http://doc.qt.io/qt-5/windows-requirements.html

这篇关于为Qt5指定OpenGL桌面而不是ES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 14:56