author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 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 test suite 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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qcoreapplication.h> |
|
46 |
#include <qdebug.h> |
|
47 |
#include <qgl.h> |
|
48 |
#include <qglpixelbuffer.h> |
|
49 |
#include <qglframebufferobject.h> |
|
50 |
#include <qglcolormap.h> |
|
51 |
#include <qpaintengine.h> |
|
52 |
||
53 |
#include <QGraphicsView> |
|
54 |
#include <QGraphicsProxyWidget> |
|
55 |
#include <QVBoxLayout> |
|
56 |
||
57 |
#ifdef QT_BUILD_INTERNAL |
|
58 |
#include <QtOpenGL/private/qgl_p.h> |
|
59 |
#endif |
|
60 |
||
61 |
//TESTED_CLASS= |
|
62 |
//TESTED_FILES= |
|
63 |
||
64 |
class tst_QGL : public QObject |
|
65 |
{ |
|
66 |
Q_OBJECT |
|
67 |
||
68 |
public: |
|
69 |
tst_QGL(); |
|
70 |
virtual ~tst_QGL(); |
|
71 |
||
72 |
private slots: |
|
73 |
void getSetCheck(); |
|
74 |
void openGLVersionCheck(); |
|
75 |
void graphicsViewClipping(); |
|
76 |
void partialGLWidgetUpdates_data(); |
|
77 |
void partialGLWidgetUpdates(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
void glWidgetWithAlpha(); |
0 | 79 |
void glWidgetRendering(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
void glFBOSimpleRendering(); |
0 | 81 |
void glFBORendering(); |
82 |
void multipleFBOInterleavedRendering(); |
|
83 |
void glFBOUseInGLWidget(); |
|
84 |
void glPBufferRendering(); |
|
85 |
void glWidgetReparent(); |
|
86 |
void glWidgetRenderPixmap(); |
|
87 |
void colormap(); |
|
88 |
void fboFormat(); |
|
89 |
void testDontCrashOnDanglingResources(); |
|
90 |
void replaceClipping(); |
|
91 |
void clipTest(); |
|
92 |
void destroyFBOAfterContext(); |
|
93 |
void shareRegister(); |
|
94 |
}; |
|
95 |
||
96 |
tst_QGL::tst_QGL() |
|
97 |
{ |
|
98 |
} |
|
99 |
||
100 |
tst_QGL::~tst_QGL() |
|
101 |
{ |
|
102 |
} |
|
103 |
||
104 |
class MyGLContext : public QGLContext |
|
105 |
{ |
|
106 |
public: |
|
107 |
MyGLContext(const QGLFormat& format) : QGLContext(format) {} |
|
108 |
bool windowCreated() const { return QGLContext::windowCreated(); } |
|
109 |
void setWindowCreated(bool on) { QGLContext::setWindowCreated(on); } |
|
110 |
bool initialized() const { return QGLContext::initialized(); } |
|
111 |
void setInitialized(bool on) { QGLContext::setInitialized(on); } |
|
112 |
}; |
|
113 |
||
114 |
class MyGLWidget : public QGLWidget |
|
115 |
{ |
|
116 |
public: |
|
117 |
MyGLWidget() : QGLWidget() {} |
|
118 |
bool autoBufferSwap() const { return QGLWidget::autoBufferSwap(); } |
|
119 |
void setAutoBufferSwap(bool on) { QGLWidget::setAutoBufferSwap(on); } |
|
120 |
}; |
|
121 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
static int appDefaultDepth() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
static int depth = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
if (depth == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
QPixmap pm(1, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
depth = pm.depth(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
return depth; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
|
0 | 132 |
// Using INT_MIN and INT_MAX will cause failures on systems |
133 |
// where "int" is 64-bit, so use the explicit values instead. |
|
134 |
#define TEST_INT_MIN (-2147483647 - 1) |
|
135 |
#define TEST_INT_MAX 2147483647 |
|
136 |
||
137 |
// Testing get/set functions |
|
138 |
void tst_QGL::getSetCheck() |
|
139 |
{ |
|
140 |
if (!QGLFormat::hasOpenGL()) |
|
141 |
QSKIP("QGL not supported on this platform", SkipAll); |
|
142 |
||
143 |
QGLFormat obj1; |
|
144 |
// int QGLFormat::depthBufferSize() |
|
145 |
// void QGLFormat::setDepthBufferSize(int) |
|
146 |
QCOMPARE(-1, obj1.depthBufferSize()); |
|
147 |
obj1.setDepthBufferSize(0); |
|
148 |
QCOMPARE(0, obj1.depthBufferSize()); |
|
149 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size -2147483648"); |
|
150 |
obj1.setDepthBufferSize(TEST_INT_MIN); |
|
151 |
QCOMPARE(0, obj1.depthBufferSize()); // Makes no sense with a negative buffer size |
|
152 |
obj1.setDepthBufferSize(3); |
|
153 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size -1"); |
|
154 |
obj1.setDepthBufferSize(-1); |
|
155 |
QCOMPARE(3, obj1.depthBufferSize()); |
|
156 |
obj1.setDepthBufferSize(TEST_INT_MAX); |
|
157 |
QCOMPARE(TEST_INT_MAX, obj1.depthBufferSize()); |
|
158 |
||
159 |
// int QGLFormat::accumBufferSize() |
|
160 |
// void QGLFormat::setAccumBufferSize(int) |
|
161 |
QCOMPARE(-1, obj1.accumBufferSize()); |
|
162 |
obj1.setAccumBufferSize(0); |
|
163 |
QCOMPARE(0, obj1.accumBufferSize()); |
|
164 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size -2147483648"); |
|
165 |
obj1.setAccumBufferSize(TEST_INT_MIN); |
|
166 |
QCOMPARE(0, obj1.accumBufferSize()); // Makes no sense with a negative buffer size |
|
167 |
obj1.setAccumBufferSize(3); |
|
168 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size -1"); |
|
169 |
obj1.setAccumBufferSize(-1); |
|
170 |
QCOMPARE(3, obj1.accumBufferSize()); |
|
171 |
obj1.setAccumBufferSize(TEST_INT_MAX); |
|
172 |
QCOMPARE(TEST_INT_MAX, obj1.accumBufferSize()); |
|
173 |
||
174 |
// int QGLFormat::redBufferSize() |
|
175 |
// void QGLFormat::setRedBufferSize(int) |
|
176 |
QCOMPARE(-1, obj1.redBufferSize()); |
|
177 |
obj1.setRedBufferSize(0); |
|
178 |
QCOMPARE(0, obj1.redBufferSize()); |
|
179 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setRedBufferSize: Cannot set negative red buffer size -2147483648"); |
|
180 |
obj1.setRedBufferSize(TEST_INT_MIN); |
|
181 |
QCOMPARE(0, obj1.redBufferSize()); // Makes no sense with a negative buffer size |
|
182 |
obj1.setRedBufferSize(3); |
|
183 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setRedBufferSize: Cannot set negative red buffer size -1"); |
|
184 |
obj1.setRedBufferSize(-1); |
|
185 |
QCOMPARE(3, obj1.redBufferSize()); |
|
186 |
obj1.setRedBufferSize(TEST_INT_MAX); |
|
187 |
QCOMPARE(TEST_INT_MAX, obj1.redBufferSize()); |
|
188 |
||
189 |
// int QGLFormat::greenBufferSize() |
|
190 |
// void QGLFormat::setGreenBufferSize(int) |
|
191 |
QCOMPARE(-1, obj1.greenBufferSize()); |
|
192 |
obj1.setGreenBufferSize(0); |
|
193 |
QCOMPARE(0, obj1.greenBufferSize()); |
|
194 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setGreenBufferSize: Cannot set negative green buffer size -2147483648"); |
|
195 |
obj1.setGreenBufferSize(TEST_INT_MIN); |
|
196 |
QCOMPARE(0, obj1.greenBufferSize()); // Makes no sense with a negative buffer size |
|
197 |
obj1.setGreenBufferSize(3); |
|
198 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setGreenBufferSize: Cannot set negative green buffer size -1"); |
|
199 |
obj1.setGreenBufferSize(-1); |
|
200 |
QCOMPARE(3, obj1.greenBufferSize()); |
|
201 |
obj1.setGreenBufferSize(TEST_INT_MAX); |
|
202 |
QCOMPARE(TEST_INT_MAX, obj1.greenBufferSize()); |
|
203 |
||
204 |
// int QGLFormat::blueBufferSize() |
|
205 |
// void QGLFormat::setBlueBufferSize(int) |
|
206 |
QCOMPARE(-1, obj1.blueBufferSize()); |
|
207 |
obj1.setBlueBufferSize(0); |
|
208 |
QCOMPARE(0, obj1.blueBufferSize()); |
|
209 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size -2147483648"); |
|
210 |
obj1.setBlueBufferSize(TEST_INT_MIN); |
|
211 |
QCOMPARE(0, obj1.blueBufferSize()); // Makes no sense with a negative buffer size |
|
212 |
obj1.setBlueBufferSize(3); |
|
213 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size -1"); |
|
214 |
obj1.setBlueBufferSize(-1); |
|
215 |
QCOMPARE(3, obj1.blueBufferSize()); |
|
216 |
obj1.setBlueBufferSize(TEST_INT_MAX); |
|
217 |
QCOMPARE(TEST_INT_MAX, obj1.blueBufferSize()); |
|
218 |
||
219 |
// int QGLFormat::alphaBufferSize() |
|
220 |
// void QGLFormat::setAlphaBufferSize(int) |
|
221 |
QCOMPARE(-1, obj1.alphaBufferSize()); |
|
222 |
QCOMPARE(false, obj1.alpha()); |
|
223 |
QVERIFY(!obj1.testOption(QGL::AlphaChannel)); |
|
224 |
QVERIFY(obj1.testOption(QGL::NoAlphaChannel)); |
|
225 |
obj1.setAlphaBufferSize(0); |
|
226 |
QCOMPARE(true, obj1.alpha()); // setAlphaBufferSize() enables alpha. |
|
227 |
QCOMPARE(0, obj1.alphaBufferSize()); |
|
228 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size -2147483648"); |
|
229 |
obj1.setAlphaBufferSize(TEST_INT_MIN); |
|
230 |
QCOMPARE(0, obj1.alphaBufferSize()); // Makes no sense with a negative buffer size |
|
231 |
obj1.setAlphaBufferSize(3); |
|
232 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size -1"); |
|
233 |
obj1.setAlphaBufferSize(-1); |
|
234 |
QCOMPARE(3, obj1.alphaBufferSize()); |
|
235 |
obj1.setAlphaBufferSize(TEST_INT_MAX); |
|
236 |
QCOMPARE(TEST_INT_MAX, obj1.alphaBufferSize()); |
|
237 |
||
238 |
// int QGLFormat::stencilBufferSize() |
|
239 |
// void QGLFormat::setStencilBufferSize(int) |
|
240 |
QCOMPARE(-1, obj1.stencilBufferSize()); |
|
241 |
obj1.setStencilBufferSize(0); |
|
242 |
QCOMPARE(0, obj1.stencilBufferSize()); |
|
243 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size -2147483648"); |
|
244 |
obj1.setStencilBufferSize(TEST_INT_MIN); |
|
245 |
QCOMPARE(0, obj1.stencilBufferSize()); // Makes no sense with a negative buffer size |
|
246 |
obj1.setStencilBufferSize(3); |
|
247 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size -1"); |
|
248 |
obj1.setStencilBufferSize(-1); |
|
249 |
QCOMPARE(3, obj1.stencilBufferSize()); |
|
250 |
obj1.setStencilBufferSize(TEST_INT_MAX); |
|
251 |
QCOMPARE(TEST_INT_MAX, obj1.stencilBufferSize()); |
|
252 |
||
253 |
// bool QGLFormat::sampleBuffers() |
|
254 |
// void QGLFormat::setSampleBuffers(bool) |
|
255 |
QCOMPARE(false, obj1.sampleBuffers()); |
|
256 |
QVERIFY(!obj1.testOption(QGL::SampleBuffers)); |
|
257 |
QVERIFY(obj1.testOption(QGL::NoSampleBuffers)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
|
0 | 259 |
obj1.setSampleBuffers(false); |
260 |
QCOMPARE(false, obj1.sampleBuffers()); |
|
261 |
QVERIFY(obj1.testOption(QGL::NoSampleBuffers)); |
|
262 |
obj1.setSampleBuffers(true); |
|
263 |
QCOMPARE(true, obj1.sampleBuffers()); |
|
264 |
QVERIFY(obj1.testOption(QGL::SampleBuffers)); |
|
265 |
||
266 |
// int QGLFormat::samples() |
|
267 |
// void QGLFormat::setSamples(int) |
|
268 |
QCOMPARE(-1, obj1.samples()); |
|
269 |
obj1.setSamples(0); |
|
270 |
QCOMPARE(0, obj1.samples()); |
|
271 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setSamples: Cannot have negative number of samples per pixel -2147483648"); |
|
272 |
obj1.setSamples(TEST_INT_MIN); |
|
273 |
QCOMPARE(0, obj1.samples()); // Makes no sense with a negative sample size |
|
274 |
obj1.setSamples(3); |
|
275 |
QTest::ignoreMessage(QtWarningMsg, "QGLFormat::setSamples: Cannot have negative number of samples per pixel -1"); |
|
276 |
obj1.setSamples(-1); |
|
277 |
QCOMPARE(3, obj1.samples()); |
|
278 |
obj1.setSamples(TEST_INT_MAX); |
|
279 |
QCOMPARE(TEST_INT_MAX, obj1.samples()); |
|
280 |
||
281 |
// int QGLFormat::swapInterval() |
|
282 |
// void QGLFormat::setSwapInterval(int) |
|
283 |
QCOMPARE(-1, obj1.swapInterval()); |
|
284 |
obj1.setSwapInterval(0); |
|
285 |
QCOMPARE(0, obj1.swapInterval()); |
|
286 |
obj1.setSwapInterval(TEST_INT_MIN); |
|
287 |
QCOMPARE(TEST_INT_MIN, obj1.swapInterval()); |
|
288 |
obj1.setSwapInterval(-1); |
|
289 |
QCOMPARE(-1, obj1.swapInterval()); |
|
290 |
obj1.setSwapInterval(TEST_INT_MAX); |
|
291 |
QCOMPARE(TEST_INT_MAX, obj1.swapInterval()); |
|
292 |
||
293 |
// bool QGLFormat::doubleBuffer() |
|
294 |
// void QGLFormat::setDoubleBuffer(bool) |
|
295 |
QCOMPARE(true, obj1.doubleBuffer()); |
|
296 |
QVERIFY(obj1.testOption(QGL::DoubleBuffer)); |
|
297 |
QVERIFY(!obj1.testOption(QGL::SingleBuffer)); |
|
298 |
obj1.setDoubleBuffer(false); |
|
299 |
QCOMPARE(false, obj1.doubleBuffer()); |
|
300 |
QVERIFY(!obj1.testOption(QGL::DoubleBuffer)); |
|
301 |
QVERIFY(obj1.testOption(QGL::SingleBuffer)); |
|
302 |
obj1.setDoubleBuffer(true); |
|
303 |
QCOMPARE(true, obj1.doubleBuffer()); |
|
304 |
QVERIFY(obj1.testOption(QGL::DoubleBuffer)); |
|
305 |
QVERIFY(!obj1.testOption(QGL::SingleBuffer)); |
|
306 |
||
307 |
// bool QGLFormat::depth() |
|
308 |
// void QGLFormat::setDepth(bool) |
|
309 |
QCOMPARE(true, obj1.depth()); |
|
310 |
QVERIFY(obj1.testOption(QGL::DepthBuffer)); |
|
311 |
QVERIFY(!obj1.testOption(QGL::NoDepthBuffer)); |
|
312 |
obj1.setDepth(false); |
|
313 |
QCOMPARE(false, obj1.depth()); |
|
314 |
QVERIFY(!obj1.testOption(QGL::DepthBuffer)); |
|
315 |
QVERIFY(obj1.testOption(QGL::NoDepthBuffer)); |
|
316 |
obj1.setDepth(true); |
|
317 |
QCOMPARE(true, obj1.depth()); |
|
318 |
QVERIFY(obj1.testOption(QGL::DepthBuffer)); |
|
319 |
QVERIFY(!obj1.testOption(QGL::NoDepthBuffer)); |
|
320 |
||
321 |
// bool QGLFormat::rgba() |
|
322 |
// void QGLFormat::setRgba(bool) |
|
323 |
QCOMPARE(true, obj1.rgba()); |
|
324 |
QVERIFY(obj1.testOption(QGL::Rgba)); |
|
325 |
QVERIFY(!obj1.testOption(QGL::ColorIndex)); |
|
326 |
obj1.setRgba(false); |
|
327 |
QCOMPARE(false, obj1.rgba()); |
|
328 |
QVERIFY(!obj1.testOption(QGL::Rgba)); |
|
329 |
QVERIFY(obj1.testOption(QGL::ColorIndex)); |
|
330 |
obj1.setRgba(true); |
|
331 |
QCOMPARE(true, obj1.rgba()); |
|
332 |
QVERIFY(obj1.testOption(QGL::Rgba)); |
|
333 |
QVERIFY(!obj1.testOption(QGL::ColorIndex)); |
|
334 |
||
335 |
// bool QGLFormat::alpha() |
|
336 |
// void QGLFormat::setAlpha(bool) |
|
337 |
QVERIFY(obj1.testOption(QGL::AlphaChannel)); |
|
338 |
QVERIFY(!obj1.testOption(QGL::NoAlphaChannel)); |
|
339 |
obj1.setAlpha(false); |
|
340 |
QCOMPARE(false, obj1.alpha()); |
|
341 |
QVERIFY(!obj1.testOption(QGL::AlphaChannel)); |
|
342 |
QVERIFY(obj1.testOption(QGL::NoAlphaChannel)); |
|
343 |
obj1.setAlpha(true); |
|
344 |
QCOMPARE(true, obj1.alpha()); |
|
345 |
QVERIFY(obj1.testOption(QGL::AlphaChannel)); |
|
346 |
QVERIFY(!obj1.testOption(QGL::NoAlphaChannel)); |
|
347 |
||
348 |
// bool QGLFormat::accum() |
|
349 |
// void QGLFormat::setAccum(bool) |
|
350 |
QCOMPARE(false, obj1.accum()); |
|
351 |
QVERIFY(!obj1.testOption(QGL::AccumBuffer)); |
|
352 |
QVERIFY(obj1.testOption(QGL::NoAccumBuffer)); |
|
353 |
obj1.setAccum(false); |
|
354 |
QCOMPARE(false, obj1.accum()); |
|
355 |
QVERIFY(!obj1.testOption(QGL::AccumBuffer)); |
|
356 |
QVERIFY(obj1.testOption(QGL::NoAccumBuffer)); |
|
357 |
obj1.setAccum(true); |
|
358 |
QCOMPARE(true, obj1.accum()); |
|
359 |
QVERIFY(obj1.testOption(QGL::AccumBuffer)); |
|
360 |
QVERIFY(!obj1.testOption(QGL::NoAccumBuffer)); |
|
361 |
||
362 |
// bool QGLFormat::stencil() |
|
363 |
// void QGLFormat::setStencil(bool) |
|
364 |
QCOMPARE(true, obj1.stencil()); |
|
365 |
QVERIFY(obj1.testOption(QGL::StencilBuffer)); |
|
366 |
QVERIFY(!obj1.testOption(QGL::NoStencilBuffer)); |
|
367 |
obj1.setStencil(false); |
|
368 |
QCOMPARE(false, obj1.stencil()); |
|
369 |
QVERIFY(!obj1.testOption(QGL::StencilBuffer)); |
|
370 |
QVERIFY(obj1.testOption(QGL::NoStencilBuffer)); |
|
371 |
obj1.setStencil(true); |
|
372 |
QCOMPARE(true, obj1.stencil()); |
|
373 |
QVERIFY(obj1.testOption(QGL::StencilBuffer)); |
|
374 |
QVERIFY(!obj1.testOption(QGL::NoStencilBuffer)); |
|
375 |
||
376 |
// bool QGLFormat::stereo() |
|
377 |
// void QGLFormat::setStereo(bool) |
|
378 |
QCOMPARE(false, obj1.stereo()); |
|
379 |
QVERIFY(!obj1.testOption(QGL::StereoBuffers)); |
|
380 |
QVERIFY(obj1.testOption(QGL::NoStereoBuffers)); |
|
381 |
obj1.setStereo(false); |
|
382 |
QCOMPARE(false, obj1.stereo()); |
|
383 |
QVERIFY(!obj1.testOption(QGL::StereoBuffers)); |
|
384 |
QVERIFY(obj1.testOption(QGL::NoStereoBuffers)); |
|
385 |
obj1.setStereo(true); |
|
386 |
QCOMPARE(true, obj1.stereo()); |
|
387 |
QVERIFY(obj1.testOption(QGL::StereoBuffers)); |
|
388 |
QVERIFY(!obj1.testOption(QGL::NoStereoBuffers)); |
|
389 |
||
390 |
// bool QGLFormat::directRendering() |
|
391 |
// void QGLFormat::setDirectRendering(bool) |
|
392 |
QCOMPARE(true, obj1.directRendering()); |
|
393 |
QVERIFY(obj1.testOption(QGL::DirectRendering)); |
|
394 |
QVERIFY(!obj1.testOption(QGL::IndirectRendering)); |
|
395 |
obj1.setDirectRendering(false); |
|
396 |
QCOMPARE(false, obj1.directRendering()); |
|
397 |
QVERIFY(!obj1.testOption(QGL::DirectRendering)); |
|
398 |
QVERIFY(obj1.testOption(QGL::IndirectRendering)); |
|
399 |
obj1.setDirectRendering(true); |
|
400 |
QCOMPARE(true, obj1.directRendering()); |
|
401 |
QVERIFY(obj1.testOption(QGL::DirectRendering)); |
|
402 |
QVERIFY(!obj1.testOption(QGL::IndirectRendering)); |
|
403 |
||
404 |
// bool QGLFormat::overlay() |
|
405 |
// void QGLFormat::setOverlay(bool) |
|
406 |
QCOMPARE(false, obj1.hasOverlay()); |
|
407 |
QVERIFY(!obj1.testOption(QGL::HasOverlay)); |
|
408 |
QVERIFY(obj1.testOption(QGL::NoOverlay)); |
|
409 |
obj1.setOverlay(false); |
|
410 |
QCOMPARE(false, obj1.hasOverlay()); |
|
411 |
QVERIFY(!obj1.testOption(QGL::HasOverlay)); |
|
412 |
QVERIFY(obj1.testOption(QGL::NoOverlay)); |
|
413 |
obj1.setOverlay(true); |
|
414 |
QCOMPARE(true, obj1.hasOverlay()); |
|
415 |
QVERIFY(obj1.testOption(QGL::HasOverlay)); |
|
416 |
QVERIFY(!obj1.testOption(QGL::NoOverlay)); |
|
417 |
||
418 |
// int QGLFormat::plane() |
|
419 |
// void QGLFormat::setPlane(int) |
|
420 |
QCOMPARE(0, obj1.plane()); |
|
421 |
obj1.setPlane(0); |
|
422 |
QCOMPARE(0, obj1.plane()); |
|
423 |
obj1.setPlane(TEST_INT_MIN); |
|
424 |
QCOMPARE(TEST_INT_MIN, obj1.plane()); |
|
425 |
obj1.setPlane(TEST_INT_MAX); |
|
426 |
QCOMPARE(TEST_INT_MAX, obj1.plane()); |
|
427 |
||
428 |
// operator== and operator!= for QGLFormat |
|
429 |
QGLFormat format1; |
|
430 |
QGLFormat format2; |
|
431 |
||
432 |
QVERIFY(format1 == format2); |
|
433 |
QVERIFY(!(format1 != format2)); |
|
434 |
format1.setDoubleBuffer(false); |
|
435 |
QVERIFY(!(format1 == format2)); |
|
436 |
QVERIFY(format1 != format2); |
|
437 |
format2.setDoubleBuffer(false); |
|
438 |
QVERIFY(format1 == format2); |
|
439 |
QVERIFY(!(format1 != format2)); |
|
440 |
||
441 |
format1.setDepthBufferSize(8); |
|
442 |
QVERIFY(!(format1 == format2)); |
|
443 |
QVERIFY(format1 != format2); |
|
444 |
format2.setDepthBufferSize(8); |
|
445 |
QVERIFY(format1 == format2); |
|
446 |
QVERIFY(!(format1 != format2)); |
|
447 |
||
448 |
format1.setAccumBufferSize(8); |
|
449 |
QVERIFY(!(format1 == format2)); |
|
450 |
QVERIFY(format1 != format2); |
|
451 |
format2.setAccumBufferSize(8); |
|
452 |
QVERIFY(format1 == format2); |
|
453 |
QVERIFY(!(format1 != format2)); |
|
454 |
||
455 |
format1.setRedBufferSize(8); |
|
456 |
QVERIFY(!(format1 == format2)); |
|
457 |
QVERIFY(format1 != format2); |
|
458 |
format2.setRedBufferSize(8); |
|
459 |
QVERIFY(format1 == format2); |
|
460 |
QVERIFY(!(format1 != format2)); |
|
461 |
||
462 |
format1.setGreenBufferSize(8); |
|
463 |
QVERIFY(!(format1 == format2)); |
|
464 |
QVERIFY(format1 != format2); |
|
465 |
format2.setGreenBufferSize(8); |
|
466 |
QVERIFY(format1 == format2); |
|
467 |
QVERIFY(!(format1 != format2)); |
|
468 |
||
469 |
format1.setBlueBufferSize(8); |
|
470 |
QVERIFY(!(format1 == format2)); |
|
471 |
QVERIFY(format1 != format2); |
|
472 |
format2.setBlueBufferSize(8); |
|
473 |
QVERIFY(format1 == format2); |
|
474 |
QVERIFY(!(format1 != format2)); |
|
475 |
||
476 |
format1.setAlphaBufferSize(8); |
|
477 |
QVERIFY(!(format1 == format2)); |
|
478 |
QVERIFY(format1 != format2); |
|
479 |
format2.setAlphaBufferSize(8); |
|
480 |
QVERIFY(format1 == format2); |
|
481 |
QVERIFY(!(format1 != format2)); |
|
482 |
||
483 |
format1.setStencilBufferSize(8); |
|
484 |
QVERIFY(!(format1 == format2)); |
|
485 |
QVERIFY(format1 != format2); |
|
486 |
format2.setStencilBufferSize(8); |
|
487 |
QVERIFY(format1 == format2); |
|
488 |
QVERIFY(!(format1 != format2)); |
|
489 |
||
490 |
format1.setSamples(8); |
|
491 |
QVERIFY(!(format1 == format2)); |
|
492 |
QVERIFY(format1 != format2); |
|
493 |
format2.setSamples(8); |
|
494 |
QVERIFY(format1 == format2); |
|
495 |
QVERIFY(!(format1 != format2)); |
|
496 |
||
497 |
format1.setSwapInterval(8); |
|
498 |
QVERIFY(!(format1 == format2)); |
|
499 |
QVERIFY(format1 != format2); |
|
500 |
format2.setSwapInterval(8); |
|
501 |
QVERIFY(format1 == format2); |
|
502 |
QVERIFY(!(format1 != format2)); |
|
503 |
||
504 |
format1.setPlane(8); |
|
505 |
QVERIFY(!(format1 == format2)); |
|
506 |
QVERIFY(format1 != format2); |
|
507 |
format2.setPlane(8); |
|
508 |
QVERIFY(format1 == format2); |
|
509 |
QVERIFY(!(format1 != format2)); |
|
510 |
||
511 |
// Copy constructor and assignment for QGLFormat. |
|
512 |
QGLFormat format3(format1); |
|
513 |
QGLFormat format4; |
|
514 |
QVERIFY(format1 == format3); |
|
515 |
QVERIFY(format1 != format4); |
|
516 |
format4 = format1; |
|
517 |
QVERIFY(format1 == format4); |
|
518 |
||
519 |
// Check that modifying a copy doesn't affect the original. |
|
520 |
format3.setRedBufferSize(16); |
|
521 |
format4.setPlane(16); |
|
522 |
QCOMPARE(format1.redBufferSize(), 8); |
|
523 |
QCOMPARE(format1.plane(), 8); |
|
524 |
||
525 |
// Check the QGLFormat constructor that takes an option list. |
|
526 |
QGLFormat format5 |
|
527 |
(QGL::DepthBuffer | QGL::StereoBuffers | QGL::ColorIndex, 3); |
|
528 |
QVERIFY(format5.depth()); |
|
529 |
QVERIFY(format5.stereo()); |
|
530 |
QVERIFY(format5.doubleBuffer()); // From defaultFormat() |
|
531 |
QVERIFY(!format5.hasOverlay()); // From defaultFormat() |
|
532 |
QVERIFY(!format5.rgba()); |
|
533 |
QCOMPARE(format5.plane(), 3); |
|
534 |
||
535 |
// The default format should be the same as QGLFormat(). |
|
536 |
QVERIFY(QGLFormat::defaultFormat() == QGLFormat()); |
|
537 |
||
538 |
// Modify the default format and check that it was changed. |
|
539 |
QGLFormat::setDefaultFormat(format1); |
|
540 |
QVERIFY(QGLFormat::defaultFormat() == format1); |
|
541 |
||
542 |
// Restore the default format. |
|
543 |
QGLFormat::setDefaultFormat(QGLFormat()); |
|
544 |
QVERIFY(QGLFormat::defaultFormat() == QGLFormat()); |
|
545 |
||
546 |
// Check the default overlay format's expected values. |
|
547 |
QGLFormat overlay(QGLFormat::defaultOverlayFormat()); |
|
548 |
QCOMPARE(overlay.depthBufferSize(), -1); |
|
549 |
QCOMPARE(overlay.accumBufferSize(), -1); |
|
550 |
QCOMPARE(overlay.redBufferSize(), -1); |
|
551 |
QCOMPARE(overlay.greenBufferSize(), -1); |
|
552 |
QCOMPARE(overlay.blueBufferSize(), -1); |
|
553 |
QCOMPARE(overlay.alphaBufferSize(), -1); |
|
554 |
QCOMPARE(overlay.samples(), -1); |
|
555 |
QCOMPARE(overlay.swapInterval(), -1); |
|
556 |
QCOMPARE(overlay.plane(), 1); |
|
557 |
QVERIFY(!overlay.sampleBuffers()); |
|
558 |
QVERIFY(!overlay.doubleBuffer()); |
|
559 |
QVERIFY(!overlay.depth()); |
|
560 |
QVERIFY(!overlay.rgba()); |
|
561 |
QVERIFY(!overlay.alpha()); |
|
562 |
QVERIFY(!overlay.accum()); |
|
563 |
QVERIFY(!overlay.stencil()); |
|
564 |
QVERIFY(!overlay.stereo()); |
|
565 |
QVERIFY(overlay.directRendering()); // Only option that should be on. |
|
566 |
QVERIFY(!overlay.hasOverlay()); // Overlay doesn't need an overlay! |
|
567 |
||
568 |
// Modify the default overlay format and check that it was changed. |
|
569 |
QGLFormat::setDefaultOverlayFormat(format1); |
|
570 |
QVERIFY(QGLFormat::defaultOverlayFormat() == format1); |
|
571 |
||
572 |
// Restore the default overlay format. |
|
573 |
QGLFormat::setDefaultOverlayFormat(overlay); |
|
574 |
QVERIFY(QGLFormat::defaultOverlayFormat() == overlay); |
|
575 |
||
576 |
MyGLContext obj2(obj1); |
|
577 |
// bool QGLContext::windowCreated() |
|
578 |
// void QGLContext::setWindowCreated(bool) |
|
579 |
obj2.setWindowCreated(false); |
|
580 |
QCOMPARE(false, obj2.windowCreated()); |
|
581 |
obj2.setWindowCreated(true); |
|
582 |
QCOMPARE(true, obj2.windowCreated()); |
|
583 |
||
584 |
// bool QGLContext::initialized() |
|
585 |
// void QGLContext::setInitialized(bool) |
|
586 |
obj2.setInitialized(false); |
|
587 |
QCOMPARE(false, obj2.initialized()); |
|
588 |
obj2.setInitialized(true); |
|
589 |
QCOMPARE(true, obj2.initialized()); |
|
590 |
||
591 |
MyGLWidget obj3; |
|
592 |
// bool QGLWidget::autoBufferSwap() |
|
593 |
// void QGLWidget::setAutoBufferSwap(bool) |
|
594 |
obj3.setAutoBufferSwap(false); |
|
595 |
QCOMPARE(false, obj3.autoBufferSwap()); |
|
596 |
obj3.setAutoBufferSwap(true); |
|
597 |
QCOMPARE(true, obj3.autoBufferSwap()); |
|
598 |
} |
|
599 |
||
600 |
#ifdef QT_BUILD_INTERNAL |
|
601 |
QT_BEGIN_NAMESPACE |
|
602 |
extern QGLFormat::OpenGLVersionFlags qOpenGLVersionFlagsFromString(const QString &versionString); |
|
603 |
QT_END_NAMESPACE |
|
604 |
#endif |
|
605 |
||
606 |
void tst_QGL::openGLVersionCheck() |
|
607 |
{ |
|
608 |
#ifdef QT_BUILD_INTERNAL |
|
609 |
if (!QGLFormat::hasOpenGL()) |
|
610 |
QSKIP("QGL not supported on this platform", SkipAll); |
|
611 |
||
612 |
QString versionString; |
|
613 |
QGLFormat::OpenGLVersionFlags expectedFlag; |
|
614 |
QGLFormat::OpenGLVersionFlags versionFlag; |
|
615 |
||
616 |
versionString = "1.1 Irix 6.5"; |
|
617 |
expectedFlag = QGLFormat::OpenGL_Version_1_1; |
|
618 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
619 |
QCOMPARE(versionFlag, expectedFlag); |
|
620 |
||
621 |
versionString = "1.2 Microsoft"; |
|
622 |
expectedFlag = QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
623 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
624 |
QCOMPARE(versionFlag, expectedFlag); |
|
625 |
||
626 |
versionString = "1.2.1"; |
|
627 |
expectedFlag = QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
628 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
629 |
QCOMPARE(versionFlag, expectedFlag); |
|
630 |
||
631 |
versionString = "1.3 NVIDIA"; |
|
632 |
expectedFlag = QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
633 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
634 |
QCOMPARE(versionFlag, expectedFlag); |
|
635 |
||
636 |
versionString = "1.4"; |
|
637 |
expectedFlag = QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
638 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
639 |
QCOMPARE(versionFlag, expectedFlag); |
|
640 |
||
641 |
versionString = "1.5 NVIDIA"; |
|
642 |
expectedFlag = QGLFormat::OpenGL_Version_1_5 | QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
643 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
644 |
QCOMPARE(versionFlag, expectedFlag); |
|
645 |
||
646 |
versionString = "2.0.2 NVIDIA 87.62"; |
|
647 |
expectedFlag = QGLFormat::OpenGL_Version_2_0 | QGLFormat::OpenGL_Version_1_5 | QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
648 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
649 |
QCOMPARE(versionFlag, expectedFlag); |
|
650 |
||
651 |
versionString = "2.1 NVIDIA"; |
|
652 |
expectedFlag = QGLFormat::OpenGL_Version_2_1 | QGLFormat::OpenGL_Version_2_0 | QGLFormat::OpenGL_Version_1_5 | QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
653 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
654 |
QCOMPARE(versionFlag, expectedFlag); |
|
655 |
||
656 |
versionString = "2.1"; |
|
657 |
expectedFlag = QGLFormat::OpenGL_Version_2_1 | QGLFormat::OpenGL_Version_2_0 | QGLFormat::OpenGL_Version_1_5 | QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
658 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
659 |
QCOMPARE(versionFlag, expectedFlag); |
|
660 |
||
661 |
versionString = "OpenGL ES-CM 1.0 ATI"; |
|
662 |
expectedFlag = QGLFormat::OpenGL_ES_Common_Version_1_0 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
663 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
664 |
QCOMPARE(versionFlag, expectedFlag); |
|
665 |
||
666 |
versionString = "OpenGL ES-CL 1.0 ATI"; |
|
667 |
expectedFlag = QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
668 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
669 |
QCOMPARE(versionFlag, expectedFlag); |
|
670 |
||
671 |
versionString = "OpenGL ES-CM 1.1 ATI"; |
|
672 |
expectedFlag = QGLFormat::OpenGL_ES_Common_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1 | QGLFormat::OpenGL_ES_Common_Version_1_0 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
673 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
674 |
QCOMPARE(versionFlag, expectedFlag); |
|
675 |
||
676 |
versionString = "OpenGL ES-CL 1.1 ATI"; |
|
677 |
expectedFlag = QGLFormat::OpenGL_ES_CommonLite_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; |
|
678 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
679 |
QCOMPARE(versionFlag, expectedFlag); |
|
680 |
||
681 |
versionString = "OpenGL ES 2.0 ATI"; |
|
682 |
expectedFlag = QGLFormat::OpenGL_ES_Version_2_0; |
|
683 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
684 |
QCOMPARE(versionFlag, expectedFlag); |
|
685 |
||
686 |
versionString = "3.0"; |
|
687 |
expectedFlag = QGLFormat::OpenGL_Version_3_0 | QGLFormat::OpenGL_Version_2_1 | QGLFormat::OpenGL_Version_2_0 | QGLFormat::OpenGL_Version_1_5 | QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1; |
|
688 |
versionFlag = qOpenGLVersionFlagsFromString(versionString); |
|
689 |
QCOMPARE(versionFlag, expectedFlag); |
|
690 |
||
691 |
QGLWidget glWidget; |
|
692 |
glWidget.show(); |
|
693 |
glWidget.makeCurrent(); |
|
694 |
||
695 |
// This is unfortunately the only test we can make on the actual openGLVersionFlags() |
|
696 |
// However, the complicated parts are in openGLVersionFlags(const QString &versionString) |
|
697 |
// tested above |
|
698 |
||
699 |
#if defined(QT_OPENGL_ES_1) |
|
700 |
QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Common_Version_1_0); |
|
701 |
#elif defined(QT_OPENGL_ES_1_CL) |
|
702 |
QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_CommonLite_Version_1_0); |
|
703 |
#elif defined(QT_OPENGL_ES_2) |
|
704 |
QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0); |
|
705 |
#else |
|
706 |
QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_1); |
|
707 |
#endif //defined(QT_OPENGL_ES_1) |
|
708 |
#endif //QT_BUILD_INTERNAL |
|
709 |
} |
|
710 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
711 |
static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
712 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
713 |
static int maxFuzz = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
static bool maxFuzzSet = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
// On 16 bpp systems, we need to allow for more fuzz: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
if (!maxFuzzSet) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
718 |
maxFuzzSet = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
719 |
if (appDefaultDepth() < 24) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
720 |
maxFuzz = 32; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
int redFuzz = qAbs(qRed(testPixel) - qRed(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
int greenFuzz = qAbs(qGreen(testPixel) - qGreen(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
int blueFuzz = qAbs(qBlue(testPixel) - qBlue(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
int alphaFuzz = qAbs(qAlpha(testPixel) - qAlpha(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
if (refPixel != 0 && testPixel == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
QString msg; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
if (x >= 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
msg = QString("Test pixel [%1, %2] is null (black) when it should be (%3,%4,%5,%6)") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
732 |
.arg(x).arg(y) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
.arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
734 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
735 |
msg = QString("Test pixel is null (black) when it should be (%2,%3,%4,%5)") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
736 |
.arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
737 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
QTest::qFail(msg.toLatin1(), file, line); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
741 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
742 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
743 |
if (redFuzz > maxFuzz || greenFuzz > maxFuzz || blueFuzz > maxFuzz || alphaFuzz > maxFuzz) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
744 |
QString msg; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
if (x >= 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
msg = QString("Pixel [%1,%2]: ").arg(x).arg(y); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
msg = QString("Pixel "); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
751 |
msg += QString("Max fuzz (%1) exceeded: (%2,%3,%4,%5) vs (%6,%7,%8,%9)") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
752 |
.arg(maxFuzz) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
.arg(qRed(testPixel)).arg(qGreen(testPixel)).arg(qBlue(testPixel)).arg(qAlpha(testPixel)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
.arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
QTest::qFail(msg.toLatin1(), file, line); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
static void fuzzyCompareImages(const QImage &testImage, const QImage &referenceImage, const char* file, int line) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
QCOMPARE(testImage.width(), referenceImage.width()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
QCOMPARE(testImage.height(), referenceImage.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
for (int y = 0; y < testImage.height(); y++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
for (int x = 0; x < testImage.width(); x++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
if (!fuzzyComparePixels(testImage.pixel(x, y), referenceImage.pixel(x, y), file, line, x, y)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
// Might as well save the images for easier debugging: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
referenceImage.save("referenceImage.png"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
testImage.save("testImage.png"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
#define QFUZZY_COMPARE_IMAGES(A,B) \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
fuzzyCompareImages(A, B, __FILE__, __LINE__) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
#define QFUZZY_COMPARE_PIXELS(A,B) \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
fuzzyComparePixels(A, B, __FILE__, __LINE__) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
|
0 | 784 |
class UnclippedWidget : public QWidget |
785 |
{ |
|
786 |
public: |
|
787 |
void paintEvent(QPaintEvent *) |
|
788 |
{ |
|
789 |
QPainter p(this); |
|
790 |
p.fillRect(rect().adjusted(-1000, -1000, 1000, 1000), Qt::black); |
|
791 |
} |
|
792 |
}; |
|
793 |
||
794 |
void tst_QGL::graphicsViewClipping() |
|
795 |
{ |
|
796 |
const int size = 64; |
|
797 |
UnclippedWidget *widget = new UnclippedWidget; |
|
798 |
widget->setFixedSize(size, size); |
|
799 |
||
800 |
QGraphicsScene scene; |
|
801 |
||
802 |
scene.addWidget(widget)->setPos(0, 0); |
|
803 |
||
804 |
QGraphicsView view(&scene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
#ifdef Q_WS_QWS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
806 |
view.setWindowFlags(Qt::FramelessWindowHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
#endif |
0 | 808 |
view.resize(2*size, 2*size); |
809 |
||
810 |
QGLWidget *viewport = new QGLWidget; |
|
811 |
view.setViewport(viewport); |
|
812 |
view.show(); |
|
813 |
||
814 |
if (!viewport->isValid()) |
|
815 |
return; |
|
816 |
||
817 |
scene.setSceneRect(view.viewport()->rect()); |
|
818 |
||
819 |
#ifdef Q_WS_X11 |
|
820 |
qt_x11_wait_for_window_manager(&view); |
|
821 |
#endif |
|
822 |
QTest::qWait(500); |
|
823 |
||
824 |
QImage image = viewport->grabFrameBuffer(); |
|
825 |
QImage expected = image; |
|
826 |
||
827 |
QPainter p(&expected); |
|
828 |
p.fillRect(expected.rect(), Qt::white); |
|
829 |
p.fillRect(QRect(0, 0, size, size), Qt::black); |
|
830 |
p.end(); |
|
831 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
QFUZZY_COMPARE_IMAGES(image, expected); |
0 | 833 |
} |
834 |
||
835 |
void tst_QGL::partialGLWidgetUpdates_data() |
|
836 |
{ |
|
837 |
QTest::addColumn<bool>("doubleBufferedContext"); |
|
838 |
QTest::addColumn<bool>("autoFillBackground"); |
|
839 |
QTest::addColumn<bool>("supportsPartialUpdates"); |
|
840 |
||
841 |
QTest::newRow("Double buffered context") << true << true << false; |
|
842 |
QTest::newRow("Double buffered context without auto-fill background") << true << false << false; |
|
843 |
QTest::newRow("Single buffered context") << false << true << false; |
|
844 |
QTest::newRow("Single buffered context without auto-fill background") << false << false << true; |
|
845 |
} |
|
846 |
||
847 |
void tst_QGL::partialGLWidgetUpdates() |
|
848 |
{ |
|
849 |
if (!QGLFormat::hasOpenGL()) |
|
850 |
QSKIP("QGL not supported on this platform", SkipAll); |
|
851 |
||
852 |
QFETCH(bool, doubleBufferedContext); |
|
853 |
QFETCH(bool, autoFillBackground); |
|
854 |
QFETCH(bool, supportsPartialUpdates); |
|
855 |
||
856 |
class MyGLWidget : public QGLWidget |
|
857 |
{ |
|
858 |
public: |
|
859 |
QRegion paintEventRegion; |
|
860 |
void paintEvent(QPaintEvent *e) |
|
861 |
{ |
|
862 |
paintEventRegion = e->region(); |
|
863 |
} |
|
864 |
}; |
|
865 |
||
866 |
QGLFormat format = QGLFormat::defaultFormat(); |
|
867 |
format.setDoubleBuffer(doubleBufferedContext); |
|
868 |
QGLFormat::setDefaultFormat(format); |
|
869 |
||
870 |
MyGLWidget widget; |
|
871 |
widget.setFixedSize(150, 150); |
|
872 |
widget.setAutoFillBackground(autoFillBackground); |
|
873 |
widget.show(); |
|
874 |
#ifdef Q_WS_X11 |
|
875 |
qt_x11_wait_for_window_manager(&widget); |
|
876 |
#endif |
|
877 |
QTest::qWait(200); |
|
878 |
||
879 |
if (widget.format().doubleBuffer() != doubleBufferedContext) |
|
880 |
QSKIP("Platform does not support requested format", SkipAll); |
|
881 |
||
882 |
widget.paintEventRegion = QRegion(); |
|
883 |
widget.repaint(50, 50, 50, 50); |
|
884 |
#ifdef Q_WS_MAC |
|
885 |
// repaint() is not immediate on the Mac; it has to go through the event loop. |
|
886 |
QTest::qWait(200); |
|
887 |
#endif |
|
888 |
if (supportsPartialUpdates) |
|
889 |
QCOMPARE(widget.paintEventRegion, QRegion(50, 50, 50, 50)); |
|
890 |
else |
|
891 |
QCOMPARE(widget.paintEventRegion, QRegion(widget.rect())); |
|
892 |
} |
|
893 |
||
894 |
||
895 |
// This tests that rendering to a QGLPBuffer using QPainter works. |
|
896 |
void tst_QGL::glPBufferRendering() |
|
897 |
{ |
|
898 |
if (!QGLPixelBuffer::hasOpenGLPbuffers()) |
|
899 |
QSKIP("QGLPixelBuffer not supported on this platform", SkipSingle); |
|
900 |
||
901 |
QGLPixelBuffer* pbuf = new QGLPixelBuffer(128, 128); |
|
902 |
||
903 |
QPainter p; |
|
904 |
bool begun = p.begin(pbuf); |
|
905 |
QVERIFY(begun); |
|
906 |
||
907 |
QPaintEngine::Type engineType = p.paintEngine()->type(); |
|
908 |
QVERIFY(engineType == QPaintEngine::OpenGL || engineType == QPaintEngine::OpenGL2); |
|
909 |
||
910 |
p.fillRect(0, 0, 128, 128, Qt::red); |
|
911 |
p.fillRect(32, 32, 64, 64, Qt::blue); |
|
912 |
p.end(); |
|
913 |
||
914 |
QImage fb = pbuf->toImage(); |
|
915 |
delete pbuf; |
|
916 |
||
917 |
QImage reference(128, 128, fb.format()); |
|
918 |
p.begin(&reference); |
|
919 |
p.fillRect(0, 0, 128, 128, Qt::red); |
|
920 |
p.fillRect(32, 32, 64, 64, Qt::blue); |
|
921 |
p.end(); |
|
922 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
923 |
QFUZZY_COMPARE_IMAGES(fb, reference); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
925 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
926 |
void tst_QGL::glWidgetWithAlpha() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
927 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
928 |
QGLWidget* w = new QGLWidget(QGLFormat(QGL::AlphaChannel)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
929 |
w->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
930 |
#ifdef Q_WS_X11 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
931 |
qt_x11_wait_for_window_manager(w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
932 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
933 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
934 |
delete w; |
0 | 935 |
} |
936 |
||
937 |
class GLWidget : public QGLWidget |
|
938 |
{ |
|
939 |
public: |
|
940 |
GLWidget(QWidget* p = 0) |
|
941 |
: QGLWidget(p), beginOk(false), engineType(QPaintEngine::MaxUser) {} |
|
942 |
bool beginOk; |
|
943 |
QPaintEngine::Type engineType; |
|
944 |
void paintGL() |
|
945 |
{ |
|
946 |
QPainter p; |
|
947 |
beginOk = p.begin(this); |
|
948 |
QPaintEngine* pe = p.paintEngine(); |
|
949 |
engineType = pe->type(); |
|
950 |
||
951 |
// This test only ensures it's possible to paint onto a QGLWidget. Full |
|
952 |
// paint engine feature testing is way out of scope! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
p.fillRect(-1, -1, width()+2, height()+2, Qt::red); |
0 | 954 |
|
955 |
// No p.end() or swap buffers, should be done automatically |
|
956 |
} |
|
957 |
||
958 |
}; |
|
959 |
||
960 |
void tst_QGL::glWidgetRendering() |
|
961 |
{ |
|
962 |
GLWidget w; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
963 |
#ifdef Q_WS_QWS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
964 |
w.setWindowFlags(Qt::FramelessWindowHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
965 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
966 |
w.setGeometry(100, 100, 200, 200); |
0 | 967 |
w.show(); |
968 |
||
969 |
#ifdef Q_WS_X11 |
|
970 |
qt_x11_wait_for_window_manager(&w); |
|
971 |
#endif |
|
972 |
QTest::qWait(200); |
|
973 |
||
974 |
QVERIFY(w.beginOk); |
|
975 |
QVERIFY(w.engineType == QPaintEngine::OpenGL || w.engineType == QPaintEngine::OpenGL2); |
|
976 |
||
977 |
QImage fb = w.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); |
|
978 |
QImage reference(fb.size(), QImage::Format_RGB32); |
|
979 |
reference.fill(0xffff0000); |
|
980 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
QFUZZY_COMPARE_IMAGES(fb, reference); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
void tst_QGL::glFBOSimpleRendering() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
986 |
if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
987 |
QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
988 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
989 |
QGLWidget glw; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
990 |
glw.makeCurrent(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
991 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
992 |
// No multisample with combined depth/stencil attachment: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
993 |
QGLFramebufferObjectFormat fboFormat; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
994 |
fboFormat.setAttachment(QGLFramebufferObject::NoAttachment); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
995 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
996 |
// Don't complicate things by using NPOT: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
997 |
QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
998 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
999 |
fbo->bind(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1000 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1001 |
glClearColor(1.0, 0.0, 0.0, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1002 |
glClear(GL_COLOR_BUFFER_BIT); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1003 |
glFinish(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1004 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1005 |
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1006 |
QImage reference(fb.size(), QImage::Format_RGB32); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1007 |
reference.fill(0xffff0000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1008 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1009 |
QFUZZY_COMPARE_IMAGES(fb, reference); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1010 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1011 |
delete fbo; |
0 | 1012 |
} |
1013 |
||
1014 |
// NOTE: This tests that CombinedDepthStencil attachment works by assuming the |
|
1015 |
// GL2 engine is being used and is implemented the same way as it was when |
|
1016 |
// this autotest was written. If this is not the case, there may be some |
|
1017 |
// false-positives: I.e. The test passes when either the depth or stencil |
|
1018 |
// buffer is actually missing. But that's probably ok anyway. |
|
1019 |
void tst_QGL::glFBORendering() |
|
1020 |
{ |
|
1021 |
if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) |
|
1022 |
QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); |
|
1023 |
||
1024 |
QGLWidget glw; |
|
1025 |
glw.makeCurrent(); |
|
1026 |
||
1027 |
// No multisample with combined depth/stencil attachment: |
|
1028 |
QGLFramebufferObjectFormat fboFormat; |
|
1029 |
fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1030 |
||
1031 |
// Don't complicate things by using NPOT: |
|
1032 |
QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat); |
|
1033 |
||
1034 |
QPainter fboPainter; |
|
1035 |
bool painterBegun = fboPainter.begin(fbo); |
|
1036 |
QVERIFY(painterBegun); |
|
1037 |
||
1038 |
QPainterPath intersectingPath; |
|
1039 |
intersectingPath.moveTo(0, 0); |
|
1040 |
intersectingPath.lineTo(100, 0); |
|
1041 |
intersectingPath.lineTo(0, 100); |
|
1042 |
intersectingPath.lineTo(100, 100); |
|
1043 |
intersectingPath.closeSubpath(); |
|
1044 |
||
1045 |
QPainterPath trianglePath; |
|
1046 |
trianglePath.moveTo(50, 0); |
|
1047 |
trianglePath.lineTo(100, 100); |
|
1048 |
trianglePath.lineTo(0, 100); |
|
1049 |
trianglePath.closeSubpath(); |
|
1050 |
||
1051 |
fboPainter.fillRect(0, 0, fbo->width(), fbo->height(), Qt::red); // Background |
|
1052 |
fboPainter.translate(14, 14); |
|
1053 |
fboPainter.fillPath(intersectingPath, Qt::blue); // Test stencil buffer works |
|
1054 |
fboPainter.translate(128, 0); |
|
1055 |
fboPainter.setClipPath(trianglePath); // Test depth buffer works |
|
1056 |
fboPainter.setTransform(QTransform()); // reset xform |
|
1057 |
fboPainter.fillRect(0, 0, fbo->width(), fbo->height(), Qt::green); |
|
1058 |
fboPainter.end(); |
|
1059 |
||
1060 |
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); |
|
1061 |
delete fbo; |
|
1062 |
||
1063 |
// As we're doing more than trivial painting, we can't just compare to |
|
1064 |
// an image rendered with raster. Instead, we sample at well-defined |
|
1065 |
// test-points: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1066 |
QFUZZY_COMPARE_PIXELS(fb.pixel(39, 64), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1067 |
QFUZZY_COMPARE_PIXELS(fb.pixel(89, 64), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1068 |
QFUZZY_COMPARE_PIXELS(fb.pixel(64, 39), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1069 |
QFUZZY_COMPARE_PIXELS(fb.pixel(64, 89), QColor(Qt::blue).rgb()); |
0 | 1070 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1071 |
QFUZZY_COMPARE_PIXELS(fb.pixel(167, 39), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1072 |
QFUZZY_COMPARE_PIXELS(fb.pixel(217, 39), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1073 |
QFUZZY_COMPARE_PIXELS(fb.pixel(192, 64), QColor(Qt::green).rgb()); |
0 | 1074 |
} |
1075 |
||
1076 |
||
1077 |
// Tests multiple QPainters active on different FBOs at the same time, with |
|
1078 |
// interleaving painting. Performance-wise, this is sub-optimal, but it still |
|
1079 |
// has to work flawlessly |
|
1080 |
void tst_QGL::multipleFBOInterleavedRendering() |
|
1081 |
{ |
|
1082 |
if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) |
|
1083 |
QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); |
|
1084 |
||
1085 |
QGLWidget glw; |
|
1086 |
glw.makeCurrent(); |
|
1087 |
||
1088 |
// No multisample with combined depth/stencil attachment: |
|
1089 |
QGLFramebufferObjectFormat fboFormat; |
|
1090 |
fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1091 |
||
1092 |
QGLFramebufferObject *fbo1 = new QGLFramebufferObject(256, 128, fboFormat); |
|
1093 |
QGLFramebufferObject *fbo2 = new QGLFramebufferObject(256, 128, fboFormat); |
|
1094 |
QGLFramebufferObject *fbo3 = new QGLFramebufferObject(256, 128, fboFormat); |
|
1095 |
||
1096 |
QPainter fbo1Painter; |
|
1097 |
QPainter fbo2Painter; |
|
1098 |
QPainter fbo3Painter; |
|
1099 |
||
1100 |
QVERIFY(fbo1Painter.begin(fbo1)); |
|
1101 |
QVERIFY(fbo2Painter.begin(fbo2)); |
|
1102 |
QVERIFY(fbo3Painter.begin(fbo3)); |
|
1103 |
||
1104 |
// Confirm we're using the GL2 engine, as interleaved rendering isn't supported |
|
1105 |
// on the GL1 engine: |
|
1106 |
if (fbo1Painter.paintEngine()->type() != QPaintEngine::OpenGL2) |
|
1107 |
QSKIP("Interleaved GL rendering requires OpenGL 2.0 or higher", SkipSingle); |
|
1108 |
||
1109 |
QPainterPath intersectingPath; |
|
1110 |
intersectingPath.moveTo(0, 0); |
|
1111 |
intersectingPath.lineTo(100, 0); |
|
1112 |
intersectingPath.lineTo(0, 100); |
|
1113 |
intersectingPath.lineTo(100, 100); |
|
1114 |
intersectingPath.closeSubpath(); |
|
1115 |
||
1116 |
QPainterPath trianglePath; |
|
1117 |
trianglePath.moveTo(50, 0); |
|
1118 |
trianglePath.lineTo(100, 100); |
|
1119 |
trianglePath.lineTo(0, 100); |
|
1120 |
trianglePath.closeSubpath(); |
|
1121 |
||
1122 |
fbo1Painter.fillRect(0, 0, fbo1->width(), fbo1->height(), Qt::red); // Background |
|
1123 |
fbo2Painter.fillRect(0, 0, fbo2->width(), fbo2->height(), Qt::green); // Background |
|
1124 |
fbo3Painter.fillRect(0, 0, fbo3->width(), fbo3->height(), Qt::blue); // Background |
|
1125 |
||
1126 |
fbo1Painter.translate(14, 14); |
|
1127 |
fbo2Painter.translate(14, 14); |
|
1128 |
fbo3Painter.translate(14, 14); |
|
1129 |
||
1130 |
fbo1Painter.fillPath(intersectingPath, Qt::blue); // Test stencil buffer works |
|
1131 |
fbo2Painter.fillPath(intersectingPath, Qt::red); // Test stencil buffer works |
|
1132 |
fbo3Painter.fillPath(intersectingPath, Qt::green); // Test stencil buffer works |
|
1133 |
||
1134 |
fbo1Painter.translate(128, 0); |
|
1135 |
fbo2Painter.translate(128, 0); |
|
1136 |
fbo3Painter.translate(128, 0); |
|
1137 |
||
1138 |
fbo1Painter.setClipPath(trianglePath); |
|
1139 |
fbo2Painter.setClipPath(trianglePath); |
|
1140 |
fbo3Painter.setClipPath(trianglePath); |
|
1141 |
||
1142 |
fbo1Painter.setTransform(QTransform()); // reset xform |
|
1143 |
fbo2Painter.setTransform(QTransform()); // reset xform |
|
1144 |
fbo3Painter.setTransform(QTransform()); // reset xform |
|
1145 |
||
1146 |
fbo1Painter.fillRect(0, 0, fbo1->width(), fbo1->height(), Qt::green); |
|
1147 |
fbo2Painter.fillRect(0, 0, fbo2->width(), fbo2->height(), Qt::blue); |
|
1148 |
fbo3Painter.fillRect(0, 0, fbo3->width(), fbo3->height(), Qt::red); |
|
1149 |
||
1150 |
fbo1Painter.end(); |
|
1151 |
fbo2Painter.end(); |
|
1152 |
fbo3Painter.end(); |
|
1153 |
||
1154 |
QImage fb1 = fbo1->toImage().convertToFormat(QImage::Format_RGB32); |
|
1155 |
QImage fb2 = fbo2->toImage().convertToFormat(QImage::Format_RGB32); |
|
1156 |
QImage fb3 = fbo3->toImage().convertToFormat(QImage::Format_RGB32); |
|
1157 |
delete fbo1; |
|
1158 |
delete fbo2; |
|
1159 |
delete fbo3; |
|
1160 |
||
1161 |
// As we're doing more than trivial painting, we can't just compare to |
|
1162 |
// an image rendered with raster. Instead, we sample at well-defined |
|
1163 |
// test-points: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1164 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(39, 64), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1165 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(89, 64), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1166 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(64, 39), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1167 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(64, 89), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1168 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(167, 39), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1169 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(217, 39), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1170 |
QFUZZY_COMPARE_PIXELS(fb1.pixel(192, 64), QColor(Qt::green).rgb()); |
0 | 1171 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(39, 64), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1173 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(89, 64), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1174 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(64, 39), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(64, 89), QColor(Qt::red).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1176 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(167, 39), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(217, 39), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
QFUZZY_COMPARE_PIXELS(fb2.pixel(192, 64), QColor(Qt::blue).rgb()); |
0 | 1179 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(39, 64), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(89, 64), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(64, 39), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(64, 89), QColor(Qt::green).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(167, 39), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(217, 39), QColor(Qt::blue).rgb()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
QFUZZY_COMPARE_PIXELS(fb3.pixel(192, 64), QColor(Qt::red).rgb()); |
0 | 1187 |
} |
1188 |
||
1189 |
class FBOUseInGLWidget : public QGLWidget |
|
1190 |
{ |
|
1191 |
public: |
|
1192 |
bool widgetPainterBeginOk; |
|
1193 |
bool fboPainterBeginOk; |
|
1194 |
QImage fboImage; |
|
1195 |
protected: |
|
1196 |
void paintEvent(QPaintEvent*) |
|
1197 |
{ |
|
1198 |
QPainter widgetPainter; |
|
1199 |
widgetPainterBeginOk = widgetPainter.begin(this); |
|
1200 |
QGLFramebufferObjectFormat fboFormat; |
|
1201 |
fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1202 |
QGLFramebufferObject *fbo = new QGLFramebufferObject(128, 128, fboFormat); |
|
1203 |
||
1204 |
QPainter fboPainter; |
|
1205 |
fboPainterBeginOk = fboPainter.begin(fbo); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
fboPainter.fillRect(-1, -1, 130, 130, Qt::red); |
0 | 1207 |
fboPainter.end(); |
1208 |
fboImage = fbo->toImage(); |
|
1209 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1210 |
widgetPainter.fillRect(-1, -1, width()+2, width()+2, Qt::blue); |
0 | 1211 |
|
1212 |
delete fbo; |
|
1213 |
} |
|
1214 |
||
1215 |
}; |
|
1216 |
||
1217 |
void tst_QGL::glFBOUseInGLWidget() |
|
1218 |
{ |
|
1219 |
if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) |
|
1220 |
QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); |
|
1221 |
||
1222 |
FBOUseInGLWidget w; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
#ifdef Q_WS_QWS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1224 |
w.setWindowFlags(Qt::FramelessWindowHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
#endif |
0 | 1226 |
w.resize(128, 128); |
1227 |
w.show(); |
|
1228 |
||
1229 |
#ifdef Q_WS_X11 |
|
1230 |
qt_x11_wait_for_window_manager(&w); |
|
1231 |
#endif |
|
1232 |
QTest::qWait(200); |
|
1233 |
||
1234 |
QVERIFY(w.widgetPainterBeginOk); |
|
1235 |
QVERIFY(w.fboPainterBeginOk); |
|
1236 |
||
1237 |
QImage widgetFB = w.grabFrameBuffer(false); |
|
1238 |
QImage widgetReference(widgetFB.size(), widgetFB.format()); |
|
1239 |
widgetReference.fill(0xff0000ff); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1240 |
QFUZZY_COMPARE_IMAGES(widgetFB, widgetReference); |
0 | 1241 |
|
1242 |
QImage fboReference(w.fboImage.size(), w.fboImage.format()); |
|
1243 |
fboReference.fill(0xffff0000); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1244 |
QFUZZY_COMPARE_IMAGES(w.fboImage, fboReference); |
0 | 1245 |
} |
1246 |
||
1247 |
void tst_QGL::glWidgetReparent() |
|
1248 |
{ |
|
1249 |
// Try it as a top-level first: |
|
1250 |
GLWidget *widget = new GLWidget; |
|
1251 |
widget->setGeometry(0, 0, 200, 30); |
|
1252 |
widget->show(); |
|
1253 |
||
1254 |
QWidget grandParentWidget; |
|
1255 |
grandParentWidget.setPalette(Qt::blue); |
|
1256 |
QVBoxLayout grandParentLayout(&grandParentWidget); |
|
1257 |
||
1258 |
QWidget parentWidget(&grandParentWidget); |
|
1259 |
grandParentLayout.addWidget(&parentWidget); |
|
1260 |
parentWidget.setPalette(Qt::green); |
|
1261 |
parentWidget.setAutoFillBackground(true); |
|
1262 |
QVBoxLayout parentLayout(&parentWidget); |
|
1263 |
||
1264 |
grandParentWidget.setGeometry(0, 100, 200, 200); |
|
1265 |
grandParentWidget.show(); |
|
1266 |
||
1267 |
#ifdef Q_WS_X11 |
|
1268 |
qt_x11_wait_for_window_manager(widget); |
|
1269 |
qt_x11_wait_for_window_manager(&parentWidget); |
|
1270 |
#endif |
|
1271 |
QTest::qWait(200); |
|
1272 |
||
1273 |
QVERIFY(parentWidget.children().count() == 1); // The layout |
|
1274 |
||
1275 |
// Now both widgets should be created & shown, time to re-parent: |
|
1276 |
parentLayout.addWidget(widget); |
|
1277 |
||
1278 |
#ifdef Q_WS_X11 |
|
1279 |
qt_x11_wait_for_window_manager(&parentWidget); |
|
1280 |
#endif |
|
1281 |
QTest::qWait(200); |
|
1282 |
||
1283 |
QVERIFY(parentWidget.children().count() == 2); // Layout & glwidget |
|
1284 |
QVERIFY(parentWidget.children().contains(widget)); |
|
1285 |
QVERIFY(widget->height() > 30); |
|
1286 |
||
1287 |
delete widget; |
|
1288 |
||
1289 |
#ifdef Q_WS_X11 |
|
1290 |
qt_x11_wait_for_window_manager(&parentWidget); |
|
1291 |
#endif |
|
1292 |
QTest::qWait(200); |
|
1293 |
||
1294 |
QVERIFY(parentWidget.children().count() == 1); // The layout |
|
1295 |
||
1296 |
// Now do pretty much the same thing, but don't show the |
|
1297 |
// widget first: |
|
1298 |
widget = new GLWidget; |
|
1299 |
parentLayout.addWidget(widget); |
|
1300 |
||
1301 |
#ifdef Q_WS_X11 |
|
1302 |
qt_x11_wait_for_window_manager(&parentWidget); |
|
1303 |
#endif |
|
1304 |
QTest::qWait(200); |
|
1305 |
||
1306 |
QVERIFY(parentWidget.children().count() == 2); // Layout & glwidget |
|
1307 |
QVERIFY(parentWidget.children().contains(widget)); |
|
1308 |
QVERIFY(widget->height() > 30); |
|
1309 |
||
1310 |
delete widget; |
|
1311 |
} |
|
1312 |
||
1313 |
class RenderPixmapWidget : public QGLWidget |
|
1314 |
{ |
|
1315 |
protected: |
|
1316 |
void initializeGL() { |
|
1317 |
// Set some gl state: |
|
1318 |
glClearColor(1.0, 0.0, 0.0, 1.0); |
|
1319 |
} |
|
1320 |
||
1321 |
void paintGL() { |
|
1322 |
glClear(GL_COLOR_BUFFER_BIT); |
|
1323 |
} |
|
1324 |
}; |
|
1325 |
||
1326 |
void tst_QGL::glWidgetRenderPixmap() |
|
1327 |
{ |
|
1328 |
RenderPixmapWidget *w = new RenderPixmapWidget; |
|
1329 |
||
1330 |
QPixmap pm = w->renderPixmap(100, 100, false); |
|
1331 |
||
1332 |
delete w; |
|
1333 |
||
1334 |
QImage fb = pm.toImage().convertToFormat(QImage::Format_RGB32); |
|
1335 |
QImage reference(fb.size(), QImage::Format_RGB32); |
|
1336 |
reference.fill(0xffff0000); |
|
1337 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
QFUZZY_COMPARE_IMAGES(fb, reference); |
0 | 1339 |
} |
1340 |
||
1341 |
class ColormapExtended : public QGLColormap |
|
1342 |
{ |
|
1343 |
public: |
|
1344 |
ColormapExtended() {} |
|
1345 |
||
1346 |
Qt::HANDLE handle() { return QGLColormap::handle(); } |
|
1347 |
void setHandle(Qt::HANDLE handle) { QGLColormap::setHandle(handle); } |
|
1348 |
}; |
|
1349 |
||
1350 |
void tst_QGL::colormap() |
|
1351 |
{ |
|
1352 |
// Check the properties of the default empty colormap. |
|
1353 |
QGLColormap cmap1; |
|
1354 |
QVERIFY(cmap1.isEmpty()); |
|
1355 |
QCOMPARE(cmap1.size(), 0); |
|
1356 |
QVERIFY(cmap1.entryRgb(0) == 0); |
|
1357 |
QVERIFY(cmap1.entryRgb(-1) == 0); |
|
1358 |
QVERIFY(cmap1.entryRgb(100) == 0); |
|
1359 |
QVERIFY(!cmap1.entryColor(0).isValid()); |
|
1360 |
QVERIFY(!cmap1.entryColor(-1).isValid()); |
|
1361 |
QVERIFY(!cmap1.entryColor(100).isValid()); |
|
1362 |
QCOMPARE(cmap1.find(qRgb(255, 0, 0)), -1); |
|
1363 |
QCOMPARE(cmap1.findNearest(qRgb(255, 0, 0)), -1); |
|
1364 |
||
1365 |
// Set an entry and re-test. |
|
1366 |
cmap1.setEntry(56, qRgb(255, 0, 0)); |
|
1367 |
// The colormap is still considered "empty" even though it |
|
1368 |
// has entries in it now. The isEmpty() method is used to |
|
1369 |
// detect when the colormap is in use by a GL widget, |
|
1370 |
// not to detect when it is empty! |
|
1371 |
QVERIFY(cmap1.isEmpty()); |
|
1372 |
QCOMPARE(cmap1.size(), 256); |
|
1373 |
QVERIFY(cmap1.entryRgb(0) == 0); |
|
1374 |
QVERIFY(cmap1.entryColor(0) == QColor(0, 0, 0, 255)); |
|
1375 |
QVERIFY(cmap1.entryRgb(56) == qRgb(255, 0, 0)); |
|
1376 |
QVERIFY(cmap1.entryColor(56) == QColor(255, 0, 0, 255)); |
|
1377 |
QCOMPARE(cmap1.find(qRgb(255, 0, 0)), 56); |
|
1378 |
QCOMPARE(cmap1.findNearest(qRgb(255, 0, 0)), 56); |
|
1379 |
||
1380 |
// Set some more entries. |
|
1381 |
static QRgb const colors[] = { |
|
1382 |
qRgb(255, 0, 0), |
|
1383 |
qRgb(0, 255, 0), |
|
1384 |
qRgb(255, 255, 255), |
|
1385 |
qRgb(0, 0, 255), |
|
1386 |
qRgb(0, 0, 0) |
|
1387 |
}; |
|
1388 |
cmap1.setEntry(57, QColor(0, 255, 0)); |
|
1389 |
cmap1.setEntries(3, colors + 2, 58); |
|
1390 |
cmap1.setEntries(5, colors, 251); |
|
1391 |
int idx; |
|
1392 |
for (idx = 0; idx < 5; ++idx) { |
|
1393 |
QVERIFY(cmap1.entryRgb(56 + idx) == colors[idx]); |
|
1394 |
QVERIFY(cmap1.entryColor(56 + idx) == QColor(colors[idx])); |
|
1395 |
QVERIFY(cmap1.entryRgb(251 + idx) == colors[idx]); |
|
1396 |
QVERIFY(cmap1.entryColor(251 + idx) == QColor(colors[idx])); |
|
1397 |
} |
|
1398 |
QCOMPARE(cmap1.size(), 256); |
|
1399 |
||
1400 |
// Perform color lookups. |
|
1401 |
QCOMPARE(cmap1.find(qRgb(255, 0, 0)), 56); |
|
1402 |
QCOMPARE(cmap1.find(qRgb(0, 0, 0)), 60); // Actually finds 0, 0, 0, 255. |
|
1403 |
QCOMPARE(cmap1.find(qRgba(0, 0, 0, 0)), 0); |
|
1404 |
QCOMPARE(cmap1.find(qRgb(0, 255, 0)), 57); |
|
1405 |
QCOMPARE(cmap1.find(qRgb(255, 255, 255)), 58); |
|
1406 |
QCOMPARE(cmap1.find(qRgb(0, 0, 255)), 59); |
|
1407 |
QCOMPARE(cmap1.find(qRgb(140, 0, 0)), -1); |
|
1408 |
QCOMPARE(cmap1.find(qRgb(0, 140, 0)), -1); |
|
1409 |
QCOMPARE(cmap1.find(qRgb(0, 0, 140)), -1); |
|
1410 |
QCOMPARE(cmap1.find(qRgb(64, 0, 0)), -1); |
|
1411 |
QCOMPARE(cmap1.find(qRgb(0, 64, 0)), -1); |
|
1412 |
QCOMPARE(cmap1.find(qRgb(0, 0, 64)), -1); |
|
1413 |
QCOMPARE(cmap1.findNearest(qRgb(255, 0, 0)), 56); |
|
1414 |
QCOMPARE(cmap1.findNearest(qRgb(0, 0, 0)), 60); |
|
1415 |
QCOMPARE(cmap1.findNearest(qRgba(0, 0, 0, 0)), 0); |
|
1416 |
QCOMPARE(cmap1.findNearest(qRgb(0, 255, 0)), 57); |
|
1417 |
QCOMPARE(cmap1.findNearest(qRgb(255, 255, 255)), 58); |
|
1418 |
QCOMPARE(cmap1.findNearest(qRgb(0, 0, 255)), 59); |
|
1419 |
QCOMPARE(cmap1.findNearest(qRgb(140, 0, 0)), 56); |
|
1420 |
QCOMPARE(cmap1.findNearest(qRgb(0, 140, 0)), 57); |
|
1421 |
QCOMPARE(cmap1.findNearest(qRgb(0, 0, 140)), 59); |
|
1422 |
QCOMPARE(cmap1.findNearest(qRgb(64, 0, 0)), 0); |
|
1423 |
QCOMPARE(cmap1.findNearest(qRgb(0, 64, 0)), 0); |
|
1424 |
QCOMPARE(cmap1.findNearest(qRgb(0, 0, 64)), 0); |
|
1425 |
||
1426 |
// Make some copies of the colormap and check that they are the same. |
|
1427 |
QGLColormap cmap2(cmap1); |
|
1428 |
QGLColormap cmap3; |
|
1429 |
cmap3 = cmap1; |
|
1430 |
QVERIFY(cmap2.isEmpty()); |
|
1431 |
QVERIFY(cmap3.isEmpty()); |
|
1432 |
QCOMPARE(cmap2.size(), 256); |
|
1433 |
QCOMPARE(cmap3.size(), 256); |
|
1434 |
for (idx = 0; idx < 256; ++idx) { |
|
1435 |
QCOMPARE(cmap1.entryRgb(idx), cmap2.entryRgb(idx)); |
|
1436 |
QCOMPARE(cmap1.entryRgb(idx), cmap3.entryRgb(idx)); |
|
1437 |
} |
|
1438 |
||
1439 |
// Modify an entry in one of the copies and recheck the original. |
|
1440 |
cmap2.setEntry(45, qRgb(255, 0, 0)); |
|
1441 |
for (idx = 0; idx < 256; ++idx) { |
|
1442 |
if (idx != 45) |
|
1443 |
QCOMPARE(cmap1.entryRgb(idx), cmap2.entryRgb(idx)); |
|
1444 |
else |
|
1445 |
QCOMPARE(cmap2.entryRgb(45), qRgb(255, 0, 0)); |
|
1446 |
QCOMPARE(cmap1.entryRgb(idx), cmap3.entryRgb(idx)); |
|
1447 |
} |
|
1448 |
||
1449 |
// Check that setting the handle will cause isEmpty() to work right. |
|
1450 |
ColormapExtended cmap4; |
|
1451 |
cmap4.setEntry(56, qRgb(255, 0, 0)); |
|
1452 |
QVERIFY(cmap4.isEmpty()); |
|
1453 |
QCOMPARE(cmap4.size(), 256); |
|
1454 |
cmap4.setHandle(Qt::HANDLE(42)); |
|
1455 |
QVERIFY(cmap4.handle() == Qt::HANDLE(42)); |
|
1456 |
QVERIFY(!cmap4.isEmpty()); |
|
1457 |
QCOMPARE(cmap4.size(), 256); |
|
1458 |
} |
|
1459 |
||
1460 |
#ifndef QT_OPENGL_ES |
|
1461 |
#define DEFAULT_FORMAT GL_RGBA8 |
|
1462 |
#else |
|
1463 |
#define DEFAULT_FORMAT GL_RGBA |
|
1464 |
#endif |
|
1465 |
||
1466 |
#ifndef GL_TEXTURE_3D |
|
1467 |
#define GL_TEXTURE_3D 0x806F |
|
1468 |
#endif |
|
1469 |
||
1470 |
#ifndef GL_RGB16 |
|
1471 |
#define GL_RGB16 0x8054 |
|
1472 |
#endif |
|
1473 |
||
1474 |
void tst_QGL::fboFormat() |
|
1475 |
{ |
|
1476 |
// Check the initial conditions. |
|
1477 |
QGLFramebufferObjectFormat format1; |
|
1478 |
QCOMPARE(format1.samples(), 0); |
|
1479 |
QVERIFY(format1.attachment() == QGLFramebufferObject::NoAttachment); |
|
1480 |
QCOMPARE(int(format1.textureTarget()), int(GL_TEXTURE_2D)); |
|
1481 |
QCOMPARE(int(format1.internalTextureFormat()), int(DEFAULT_FORMAT)); |
|
1482 |
||
1483 |
// Modify the values and re-check. |
|
1484 |
format1.setSamples(8); |
|
1485 |
format1.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1486 |
format1.setTextureTarget(GL_TEXTURE_3D); |
|
1487 |
format1.setInternalTextureFormat(GL_RGB16); |
|
1488 |
QCOMPARE(format1.samples(), 8); |
|
1489 |
QVERIFY(format1.attachment() == QGLFramebufferObject::CombinedDepthStencil); |
|
1490 |
QCOMPARE(int(format1.textureTarget()), int(GL_TEXTURE_3D)); |
|
1491 |
QCOMPARE(int(format1.internalTextureFormat()), int(GL_RGB16)); |
|
1492 |
||
1493 |
// Make copies and check that they are the same. |
|
1494 |
QGLFramebufferObjectFormat format2(format1); |
|
1495 |
QGLFramebufferObjectFormat format3; |
|
1496 |
QCOMPARE(format2.samples(), 8); |
|
1497 |
QVERIFY(format2.attachment() == QGLFramebufferObject::CombinedDepthStencil); |
|
1498 |
QCOMPARE(int(format2.textureTarget()), int(GL_TEXTURE_3D)); |
|
1499 |
QCOMPARE(int(format2.internalTextureFormat()), int(GL_RGB16)); |
|
1500 |
format3 = format1; |
|
1501 |
QCOMPARE(format3.samples(), 8); |
|
1502 |
QVERIFY(format3.attachment() == QGLFramebufferObject::CombinedDepthStencil); |
|
1503 |
QCOMPARE(int(format3.textureTarget()), int(GL_TEXTURE_3D)); |
|
1504 |
QCOMPARE(int(format3.internalTextureFormat()), int(GL_RGB16)); |
|
1505 |
||
1506 |
// Modify the copies and check that the original is unchanged. |
|
1507 |
format2.setSamples(9); |
|
1508 |
format3.setTextureTarget(GL_TEXTURE_2D); |
|
1509 |
QCOMPARE(format1.samples(), 8); |
|
1510 |
QVERIFY(format1.attachment() == QGLFramebufferObject::CombinedDepthStencil); |
|
1511 |
QCOMPARE(int(format1.textureTarget()), int(GL_TEXTURE_3D)); |
|
1512 |
QCOMPARE(int(format1.internalTextureFormat()), int(GL_RGB16)); |
|
1513 |
||
1514 |
// operator== and operator!= for QGLFramebufferObjectFormat. |
|
1515 |
QGLFramebufferObjectFormat format1c; |
|
1516 |
QGLFramebufferObjectFormat format2c; |
|
1517 |
||
1518 |
QVERIFY(format1c == format2c); |
|
1519 |
QVERIFY(!(format1c != format2c)); |
|
1520 |
format1c.setSamples(8); |
|
1521 |
QVERIFY(!(format1c == format2c)); |
|
1522 |
QVERIFY(format1c != format2c); |
|
1523 |
format2c.setSamples(8); |
|
1524 |
QVERIFY(format1c == format2c); |
|
1525 |
QVERIFY(!(format1c != format2c)); |
|
1526 |
||
1527 |
format1c.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1528 |
QVERIFY(!(format1c == format2c)); |
|
1529 |
QVERIFY(format1c != format2c); |
|
1530 |
format2c.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1531 |
QVERIFY(format1c == format2c); |
|
1532 |
QVERIFY(!(format1c != format2c)); |
|
1533 |
||
1534 |
format1c.setTextureTarget(GL_TEXTURE_3D); |
|
1535 |
QVERIFY(!(format1c == format2c)); |
|
1536 |
QVERIFY(format1c != format2c); |
|
1537 |
format2c.setTextureTarget(GL_TEXTURE_3D); |
|
1538 |
QVERIFY(format1c == format2c); |
|
1539 |
QVERIFY(!(format1c != format2c)); |
|
1540 |
||
1541 |
format1c.setInternalTextureFormat(GL_RGB16); |
|
1542 |
QVERIFY(!(format1c == format2c)); |
|
1543 |
QVERIFY(format1c != format2c); |
|
1544 |
format2c.setInternalTextureFormat(GL_RGB16); |
|
1545 |
QVERIFY(format1c == format2c); |
|
1546 |
QVERIFY(!(format1c != format2c)); |
|
1547 |
||
1548 |
QGLFramebufferObjectFormat format3c(format1c); |
|
1549 |
QGLFramebufferObjectFormat format4c; |
|
1550 |
QVERIFY(format1c == format3c); |
|
1551 |
QVERIFY(!(format1c != format3c)); |
|
1552 |
format3c.setInternalTextureFormat(DEFAULT_FORMAT); |
|
1553 |
QVERIFY(!(format1c == format3c)); |
|
1554 |
QVERIFY(format1c != format3c); |
|
1555 |
||
1556 |
format4c = format1c; |
|
1557 |
QVERIFY(format1c == format4c); |
|
1558 |
QVERIFY(!(format1c != format4c)); |
|
1559 |
format4c.setInternalTextureFormat(DEFAULT_FORMAT); |
|
1560 |
QVERIFY(!(format1c == format4c)); |
|
1561 |
QVERIFY(format1c != format4c); |
|
1562 |
} |
|
1563 |
||
1564 |
void tst_QGL::testDontCrashOnDanglingResources() |
|
1565 |
{ |
|
1566 |
// We have a number of Q_GLOBAL_STATICS inside the QtOpenGL |
|
1567 |
// library. This test is verify that we don't crash as a result of |
|
1568 |
// them calling into libgl on application shutdown. |
|
1569 |
QWidget *widget = new UnclippedWidget(); |
|
1570 |
widget->show(); |
|
1571 |
qApp->processEvents(); |
|
1572 |
widget->hide(); |
|
1573 |
} |
|
1574 |
||
1575 |
class ReplaceClippingGLWidget : public QGLWidget |
|
1576 |
{ |
|
1577 |
public: |
|
1578 |
void paint(QPainter *painter) |
|
1579 |
{ |
|
1580 |
painter->fillRect(rect(), Qt::white); |
|
1581 |
||
1582 |
QPainterPath path; |
|
1583 |
path.addRect(0, 0, 100, 100); |
|
1584 |
path.addRect(50, 50, 100, 100); |
|
1585 |
||
1586 |
painter->setClipRect(0, 0, 150, 150); |
|
1587 |
painter->fillPath(path, Qt::red); |
|
1588 |
||
1589 |
painter->translate(150, 150); |
|
1590 |
painter->setClipRect(0, 0, 150, 150); |
|
1591 |
painter->fillPath(path, Qt::red); |
|
1592 |
} |
|
1593 |
||
1594 |
protected: |
|
1595 |
void paintEvent(QPaintEvent*) |
|
1596 |
{ |
|
1597 |
// clear the stencil with junk |
|
1598 |
glStencilMask(0xFFFF); |
|
1599 |
glClearStencil(0xFFFF); |
|
1600 |
glDisable(GL_STENCIL_TEST); |
|
1601 |
glDisable(GL_SCISSOR_TEST); |
|
1602 |
glClear(GL_STENCIL_BUFFER_BIT); |
|
1603 |
||
1604 |
QPainter painter(this); |
|
1605 |
paint(&painter); |
|
1606 |
} |
|
1607 |
}; |
|
1608 |
||
1609 |
void tst_QGL::replaceClipping() |
|
1610 |
{ |
|
1611 |
ReplaceClippingGLWidget glw; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1612 |
#ifdef Q_WS_QWS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1613 |
glw.setWindowFlags(Qt::FramelessWindowHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1614 |
#endif |
0 | 1615 |
glw.resize(300, 300); |
1616 |
glw.show(); |
|
1617 |
||
1618 |
#ifdef Q_WS_X11 |
|
1619 |
qt_x11_wait_for_window_manager(&glw); |
|
1620 |
#endif |
|
1621 |
QTest::qWait(200); |
|
1622 |
||
1623 |
QImage reference(300, 300, QImage::Format_RGB32); |
|
1624 |
QPainter referencePainter(&reference); |
|
1625 |
glw.paint(&referencePainter); |
|
1626 |
referencePainter.end(); |
|
1627 |
||
1628 |
const QImage widgetFB = glw.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); |
|
1629 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1630 |
// Sample pixels in a grid pattern which avoids false failures due to |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1631 |
// off-by-one pixel errors on some buggy GL implementations |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1632 |
for (int x = 25; x < reference.width(); x += 50) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1633 |
for (int y = 25; y < reference.width(); y += 50) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1634 |
QFUZZY_COMPARE_PIXELS(widgetFB.pixel(x, y), reference.pixel(x, y)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1635 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1636 |
} |
0 | 1637 |
} |
1638 |
||
1639 |
class ClipTestGLWidget : public QGLWidget |
|
1640 |
{ |
|
1641 |
public: |
|
1642 |
void paint(QPainter *painter) |
|
1643 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1644 |
painter->fillRect(-1, -1, width()+2, height()+2, Qt::white); |
0 | 1645 |
painter->setClipRect(10, 10, width()-20, height()-20); |
1646 |
painter->fillRect(rect(), Qt::cyan); |
|
1647 |
||
1648 |
painter->save(); |
|
1649 |
painter->setClipRect(10, 10, 100, 100, Qt::IntersectClip); |
|
1650 |
||
1651 |
painter->fillRect(rect(), Qt::blue); |
|
1652 |
||
1653 |
painter->save(); |
|
1654 |
painter->setClipRect(10, 10, 50, 50, Qt::IntersectClip); |
|
1655 |
painter->fillRect(rect(), Qt::red); |
|
1656 |
painter->restore(); |
|
1657 |
painter->fillRect(0, 0, 40, 40, Qt::white); |
|
1658 |
painter->save(); |
|
1659 |
||
1660 |
painter->setClipRect(0, 0, 35, 35, Qt::IntersectClip); |
|
1661 |
painter->fillRect(rect(), Qt::black); |
|
1662 |
painter->restore(); |
|
1663 |
||
1664 |
painter->fillRect(0, 0, 30, 30, Qt::magenta); |
|
1665 |
||
1666 |
painter->save(); |
|
1667 |
painter->setClipRect(60, 10, 50, 50, Qt::ReplaceClip); |
|
1668 |
painter->fillRect(rect(), Qt::green); |
|
1669 |
painter->restore(); |
|
1670 |
||
1671 |
painter->save(); |
|
1672 |
painter->setClipRect(0, 60, 60, 25, Qt::IntersectClip); |
|
1673 |
painter->setClipRect(60, 60, 50, 25, Qt::UniteClip); |
|
1674 |
painter->fillRect(rect(), Qt::yellow); |
|
1675 |
painter->restore(); |
|
1676 |
||
1677 |
painter->restore(); |
|
1678 |
||
1679 |
painter->translate(100, 100); |
|
1680 |
||
1681 |
{ |
|
1682 |
QPainterPath path; |
|
1683 |
path.addRect(10, 10, 100, 100); |
|
1684 |
path.addRect(10, 10, 10, 10); |
|
1685 |
painter->setClipPath(path, Qt::IntersectClip); |
|
1686 |
} |
|
1687 |
||
1688 |
painter->fillRect(rect(), Qt::blue); |
|
1689 |
||
1690 |
painter->save(); |
|
1691 |
{ |
|
1692 |
QPainterPath path; |
|
1693 |
path.addRect(10, 10, 50, 50); |
|
1694 |
path.addRect(10, 10, 10, 10); |
|
1695 |
painter->setClipPath(path, Qt::IntersectClip); |
|
1696 |
} |
|
1697 |
painter->fillRect(rect(), Qt::red); |
|
1698 |
painter->restore(); |
|
1699 |
painter->fillRect(0, 0, 40, 40, Qt::white); |
|
1700 |
painter->save(); |
|
1701 |
||
1702 |
{ |
|
1703 |
QPainterPath path; |
|
1704 |
path.addRect(0, 0, 35, 35); |
|
1705 |
path.addRect(10, 10, 10, 10); |
|
1706 |
painter->setClipPath(path, Qt::IntersectClip); |
|
1707 |
} |
|
1708 |
painter->fillRect(rect(), Qt::black); |
|
1709 |
painter->restore(); |
|
1710 |
||
1711 |
painter->fillRect(0, 0, 30, 30, Qt::magenta); |
|
1712 |
||
1713 |
painter->save(); |
|
1714 |
{ |
|
1715 |
QPainterPath path; |
|
1716 |
path.addRect(60, 10, 50, 50); |
|
1717 |
path.addRect(10, 10, 10, 10); |
|
1718 |
painter->setClipPath(path, Qt::ReplaceClip); |
|
1719 |
} |
|
1720 |
painter->fillRect(rect(), Qt::green); |
|
1721 |
painter->restore(); |
|
1722 |
||
1723 |
painter->save(); |
|
1724 |
{ |
|
1725 |
QPainterPath path; |
|
1726 |
path.addRect(0, 60, 60, 25); |
|
1727 |
path.addRect(10, 10, 10, 10); |
|
1728 |
painter->setClipPath(path, Qt::IntersectClip); |
|
1729 |
} |
|
1730 |
painter->setClipRect(60, 60, 50, 25, Qt::UniteClip); |
|
1731 |
painter->fillRect(rect(), Qt::yellow); |
|
1732 |
painter->restore(); |
|
1733 |
} |
|
1734 |
||
1735 |
protected: |
|
1736 |
void paintEvent(QPaintEvent*) |
|
1737 |
{ |
|
1738 |
QPainter painter(this); |
|
1739 |
paint(&painter); |
|
1740 |
} |
|
1741 |
}; |
|
1742 |
||
1743 |
void tst_QGL::clipTest() |
|
1744 |
{ |
|
1745 |
ClipTestGLWidget glw; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1746 |
#ifdef Q_WS_QWS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1747 |
glw.setWindowFlags(Qt::FramelessWindowHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1748 |
#endif |
0 | 1749 |
glw.resize(220, 220); |
1750 |
glw.show(); |
|
1751 |
||
1752 |
#ifdef Q_WS_X11 |
|
1753 |
qt_x11_wait_for_window_manager(&glw); |
|
1754 |
#endif |
|
1755 |
QTest::qWait(200); |
|
1756 |
||
1757 |
QImage reference(glw.size(), QImage::Format_RGB32); |
|
1758 |
QPainter referencePainter(&reference); |
|
1759 |
glw.paint(&referencePainter); |
|
1760 |
referencePainter.end(); |
|
1761 |
||
1762 |
const QImage widgetFB = glw.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); |
|
1763 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1764 |
// Sample pixels in a grid pattern which avoids false failures due to |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1765 |
// off-by-one pixel errors on some buggy GL implementations |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1766 |
for (int x = 2; x < reference.width(); x += 5) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1767 |
for (int y = 2; y < reference.width(); y += 5) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1768 |
QFUZZY_COMPARE_PIXELS(widgetFB.pixel(x, y), reference.pixel(x, y)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1769 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1770 |
} |
0 | 1771 |
} |
1772 |
||
1773 |
void tst_QGL::destroyFBOAfterContext() |
|
1774 |
{ |
|
1775 |
if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) |
|
1776 |
QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); |
|
1777 |
||
1778 |
QGLWidget *glw = new QGLWidget(); |
|
1779 |
glw->makeCurrent(); |
|
1780 |
||
1781 |
// No multisample with combined depth/stencil attachment: |
|
1782 |
QGLFramebufferObjectFormat fboFormat; |
|
1783 |
fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
1784 |
||
1785 |
// Don't complicate things by using NPOT: |
|
1786 |
QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat); |
|
1787 |
||
1788 |
// The handle should be valid until the context is destroyed. |
|
1789 |
QVERIFY(fbo->handle() != 0); |
|
1790 |
QVERIFY(fbo->isValid()); |
|
1791 |
||
1792 |
delete glw; |
|
1793 |
||
1794 |
// The handle should now be zero. |
|
1795 |
QVERIFY(fbo->handle() == 0); |
|
1796 |
QVERIFY(!fbo->isValid()); |
|
1797 |
||
1798 |
delete fbo; |
|
1799 |
} |
|
1800 |
||
1801 |
#ifdef QT_BUILD_INTERNAL |
|
1802 |
||
1803 |
class tst_QGLResource : public QObject |
|
1804 |
{ |
|
1805 |
Q_OBJECT |
|
1806 |
public: |
|
1807 |
tst_QGLResource(QObject *parent = 0) : QObject(parent) {} |
|
1808 |
~tst_QGLResource() { ++deletions; } |
|
1809 |
||
1810 |
static int deletions; |
|
1811 |
}; |
|
1812 |
||
1813 |
int tst_QGLResource::deletions = 0; |
|
1814 |
||
1815 |
static void qt_shared_test_free(void *data) |
|
1816 |
{ |
|
1817 |
delete reinterpret_cast<tst_QGLResource *>(data); |
|
1818 |
} |
|
1819 |
||
1820 |
Q_GLOBAL_STATIC_WITH_ARGS(QGLContextResource, qt_shared_test, (qt_shared_test_free)) |
|
1821 |
||
1822 |
#endif |
|
1823 |
||
1824 |
void tst_QGL::shareRegister() |
|
1825 |
{ |
|
1826 |
#ifdef QT_BUILD_INTERNAL |
|
1827 |
QGLShareRegister *shareReg = qgl_share_reg(); |
|
1828 |
QVERIFY(shareReg != 0); |
|
1829 |
||
1830 |
// Create a context. |
|
1831 |
QGLWidget *glw1 = new QGLWidget(); |
|
1832 |
glw1->makeCurrent(); |
|
1833 |
||
1834 |
// Nothing should be sharing with glw1's context yet. |
|
1835 |
QList<const QGLContext *> list; |
|
1836 |
list = shareReg->shares(glw1->context()); |
|
1837 |
QCOMPARE(list.size(), 0); |
|
1838 |
||
1839 |
// Create a guard for the first context. |
|
1840 |
QGLSharedResourceGuard guard(glw1->context()); |
|
1841 |
QVERIFY(guard.id() == 0); |
|
1842 |
guard.setId(3); |
|
1843 |
QVERIFY(guard.id() == 3); |
|
1844 |
||
1845 |
// Add a resource to the first context. |
|
1846 |
tst_QGLResource *res1 = new tst_QGLResource(); |
|
1847 |
QVERIFY(!qt_shared_test()->value(glw1->context())); |
|
1848 |
qt_shared_test()->insert(glw1->context(), res1); |
|
1849 |
QVERIFY(qt_shared_test()->value(glw1->context()) == res1); |
|
1850 |
||
1851 |
// Create another context that shares with the first. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1852 |
QVERIFY(!glw1->isSharing()); |
0 | 1853 |
QGLWidget *glw2 = new QGLWidget(0, glw1); |
1854 |
if (!glw2->isSharing()) { |
|
1855 |
delete glw2; |
|
1856 |
delete glw1; |
|
1857 |
QSKIP("Context sharing is not supported", SkipSingle); |
|
1858 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1859 |
QVERIFY(glw1->isSharing()); |
0 | 1860 |
QVERIFY(glw1->context() != glw2->context()); |
1861 |
||
1862 |
// Check that the first context's resource is also on the second. |
|
1863 |
QVERIFY(qt_shared_test()->value(glw1->context()) == res1); |
|
1864 |
QVERIFY(qt_shared_test()->value(glw2->context()) == res1); |
|
1865 |
||
1866 |
// Guard should still be the same. |
|
1867 |
QVERIFY(guard.context() == glw1->context()); |
|
1868 |
QVERIFY(guard.id() == 3); |
|
1869 |
||
1870 |
// Now there are two items in the share lists. |
|
1871 |
list = shareReg->shares(glw1->context()); |
|
1872 |
QCOMPARE(list.size(), 2); |
|
1873 |
QVERIFY(list.contains(glw1->context())); |
|
1874 |
QVERIFY(list.contains(glw2->context())); |
|
1875 |
list = shareReg->shares(glw2->context()); |
|
1876 |
QCOMPARE(list.size(), 2); |
|
1877 |
QVERIFY(list.contains(glw1->context())); |
|
1878 |
QVERIFY(list.contains(glw2->context())); |
|
1879 |
||
1880 |
// Check the sharing relationships. |
|
1881 |
QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
|
1882 |
QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
|
1883 |
QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
|
1884 |
QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context())); |
|
1885 |
QVERIFY(!QGLContext::areSharing(0, glw2->context())); |
|
1886 |
QVERIFY(!QGLContext::areSharing(glw1->context(), 0)); |
|
1887 |
QVERIFY(!QGLContext::areSharing(0, 0)); |
|
1888 |
||
1889 |
// Create a third context, not sharing with the others. |
|
1890 |
QGLWidget *glw3 = new QGLWidget(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1891 |
QVERIFY(!glw3->isSharing()); |
0 | 1892 |
|
1893 |
// Create a guard on the standalone context. |
|
1894 |
QGLSharedResourceGuard guard3(glw3->context()); |
|
1895 |
guard3.setId(5); |
|
1896 |
||
1897 |
// Add a resource to the third context. |
|
1898 |
tst_QGLResource *res3 = new tst_QGLResource(); |
|
1899 |
QVERIFY(!qt_shared_test()->value(glw3->context())); |
|
1900 |
qt_shared_test()->insert(glw3->context(), res3); |
|
1901 |
QVERIFY(qt_shared_test()->value(glw1->context()) == res1); |
|
1902 |
QVERIFY(qt_shared_test()->value(glw2->context()) == res1); |
|
1903 |
QVERIFY(qt_shared_test()->value(glw3->context()) == res3); |
|
1904 |
||
1905 |
// First two should still be sharing, but third is in its own list. |
|
1906 |
list = shareReg->shares(glw1->context()); |
|
1907 |
QCOMPARE(list.size(), 2); |
|
1908 |
QVERIFY(list.contains(glw1->context())); |
|
1909 |
QVERIFY(list.contains(glw2->context())); |
|
1910 |
list = shareReg->shares(glw2->context()); |
|
1911 |
QCOMPARE(list.size(), 2); |
|
1912 |
QVERIFY(list.contains(glw1->context())); |
|
1913 |
QVERIFY(list.contains(glw2->context())); |
|
1914 |
list = shareReg->shares(glw3->context()); |
|
1915 |
QCOMPARE(list.size(), 0); |
|
1916 |
||
1917 |
// Check the sharing relationships again. |
|
1918 |
QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
|
1919 |
QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
|
1920 |
QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
|
1921 |
QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context())); |
|
1922 |
QVERIFY(!QGLContext::areSharing(glw1->context(), glw3->context())); |
|
1923 |
QVERIFY(!QGLContext::areSharing(glw2->context(), glw3->context())); |
|
1924 |
QVERIFY(!QGLContext::areSharing(glw3->context(), glw1->context())); |
|
1925 |
QVERIFY(!QGLContext::areSharing(glw3->context(), glw2->context())); |
|
1926 |
QVERIFY(QGLContext::areSharing(glw3->context(), glw3->context())); |
|
1927 |
QVERIFY(!QGLContext::areSharing(0, glw2->context())); |
|
1928 |
QVERIFY(!QGLContext::areSharing(glw1->context(), 0)); |
|
1929 |
QVERIFY(!QGLContext::areSharing(0, glw3->context())); |
|
1930 |
QVERIFY(!QGLContext::areSharing(glw3->context(), 0)); |
|
1931 |
QVERIFY(!QGLContext::areSharing(0, 0)); |
|
1932 |
||
1933 |
// Shared guard should still be the same. |
|
1934 |
QVERIFY(guard.context() == glw1->context()); |
|
1935 |
QVERIFY(guard.id() == 3); |
|
1936 |
||
1937 |
// Delete the first context. |
|
1938 |
delete glw1; |
|
1939 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1940 |
// The second context should no longer register as sharing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1941 |
QVERIFY(!glw2->isSharing()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1942 |
|
0 | 1943 |
// The first context's resource should transfer to the second context. |
1944 |
QCOMPARE(tst_QGLResource::deletions, 0); |
|
1945 |
QVERIFY(qt_shared_test()->value(glw2->context()) == res1); |
|
1946 |
QVERIFY(qt_shared_test()->value(glw3->context()) == res3); |
|
1947 |
||
1948 |
// Shared guard should now be the second context, with the id the same. |
|
1949 |
QVERIFY(guard.context() == glw2->context()); |
|
1950 |
QVERIFY(guard.id() == 3); |
|
1951 |
QVERIFY(guard3.context() == glw3->context()); |
|
1952 |
QVERIFY(guard3.id() == 5); |
|
1953 |
||
1954 |
// Re-check the share list for the second context (should be empty now). |
|
1955 |
list = shareReg->shares(glw2->context()); |
|
1956 |
QCOMPARE(list.size(), 0); |
|
1957 |
||
1958 |
// Clean up and check that the resources are properly deleted. |
|
1959 |
delete glw2; |
|
1960 |
QCOMPARE(tst_QGLResource::deletions, 1); |
|
1961 |
delete glw3; |
|
1962 |
QCOMPARE(tst_QGLResource::deletions, 2); |
|
1963 |
||
1964 |
// Guards should now be null and the id zero. |
|
1965 |
QVERIFY(guard.context() == 0); |
|
1966 |
QVERIFY(guard.id() == 0); |
|
1967 |
QVERIFY(guard3.context() == 0); |
|
1968 |
QVERIFY(guard3.id() == 0); |
|
1969 |
#endif |
|
1970 |
} |
|
1971 |
||
1972 |
QTEST_MAIN(tst_QGL) |
|
1973 |
#include "tst_qgl.moc" |