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