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 QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QGLScreen>
43 #include <QGLContext>
44 #include <QGLWidget>
45 #include "private/qglwindowsurface_qws_p.h"
46
47 QT_BEGIN_NAMESPACE
48
49 class QGLScreenPrivate
50 {
51 public:
52 QGLScreen::Options options;
53 QGLScreenSurfaceFunctions *functions;
54 };
55
56 /*!
57 \internal
58 \preliminary
59 \class QGLScreen
60
61 \brief This class encapsulates an OpenGL screen driver.
62 */
63
QGLScreen(int displayId)64 QGLScreen::QGLScreen(int displayId)
65 : QScreen(displayId, GLClass), d_ptr(new QGLScreenPrivate)
66 {
67 d_ptr->options = NoOptions;
68 d_ptr->functions = new QGLScreenSurfaceFunctions();
69 }
70
~QGLScreen()71 QGLScreen::~QGLScreen()
72 {
73 delete d_ptr->functions;
74 delete d_ptr;
75 }
76
77 /*!
78 \since 4.3
79 \obsolete
80
81 Initializes the \a context and sets up the QGLWindowSurface of the
82 QWidget of \a context based on the parameters of \a context and
83 based on its own requirements. The format() of \a context needs
84 to be updated with the actual parameters of the OpenGLES drawable
85 that was set up.
86
87 \a shareContext is used in the same way as for QGLContext. It is
88 the context with which \a context shares display lists and texture
89 ids etc. The window surface must be set up so that this sharing
90 works.
91
92 Returns true in case of success and false if it is not possible to
93 create the necessary OpenGLES drawable/context.
94
95 Since 4.4.2, this function will be not be called if options()
96 indicates that a native window or pixmap drawable can be created
97 via the functions in the surfaceFunctions() object.
98
99 This function is obsolete in Qt 4.5 and higher. Use surfaceFunctions()
100 instead.
101
102 \sa options(), surfaceFunctions()
103 */
104 bool
chooseContext(QGLContext * context,const QGLContext * shareContext)105 QGLScreen::chooseContext(QGLContext *context, const QGLContext *shareContext)
106 {
107 Q_UNUSED(context);
108 Q_UNUSED(shareContext);
109 return false;
110 }
111
112 /*!
113 \enum QGLScreen::Option
114 This enum defines options that can be set on QGLScreen instances.
115
116 \value NoOptions There are no special options on the screen. This is the default.
117 \value NativeWindows Native windows can be created with QGLScreenSurfaceFunctions::createNativeWindow().
118 \value NativePixmaps Native pixmaps can be created with QGLScreenSurfaceFunctions::createNativePixmap().
119 \value NativeImages Native images can be created with QGLScreenSurfaceFunctions::createNativeImage().
120 \value Overlays The screen supports GL overlays.
121 */
122
123 /*!
124 \since 4.4.2
125
126 Returns the options associated with this QGLScreen.
127
128 \sa setOptions()
129 */
options() const130 QGLScreen::Options QGLScreen::options() const
131 {
132 return d_ptr->options;
133 }
134
135 /*!
136 \since 4.4.2
137
138 Sets the options associated with this QGLScreen to \a value.
139
140 \sa options()
141 */
setOptions(QGLScreen::Options value)142 void QGLScreen::setOptions(QGLScreen::Options value)
143 {
144 d_ptr->options = value;
145 }
146
147 /*!
148 \since 4.4.2
149
150 Returns the surface functions object for this QGLScreen.
151
152 \sa setSurfaceFunctions()
153 */
surfaceFunctions() const154 QGLScreenSurfaceFunctions *QGLScreen::surfaceFunctions() const
155 {
156 return d_ptr->functions;
157 }
158
159 /*!
160 \since 4.4.2
161
162 Sets the surface functions object for this QGLScreen to \a functions.
163 The QGLScreen will take over ownership of \a functions and delete
164 it when the QGLScreen is deleted.
165
166 \sa setSurfaceFunctions()
167 */
setSurfaceFunctions(QGLScreenSurfaceFunctions * functions)168 void QGLScreen::setSurfaceFunctions(QGLScreenSurfaceFunctions *functions)
169 {
170 if (functions && functions != d_ptr->functions) {
171 delete d_ptr->functions;
172 d_ptr->functions = functions;
173 }
174 }
175
176 /*!
177 \internal
178 \preliminary
179 \class QGLScreenSurfaceFunctions
180 \brief The QGLScreenSurfaceFunctions class encapsulates the functions for creating native windows and pixmaps for OpenGL ES.
181 */
182
183 /*!
184 \since 4.4.2
185
186 Creates a native OpenGLES drawable for the surface of \a widget and
187 returns it in \a native. Returns true if the OpenGLES drawable could
188 be created, or false if windows are not supported.
189
190 This function will be called if the NativeWindows option is set on
191 the screen.
192
193 \sa createNativePixmap(), createNativeImage(), QGLScreen::options()
194 */
createNativeWindow(QWidget * widget,EGLNativeWindowType * native)195 bool QGLScreenSurfaceFunctions::createNativeWindow(QWidget *widget, EGLNativeWindowType *native)
196 {
197 Q_UNUSED(widget);
198 Q_UNUSED(native);
199 return false;
200 }
201
202 /*!
203 \since 4.4.2
204
205 Creates a native OpenGLES drawable for directly rendering into
206 \a pixmap and returns it in \a native. Returns true if the OpenGLES
207 drawable could be created, or false if direct rendering into pixmaps
208 is not supported.
209
210 This function will be called if the NativePixmaps option is set on
211 the screen.
212
213 \sa createNativeWindow(), createNativeImage(), QGLScreen::options()
214 */
createNativePixmap(QPixmap * pixmap,EGLNativePixmapType * native)215 bool QGLScreenSurfaceFunctions::createNativePixmap(QPixmap *pixmap, EGLNativePixmapType *native)
216 {
217 Q_UNUSED(pixmap);
218 Q_UNUSED(native);
219 return false;
220 }
221
222 /*!
223 \since 4.4.2
224
225 Creates a native OpenGLES drawable for directly rendering into
226 \a image and returns it in \a native. Returns true if the OpenGLES
227 drawable could be created, or false if direct rendering into images
228 is not supported.
229
230 This function will be called if the NativeImages option is set on
231 the screen.
232
233 \sa createNativeWindow(), createNativePixmap(), QGLScreen::options()
234 */
createNativeImage(QImage * image,EGLNativePixmapType * native)235 bool QGLScreenSurfaceFunctions::createNativeImage(QImage *image, EGLNativePixmapType *native)
236 {
237 Q_UNUSED(image);
238 Q_UNUSED(native);
239 return false;
240 }
241
242 QT_END_NAMESPACE
243