summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-06-20 11:58:34 +0200
committerLaszlo Agocs <laszlo.agocs@digia.com>2014-08-01 17:13:59 +0200
commite453484bca5add5973602044ff0fbc224f819a07 (patch)
tree67f8b2afcb6622fee78f45959980324eeaf4accf /tests/manual
parent718f248a8921ad310cbb9e099b16f5ffa0c860c1 (diff)
Make QOpenGLWidget public
QOpenGLWidget is now public. In addition Qt::WA_AlwaysStackOnTop is introduced to support the special case of semi-transparent QOpenGLWidget or QQuickWidget on top of regular widgets. hellogl_es2 becomes the qopenglwidget example. This example performs painting both via QPainter and native GL commands and has the OpenGL widget combined with other, normal widgets. The widget stack receives some changes when it comes to renderToTexture widgets like QQuickWidget and QOpenGLWidget. Calling update() will now result in a paint event, which is essential for QOpenGLWidget since we want it to behave like a regular widget. The dirty region handling is extended specially for such widgets due to performance reasons. (an OpenGL content update must not result in any backingstore painting, and is thus handled as a different kind of dirtiness) [ChangeLog] Added QOpenGLWidget. This widget serves as a replacement for QGLWidget. Task-number: QTBUG-36899 Task-number: QTBUG-40086 Change-Id: Ibf7f82fea99b39edfffd2fc088e7e0eadbca25cf Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/qopenglwidget/openglwidget/main.cpp17
-rw-r--r--tests/manual/qopenglwidget/openglwidget/openglwidget.cpp7
-rw-r--r--tests/manual/qopenglwidget/openglwidget/openglwidget.h2
3 files changed, 21 insertions, 5 deletions
diff --git a/tests/manual/qopenglwidget/openglwidget/main.cpp b/tests/manual/qopenglwidget/openglwidget/main.cpp
index 68f9be7199..0268d47767 100644
--- a/tests/manual/qopenglwidget/openglwidget/main.cpp
+++ b/tests/manual/qopenglwidget/openglwidget/main.cpp
@@ -45,20 +45,32 @@
#include <QMdiArea>
#include <QLCDNumber>
#include <QTimer>
-
+#include <QSurfaceFormat>
+#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+ QSurfaceFormat format;
+ if (QCoreApplication::arguments().contains(QLatin1String("--multisample")))
+ format.setSamples(4);
+ if (QCoreApplication::arguments().contains(QLatin1String("--coreprofile"))) {
+ format.setVersion(3, 2);
+ format.setProfile(QSurfaceFormat::CoreProfile);
+ }
+ qDebug() << "Requesting" << format;
+
QMdiArea w;
w.resize(400,400);
OpenGLWidget *glw = new OpenGLWidget;
+ glw->setFormat(format);
w.addSubWindow(glw);
glw->setMinimumSize(100,100);
OpenGLWidget *glw2 = new OpenGLWidget;
+ glw2->setFormat(format);
glw2->setMinimumSize(100,100);
w.addSubWindow(glw2);
@@ -69,5 +81,8 @@ int main(int argc, char *argv[])
w.show();
+ if (glw->isValid())
+ qDebug() << "Got" << glw->format();
+
return a.exec();
}
diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp
index bec89b6b41..516de35ff8 100644
--- a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp
+++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp
@@ -58,7 +58,7 @@
#include <QtCore/qmath.h>
#include <qopengl.h>
-class OpenGLWidgetPrivate
+class OpenGLWidgetPrivate : protected QOpenGLFunctions
{
public:
OpenGLWidgetPrivate(QWidget *q)
@@ -91,7 +91,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{
d = new OpenGLWidgetPrivate(this);
QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(updateGL()));
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(30);
}
@@ -137,6 +137,7 @@ static const char *fragmentShaderSource =
void OpenGLWidgetPrivate::initialize()
{
+ initializeOpenGLFunctions();
m_program = new QOpenGLShaderProgram;
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
@@ -157,7 +158,7 @@ void OpenGLWidgetPrivate::render()
m_program->bind();
QMatrix4x4 matrix;
- matrix.perspective(60, 4.0/3.0, 0.1, 100.0);
+ matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f);
matrix.translate(0, 0, -2);
matrix.rotate(100.0f * m_frame / 30/*screen()->refreshRate()*/, 0, 1, 0);
diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.h b/tests/manual/qopenglwidget/openglwidget/openglwidget.h
index eaba27df26..ada01d4cc1 100644
--- a/tests/manual/qopenglwidget/openglwidget/openglwidget.h
+++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.h
@@ -42,7 +42,7 @@
#ifndef OPENGLWIDGET_H
#define OPENGLWIDGET_H
-#include <QtWidgets/private/qopenglwidget_p.h>
+#include <QtWidgets/QOpenGLWidget>
class OpenGLWidgetPrivate;
class OpenGLWidget : public QOpenGLWidget