summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/engine/q3dwindow.cpp
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-03-19 11:35:03 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-03-19 11:35:03 +0200
commitfe9bdb34089ab741f36b3dc627b2c0891283891d (patch)
tree7548d6b1e8c74285953a19f440974df99cb7f858 /src/datavis3d/engine/q3dwindow.cpp
parentd1bac9cb0de4051c870fe9e65cf33436adcfe815 (diff)
Implemented Qpainter text drawing on top of opengl scene
Diffstat (limited to 'src/datavis3d/engine/q3dwindow.cpp')
-rw-r--r--src/datavis3d/engine/q3dwindow.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/datavis3d/engine/q3dwindow.cpp b/src/datavis3d/engine/q3dwindow.cpp
index 68f41b51..52138251 100644
--- a/src/datavis3d/engine/q3dwindow.cpp
+++ b/src/datavis3d/engine/q3dwindow.cpp
@@ -64,9 +64,15 @@ Q3DWindow::Q3DWindow(QWindow *parent)
surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
//surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); // OpenGL crashes with ANGLE, comment out or define OpenGLES
setFormat(surfaceFormat);
- qDebug() << "OpenGL version" << format().majorVersion() << format().minorVersion();
- qDebug() << "OpenGL renderer" << format().renderableType();
- qDebug() << "OpenGL swapBehavior" << format().swapBehavior();
+
+ create();
+
+ d_ptr->m_context->setFormat(requestedFormat());
+ d_ptr->m_context->create();
+ d_ptr->m_context->makeCurrent(this);
+
+ initializeOpenGLFunctions();
+ initialize();
}
Q3DWindow::~Q3DWindow()
@@ -80,23 +86,20 @@ void Q3DWindow::render(QPainter *painter)
void Q3DWindow::initialize()
{
+ qDebug() << "OpenGL version" << format().majorVersion() << format().minorVersion();
+ qDebug() << "OpenGL renderer" << format().renderableType();
+ qDebug() << "OpenGL swapBehavior" << format().swapBehavior();
+ setAnimating(true);
}
void Q3DWindow::render()
{
-// if (!d_ptr->m_device)
-// d_ptr->m_device = new QOpenGLPaintDevice;
-
-// d_ptr->m_device->setSize(size());
-
-// QPainter painter(d_ptr->m_device);
-// render(&painter);
}
void Q3DWindow::renderLater()
{
- if (!d_ptr->m_update_pending) {
- d_ptr->m_update_pending = true;
+ if (!d_ptr->m_updatePending) {
+ d_ptr->m_updatePending = true;
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
}
}
@@ -133,25 +136,18 @@ void Q3DWindow::renderNow()
if (!isExposed())
return;
- d_ptr->m_update_pending = false;
-
- bool needsInitialize = false;
+ static bool needsInit = true;
- if (!d_ptr->m_context) {
- d_ptr->m_context = new QOpenGLContext(this);
- d_ptr->m_context->setFormat(requestedFormat());
- d_ptr->m_context->create();
+ d_ptr->m_updatePending = false;
- needsInitialize = true;
+ if (needsInit) {
+ getDevice();
+ initialize();
+ needsInit = false;
}
d_ptr->m_context->makeCurrent(this);
- if (needsInitialize) {
- initializeOpenGLFunctions();
- initialize();
- }
-
render();
d_ptr->m_context->swapBuffers(this);
@@ -168,11 +164,19 @@ void Q3DWindow::setAnimating(bool animating)
renderLater();
}
+QOpenGLPaintDevice *Q3DWindow::getDevice()
+{
+ if (!d_ptr->m_device)
+ d_ptr->m_device = new QOpenGLPaintDevice;
+ d_ptr->m_device->setSize(size());
+ return d_ptr->m_device;
+}
+
Q3DWindowPrivate::Q3DWindowPrivate(Q3DWindow *q)
: q_ptr(q)
- , m_update_pending(false)
- , m_animating(true)
- , m_context(0)
+ , m_updatePending(false)
+ , m_animating(false)
+ , m_context(new QOpenGLContext(q))
, m_device(0)
{
}