1 #include "opengl_checker.h" 2 3 #include "QsLog.h" 4 OpenGLChecker()5OpenGLChecker::OpenGLChecker() 6 : compatibleOpenGLVersion(true) 7 { 8 QOpenGLContext *openGLContext = new QOpenGLContext(); 9 openGLContext->create(); 10 11 if (!openGLContext->isValid()) { 12 compatibleOpenGLVersion = false; 13 description = "unable to create QOpenGLContext"; 14 } 15 16 QSurfaceFormat format = openGLContext->format(); 17 18 int majorVersion = format.majorVersion(); 19 int minorVersion = format.minorVersion(); 20 QString type; 21 22 switch (format.renderableType()) { 23 case QSurfaceFormat::OpenGL: 24 type = "desktop"; 25 break; 26 27 case QSurfaceFormat::OpenGLES: 28 type = "OpenGL ES"; 29 break; 30 31 case QSurfaceFormat::OpenVG: 32 type = "OpenVG"; 33 break; 34 35 default: 36 case QSurfaceFormat::DefaultRenderableType: 37 type = "unknown"; 38 break; 39 } 40 41 delete openGLContext; 42 43 description = QString("%1.%2 %3").arg(majorVersion).arg(minorVersion).arg(type); 44 45 if (format.renderableType() != QSurfaceFormat::OpenGL) //Desktop OpenGL 46 compatibleOpenGLVersion = false; 47 48 #ifdef Q_OS_WIN //TODO check Qt version, and set this values depending on the use of QOpenGLWidget or QGLWidget 49 static const int majorTargetVersion = 1; 50 static const int minorTargetVersion = 4; 51 #else 52 static const int majorTargetVersion = 2; 53 static const int minorTargetVersion = 0; 54 #endif 55 56 if (majorVersion < majorTargetVersion) 57 compatibleOpenGLVersion = false; 58 if (majorVersion == majorTargetVersion && minorVersion < minorTargetVersion) 59 compatibleOpenGLVersion = false; 60 } 61 textVersionDescription()62QString OpenGLChecker::textVersionDescription() 63 { 64 return description; 65 } 66 hasCompatibleOpenGLVersion()67bool OpenGLChecker::hasCompatibleOpenGLVersion() 68 { 69 return compatibleOpenGLVersion; 70 } 71