| 1 |
// Copyright (C) 2017 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#include <QGuiApplication> |
| 5 |
#include <QSurfaceFormat> |
| 6 |
#include <QOffscreenSurface> |
| 7 |
#include <QOpenGLContext> |
| 8 |
#include <QDebug> |
| 9 |
#include <QPair> |
| 10 |
#include "glwindow.h" |
| 11 |
|
| 12 |
bool OGLSupports(int major, int minor, bool gles = false, QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile) |
| 13 |
{ |
| 14 |
QOpenGLContext ctx; |
| 15 |
QSurfaceFormat fmt; |
| 16 |
fmt.setVersion(major, minor); |
| 17 |
if (gles) { |
| 18 |
fmt.setRenderableType(QSurfaceFormat::OpenGLES); |
| 19 |
} else { |
| 20 |
fmt.setRenderableType(QSurfaceFormat::OpenGL); |
| 21 |
fmt.setProfile(profile); |
| 22 |
} |
| 23 |
|
| 24 |
ctx.setFormat(fmt); |
| 25 |
ctx.create(); |
| 26 |
if (!ctx.isValid()) |
| 27 |
return false; |
| 28 |
int ctxMajor = ctx.format().majorVersion(); |
| 29 |
int ctxMinor = ctx.format().minorVersion(); |
| 30 |
bool isGles = (ctx.format().renderableType() == QSurfaceFormat::OpenGLES); |
| 31 |
|
| 32 |
if (isGles != gles) return false; |
| 33 |
if (ctxMajor < major) return false; |
| 34 |
if (ctxMajor == major && ctxMinor < minor) |
| 35 |
return false; |
| 36 |
if (!gles && ctx.format().profile() != profile) |
| 37 |
return false; |
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
int main(int argc, char *argv[]) |
| 42 |
{ |
| 43 |
QGuiApplication app(argc, argv); |
| 44 |
|
| 45 |
qDebug() << "Support for GL 2.0 noprof "<<( OGLSupports(2,0,false) ? "yes" : "no"); |
| 46 |
qDebug() << "Support for GL 2.0 core "<<( OGLSupports(2,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 47 |
qDebug() << "Support for GL 2.0 compat "<<( OGLSupports(2,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 48 |
qDebug() << "Support for GL 2.1 noprof "<<( OGLSupports(2,1,false) ? "yes" : "no"); |
| 49 |
qDebug() << "Support for GL 2.1 core "<<( OGLSupports(2,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 50 |
qDebug() << "Support for GL 2.1 compat "<<( OGLSupports(2,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 51 |
qDebug() << "Support for GL 3.0 noprof "<<( OGLSupports(3,0,false) ? "yes" : "no"); |
| 52 |
qDebug() << "Support for GL 3.0 core "<<( OGLSupports(3,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 53 |
qDebug() << "Support for GL 3.0 compat "<<( OGLSupports(3,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 54 |
qDebug() << "Support for GL 3.1 noprof "<<( OGLSupports(3,1,false) ? "yes" : "no"); |
| 55 |
qDebug() << "Support for GL 3.1 core "<<( OGLSupports(3,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 56 |
qDebug() << "Support for GL 3.1 compat "<<( OGLSupports(3,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 57 |
qDebug() << "Support for GL 3.2 core "<<( OGLSupports(3,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 58 |
qDebug() << "Support for GL 3.2 compat "<<( OGLSupports(3,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 59 |
qDebug() << "Support for GL 3.3 core "<<( OGLSupports(3,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 60 |
qDebug() << "Support for GL 3.3 compat "<<( OGLSupports(3,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 61 |
qDebug() << "Support for GL 4.0 core "<<( OGLSupports(4,0,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 62 |
qDebug() << "Support for GL 4.0 compat "<<( OGLSupports(4,0,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 63 |
qDebug() << "Support for GL 4.1 core "<<( OGLSupports(4,1,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 64 |
qDebug() << "Support for GL 4.1 compat "<<( OGLSupports(4,1,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 65 |
qDebug() << "Support for GL 4.2 core "<<( OGLSupports(4,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 66 |
qDebug() << "Support for GL 4.2 compat "<<( OGLSupports(4,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 67 |
qDebug() << "Support for GL 4.3 core "<<( OGLSupports(4,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 68 |
qDebug() << "Support for GL 4.3 compat "<<( OGLSupports(4,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 69 |
qDebug() << "Support for GL 4.4 core "<<( OGLSupports(4,4,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 70 |
qDebug() << "Support for GL 4.4 compat "<<( OGLSupports(4,4,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 71 |
qDebug() << "Support for GL 4.5 core "<<( OGLSupports(4,5,false,QSurfaceFormat::CoreProfile) ? "yes" : "no"); |
| 72 |
qDebug() << "Support for GL 4.5 compat "<<( OGLSupports(4,5,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no"); |
| 73 |
qDebug() << "Support for GLES 2.0 "<<( OGLSupports(2,0,true) ? "yes" : "no"); |
| 74 |
qDebug() << "Support for GLES 3.0 "<<( OGLSupports(3,0,true) ? "yes" : "no"); |
| 75 |
qDebug() << "Support for GLES 3.1 "<<( OGLSupports(3,1,true) ? "yes" : "no"); |
| 76 |
qDebug() << "Support for GLES 3.2 "<<( OGLSupports(3,2,true) ? "yes" : "no"); |
| 77 |
|
| 78 |
QSurfaceFormat fmt; |
| 79 |
fmt.setDepthBufferSize(24); |
| 80 |
|
| 81 |
// Request OpenGL ES 3.1 context, as this is a GLES example. If not available, go for OpenGL 4.3 core. |
| 82 |
if (OGLSupports(3,1,true)) { |
| 83 |
qDebug("Requesting 3.1 GLES context"); |
| 84 |
fmt.setVersion(3, 1); |
| 85 |
fmt.setRenderableType(QSurfaceFormat::OpenGLES); |
| 86 |
} else if (OGLSupports(4,3,false,QSurfaceFormat::CoreProfile)) { |
| 87 |
qDebug("Requesting 4.3 core context"); |
| 88 |
fmt.setVersion(4, 3); |
| 89 |
fmt.setRenderableType(QSurfaceFormat::OpenGL); |
| 90 |
fmt.setProfile(QSurfaceFormat::CoreProfile); |
| 91 |
} else { |
| 92 |
qWarning("Error: This system does not support OpenGL Compute Shaders! Exiting."); |
| 93 |
return -1; |
| 94 |
} |
| 95 |
QSurfaceFormat::setDefaultFormat(fmt); |
| 96 |
|
| 97 |
GLWindow glWindow; |
| 98 |
glWindow.showMaximized(); |
| 99 |
|
| 100 |
return app.exec(); |
| 101 |
} |