Reputation: 51
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:
QOpenGLFunctions_4_3_Compatibility* m_funcs;
@terraintessellationscene.cpp:
m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Compatibility>();
if ( !m_funcs )
{
qFatal("Requires OpenGL >= 4.0");
exit( 1 );
}
m_funcs->initializeOpenGLFunctions();
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.
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.
Update 2
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.
Update 3
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();
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)
Update 4: Final solution
"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
Upvotes: 5
Views: 2176
Reputation: 48196
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 line 24
format.setProfile( QSurfaceFormat::CompatibilityProfile);
and only call the versionFunctions after context has been created
Upvotes: 0