Can't use QOpenGLFunctions_4_3_Compatibility with QOpenGLContext::versionFunctions
-
wrote on 21 May 2014, 09:29 last edited by
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() (segfault). 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.
glGetString(GL_VERSION) returns "4.3.12618 Core Profile Forward-Compatible Context 13.251.0.0" and QOpenGLContext::format() returns QSurfaceFormat(version 4.3, options QFlags(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 4, swapBehavior 2, swapInterval 1, profile 1)
-
wrote on 21 May 2014, 12:50 last edited by
Update:
It seems QOpenGLContext create(), after setting the QSurfaceFormat properly, is completely rejecting the compatibility setting and creating a Core context instead, completely ignoring my request for a compatibility context and yet returning true as a sucessfull operation that couldn't follow QSurfaceFormat format rules.
@QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setDepthBufferSize( 24 );
format.setMajorVersion( 4 );
format.setMinorVersion( 3 );
format.setSamples( 4 );
format.setProfile(QSurfaceFormat::CompatibilityProfile);
resize( 1366, 768 );
setFormat(format);
create();m_context = new QOpenGLContext;
m_context->setFormat(format);// BEFORE CREATING
qDebug() << "Current Context 1:" << m_context->format();
QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION))));
qDebug() << "Driver Version String 1:" << versionString;m_context->create();
// AFTER CREATING
qDebug() << "Current Context 2:" << m_context->format();
QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION))));
qDebug() << "Driver Version String 2:" << versionString;m_context->makeCurrent( this );@
Output:
@Current Context 1:
QSurfaceFormat(version 4.3, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize -1, samples 4, swapBehavior 0, swapInterval 1, profile 2)
Driver Version String 1:
""Current Context 2:
QSurfaceFormat(version 4.3, options QFlags(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 4, swapBehavior 2, swapInterval 1, profile 1)
Driver Version String 2:
""@ -
wrote on 21 May 2014, 12:54 last edited by
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.
-
Hi and welcome to devnet,
Glad you found a solution !
You should also contact KDAB about this issue so they can update their example
-
wrote on 22 May 2014, 10:16 last edited by
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.
-
wrote on 22 May 2014, 11:03 last edited by
[quote author="agocs" date="1400753800"]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.
[/quote]
Thanks, that really explains the issue, even though I got lucky and got te compatibility context by creating the context first before setFormat.
And yes, it works properly when I set QSurfaceFormat::DeprecatedFunctions. I've search for hours in the AMD developers forum and other docs and couldn't find any reference for this type of behavior :(
1/6