From 0d5caf7904098186e50009627996191dc7f8687b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Mon, 4 Nov 2013 13:40:09 +0200 Subject: Surface toggling API implemented Task-number: QTRD-2337 Change-Id: I59695a042c864faed90839c4e566fcece5cb94f4 Reviewed-by: Miikka Heikkinen --- .../doc/src/qtdatavisualization-qml-surface3d.qdoc | 6 + src/datavisualization/engine/q3dsurface.cpp | 14 +++ src/datavisualization/engine/q3dsurface.h | 4 + .../engine/surface3dcontroller.cpp | 18 +++ .../engine/surface3dcontroller_p.h | 6 + src/datavisualization/engine/surface3drenderer.cpp | 125 +++++++++++---------- src/datavisualization/engine/surface3drenderer_p.h | 2 + 7 files changed, 118 insertions(+), 57 deletions(-) (limited to 'src/datavisualization') diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc index 92b0e7d9..55a0d1d1 100644 --- a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc +++ b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc @@ -79,6 +79,12 @@ The smoothing of surface. If false, the shading of the surface is flat. */ +/*! + * \qmlproperty bool Surface3D::surfaceVisible + * The surface visibility. If false, no surface is drawn. If surface grid is enabled, it is still + * drawn. + */ + /*! \qmlproperty bool Surface3D::surfaceGridEnabled The surface grid visibility. If false, no surface grid is drawn. diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp index 7b9e32bb..a91df086 100644 --- a/src/datavisualization/engine/q3dsurface.cpp +++ b/src/datavisualization/engine/q3dsurface.cpp @@ -276,6 +276,20 @@ QDataVis::SelectionFlags Q3DSurface::selectionMode() const return d_ptr->m_shared->selectionMode(); } +/*! + * \property Q3DSurface::surfaceVisible + * + * Sets surface to \a visible. It is preset to \c true by default. + */ +void Q3DSurface::setSurfaceVisible(bool visible) +{ + d_ptr->m_shared->setSurfaceVisible(visible); +} + +bool Q3DSurface::isSurfaceVisible() const +{ + return d_ptr->m_shared->surfaceVisible(); +} /*! * \property Q3DSurface::surfaceGridEnabled diff --git a/src/datavisualization/engine/q3dsurface.h b/src/datavisualization/engine/q3dsurface.h index c131f245..ca3c3965 100644 --- a/src/datavisualization/engine/q3dsurface.h +++ b/src/datavisualization/engine/q3dsurface.h @@ -38,6 +38,7 @@ class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public Q3DWindow Q_PROPERTY(QtDataVisualization::QDataVis::LabelStyle labelStyle READ labelStyle WRITE setLabelStyle) Q_PROPERTY(QtDataVisualization::QDataVis::Theme theme READ theme WRITE setTheme) Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(bool surfaceVisible READ isSurfaceVisible WRITE setSurfaceVisible) Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible) Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) Q_PROPERTY(bool smoothSurfaceEnabled READ isSmoothSurfaceEnabled WRITE setSmoothSurfaceEnabled) @@ -52,6 +53,9 @@ public: explicit Q3DSurface(); ~Q3DSurface(); + void setSurfaceVisible(bool visible); + bool isSurfaceVisible() const; + void setGridVisible(bool visible); bool isGridVisible() const; diff --git a/src/datavisualization/engine/surface3dcontroller.cpp b/src/datavisualization/engine/surface3dcontroller.cpp index ec1cae30..04943bf9 100644 --- a/src/datavisualization/engine/surface3dcontroller.cpp +++ b/src/datavisualization/engine/surface3dcontroller.cpp @@ -34,6 +34,7 @@ Surface3DController::Surface3DController(QRect rect) : Abstract3DController(rect), m_renderer(0), m_isSmoothSurfaceEnabled(false), + m_isSurfaceEnabled(true), m_isSurfaceGridEnabled(true), m_selectedPoint(noSelectionPoint()) { @@ -91,6 +92,11 @@ void Surface3DController::synchDataToRenderer() emit smoothSurfaceEnabledChanged(m_isSmoothSurfaceEnabled); } + if (m_changeTracker.surfaceVisibilityChanged) { + m_renderer->updateSurfaceVisibilityStatus(m_isSurfaceEnabled); + m_changeTracker.surfaceVisibilityChanged = false; + } + if (m_changeTracker.surfaceGridChanged) { m_renderer->updateSurfaceGridStatus(m_isSurfaceGridEnabled); m_changeTracker.surfaceGridChanged = false; @@ -145,6 +151,18 @@ bool Surface3DController::smoothSurface() return m_isSmoothSurfaceEnabled; } +void Surface3DController::setSurfaceVisible(bool visible) +{ + m_isSurfaceEnabled = visible; + m_changeTracker.surfaceVisibilityChanged = true; + emitNeedRender(); +} + +bool Surface3DController::surfaceVisible() const +{ + return m_isSurfaceEnabled; +} + void Surface3DController::setSurfaceGrid(bool enable) { m_isSurfaceGridEnabled = enable; diff --git a/src/datavisualization/engine/surface3dcontroller_p.h b/src/datavisualization/engine/surface3dcontroller_p.h index 83a52b7d..1010f09b 100644 --- a/src/datavisualization/engine/surface3dcontroller_p.h +++ b/src/datavisualization/engine/surface3dcontroller_p.h @@ -41,12 +41,14 @@ class Surface3DRenderer; struct Surface3DChangeBitField { bool gradientColorChanged : 1; bool smoothStatusChanged : 1; + bool surfaceVisibilityChanged : 1; bool surfaceGridChanged : 1; bool selectedPointChanged : 1; Surface3DChangeBitField() : gradientColorChanged(true), smoothStatusChanged(true), + surfaceVisibilityChanged(true), surfaceGridChanged(true), selectedPointChanged(true) { @@ -61,6 +63,7 @@ private: Surface3DChangeBitField m_changeTracker; Surface3DRenderer *m_renderer; bool m_isSmoothSurfaceEnabled; + bool m_isSurfaceEnabled; bool m_isSurfaceGridEnabled; QLinearGradient m_userDefinedGradient; QPoint m_selectedPoint; @@ -72,6 +75,9 @@ public: void initializeOpenGL(); virtual void synchDataToRenderer(); + void setSurfaceVisible(bool visible); + bool surfaceVisible() const; + void setSmoothSurface(bool enable); bool smoothSurface(); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 063ddd7e..92a68461 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -102,6 +102,8 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_shadowQualityToShader(33.3f), m_cachedSmoothSurface(true), m_flatSupported(true), + m_cachedSurfaceOn(true), + m_cachedSurfaceGridOn(true), m_selectionPointer(0), m_selectionActive(false), m_xFlipped(false), @@ -506,16 +508,8 @@ void Surface3DRenderer::drawSlicedScene() } if (m_surfaceObj) { - ShaderHelper *surfaceShader = m_shader; - surfaceShader->bind(); - - if (m_cachedSurfaceGridOn) { - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(0.5f, 1.0f); - } - - QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; + QMatrix4x4 modelMatrix; QMatrix4x4 itModelMatrix; modelMatrix.translate(offset, 0.0f, 0.0f); @@ -525,27 +519,37 @@ void Surface3DRenderer::drawSlicedScene() MVPMatrix = projectionViewMatrix * modelMatrix; - QVector3D color; - if (rowMode) - color = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor); - else - color = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor); - - // Set shader bindings - surfaceShader->setUniformValue(surfaceShader->lightP(), lightPos); - surfaceShader->setUniformValue(surfaceShader->view(), viewMatrix); - surfaceShader->setUniformValue(surfaceShader->model(), modelMatrix); - surfaceShader->setUniformValue(surfaceShader->nModel(), - itModelMatrix.inverted().transposed()); - surfaceShader->setUniformValue(surfaceShader->MVP(), MVPMatrix); - surfaceShader->setUniformValue(surfaceShader->color(), color); - surfaceShader->setUniformValue(surfaceShader->lightS(), 0.25f); - surfaceShader->setUniformValue(surfaceShader->ambientS(), - m_cachedTheme.m_ambientStrength * 2.0f); + if (m_cachedSurfaceOn) { + if (m_cachedSurfaceGridOn) { + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(0.5f, 1.0f); + } - m_drawer->drawObject(surfaceShader, m_sliceSurfaceObj); + ShaderHelper *surfaceShader = m_shader; + surfaceShader->bind(); - surfaceShader->release(); + QVector3D color; + if (rowMode) + color = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor); + else + color = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor); + + // Set shader bindings + surfaceShader->setUniformValue(surfaceShader->lightP(), lightPos); + surfaceShader->setUniformValue(surfaceShader->view(), viewMatrix); + surfaceShader->setUniformValue(surfaceShader->model(), modelMatrix); + surfaceShader->setUniformValue(surfaceShader->nModel(), + itModelMatrix.inverted().transposed()); + surfaceShader->setUniformValue(surfaceShader->MVP(), MVPMatrix); + surfaceShader->setUniformValue(surfaceShader->color(), color); + surfaceShader->setUniformValue(surfaceShader->lightS(), 0.25f); + surfaceShader->setUniformValue(surfaceShader->ambientS(), + m_cachedTheme.m_ambientStrength * 2.0f); + + m_drawer->drawObject(surfaceShader, m_sliceSurfaceObj); + + surfaceShader->release(); + } // Draw surface grid if (m_cachedSurfaceGridOn) { @@ -787,7 +791,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Draw depth buffer #if !defined(QT_OPENGL_ES_2) GLfloat adjustedLightStrength = m_cachedTheme.m_lightStrength / 10.0f; - if (m_cachedShadowQuality > QDataVis::ShadowQualityNone && m_surfaceObj) { + if (m_cachedShadowQuality > QDataVis::ShadowQualityNone && m_surfaceObj && m_cachedSurfaceOn) { // Render scene into a depth texture for using with shadow mapping // Enable drawing to depth framebuffer glBindFramebuffer(GL_FRAMEBUFFER, m_depthFrameBuffer); @@ -939,7 +943,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Draw the surface if (m_surfaceObj && m_sampleSpace.width() >= 2 && m_sampleSpace.height() >= 2) { m_surfaceShader->bind(); - // For surface we can see climpses from underneath glDisable(GL_CULL_FACE); if (m_cachedSurfaceGridOn) { @@ -960,40 +963,43 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) #else MVPMatrix = projectionViewMatrix * modelMatrix; #endif - // Set shader bindings - m_surfaceShader->setUniformValue(m_surfaceShader->lightP(), lightPos); - m_surfaceShader->setUniformValue(m_surfaceShader->view(), viewMatrix); - m_surfaceShader->setUniformValue(m_surfaceShader->model(), modelMatrix); - m_surfaceShader->setUniformValue(m_surfaceShader->nModel(), - itModelMatrix.inverted().transposed()); - m_surfaceShader->setUniformValue(m_surfaceShader->MVP(), MVPMatrix); - m_surfaceShader->setUniformValue(m_surfaceShader->ambientS(), - m_cachedTheme.m_ambientStrength); + + if (m_cachedSurfaceOn) { + // Set shader bindings + m_surfaceShader->setUniformValue(m_surfaceShader->lightP(), lightPos); + m_surfaceShader->setUniformValue(m_surfaceShader->view(), viewMatrix); + m_surfaceShader->setUniformValue(m_surfaceShader->model(), modelMatrix); + m_surfaceShader->setUniformValue(m_surfaceShader->nModel(), + itModelMatrix.inverted().transposed()); + m_surfaceShader->setUniformValue(m_surfaceShader->MVP(), MVPMatrix); + m_surfaceShader->setUniformValue(m_surfaceShader->ambientS(), + m_cachedTheme.m_ambientStrength); #if !defined(QT_OPENGL_ES_2) - if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - // Set shadow shader bindings - QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; - m_surfaceShader->setUniformValue(m_surfaceShader->shadowQ(), m_shadowQualityToShader); - m_surfaceShader->setUniformValue(m_surfaceShader->depth(), depthMVPMatrix); - m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), adjustedLightStrength); + if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { + // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; + m_surfaceShader->setUniformValue(m_surfaceShader->shadowQ(), m_shadowQualityToShader); + m_surfaceShader->setUniformValue(m_surfaceShader->depth(), depthMVPMatrix); + m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), adjustedLightStrength); - // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture, m_depthTexture); - } else + // Draw the object + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture, m_depthTexture); + } else #endif - { - // Set shadowless shader bindings - m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), - m_cachedTheme.m_lightStrength); + { + // Set shadowless shader bindings + m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), + m_cachedTheme.m_lightStrength); - // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture); - } + // Draw the object + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture); + } - m_surfaceShader->release(); + m_surfaceShader->release(); - glEnable(GL_CULL_FACE); + glEnable(GL_CULL_FACE); + } // Draw surface grid if (m_cachedSurfaceGridOn) { @@ -1772,6 +1778,11 @@ void Surface3DRenderer::updateSelectedPoint(const QPoint &position) m_selectionDirty = true; } +void Surface3DRenderer::updateSurfaceVisibilityStatus(bool visible) +{ + m_cachedSurfaceOn = visible; +} + void Surface3DRenderer::updateSurfaceGridStatus(bool enable) { m_cachedSurfaceGridOn = enable; diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index 54257cde..875e79c6 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -110,6 +110,7 @@ private: GLfloat m_shadowQualityToShader; bool m_cachedSmoothSurface; bool m_flatSupported; + bool m_cachedSurfaceOn; bool m_cachedSurfaceGridOn; SelectionPointer *m_selectionPointer; bool m_selectionActive; @@ -134,6 +135,7 @@ public: void updateScene(Q3DScene *scene); void updateInputState(QDataVis::InputState state); bool updateSmoothStatus(bool enable); + void updateSurfaceVisibilityStatus(bool visible); void updateSurfaceGridStatus(bool enable); void updateSurfaceGradient(const QLinearGradient &gradient); void updateSlicingActive(bool isSlicing); -- cgit v1.2.3