Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qplatformopenglcontext.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qplatformopenglcontext.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #include <QOpenGLFunctions> | - | ||||||||||||
37 | - | |||||||||||||
38 | QT_BEGIN_NAMESPACE | - | ||||||||||||
39 | - | |||||||||||||
40 | /*! | - | ||||||||||||
41 | \class QPlatformOpenGLContext | - | ||||||||||||
42 | \since 4.8 | - | ||||||||||||
43 | \internal | - | ||||||||||||
44 | \preliminary | - | ||||||||||||
45 | \ingroup qpa | - | ||||||||||||
46 | - | |||||||||||||
47 | \brief The QPlatformOpenGLContext class provides an abstraction for native GL contexts. | - | ||||||||||||
48 | - | |||||||||||||
49 | In QPA the way to support OpenGL or OpenVG or other technologies that requires a native GL | - | ||||||||||||
50 | context is through the QPlatformOpenGLContext wrapper. | - | ||||||||||||
51 | - | |||||||||||||
52 | There is no factory function for QPlatformOpenGLContexts, but rather only one accessor function. | - | ||||||||||||
53 | The only place to retrieve a QPlatformOpenGLContext from is through a QPlatformWindow. | - | ||||||||||||
54 | - | |||||||||||||
55 | The context which is current for a specific thread can be collected by the currentContext() | - | ||||||||||||
56 | function. This is how QPlatformOpenGLContext also makes it possible to use the Qt GUI module | - | ||||||||||||
57 | withhout using QOpenGLWidget. When using QOpenGLContext::currentContext(), it will ask | - | ||||||||||||
58 | QPlatformOpenGLContext for the currentContext. Then a corresponding QOpenGLContext will be returned, | - | ||||||||||||
59 | which maps to the QPlatformOpenGLContext. | - | ||||||||||||
60 | */ | - | ||||||||||||
61 | - | |||||||||||||
62 | /*! \fn void QPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface) | - | ||||||||||||
63 | Reimplement in subclass to native swap buffers calls | - | ||||||||||||
64 | - | |||||||||||||
65 | The implementation must support being called in a thread different than the gui-thread. | - | ||||||||||||
66 | */ | - | ||||||||||||
67 | - | |||||||||||||
68 | /*! \fn QFunctionPointer QPlatformOpenGLContext::getProcAddress(const QByteArray &procName) | - | ||||||||||||
69 | Reimplement in subclass to native getProcAddr calls. | - | ||||||||||||
70 | - | |||||||||||||
71 | Note: its convenient to use qPrintable(const QString &str) to get the const char * pointer | - | ||||||||||||
72 | */ | - | ||||||||||||
73 | - | |||||||||||||
74 | class QPlatformOpenGLContextPrivate | - | ||||||||||||
75 | { | - | ||||||||||||
76 | public: | - | ||||||||||||
77 | QPlatformOpenGLContextPrivate() : context(0) {} never executed: end of block | 0 | ||||||||||||
78 | - | |||||||||||||
79 | QOpenGLContext *context; | - | ||||||||||||
80 | }; | - | ||||||||||||
81 | - | |||||||||||||
82 | QPlatformOpenGLContext::QPlatformOpenGLContext() | - | ||||||||||||
83 | : d_ptr(new QPlatformOpenGLContextPrivate) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | } never executed: end of block | 0 | ||||||||||||
86 | - | |||||||||||||
87 | QPlatformOpenGLContext::~QPlatformOpenGLContext() | - | ||||||||||||
88 | { | - | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | /*! | - | ||||||||||||
92 | Called after a new instance is constructed. The default implementation does nothing. | - | ||||||||||||
93 | - | |||||||||||||
94 | Subclasses can use this function to perform additional initialization that relies on | - | ||||||||||||
95 | virtual functions. | - | ||||||||||||
96 | */ | - | ||||||||||||
97 | void QPlatformOpenGLContext::initialize() | - | ||||||||||||
98 | { | - | ||||||||||||
99 | } | - | ||||||||||||
100 | - | |||||||||||||
101 | /*! | - | ||||||||||||
102 | Reimplement in subclass if your platform uses framebuffer objects for surfaces. | - | ||||||||||||
103 | - | |||||||||||||
104 | The default implementation returns 0. | - | ||||||||||||
105 | */ | - | ||||||||||||
106 | GLuint QPlatformOpenGLContext::defaultFramebufferObject(QPlatformSurface *) const | - | ||||||||||||
107 | { | - | ||||||||||||
108 | return 0; never executed: return 0; | 0 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | QOpenGLContext *QPlatformOpenGLContext::context() const | - | ||||||||||||
112 | { | - | ||||||||||||
113 | Q_D(const QPlatformOpenGLContext); | - | ||||||||||||
114 | return d->context; never executed: return d->context; | 0 | ||||||||||||
115 | } | - | ||||||||||||
116 | - | |||||||||||||
117 | void QPlatformOpenGLContext::setContext(QOpenGLContext *context) | - | ||||||||||||
118 | { | - | ||||||||||||
119 | Q_D(QPlatformOpenGLContext); | - | ||||||||||||
120 | d->context = context; | - | ||||||||||||
121 | } never executed: end of block | 0 | ||||||||||||
122 | - | |||||||||||||
123 | bool QPlatformOpenGLContext::parseOpenGLVersion(const QByteArray &versionString, int &major, int &minor) | - | ||||||||||||
124 | { | - | ||||||||||||
125 | bool majorOk = false; | - | ||||||||||||
126 | bool minorOk = false; | - | ||||||||||||
127 | QList<QByteArray> parts = versionString.split(' '); | - | ||||||||||||
128 | if (versionString.startsWith(QByteArrayLiteral("OpenGL ES"))) { never executed: return ba;
| 0 | ||||||||||||
129 | if (parts.size() >= 3) {
| 0 | ||||||||||||
130 | QList<QByteArray> versionParts = parts.at(2).split('.'); | - | ||||||||||||
131 | if (versionParts.size() >= 2) {
| 0 | ||||||||||||
132 | major = versionParts.at(0).toInt(&majorOk); | - | ||||||||||||
133 | minor = versionParts.at(1).toInt(&minorOk); | - | ||||||||||||
134 | // Nexus 6 has "OpenGL ES 3.0V@95.0 (GIT@I86da836d38)" | - | ||||||||||||
135 | if (!minorOk)
| 0 | ||||||||||||
136 | if (int idx = versionParts.at(1).indexOf('V'))
| 0 | ||||||||||||
137 | minor = versionParts.at(1).left(idx).toInt(&minorOk); never executed: minor = versionParts.at(1).left(idx).toInt(&minorOk); | 0 | ||||||||||||
138 | } else { never executed: end of block | 0 | ||||||||||||
139 | qWarning("Unrecognized OpenGL ES version"); | - | ||||||||||||
140 | } never executed: end of block | 0 | ||||||||||||
141 | } else { | - | ||||||||||||
142 | // If < 3 parts to the name, it is an unrecognised OpenGL ES | - | ||||||||||||
143 | qWarning("Unrecognised OpenGL ES version"); | - | ||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||
145 | } else { | - | ||||||||||||
146 | // Not OpenGL ES, but regular OpenGL, the version numbers are first in the string | - | ||||||||||||
147 | QList<QByteArray> versionParts = parts.at(0).split('.'); | - | ||||||||||||
148 | if (versionParts.size() >= 2) {
| 0 | ||||||||||||
149 | major = versionParts.at(0).toInt(&majorOk); | - | ||||||||||||
150 | minor = versionParts.at(1).toInt(&minorOk); | - | ||||||||||||
151 | } else { never executed: end of block | 0 | ||||||||||||
152 | qWarning("Unrecognized OpenGL version"); | - | ||||||||||||
153 | } never executed: end of block | 0 | ||||||||||||
154 | } | - | ||||||||||||
155 | - | |||||||||||||
156 | if (!majorOk || !minorOk)
| 0 | ||||||||||||
157 | qWarning("Unrecognized OpenGL version"); never executed: QMessageLogger(__FILE__, 157, __PRETTY_FUNCTION__).warning("Unrecognized OpenGL version"); | 0 | ||||||||||||
158 | return (majorOk && minorOk); never executed: return (majorOk && minorOk);
| 0 | ||||||||||||
159 | } | - | ||||||||||||
160 | - | |||||||||||||
161 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |