Unsolved QOpenGLWidget with QOpenGLFunctions_3_3_Core is initialized failed on Mac OS
-
I have a TestWidget inherited from QOpenGLWidget and QOpenGLFunctions_3_3_Core, which works fine on windows platform but failed on MacOS. my macbook pro is the latest one and OpenGL3.x is support and Graphic card shows it support 3.x 4.x as well.
When I changed to gl es with inheriting from QOpenGLFunctions everything works fine. Also I can run OpenGL example from Qt Creator normal, in which all widget inherit from QOpenGLFunctions.
Then
- it's Qt's lose to support OpenGL3.x or I miss something?
- we can only use GL ES with Qt in MacOS without modern OpenGL?
class GLTest : public QOpenGLWidget,
public QOpenGLFunctions_3_3_Core{
Q_OBJECTpublic:
static E_GL_TEST_CODE HaveGLTest();protected: //QOpenGLWidget need override virtual void initializeGL() Q_DECL_OVERRIDE; virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE; virtual void paintGL() Q_DECL_OVERRIDE; private: explicit GLTest(QWidget *parent = 0); private: E_GL_TEST_CODE m_iStatus; }; void GLTest::initializeGL() { if (!initializeOpenGLFunctions()) { m_iStatus = E_TEST_NO_DRIVER; qDebug() << "ohoop ..."; return; } const GLubyte *pvender = glGetString(GL_VENDOR); const GLubyte *prender = glGetString(GL_RENDERER); m_iStatus = E_TEST_NORMAL; }
-
Hi,
What version of Qt are you using ?
What macOS version are you running on ?
What Mac computer are you using for development ? -
@SGaist Qt5.9.5
version 10.13.3 (17D47)
MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports)
Intel Iris Plus Graphics 650 1536 MBI went to qt source and find context format is version 2.1 which makes it failed.
bool QOpenGLFunctions_3_3_Core_Pri::isContextCompatible(QOpenGLContext *context)
{
Q_ASSERT(context);
QSurfaceFormat f = context->format();
const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion());
qDebug() << v; //output is 2.1
if (v < qMakePair(3, 3))
return false;
else
return true;
} -
@fisher103
From Qt doc, I finally find that QSurfaceFormat::setDefaultFormat() should be called before constructing QApplication on Mac, in which we can set OpenGL Core Profile version. And then the initializeOpenGlFunctions work normal.
But the deeper reason of this can be also to be explored. -
The deeper reason is that Apple doesn't support modern features in compatibility contexts that are backwards compatible. In order to keep old apps working, the default of a compatibility context rather than one that only supports core profile. So if you want to use modern features, you need to opt-in.
Don't expect it to change much -- Apple has deprecated OpenGL going forward so that narrow support of core profile is probably about as good as it will get on OS-X.