QOpenGLFunctions_4_3_与QOpenGLContext :: versionFunctions的兼容性 [英] QOpenGLFunctions_4_3_Compatibility with QOpenGLContext::versionFunctions

查看:500
本文介绍了QOpenGLFunctions_4_3_与QOpenGLContext :: versionFunctions的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 http:编译Tesselation的示例: //www.kdab.com/opengl-in-qt-5-1-part-5/(包括源代码)具有兼容性配置文件,并且根本无法加载此配置文件:

I’m trying to compile Tesselation’s example from http://www.kdab.com/opengl-in-qt-5-1-part-5/ (source included) with the Compatibility profile and it’s simply incapable to load this profile:

我进行的(也是唯一的)较小修改:

The minor (and only) modifications I’ve made:

@ terraintessellationscene.h:

@terraintessellationscene.h:

QOpenGLFunctions_4_3_Compatibility* m_funcs;

@ terraintessellationscene.cpp:

@terraintessellationscene.cpp:

m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Compatibility>();
if ( !m_funcs )
{
    qFatal("Requires OpenGL >= 4.0");
    exit( 1 );
}
m_funcs->initializeOpenGLFunctions();

当我调用versionFunctions()时,它只是崩溃了.它应该工作.我可以使用任何Core Profile桌面配置文件来编译此源代码以及其他几个复杂程度不同的其他项目.稍后,我将尝试使用GLEW来查看此问题是否与QT或我对QT的使用或我的opengl驱动程序有关.

It just crashes when I call versionFunctions(). And it should work. I can compile this source and several other different project of different complexity using any Core Profile desktop profile. I'm going to try to use GLEW later on to see if this problem is related to QT or my usage of QT or my opengl driver.

我使用的是AMD的14.4 WHQL.我尝试使用预构建的5.3源和我自己编译的5.3静态版本.我尝试了两个旧的AMD驱动程序,以查看这是否是AMD提供的OpenGL程序包出现问题,但失败了.我真的很想使用versionFunctions.

I’m using lasted AMD’s 14.4 WHQL. I’ve tried to using the pre-built 5.3 source and my self-compiled static version of 5.3. I’ve tried two old AMD drivers to see if this was a problem with the OpenGL package provided by AMD and yet it fails. I really want to use versionFunctions.

更新2

在正确设置QSurfaceFormat(QOpenGLContext :: setFormat(format))之后,似乎QOpenGLContext create()完全拒绝兼容性设置(format.setProfile(QSurfaceFormat :: CompatibilityProfile)并创建了Core Profile上下文,而完全忽略了我对兼容性上下文的请求,但作为无法遵循QSurfaceFormat格式规则的成功操作返回true.

It seems QOpenGLContext create(), after setting the QSurfaceFormat properly (QOpenGLContext::setFormat(format), is completely rejecting the compatibility settings (format.setProfile( QSurfaceFormat::CompatibilityProfile) and creating a Core Profile context instead, completely ignoring my request for a compatibility context and yet returning true as a successful operation that couldn't follow QSurfaceFormat format rules.

更新3

好吧,我刚刚发现了这个问题,它与我的修改无关,它在kdab的原始代码中:

Well, I just discovered the issue and it is not related to my modifications, it’s in the original code at kdab:

// Create an OpenGL context
m_context = new QOpenGLContext;
m_context->setFormat( format );
m_context->create();

通过在setFormat之前创建上下文,我能够正确地启动适当的Compatibility Context,因为QT只是简单地设置了与setProfile(QSurfaceFormat :: CoreProfile)相关的设置的一部分

by creating the context before setFormat, I was able to correctly initiate a proper Compatibility Context, as QT was simply setting part of my settings related to setProfile( QSurfaceFormat::CoreProfile)

更新4:最终解决方案

在setFormat()之前创建上下文是错误的,并且偶然发生,因为您所请求的是纯OpenGL 2.0上下文,并且该驱动程序很可能为您提供4.3兼容性.在其他驱动程序或平台上,这可能会失败,因此请小心. 您看到的行为是由AMD驱动程序引起的:除非未设置前向兼容性集,否则它拒绝创建适当的兼容性配置文件上下文. Qt默认设置fwdcompat位,可以通过设置QSurfaceFormat上的DeprecatedFunctions选项将其关闭.因此,与DeprecatedFunctions一起请求兼容性将提供您想要的东西.其他供应商的驱动程序不存在此问题,因为兼容性配置文件应该忽略设置DeprecatedFunctions(即设置向前兼容性)." 通过agocs @ qt devnet

"Creating the context before setFormat() is wrong and works by accident since what you are requesting then is a plain OpenGL 2.0 context and the driver most likely gives you 4.3 compatibility. On other drivers or platforms this may fail so be careful. The behavior you are seeing is caused by the AMD driver: it refuses to create a proper compatibility profile context unless the forward compatibility set is not set. Qt sets the fwdcompat bit by default, it can be turned off by setting the DeprecatedFunctions option on the QSurfaceFormat. So requesting for Compatibility together with DeprecatedFunctions will give what you want. Other vendors’ drivers do not have this problem, there not setting DeprecatedFunctions (i.e. setting forward compatibility) is ignored for compatibility profiles, as it should be." via agocs @ qt devnet

推荐答案

当您需要兼容性配置文件时,您将获得核心配置文件(感谢Qt)

you are getting the core profile (thanks to Qt) while you want the compatibility profile

您应在初始化时通过以下格式设置请求兼容性配置文件

you should request the compatibility profile on initializing by setting the format as follows

window.cpp第24行

window.cpp line 24

format.setProfile( QSurfaceFormat::CompatibilityProfile);

,仅在创建上下文后调用versionFunctions

and only call the versionFunctions after context has been created

这篇关于QOpenGLFunctions_4_3_与QOpenGLContext :: versionFunctions的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆