1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the examples of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:BSD$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** BSD License Usage |
18 | ** Alternatively, you may use this file under the terms of the BSD license |
19 | ** as follows: |
20 | ** |
21 | ** "Redistribution and use in source and binary forms, with or without |
22 | ** modification, are permitted provided that the following conditions are |
23 | ** met: |
24 | ** * Redistributions of source code must retain the above copyright |
25 | ** notice, this list of conditions and the following disclaimer. |
26 | ** * Redistributions in binary form must reproduce the above copyright |
27 | ** notice, this list of conditions and the following disclaimer in |
28 | ** the documentation and/or other materials provided with the |
29 | ** distribution. |
30 | ** * Neither the name of The Qt Company Ltd nor the names of its |
31 | ** contributors may be used to endorse or promote products derived |
32 | ** from this software without specific prior written permission. |
33 | ** |
34 | ** |
35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
46 | ** |
47 | ** $QT_END_LICENSE$ |
48 | ** |
49 | ****************************************************************************/ |
50 | |
51 | #include <QGuiApplication> |
52 | #include <QSurfaceFormat> |
53 | #include <QOffscreenSurface> |
54 | #include <QOpenGLContext> |
55 | #include <QDebug> |
56 | #include <QPair> |
57 | #include "glwindow.h" |
58 | |
59 | bool OGLSupports(int major, int minor, bool gles = false, QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile) |
60 | { |
61 | QOpenGLContext ctx; |
62 | QSurfaceFormat fmt; |
63 | fmt.setVersion(major, minor); |
64 | if (gles) { |
65 | fmt.setRenderableType(QSurfaceFormat::OpenGLES); |
66 | } else { |
67 | fmt.setRenderableType(QSurfaceFormat::OpenGL); |
68 | fmt.setProfile(profile); |
69 | } |
70 | |
71 | ctx.setFormat(fmt); |
72 | ctx.create(); |
73 | if (!ctx.isValid()) |
74 | return false; |
75 | int ctxMajor = ctx.format().majorVersion(); |
76 | int ctxMinor = ctx.format().minorVersion(); |
77 | bool isGles = (ctx.format().renderableType() == QSurfaceFormat::OpenGLES); |
78 | |
79 | if (isGles != gles) return false; |
80 | if (ctxMajor < major) return false; |
81 | if (ctxMajor == major && ctxMinor < minor) |
82 | return false; |
83 | if (!gles && ctx.format().profile() != profile) |
84 | return false; |
85 | return true; |
86 | } |
87 | |
88 | int main(int argc, char *argv[]) |
89 | { |
90 | QGuiApplication app(argc, argv); |
91 | |
92 | qDebug() << "Support for GL 2.0 noprof " <<( OGLSupports(2,0,false) ? "yes" : "no" ); |
93 | qDebug() << "Support for GL 2.0 core " <<( OGLSupports(2,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
94 | qDebug() << "Support for GL 2.0 compat " <<( OGLSupports(2,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
95 | qDebug() << "Support for GL 2.1 noprof " <<( OGLSupports(2,1,false) ? "yes" : "no" ); |
96 | qDebug() << "Support for GL 2.1 core " <<( OGLSupports(2,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
97 | qDebug() << "Support for GL 2.1 compat " <<( OGLSupports(2,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
98 | qDebug() << "Support for GL 3.0 noprof " <<( OGLSupports(3,0,false) ? "yes" : "no" ); |
99 | qDebug() << "Support for GL 3.0 core " <<( OGLSupports(3,0,false, QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
100 | qDebug() << "Support for GL 3.0 compat " <<( OGLSupports(3,0,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
101 | qDebug() << "Support for GL 3.1 noprof " <<( OGLSupports(3,1,false) ? "yes" : "no" ); |
102 | qDebug() << "Support for GL 3.1 core " <<( OGLSupports(3,1,false, QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
103 | qDebug() << "Support for GL 3.1 compat " <<( OGLSupports(3,1,false, QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
104 | qDebug() << "Support for GL 3.2 core " <<( OGLSupports(3,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
105 | qDebug() << "Support for GL 3.2 compat " <<( OGLSupports(3,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
106 | qDebug() << "Support for GL 3.3 core " <<( OGLSupports(3,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
107 | qDebug() << "Support for GL 3.3 compat " <<( OGLSupports(3,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
108 | qDebug() << "Support for GL 4.0 core " <<( OGLSupports(4,0,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
109 | qDebug() << "Support for GL 4.0 compat " <<( OGLSupports(4,0,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
110 | qDebug() << "Support for GL 4.1 core " <<( OGLSupports(4,1,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
111 | qDebug() << "Support for GL 4.1 compat " <<( OGLSupports(4,1,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
112 | qDebug() << "Support for GL 4.2 core " <<( OGLSupports(4,2,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
113 | qDebug() << "Support for GL 4.2 compat " <<( OGLSupports(4,2,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
114 | qDebug() << "Support for GL 4.3 core " <<( OGLSupports(4,3,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
115 | qDebug() << "Support for GL 4.3 compat " <<( OGLSupports(4,3,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
116 | qDebug() << "Support for GL 4.4 core " <<( OGLSupports(4,4,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
117 | qDebug() << "Support for GL 4.4 compat " <<( OGLSupports(4,4,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
118 | qDebug() << "Support for GL 4.5 core " <<( OGLSupports(4,5,false,QSurfaceFormat::CoreProfile) ? "yes" : "no" ); |
119 | qDebug() << "Support for GL 4.5 compat " <<( OGLSupports(4,5,false,QSurfaceFormat::CompatibilityProfile) ? "yes" : "no" ); |
120 | qDebug() << "Support for GLES 2.0 " <<( OGLSupports(2,0,true) ? "yes" : "no" ); |
121 | qDebug() << "Support for GLES 3.0 " <<( OGLSupports(3,0,true) ? "yes" : "no" ); |
122 | qDebug() << "Support for GLES 3.1 " <<( OGLSupports(3,1,true) ? "yes" : "no" ); |
123 | qDebug() << "Support for GLES 3.2 " <<( OGLSupports(3,2,true) ? "yes" : "no" ); |
124 | |
125 | QSurfaceFormat fmt; |
126 | fmt.setDepthBufferSize(24); |
127 | |
128 | // Request OpenGL ES 3.1 context, as this is a GLES example. If not available, go for OpenGL 4.3 core. |
129 | if (OGLSupports(3,1,true)) { |
130 | qDebug("Requesting 3.1 GLES context" ); |
131 | fmt.setVersion(3, 1); |
132 | fmt.setRenderableType(QSurfaceFormat::OpenGLES); |
133 | } else if (OGLSupports(4,3,false,QSurfaceFormat::CoreProfile)) { |
134 | qDebug("Requesting 4.3 core context" ); |
135 | fmt.setVersion(4, 3); |
136 | fmt.setRenderableType(QSurfaceFormat::OpenGL); |
137 | fmt.setProfile(QSurfaceFormat::CoreProfile); |
138 | } else { |
139 | qWarning("Error: This system does not support OpenGL Compute Shaders! Exiting." ); |
140 | return -1; |
141 | } |
142 | QSurfaceFormat::setDefaultFormat(fmt); |
143 | |
144 | GLWindow glWindow; |
145 | glWindow.showMaximized(); |
146 | |
147 | return app.exec(); |
148 | } |
149 | |