summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-04-15 13:56:59 +0300
committerMika Salmela <mika.salmela@digia.com>2013-04-15 16:39:47 +0300
commitffb7741c4e83568fb026645c5e089b77de1ac45e (patch)
tree7a66ff76c1d32828ed0ef55da6d97dd9924183f3 /src
parenteb92ad69dbe1568a3055d01066d975cce9fdcc39 (diff)
Optimized label texture creation
Change-Id: I2c97fb82c1ea2fa22bf603675658e53ac82e0298 Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavis3d/engine/q3dbars.cpp106
-rw-r--r--src/datavis3d/engine/q3dbars.h1
-rw-r--r--src/datavis3d/engine/qdataitem.cpp1
-rw-r--r--src/datavis3d/global/qdatavis3dglobal.h2
-rw-r--r--src/datavis3d/global/qdatavis3namespace.h2
5 files changed, 66 insertions, 46 deletions
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index a9d18c73..87b67592 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -61,6 +61,12 @@
#include <QDebug>
+#define DISPLAY_RENDER_SPEED
+
+#ifdef DISPLAY_RENDER_SPEED
+#include <QTime>
+#endif
+
QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
#define USE_HAX0R_SELECTION // keep this defined until the "real" method works
@@ -139,7 +145,21 @@ void Q3DBars::render()
{
if (!d_ptr->m_isInitialized)
return;
-
+#ifdef DISPLAY_RENDER_SPEED
+ // For speed computation
+ static QTime lastTime = QTime::currentTime();
+ static QTime lastFrameTime = lastTime;
+ static int nbFrames = 0;
+
+ // Measure speed (as milliseconds per frame)
+ lastFrameTime = QTime::currentTime();
+ nbFrames++;
+ if (lastTime.msecsTo(lastFrameTime) >= 1000.0f) { // print only if last measurement was more than 1s ago
+ qDebug() << 1000.0f / double(nbFrames) << "ms/frame (=" << double(nbFrames) << "fps)";
+ nbFrames = 0;
+ lastTime = lastFrameTime;
+ }
+#endif
#ifdef USE_PAINTER_TEXT
if (d_ptr->m_paintDevice) {
QPainter painter(d_ptr->m_paintDevice);
@@ -445,7 +465,7 @@ void Q3DBars::drawZoomScene()
d_ptr->m_barShader->release();
#ifndef USE_PAINTER_TEXT
- // Draw labels (or values of bars)
+ // Draw bar values
d_ptr->m_labelShader->bind();
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
@@ -453,33 +473,11 @@ void Q3DBars::drawZoomScene()
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+
+ // Do the actual drawing
for (int col = 0; col < d_ptr->m_zoomSelection->d_ptr->row().size(); col++) {
QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(col);
- //
- // TODO: Optimize! Create textures only when zoomselection changes! Store the texture id's into zoomselection
- //
- // ie. move this segment elsewhere...
- // Create labels
- // Print label into a QImage using QPainter
- QImage label = Utils::printTextToImage(d_ptr->m_font
- , item->d_ptr->valueStr()
- , d_ptr->m_theme->m_textBackgroundColor
- , d_ptr->m_theme->m_textColor
- , d_ptr->m_labelTransparency);
-
- // Set label size
- item->d_ptr->setLabelSize(label.size());
- // Insert text texture into label
- item->d_ptr->setTextureId(d_ptr->m_textureHelper->create2DTexture(label, true, true));
- // ...ie. move this segment elsewhere
-
drawLabel(*item, viewMatrix, projectionMatrix, false, -45.0f);
-
- // ie. move this segment elsewhere...
- GLuint labelTexture = item->d_ptr->textureId();
- glDeleteTextures(1, &labelTexture);
- item->d_ptr->setTextureId(0);
- // ...ie. move this segment elsewhere
}
glDisable(GL_TEXTURE_2D);
@@ -908,9 +906,16 @@ void Q3DBars::drawScene()
d_ptr->m_zoomActivated = true;
d_ptr->m_sceneViewPort = QRect(0, height() - height() / 5
, width() / 5, height() / 5);
+
+ // Create label textures
+ for (int col = 0; col < d_ptr->m_zoomSelection->d_ptr->row().size(); col++) {
+ QDataItem *item = d_ptr->m_zoomSelection->d_ptr->getItem(col);
+ generateLabelTexture(item);
+ }
} else {
// Print value of selected bar
#ifndef USE_PAINTER_TEXT
+ static QDataItem *prevItem = d_ptr->m_selectedBar;
d_ptr->m_labelShader->bind();
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
@@ -918,27 +923,13 @@ void Q3DBars::drawScene()
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- // Create label
- // Print label into a QImage using QPainter
- QImage label = Utils::printTextToImage(d_ptr->m_font
- , d_ptr->m_selectedBar->d_ptr->valueStr()
- , d_ptr->m_theme->m_textBackgroundColor
- , d_ptr->m_theme->m_textColor
- , d_ptr->m_labelTransparency);
-
- // Set label size
- d_ptr->m_selectedBar->d_ptr->setLabelSize(label.size());
- // Insert text texture into label
- d_ptr->m_selectedBar->d_ptr->setTextureId(d_ptr->m_textureHelper->create2DTexture(label
- , true
- , true));
+ if (prevItem != d_ptr->m_selectedBar) {
+ generateLabelTexture(d_ptr->m_selectedBar);
+ prevItem = d_ptr->m_selectedBar;
+ }
drawLabel(*d_ptr->m_selectedBar, viewMatrix, projectionMatrix, true);
- GLuint labelTexture = d_ptr->m_selectedBar->d_ptr->textureId();
- glDeleteTextures(1, &labelTexture);
- d_ptr->m_selectedBar->d_ptr->setTextureId(0);
-
glDisable(GL_TEXTURE_2D);
if (d_ptr->m_labelTransparency > TransparencyNone)
glDisable(GL_BLEND);
@@ -953,6 +944,33 @@ void Q3DBars::drawScene()
d_ptr->m_barShader->release();
}
+void Q3DBars::generateLabelTexture(QDataItem *item)
+{
+ // Delete previous texture, if there is one
+ GLuint labelTexture = item->d_ptr->textureId();
+ if (labelTexture) {
+ // We have to do this, as we can't know if data is static or not;
+ // texture doesn't change with static data
+ // (basically we could create textures for all bars when data is added, but we
+ // may not need them -> better to do it here dynamically)
+ glDeleteTextures(1, &labelTexture);
+ item->d_ptr->setTextureId(0);
+ }
+
+ // Create labels
+ // Print label into a QImage using QPainter
+ QImage label = Utils::printTextToImage(d_ptr->m_font
+ , item->d_ptr->valueStr()
+ , d_ptr->m_theme->m_textBackgroundColor
+ , d_ptr->m_theme->m_textColor
+ , d_ptr->m_labelTransparency);
+
+ // Set label size
+ item->d_ptr->setLabelSize(label.size());
+ // Insert text texture into label
+ item->d_ptr->setTextureId(d_ptr->m_textureHelper->create2DTexture(label, true, true));
+}
+
// TODO: Move to a separate class, so that it can be used by other vis types as well (will need a lot more parameters..)
void Q3DBars::drawLabel(const QDataItem &item, const QMatrix4x4 &viewmatrix
, const QMatrix4x4 &projectionmatrix, bool useDepth, qreal rotation) // TODO: Add enum? for label position (below, middle, top etc.)
diff --git a/src/datavis3d/engine/q3dbars.h b/src/datavis3d/engine/q3dbars.h
index e3936c81..0d7ef935 100644
--- a/src/datavis3d/engine/q3dbars.h
+++ b/src/datavis3d/engine/q3dbars.h
@@ -209,6 +209,7 @@ private:
void drawLabel(const QDataItem &item, const QMatrix4x4 &viewmatrix
, const QMatrix4x4 &projectionmatrix, bool useDepth = false
, qreal rotation = 0.0f);
+ void generateLabelTexture(QDataItem *item);
QScopedPointer<Q3DBarsPrivate> d_ptr;
Q_DISABLE_COPY(Q3DBars)
};
diff --git a/src/datavis3d/engine/qdataitem.cpp b/src/datavis3d/engine/qdataitem.cpp
index d0a4ec74..28a96cc0 100644
--- a/src/datavis3d/engine/qdataitem.cpp
+++ b/src/datavis3d/engine/qdataitem.cpp
@@ -76,6 +76,7 @@ QDataItemPrivate::QDataItemPrivate(QDataItem *q, float value, const QString &lab
, m_prependLabel(false)
, m_size(QSize(0, 0))
, m_translation(QVector3D(0, 0, 0))
+ , m_textureId(0)
{
}
diff --git a/src/datavis3d/global/qdatavis3dglobal.h b/src/datavis3d/global/qdatavis3dglobal.h
index 7bd0fea3..528180b3 100644
--- a/src/datavis3d/global/qdatavis3dglobal.h
+++ b/src/datavis3d/global/qdatavis3dglobal.h
@@ -4,7 +4,7 @@
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
-** This file is part of the Qt Commercial Charts Add-on.
+** This file is part of QtDataVis3D.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
diff --git a/src/datavis3d/global/qdatavis3namespace.h b/src/datavis3d/global/qdatavis3namespace.h
index f19ed4d7..fd6e7919 100644
--- a/src/datavis3d/global/qdatavis3namespace.h
+++ b/src/datavis3d/global/qdatavis3namespace.h
@@ -3,7 +3,7 @@
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the Qt3D module of the Qt Toolkit.
+** This file is part of QtDataVis3D.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage