|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtOpenGL/qgl.h> |
|
43 #include "qgl_p.h" |
|
44 #include "qgl_egl_p.h" |
|
45 |
|
46 QT_BEGIN_NAMESPACE |
|
47 |
|
48 // Set device configuration attributes from a QGLFormat instance. |
|
49 void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f) |
|
50 { |
|
51 if (deviceType == QInternal::Pixmap || deviceType == QInternal::Image) |
|
52 props.setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT); |
|
53 else if (deviceType == QInternal::Pbuffer) |
|
54 props.setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT); |
|
55 else |
|
56 props.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); |
|
57 |
|
58 // Set the pixel format to that contained in the QGLFormat |
|
59 // if the system hasn't already chosen a fixed format to |
|
60 // match the pixmap, widget, etc. |
|
61 if (props.value(EGL_RED_SIZE) == 0 || f.redBufferSize() != -1) |
|
62 props.setValue(EGL_RED_SIZE, f.redBufferSize() == -1 ? 1 : f.redBufferSize()); |
|
63 if (props.value(EGL_GREEN_SIZE) == 0 || f.greenBufferSize() != -1) |
|
64 props.setValue(EGL_GREEN_SIZE, f.greenBufferSize() == -1 ? 1 : f.greenBufferSize()); |
|
65 if (props.value(EGL_BLUE_SIZE) == 0 || f.blueBufferSize() != -1) |
|
66 props.setValue(EGL_BLUE_SIZE, f.blueBufferSize() == -1 ? 1 : f.blueBufferSize()); |
|
67 if (f.alpha()) { |
|
68 if (props.value(EGL_ALPHA_SIZE) == 0 || f.alphaBufferSize() != -1) |
|
69 props.setValue(EGL_ALPHA_SIZE, f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize()); |
|
70 } |
|
71 |
|
72 if (f.depth()) |
|
73 props.setValue(EGL_DEPTH_SIZE, f.depthBufferSize() == -1 ? 1 : f.depthBufferSize()); |
|
74 if (f.stencil()) |
|
75 props.setValue(EGL_STENCIL_SIZE, f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize()); |
|
76 if (f.sampleBuffers()) { |
|
77 props.setValue(EGL_SAMPLE_BUFFERS, 1); |
|
78 props.setValue(EGL_SAMPLES, f.samples() == -1 ? 1 : f.samples()); |
|
79 } else { |
|
80 props.setValue(EGL_SAMPLE_BUFFERS, 0); |
|
81 } |
|
82 if (deviceType == QInternal::Widget) |
|
83 props.setValue(EGL_LEVEL, f.plane()); |
|
84 } |
|
85 |
|
86 // Updates "format" with the parameters of the selected configuration. |
|
87 void qt_egl_update_format(const QEglContext& context, QGLFormat& format) |
|
88 { |
|
89 EGLint value = 0; |
|
90 |
|
91 if (context.configAttrib(EGL_RED_SIZE, &value)) |
|
92 format.setRedBufferSize(value); |
|
93 if (context.configAttrib(EGL_GREEN_SIZE, &value)) |
|
94 format.setGreenBufferSize(value); |
|
95 if (context.configAttrib(EGL_BLUE_SIZE, &value)) |
|
96 format.setBlueBufferSize(value); |
|
97 if (context.configAttrib(EGL_ALPHA_SIZE, &value)) { |
|
98 format.setAlpha(value != 0); |
|
99 if (format.alpha()) |
|
100 format.setAlphaBufferSize(value); |
|
101 } |
|
102 |
|
103 if (context.configAttrib(EGL_DEPTH_SIZE, &value)) { |
|
104 format.setDepth(value != 0); |
|
105 if (format.depth()) |
|
106 format.setDepthBufferSize(value); |
|
107 } |
|
108 |
|
109 if (context.configAttrib(EGL_LEVEL, &value)) |
|
110 format.setPlane(value); |
|
111 |
|
112 if (context.configAttrib(EGL_SAMPLE_BUFFERS, &value)) { |
|
113 format.setSampleBuffers(value != 0); |
|
114 if (format.sampleBuffers()) { |
|
115 context.configAttrib(EGL_SAMPLES, &value); |
|
116 format.setSamples(value); |
|
117 } |
|
118 } |
|
119 |
|
120 if (context.configAttrib(EGL_STENCIL_SIZE, &value)) { |
|
121 format.setStencil(value != 0); |
|
122 if (format.stencil()) |
|
123 format.setStencilBufferSize(value); |
|
124 } |
|
125 |
|
126 // Clear the EGL error state because some of the above may |
|
127 // have errored out because the attribute is not applicable |
|
128 // to the surface type. Such errors don't matter. |
|
129 context.clearError(); |
|
130 } |
|
131 |
|
132 bool QGLFormat::hasOpenGL() |
|
133 { |
|
134 return true; |
|
135 } |
|
136 |
|
137 void QGLContext::reset() |
|
138 { |
|
139 Q_D(QGLContext); |
|
140 if (!d->valid) |
|
141 return; |
|
142 d->cleanup(); |
|
143 doneCurrent(); |
|
144 if (d->eglContext) { |
|
145 if (d->eglSurface != EGL_NO_SURFACE) { |
|
146 #ifdef Q_WS_X11 |
|
147 // Make sure we don't call eglDestroySurface on a surface which |
|
148 // was created for a different winId: |
|
149 if (d->paintDevice->devType() == QInternal::Widget) { |
|
150 QGLWidget* w = static_cast<QGLWidget*>(d->paintDevice); |
|
151 |
|
152 if (w->d_func()->eglSurfaceWindowId == w->winId()) |
|
153 eglDestroySurface(d->eglContext->display(), d->eglSurface); |
|
154 } else |
|
155 #endif |
|
156 eglDestroySurface(d->eglContext->display(), d->eglSurface); |
|
157 } |
|
158 delete d->eglContext; |
|
159 } |
|
160 d->eglContext = 0; |
|
161 d->eglSurface = EGL_NO_SURFACE; |
|
162 d->crWin = false; |
|
163 d->sharing = false; |
|
164 d->valid = false; |
|
165 d->transpColor = QColor(); |
|
166 d->initDone = false; |
|
167 qgl_share_reg()->removeShare(this); |
|
168 } |
|
169 |
|
170 void QGLContext::makeCurrent() |
|
171 { |
|
172 Q_D(QGLContext); |
|
173 if (!d->valid || !d->eglContext || d->eglSurface == EGL_NO_SURFACE) { |
|
174 qWarning("QGLContext::makeCurrent(): Cannot make invalid context current"); |
|
175 return; |
|
176 } |
|
177 |
|
178 if (d->eglContext->makeCurrent(d->eglSurface)) |
|
179 QGLContextPrivate::setCurrentContext(this); |
|
180 } |
|
181 |
|
182 void QGLContext::doneCurrent() |
|
183 { |
|
184 Q_D(QGLContext); |
|
185 if (d->eglContext) |
|
186 d->eglContext->doneCurrent(); |
|
187 |
|
188 QGLContextPrivate::setCurrentContext(0); |
|
189 } |
|
190 |
|
191 |
|
192 void QGLContext::swapBuffers() const |
|
193 { |
|
194 Q_D(const QGLContext); |
|
195 if (!d->valid || !d->eglContext) |
|
196 return; |
|
197 |
|
198 d->eglContext->swapBuffers(d->eglSurface); |
|
199 } |
|
200 |
|
201 void QGLWidget::setMouseTracking(bool enable) |
|
202 { |
|
203 QWidget::setMouseTracking(enable); |
|
204 } |
|
205 |
|
206 QColor QGLContext::overlayTransparentColor() const |
|
207 { |
|
208 return d_func()->transpColor; |
|
209 } |
|
210 |
|
211 uint QGLContext::colorIndex(const QColor &c) const |
|
212 { |
|
213 Q_UNUSED(c); |
|
214 return 0; |
|
215 } |
|
216 |
|
217 void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase) |
|
218 { |
|
219 Q_UNUSED(fnt); |
|
220 Q_UNUSED(listBase); |
|
221 } |
|
222 |
|
223 void *QGLContext::getProcAddress(const QString &proc) const |
|
224 { |
|
225 return (void*)eglGetProcAddress(reinterpret_cast<const char *>(proc.toLatin1().data())); |
|
226 } |
|
227 |
|
228 bool QGLWidgetPrivate::renderCxPm(QPixmap*) |
|
229 { |
|
230 return false; |
|
231 } |
|
232 |
|
233 QT_END_NAMESPACE |