Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplatformopenglcontext.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qplatformopenglcontext.h"
6
7
#
include
<
QOpenGLFunctions
>
8
9
QT_BEGIN_NAMESPACE
10
11
/*!
12
\class QPlatformOpenGLContext
13
\since 4.8
14
\internal
15
\preliminary
16
\ingroup qpa
17
18
\brief The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
19
20
In QPA the way to support OpenGL or OpenVG or other technologies that requires a native GL
21
context is through the QPlatformOpenGLContext wrapper.
22
23
There is no factory function for QPlatformOpenGLContexts, but rather only one accessor function.
24
The only place to retrieve a QPlatformOpenGLContext from is through a QPlatformWindow.
25
26
The context which is current for a specific thread can be collected by the currentContext()
27
function. This is how QPlatformOpenGLContext also makes it possible to use the Qt GUI module
28
withhout using QOpenGLWidget. When using QOpenGLContext::currentContext(), it will ask
29
QPlatformOpenGLContext for the currentContext. Then a corresponding QOpenGLContext will be returned,
30
which maps to the QPlatformOpenGLContext.
31
*/
32
33
/*! \fn void QPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface)
34
Reimplement in subclass to native swap buffers calls
35
36
The implementation must support being called in a thread different than the gui-thread.
37
*/
38
39
/*! \fn QFunctionPointer QPlatformOpenGLContext::getProcAddress(const char *procName)
40
41
Reimplement in subclass to allow dynamic querying of OpenGL symbols. As opposed to e.g. the wglGetProcAddress
42
function on Windows, Qt expects this methods to be able to return valid function pointers even for standard
43
OpenGL symbols.
44
*/
45
46
class
QPlatformOpenGLContextPrivate
47
{
48
public
:
49
QPlatformOpenGLContextPrivate
() :
context
(
nullptr
) {}
50
51
QOpenGLContext
*
context
;
52
};
53
54
QPlatformOpenGLContext::QPlatformOpenGLContext()
55
: d_ptr(
new
QPlatformOpenGLContextPrivate)
56
{
57
}
58
59
QPlatformOpenGLContext::~QPlatformOpenGLContext()
60
{
61
}
62
63
/*!
64
Called after a new instance is constructed. The default implementation does nothing.
65
66
Subclasses can use this function to perform additional initialization that relies on
67
virtual functions.
68
*/
69
void
QPlatformOpenGLContext::initialize()
70
{
71
}
72
73
/*!
74
Reimplement in subclass if your platform uses framebuffer objects for surfaces.
75
76
The default implementation returns 0.
77
*/
78
GLuint QPlatformOpenGLContext::defaultFramebufferObject(QPlatformSurface *)
const
79
{
80
return
0;
81
}
82
83
QOpenGLContext *QPlatformOpenGLContext::context()
const
84
{
85
Q_D(
const
QPlatformOpenGLContext);
86
return
d->context;
87
}
88
89
void
QPlatformOpenGLContext::setContext(QOpenGLContext *context)
90
{
91
Q_D(QPlatformOpenGLContext);
92
d->context = context;
93
}
94
95
bool
QPlatformOpenGLContext::parseOpenGLVersion(
const
QByteArray &versionString,
int
&major,
int
&minor)
96
{
97
bool
majorOk =
false
;
98
bool
minorOk =
false
;
99
QList<QByteArray> parts = versionString.split(
' '
);
100
if
(versionString.startsWith(QByteArrayLiteral(
"OpenGL ES"
))) {
101
if
(parts.size() >= 3) {
102
QList<QByteArray> versionParts = parts.at(2).split(
'.'
);
103
if
(versionParts.size() >= 2) {
104
major = versionParts.at(0).toInt(&majorOk);
105
minor = versionParts.at(1).toInt(&minorOk);
106
// Nexus 6 has "OpenGL ES 3.0V@95.0 (GIT@I86da836d38)"
107
if
(!minorOk)
108
if
(
int
idx = versionParts.at(1).indexOf(
'V'
))
109
minor = versionParts.at(1).left(idx).toInt(&minorOk);
110
}
else
{
111
qWarning(
"Unrecognized OpenGL ES version"
);
112
}
113
}
else
{
114
// If < 3 parts to the name, it is an unrecognised OpenGL ES
115
qWarning(
"Unrecognised OpenGL ES version"
);
116
}
117
}
else
{
118
// Not OpenGL ES, but regular OpenGL, the version numbers are first in the string
119
QList<QByteArray> versionParts = parts.at(0).split(
'.'
);
120
if
(versionParts.size() >= 2) {
121
major = versionParts.at(0).toInt(&majorOk);
122
minor = versionParts.at(1).toInt(&minorOk);
123
}
else
{
124
qWarning(
"Unrecognized OpenGL version"
);
125
}
126
}
127
128
if
(!majorOk || !minorOk)
129
qWarning(
"Unrecognized OpenGL version"
);
130
return
(majorOk && minorOk);
131
}
132
133
/*!
134
Called when the RHI begins rendering a new frame in the context. Will always be paired with a
135
call to \l endFrame().
136
*/
137
void
QPlatformOpenGLContext::beginFrame()
138
{
139
}
140
141
/*!
142
Called when the RHI ends rendering a in the context. Is always preceded by a call to
143
\l beginFrame().
144
*/
145
void
QPlatformOpenGLContext::endFrame()
146
{
147
}
148
149
QT_END_NAMESPACE
QPlatformOpenGLContextPrivate
Definition
qplatformopenglcontext.cpp:47
QPlatformOpenGLContextPrivate::context
QOpenGLContext * context
Definition
qplatformopenglcontext.cpp:51
QPlatformOpenGLContextPrivate::QPlatformOpenGLContextPrivate
QPlatformOpenGLContextPrivate()
Definition
qplatformopenglcontext.cpp:49
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
gui
kernel
qplatformopenglcontext.cpp
Generated on
for Qt by
1.18.0