summaryrefslogtreecommitdiffstats
path: root/src/datavisualization
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization')
-rw-r--r--src/datavisualization/engine/selectionpointer.cpp48
-rw-r--r--src/datavisualization/engine/selectionpointer_p.h3
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp103
3 files changed, 106 insertions, 48 deletions
diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp
index da5d5e54..d646429a 100644
--- a/src/datavisualization/engine/selectionpointer.cpp
+++ b/src/datavisualization/engine/selectionpointer.cpp
@@ -78,7 +78,7 @@ void SelectionPointer::updateScene(Q3DScene *scene)
m_cachedScene = scene;
}
-void SelectionPointer::render(GLuint defaultFboHandle, bool useOrtho)
+void SelectionPointer::renderSelectionPointer(GLuint defaultFboHandle, bool useOrtho)
{
Q_UNUSED(defaultFboHandle)
@@ -86,7 +86,6 @@ void SelectionPointer::render(GLuint defaultFboHandle, bool useOrtho)
m_mainViewPort.width(), m_mainViewPort.height());
Q3DCamera *camera = m_cachedScene->activeCamera();
- QSize textureSize = m_labelItem.size();
QMatrix4x4 itModelMatrix;
@@ -111,10 +110,6 @@ void SelectionPointer::render(GLuint defaultFboHandle, bool useOrtho)
projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f);
}
- // Calculate scale factor to get uniform font size
- GLfloat scaledFontSize = 0.05f + m_drawer->font().pointSizeF() / 500.0f;
- GLfloat scaleFactor = scaledFontSize / (GLfloat)textureSize.height();
-
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
@@ -152,11 +147,44 @@ void SelectionPointer::render(GLuint defaultFboHandle, bool useOrtho)
Utils::vectorFromColor(m_cachedTheme->lightColor()));
m_drawer->drawObject(m_pointShader, m_pointObj);
+}
- //
- // Draw the label
- //
+void SelectionPointer::renderSelectionLabel(GLuint defaultFboHandle, bool useOrtho)
+{
+ Q_UNUSED(defaultFboHandle)
+
+ glViewport(m_mainViewPort.x(), m_mainViewPort.y(),
+ m_mainViewPort.width(), m_mainViewPort.height());
+
+ Q3DCamera *camera = m_cachedScene->activeCamera();
+
+ // Get view matrix
+ QMatrix4x4 viewMatrix;
QMatrix4x4 modelMatrixLabel;
+ QMatrix4x4 projectionMatrix;
+ GLfloat viewPortRatio = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height();
+ if (m_cachedIsSlicingActivated) {
+ GLfloat sliceUnitsScaled = sliceUnits / m_autoScaleAdjustment;
+ viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), zeroVector, upVector);
+ projectionMatrix.ortho(-sliceUnitsScaled * viewPortRatio, sliceUnitsScaled * viewPortRatio,
+ -sliceUnitsScaled, sliceUnitsScaled,
+ -1.0f, 4.0f);
+ } else if (useOrtho) {
+ viewMatrix = camera->d_ptr->viewMatrix();
+ GLfloat orthoRatio = 2.0f;
+ projectionMatrix.ortho(-viewPortRatio * orthoRatio, viewPortRatio * orthoRatio,
+ -orthoRatio, orthoRatio,
+ 0.0f, 100.0f);
+ } else {
+ viewMatrix = camera->d_ptr->viewMatrix();
+ projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f);
+ }
+
+ QSize textureSize = m_labelItem.size();
+
+ // Calculate scale factor to get uniform font size
+ GLfloat scaledFontSize = 0.05f + m_drawer->font().pointSizeF() / 500.0f;
+ GLfloat scaleFactor = scaledFontSize / (GLfloat)textureSize.height();
// Position label
QVector3D labelAlign(0.0f, 1.0f * scaledFontSize + 0.05f, 0.0f);
@@ -184,6 +212,8 @@ void SelectionPointer::render(GLuint defaultFboHandle, bool useOrtho)
m_labelShader->bind();
+ QMatrix4x4 MVPMatrix;
+
// Set shader bindings
MVPMatrix = projectionMatrix * viewMatrix * modelMatrixLabel;
m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix);
diff --git a/src/datavisualization/engine/selectionpointer_p.h b/src/datavisualization/engine/selectionpointer_p.h
index 31856130..0ba9b53a 100644
--- a/src/datavisualization/engine/selectionpointer_p.h
+++ b/src/datavisualization/engine/selectionpointer_p.h
@@ -58,7 +58,8 @@ public:
explicit SelectionPointer(Drawer *drawer);
~SelectionPointer();
- void render(GLuint defaultFboHandle = 0, bool useOrtho = false);
+ void renderSelectionPointer(GLuint defaultFboHandle = 0, bool useOrtho = false);
+ void renderSelectionLabel(GLuint defaultFboHandle = 0, bool useOrtho = false);
void setPosition(const QVector3D &position);
void setLabel(const QString &label, bool themeChange = false);
void setPointerObject(ObjectHelper *object);
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index 848dc0f7..9cfa0edc 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -760,17 +760,19 @@ void Surface3DRenderer::render(GLuint defaultFboHandle)
if (m_cachedIsSlicingActivated)
drawSlicedScene();
- // Render selection ball
+ // Render selection label
if (m_selectionActive
&& m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem)) {
- foreach (SeriesRenderCache *baseCache, m_renderCacheList) {
- SurfaceSeriesRenderCache *cache = static_cast<SurfaceSeriesRenderCache *>(baseCache);
+ for (SeriesRenderCache *baseCache: m_renderCacheList) {
+ const SurfaceSeriesRenderCache *cache = static_cast<SurfaceSeriesRenderCache *>(baseCache);
if (cache->slicePointerActive() && cache->renderable() &&
m_cachedIsSlicingActivated ) {
- cache->sliceSelectionPointer()->render(defaultFboHandle);
+ cache->sliceSelectionPointer()->renderSelectionLabel(defaultFboHandle);
+ }
+ if (cache->mainPointerActive() && cache->renderable()) {
+ cache->mainSelectionPointer()->renderSelectionLabel(defaultFboHandle,
+ m_useOrthoProjection);
}
- if (cache->mainPointerActive() && cache->renderable())
- cache->mainSelectionPointer()->render(defaultFboHandle, m_useOrthoProjection);
}
}
}
@@ -1328,6 +1330,38 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
m_primarySubViewport.height());
}
+ // Selection handling
+ if (m_selectionDirty || m_selectionLabelDirty) {
+ QPoint visiblePoint = Surface3DController::invalidSelectionPosition();
+ if (m_selectedSeries) {
+ SurfaceSeriesRenderCache *cache =
+ static_cast<SurfaceSeriesRenderCache *>(
+ m_renderCacheList.value(const_cast<QSurface3DSeries *>(m_selectedSeries)));
+ if (cache && m_selectedPoint != Surface3DController::invalidSelectionPosition()) {
+ const QRect &sampleSpace = cache->sampleSpace();
+ int x = m_selectedPoint.x() - sampleSpace.y();
+ int y = m_selectedPoint.y() - sampleSpace.x();
+ if (x >= 0 && y >= 0 && x < sampleSpace.height() && y < sampleSpace.width()
+ && cache->dataArray().size()) {
+ visiblePoint = QPoint(x, y);
+ }
+ }
+ }
+
+ if (m_cachedSelectionMode == QAbstract3DGraph::SelectionNone
+ || visiblePoint == Surface3DController::invalidSelectionPosition()) {
+ m_selectionActive = false;
+ } else {
+ if (m_cachedIsSlicingActivated)
+ updateSliceDataModel(visiblePoint);
+ if (m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem))
+ surfacePointSelected(visiblePoint);
+ m_selectionActive = true;
+ }
+
+ m_selectionDirty = false;
+ }
+
// Draw the surface
if (!m_renderCacheList.isEmpty()) {
// For surface we can see glimpses from underneath
@@ -1452,6 +1486,22 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
}
}
+ // Render selection ball
+ if (m_selectionActive
+ && m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem)) {
+ for (SeriesRenderCache *baseCache: m_renderCacheList) {
+ const SurfaceSeriesRenderCache *cache = static_cast<SurfaceSeriesRenderCache *>(baseCache);
+ if (cache->slicePointerActive() && cache->renderable() &&
+ m_cachedIsSlicingActivated ) {
+ cache->sliceSelectionPointer()->renderSelectionPointer(defaultFboHandle);
+ }
+ if (cache->mainPointerActive() && cache->renderable()) {
+ cache->mainSelectionPointer()->renderSelectionPointer(defaultFboHandle,
+ m_useOrthoProjection);
+ }
+ }
+ }
+
// Bind background shader
m_backgroundShader->bind();
glCullFace(GL_BACK);
@@ -1481,7 +1531,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
MVPMatrix = projectionViewMatrix * modelMatrix;
#endif
+ bool blendEnabled = false;
QVector4D backgroundColor = Utils::vectorFromColor(m_cachedTheme->backgroundColor());
+ if (backgroundColor.w() < 1.0f) {
+ blendEnabled = true;
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
// Set shader bindings
m_backgroundShader->setUniformValue(m_backgroundShader->lightP(), lightPos);
@@ -1516,6 +1572,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Draw the object
m_drawer->drawObject(m_backgroundShader, m_backgroundObj);
}
+
+ if (blendEnabled)
+ glDisable(GL_BLEND);
}
// Draw grid lines
@@ -1865,38 +1924,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Release shader
glUseProgram(0);
-
- // Selection handling
- if (m_selectionDirty || m_selectionLabelDirty) {
- QPoint visiblePoint = Surface3DController::invalidSelectionPosition();
- if (m_selectedSeries) {
- SurfaceSeriesRenderCache *cache =
- static_cast<SurfaceSeriesRenderCache *>(
- m_renderCacheList.value(const_cast<QSurface3DSeries *>(m_selectedSeries)));
- if (cache && m_selectedPoint != Surface3DController::invalidSelectionPosition()) {
- const QRect &sampleSpace = cache->sampleSpace();
- int x = m_selectedPoint.x() - sampleSpace.y();
- int y = m_selectedPoint.y() - sampleSpace.x();
- if (x >= 0 && y >= 0 && x < sampleSpace.height() && y < sampleSpace.width()
- && cache->dataArray().size()) {
- visiblePoint = QPoint(x, y);
- }
- }
- }
-
- if (m_cachedSelectionMode == QAbstract3DGraph::SelectionNone
- || visiblePoint == Surface3DController::invalidSelectionPosition()) {
- m_selectionActive = false;
- } else {
- if (m_cachedIsSlicingActivated)
- updateSliceDataModel(visiblePoint);
- if (m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem))
- surfacePointSelected(visiblePoint);
- m_selectionActive = true;
- }
-
- m_selectionDirty = false;
- }
}
void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamera,