1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qcoreapplication.h>
#include <qdebug.h>
#include <qgl.h>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
//TESTED_CLASS=
//TESTED_FILES=
class tst_QGL : public QObject
{
Q_OBJECT
public:
tst_QGL();
virtual ~tst_QGL();
private slots:
void getSetCheck();
void openGLVersionCheck();
void graphicsViewClipping();
void partialGLWidgetUpdates_data();
void partialGLWidgetUpdates();
};
tst_QGL::tst_QGL()
{
}
tst_QGL::~tst_QGL()
{
}
class MyGLContext : public QGLContext
{
public:
MyGLContext(const QGLFormat& format) : QGLContext(format) {}
bool windowCreated() const { return QGLContext::windowCreated(); }
void setWindowCreated(bool on) { QGLContext::setWindowCreated(on); }
bool initialized() const { return QGLContext::initialized(); }
void setInitialized(bool on) { QGLContext::setInitialized(on); }
};
class MyGLWidget : public QGLWidget
{
public:
MyGLWidget() : QGLWidget() {}
bool autoBufferSwap() const { return QGLWidget::autoBufferSwap(); }
void setAutoBufferSwap(bool on) { QGLWidget::setAutoBufferSwap(on); }
};
// Testing get/set functions
void tst_QGL::getSetCheck()
{
if (!QGLFormat::hasOpenGL())
QSKIP("QGL not supported on this platform", SkipAll);
QGLFormat obj1;
// int QGLFormat::depthBufferSize()
// void QGLFormat::setDepthBufferSize(int)
obj1.setDepthBufferSize(0);
QCOMPARE(0, obj1.depthBufferSize());
obj1.setDepthBufferSize(INT_MIN);
QCOMPARE(0, obj1.depthBufferSize()); // Makes no sense with a negative buffer size
obj1.setDepthBufferSize(INT_MAX);
QCOMPARE(INT_MAX, obj1.depthBufferSize());
// int QGLFormat::accumBufferSize()
// void QGLFormat::setAccumBufferSize(int)
obj1.setAccumBufferSize(0);
QCOMPARE(0, obj1.accumBufferSize());
obj1.setAccumBufferSize(INT_MIN);
QCOMPARE(0, obj1.accumBufferSize()); // Makes no sense with a negative buffer size
obj1.setAccumBufferSize(INT_MAX);
QCOMPARE(INT_MAX, obj1.accumBufferSize());
// int QGLFormat::alphaBufferSize()
// void QGLFormat::setAlphaBufferSize(int)
obj1.setAlphaBufferSize(0);
QCOMPARE(0, obj1.alphaBufferSize());
obj1.setAlphaBufferSize(INT_MIN);
QCOMPARE(0, obj1.alphaBufferSize()); // Makes no sense with a negative buffer size
obj1.setAlphaBufferSize(INT_MAX);
QCOMPARE(INT_MAX, obj1.alphaBufferSize());
// int QGLFormat::stencilBufferSize()
// void QGLFormat::setStencilBufferSize(int)
obj1.setStencilBufferSize(0);
QCOMPARE(0, obj1.stencilBufferSize());
obj1.setStencilBufferSize(INT_MIN);
QCOMPARE(0, obj1.stencilBufferSize()); // Makes no sense with a negative buffer size
obj1.setStencilBufferSize(INT_MAX);
QCOMPARE(INT_MAX, obj1.stencilBufferSize());
// bool QGLFormat::sampleBuffers()
// void QGLFormat::setSampleBuffers(bool)
obj1.setSampleBuffers(false);
QCOMPARE(false, obj1.sampleBuffers());
obj1.setSampleBuffers(true);
QCOMPARE(true, obj1.sampleBuffers());
// int QGLFormat::samples()
// void QGLFormat::setSamples(int)
obj1.setSamples(0);
QCOMPARE(0, obj1.samples());
obj1.setSamples(INT_MIN);
QCOMPARE(0, obj1.samples()); // Makes no sense with a negative sample size
obj1.setSamples(INT_MAX);
QCOMPARE(INT_MAX, obj1.samples());
// bool QGLFormat::doubleBuffer()
// void QGLFormat::setDoubleBuffer(bool)
obj1.setDoubleBuffer(false);
QCOMPARE(false, obj1.doubleBuffer());
obj1.setDoubleBuffer(true);
QCOMPARE(true, obj1.doubleBuffer());
// bool QGLFormat::depth()
// void QGLFormat::setDepth(bool)
obj1.setDepth(false);
QCOMPARE(false, obj1.depth());
obj1.setDepth(true);
QCOMPARE(true, obj1.depth());
// bool QGLFormat::rgba()
// void QGLFormat::setRgba(bool)
obj1.setRgba(false);
QCOMPARE(false, obj1.rgba());
obj1.setRgba(true);
QCOMPARE(true, obj1.rgba());
// bool QGLFormat::alpha()
// void QGLFormat::setAlpha(bool)
obj1.setAlpha(false);
QCOMPARE(false, obj1.alpha());
obj1.setAlpha(true);
QCOMPARE(true, obj1.alpha());
// bool QGLFormat::accum()
// void QGLFormat::setAccum(bool)
obj1.setAccum(false);
QCOMPARE(false, obj1.accum());
obj1.setAccum(true);
QCOMPARE(true, obj1.accum());
// bool QGLFormat::stencil()
// void QGLFormat::setStencil(bool)
obj1.setStencil(false);
QCOMPARE(false, obj1.stencil());
obj1.setStencil(true);
QCOMPARE(true, obj1.stencil());
// bool QGLFormat::stereo()
// void QGLFormat::setStereo(bool)
obj1.setStereo(false);
QCOMPARE(false, obj1.stereo());
obj1.setStereo(true);
QCOMPARE(true, obj1.stereo());
// bool QGLFormat::directRendering()
// void QGLFormat::setDirectRendering(bool)
obj1.setDirectRendering(false);
QCOMPARE(false, obj1.directRendering());
obj1.setDirectRendering(true);
QCOMPARE(true, obj1.directRendering());
// int QGLFormat::plane()
// void QGLFormat::setPlane(int)
obj1.setPlane(0);
QCOMPARE(0, obj1.plane());
obj1.setPlane(INT_MIN);
QCOMPARE(INT_MIN, obj1.plane());
obj1.setPlane(INT_MAX);
QCOMPARE(INT_MAX, obj1.plane());
MyGLContext obj2(obj1);
// bool QGLContext::windowCreated()
// void QGLContext::setWindowCreated(bool)
obj2.setWindowCreated(false);
QCOMPARE(false, obj2.windowCreated());
obj2.setWindowCreated(true);
QCOMPARE(true, obj2.windowCreated());
// bool QGLContext::initialized()
// void QGLContext::setInitialized(bool)
obj2.setInitialized(false);
QCOMPARE(false, obj2.initialized());
obj2.setInitialized(true);
QCOMPARE(true, obj2.initialized());
MyGLWidget obj3;
// bool QGLWidget::autoBufferSwap()
// void QGLWidget::setAutoBufferSwap(bool)
obj3.setAutoBufferSwap(false);
QCOMPARE(false, obj3.autoBufferSwap());
obj3.setAutoBufferSwap(true);
QCOMPARE(true, obj3.autoBufferSwap());
}
#ifdef QT_BUILD_INTERNAL
QT_BEGIN_NAMESPACE
extern QGLFormat::OpenGLVersionFlags qOpenGLVersionFlagsFromString(const QString &versionString);
QT_END_NAMESPACE
#endif
void tst_QGL::openGLVersionCheck()
{
#ifdef QT_BUILD_INTERNAL
if (!QGLFormat::hasOpenGL())
QSKIP("QGL not supported on this platform", SkipAll);
QString versionString;
QGLFormat::OpenGLVersionFlags expectedFlag;
QGLFormat::OpenGLVersionFlags versionFlag;
versionString = "1.1 Irix 6.5";
expectedFlag = QGLFormat::OpenGL_Version_1_1;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "1.2 Microsoft";
expectedFlag = QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "1.2.1";
expectedFlag = QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "1.3 NVIDIA";
expectedFlag = QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "1.4";
expectedFlag = QGLFormat::OpenGL_Version_1_4 | QGLFormat::OpenGL_Version_1_3 | QGLFormat::OpenGL_Version_1_2 | QGLFormat::OpenGL_Version_1_1;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "1.5 NVIDIA";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "2.0.2 NVIDIA 87.62";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "2.1 NVIDIA";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "2.1";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "OpenGL ES-CM 1.0 ATI";
expectedFlag = QGLFormat::OpenGL_ES_Common_Version_1_0 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "OpenGL ES-CL 1.0 ATI";
expectedFlag = QGLFormat::OpenGL_ES_CommonLite_Version_1_0;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "OpenGL ES-CM 1.1 ATI";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "OpenGL ES-CL 1.1 ATI";
expectedFlag = QGLFormat::OpenGL_ES_CommonLite_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "OpenGL ES 2.0 ATI";
expectedFlag = QGLFormat::OpenGL_ES_Version_2_0;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
versionString = "3.0";
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;
versionFlag = qOpenGLVersionFlagsFromString(versionString);
QCOMPARE(versionFlag, expectedFlag);
QGLWidget glWidget;
glWidget.show();
glWidget.makeCurrent();
// This is unfortunately the only test we can make on the actual openGLVersionFlags()
// However, the complicated parts are in openGLVersionFlags(const QString &versionString)
// tested above
QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_1);
#endif
}
class UnclippedWidget : public QWidget
{
public:
void paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(rect().adjusted(-1000, -1000, 1000, 1000), Qt::black);
}
};
void tst_QGL::graphicsViewClipping()
{
const int size = 64;
UnclippedWidget *widget = new UnclippedWidget;
widget->setFixedSize(size, size);
QGraphicsScene scene;
scene.addWidget(widget)->setPos(0, 0);
QGraphicsView view(&scene);
view.resize(2*size, 2*size);
QGLWidget *viewport = new QGLWidget;
view.setViewport(viewport);
view.show();
if (!viewport->isValid())
return;
scene.setSceneRect(view.viewport()->rect());
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&view);
#endif
QTest::qWait(500);
QImage image = viewport->grabFrameBuffer();
QImage expected = image;
QPainter p(&expected);
p.fillRect(expected.rect(), Qt::white);
p.fillRect(QRect(0, 0, size, size), Qt::black);
p.end();
QCOMPARE(image, expected);
}
void tst_QGL::partialGLWidgetUpdates_data()
{
QTest::addColumn<bool>("doubleBufferedContext");
QTest::addColumn<bool>("autoFillBackground");
QTest::addColumn<bool>("supportsPartialUpdates");
QTest::newRow("Double buffered context") << true << true << false;
QTest::newRow("Double buffered context without auto-fill background") << true << false << false;
QTest::newRow("Single buffered context") << false << true << false;
QTest::newRow("Single buffered context without auto-fill background") << false << false << true;
}
void tst_QGL::partialGLWidgetUpdates()
{
if (!QGLFormat::hasOpenGL())
QSKIP("QGL not supported on this platform", SkipAll);
QFETCH(bool, doubleBufferedContext);
QFETCH(bool, autoFillBackground);
QFETCH(bool, supportsPartialUpdates);
class MyGLWidget : public QGLWidget
{
public:
QRegion paintEventRegion;
void paintEvent(QPaintEvent *e)
{
paintEventRegion = e->region();
}
};
QGLFormat format = QGLFormat::defaultFormat();
format.setDoubleBuffer(doubleBufferedContext);
QGLFormat::setDefaultFormat(format);
MyGLWidget widget;
widget.setFixedSize(150, 150);
widget.setAutoFillBackground(autoFillBackground);
widget.show();
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&widget);
#endif
QTest::qWait(200);
if (widget.format().doubleBuffer() != doubleBufferedContext)
QSKIP("Platform does not support requested format", SkipAll);
widget.paintEventRegion = QRegion();
widget.repaint(50, 50, 50, 50);
#ifdef Q_WS_MAC
// repaint() is not immediate on the Mac; it has to go through the event loop.
QTest::qWait(200);
#endif
if (supportsPartialUpdates)
QCOMPARE(widget.paintEventRegion, QRegion(50, 50, 50, 50));
else
QCOMPARE(widget.paintEventRegion, QRegion(widget.rect()));
}
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"
|