From 2299481acb0b36d76414ed9e0ae2b2d110ff13d8 Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Thu, 5 Jun 2014 10:32:24 +0300 Subject: Scatter perf improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-3148 Change-Id: I2c9efa84184819aaac123ee29685bc3a9e35bfe6 Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen --- .../utils/scatterpointbufferhelper.cpp | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/datavisualization/utils/scatterpointbufferhelper.cpp (limited to 'src/datavisualization/utils/scatterpointbufferhelper.cpp') diff --git a/src/datavisualization/utils/scatterpointbufferhelper.cpp b/src/datavisualization/utils/scatterpointbufferhelper.cpp new file mode 100644 index 00000000..0f290aeb --- /dev/null +++ b/src/datavisualization/utils/scatterpointbufferhelper.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "scatterpointbufferhelper_p.h" + +QT_BEGIN_NAMESPACE_DATAVISUALIZATION + +const GLfloat itemScaler = 3.0f; +const QVector3D hiddenPos(-1000.0f, -1000.0f, -1000.0f); + +ScatterPointBufferHelper::ScatterPointBufferHelper() + : m_pointbuffer(0), + m_oldRemoveIndex(0), + m_oldRemove(false) +{ + m_indicesType = GL_UNSIGNED_INT; +} + +ScatterPointBufferHelper::~ScatterPointBufferHelper() +{ + if (QOpenGLContext::currentContext()) + glDeleteBuffers(1, &m_pointbuffer); +} + +GLuint ScatterPointBufferHelper::pointBuf() +{ + if (!m_meshDataLoaded) + qFatal("No loaded object"); + return m_pointbuffer; +} + +void ScatterPointBufferHelper::pushPoint(uint pointIndex) +{ + glBindBuffer(GL_ARRAY_BUFFER, m_pointbuffer); + + if (m_oldRemove && m_oldRemoveIndex < pointIndex) { + glBufferSubData(GL_ARRAY_BUFFER, m_oldRemoveIndex * sizeof(QVector3D), + sizeof(QVector3D), &m_bufferedPoints.at(m_oldRemoveIndex)); + } + + glBufferSubData(GL_ARRAY_BUFFER, pointIndex * sizeof(QVector3D), + sizeof(QVector3D), + &hiddenPos); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + m_oldRemoveIndex = pointIndex; + m_oldRemove = true; +} + +void ScatterPointBufferHelper::popPoint() +{ + if (m_oldRemove) { + glBindBuffer(GL_ARRAY_BUFFER, m_pointbuffer); + glBufferSubData(GL_ARRAY_BUFFER, m_oldRemoveIndex * sizeof(QVector3D), + sizeof(QVector3D), &m_bufferedPoints.at(m_oldRemoveIndex)); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + + m_oldRemoveIndex = 0; + m_oldRemove = false; +} + +void ScatterPointBufferHelper::load(ScatterSeriesRenderCache *cache) +{ + initializeOpenGLFunctions(); + + ScatterRenderItemArray &renderArray = cache->renderArray(); + const int renderArraySize = renderArray.size(); + + if (m_meshDataLoaded) { + // Delete old data + glDeleteBuffers(1, &m_pointbuffer); + m_bufferedPoints.clear(); + } + + m_bufferedPoints.resize(renderArraySize); + for (int i = 0; i < renderArraySize; i++) { + ScatterRenderItem &item = renderArray[i]; + if (!item.isVisible()) + m_bufferedPoints[i] = hiddenPos; + else + m_bufferedPoints[i] = item.translation(); + } + + m_indexCount = renderArraySize; + + glGenBuffers(1, &m_pointbuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_pointbuffer); + glBufferData(GL_ARRAY_BUFFER, m_bufferedPoints.size() * sizeof(QVector3D), + &m_bufferedPoints.at(0), + GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + m_meshDataLoaded = true; +} + +QT_END_NAMESPACE_DATAVISUALIZATION -- cgit v1.2.3