mlimper
mlimper

Reputation: 5240

Setting QSurfaceFormat has no effect

I am currently having issues with getting a debug context with Qt 5.8 on Windows.

I am using Qt 5.8 to write a small OpenGL application, using a viewer class declared like this

class GLViewer3DModel : public QOpenGLWidget, protected QOpenGLFunctions
{
    //...
};

My main.cppfile uses this code, before QApplication is initialized:

 QSurfaceFormat format;     
 format.setOption(QSurfaceFormat::DebugContext);
 format.setProfile(QSurfaceFormat::CoreProfile);
 QSurfaceFormat::setDefaultFormat(format);

In the 3D viewer's constructor, the QSurfaceFormat::DebugContext option seems to be properly set. However, if I test this again within my initializeGL override, the following code

void GLViewer3DModel::initializeGL()
{
    initializeOpenGLFunctions();

    QSurfaceFormat fmt = format();
    bool hasDebug = fmt.testOption(QSurfaceFormat::DebugContext);    
    std::cout << "STILL DEBUG? " << hasDebug << std::endl;
}

prints "STILL DEBUG? 0", so for some reason the format has changed. Can I do anything to make the debug context work? I would love to use QOpenGLDebugLogger to see where something might go wrong.

FWIW, the GL_KHR_debug extension is supported on my system.

Upvotes: 2

Views: 2579

Answers (1)

Tom Kulaga
Tom Kulaga

Reputation: 138

Try setting a OpenGL version greater then 4.1 as I think that's when the debug was made core. The default constructed QSurfaceFormat requests GL 2.0 which doesn't support debug. See what you get then.

Also try initialising the logger and see what it spits back at you

Upvotes: 1

Related Questions