1/****************************************************************************
2**
3** Copyright (C) 2016 BlackBerry Ltd.
4** Copyright (C) 2016 The Qt Company Ltd.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtQuick module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qquickopenglinfo_p.h"
42#include "qopenglcontext.h"
43#include "qquickwindow.h"
44#include "qquickitem.h"
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \qmltype OpenGLInfo
50 \instantiates QQuickOpenGLInfo
51 \inqmlmodule QtQuick
52 \ingroup qtquick-effects
53 \since 5.4
54 \brief Provides information about the used OpenGL version.
55
56 The OpenGLInfo attached type provides information about the OpenGL
57 version being used to render the surface of the attachee item.
58
59 If the attachee item is not currently associated with any graphical
60 surface, the properties are set to the values of the default surface
61 format. When it becomes associated with a surface, all properties
62 will update.
63
64 \deprecated
65
66 \warning This type is deprecated. Use GraphicsInfo instead.
67
68 \sa ShaderEffect
69 */
70QQuickOpenGLInfo::QQuickOpenGLInfo(QQuickItem *item)
71 : QObject(item)
72 , m_window(nullptr)
73 , m_majorVersion(2)
74 , m_minorVersion(0)
75 , m_profile(NoProfile)
76 , m_renderableType(Unspecified)
77{
78 connect(sender: item, SIGNAL(windowChanged(QQuickWindow*)), receiver: this, SLOT(setWindow(QQuickWindow*)));
79 setWindow(item->window());
80}
81
82/*!
83 \qmlproperty int QtQuick::OpenGLInfo::majorVersion
84
85 This property holds the major OpenGL version.
86
87 The default version is \c 2.0.
88
89 \sa minorVersion, profile
90 */
91int QQuickOpenGLInfo::majorVersion() const
92{
93 return m_majorVersion;
94}
95
96/*!
97 \qmlproperty int QtQuick::OpenGLInfo::minorVersion
98
99 This property holds the minor OpenGL version.
100
101 The default version is \c 2.0.
102
103 \sa majorVersion, profile
104 */
105int QQuickOpenGLInfo::minorVersion() const
106{
107 return m_minorVersion;
108}
109
110/*!
111 \qmlproperty enumeration QtQuick::OpenGLInfo::profile
112
113 This property holds the configured OpenGL context profile.
114
115 The possible values are:
116 \list
117 \li OpenGLInfo.NoProfile (default) - OpenGL version is lower than 3.2.
118 \li OpenGLInfo.CoreProfile - Functionality deprecated in OpenGL version 3.0 is not available.
119 \li OpenGLInfo.CompatibilityProfile - Functionality from earlier OpenGL versions is available.
120 \endlist
121
122 Reusable QML components will typically use this property in bindings in order to
123 choose between core and non core profile compatible shader sources.
124
125 \sa majorVersion, minorVersion
126 */
127QQuickOpenGLInfo::ContextProfile QQuickOpenGLInfo::profile() const
128{
129 return m_profile;
130}
131
132/*!
133 \qmlproperty enumeration QtQuick::OpenGLInfo::renderableType
134
135 This property holds the renderable type.
136
137 The possible values are:
138 \list
139 \li OpenGLInfo.Unspecified (default) - Unspecified rendering method
140 \li OpenGLInfo.OpenGL - Desktop OpenGL rendering
141 \li OpenGLInfo.OpenGLES - OpenGL ES rendering
142 \endlist
143 */
144QQuickOpenGLInfo::RenderableType QQuickOpenGLInfo::renderableType() const
145{
146 return m_renderableType;
147}
148
149QQuickOpenGLInfo *QQuickOpenGLInfo::qmlAttachedProperties(QObject *object)
150{
151 if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
152 return new QQuickOpenGLInfo(item);
153 return nullptr;
154}
155
156void QQuickOpenGLInfo::updateFormat()
157{
158 QOpenGLContext *context = nullptr;
159 if (m_window)
160 context = m_window->openglContext();
161 QSurfaceFormat format = context ? context->format() : QSurfaceFormat::defaultFormat();
162
163 if (m_majorVersion != format.majorVersion()) {
164 m_majorVersion = format.majorVersion();
165 emit majorVersionChanged();
166 }
167
168 if (m_minorVersion != format.minorVersion()) {
169 m_minorVersion = format.minorVersion();
170 emit minorVersionChanged();
171 }
172
173 ContextProfile profile = static_cast<ContextProfile>(format.profile());
174 if (m_profile != profile) {
175 m_profile = profile;
176 emit profileChanged();
177 }
178
179 RenderableType renderableType = static_cast<RenderableType>(format.renderableType());
180 if (m_renderableType != renderableType) {
181 m_renderableType = renderableType;
182 emit renderableTypeChanged();
183 }
184}
185
186void QQuickOpenGLInfo::setWindow(QQuickWindow *window)
187{
188 if (m_window != window) {
189 if (m_window) {
190 disconnect(sender: m_window, SIGNAL(sceneGraphInitialized()), receiver: this, SLOT(updateFormat()));
191 disconnect(sender: m_window, SIGNAL(sceneGraphInvalidated()), receiver: this, SLOT(updateFormat()));
192 }
193 if (window) {
194 connect(sender: window, SIGNAL(sceneGraphInitialized()), receiver: this, SLOT(updateFormat()));
195 connect(sender: window, SIGNAL(sceneGraphInvalidated()), receiver: this, SLOT(updateFormat()));
196 }
197 m_window = window;
198 }
199 updateFormat();
200}
201
202QT_END_NAMESPACE
203
204#include "moc_qquickopenglinfo_p.cpp"
205

source code of qtdeclarative/src/quick/items/qquickopenglinfo.cpp