From 74e1374b246f0b6d8c4560f052b9f880c41603ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Thu, 20 Jun 2019 15:45:54 +0300 Subject: Add matteEnabled to viewer settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flag is required to disable clearing to black in qml applications, which support transparency. Task-number: QT3DS-3689 Task-number: QT3DS-3542 Change-Id: I27b1e07a394be30f0fb4841c69555dde5697a5cf Reviewed-by: Tomi Korpipää Reviewed-by: Jari Karppinen Reviewed-by: Mahmoud Badri Reviewed-by: Pasi Keränen --- src/api/studio3d/q3dscommandqueue.cpp | 5 +++ src/api/studio3d/q3dscommandqueue_p.h | 2 + src/api/studio3d/q3dsviewersettings.cpp | 50 ++++++++++++++++++++++ src/api/studio3d/q3dsviewersettings.h | 7 +-- src/api/studio3d/q3dsviewersettings_p.h | 2 + src/api/studio3dqml/q3dsrenderer.cpp | 2 + .../Qt3DSRenderRuntimeBindingImplRenderer.cpp | 1 + src/engine/Qt3DSRuntimeView.h | 1 + src/runtimerender/Qt3DSRenderContextCore.cpp | 14 ++++-- src/runtimerender/Qt3DSRenderContextCore.h | 1 + src/viewer/Qt3DSViewerApp.cpp | 6 +++ src/viewer/Qt3DSViewerApp.h | 1 + 12 files changed, 85 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/api/studio3d/q3dscommandqueue.cpp b/src/api/studio3d/q3dscommandqueue.cpp index c6071aa..e9eed29 100644 --- a/src/api/studio3d/q3dscommandqueue.cpp +++ b/src/api/studio3d/q3dscommandqueue.cpp @@ -61,6 +61,7 @@ CommandQueue::CommandQueue() , m_showRenderStats(false) , m_matteColor(Qt::black) , m_delayedLoading(false) + , m_matteEnabled(false) , m_size(0) { qRegisterMetaType(); @@ -207,6 +208,7 @@ void CommandQueue::copyCommands(CommandQueue &fromQueue) m_globalAnimationTimeChanged = m_globalAnimationTimeChanged || fromQueue.m_globalAnimationTimeChanged; m_delayedLoadingChanged = m_delayedLoadingChanged || fromQueue.m_delayedLoadingChanged; + m_matteEnabledChanged = m_matteEnabledChanged || fromQueue.m_matteEnabledChanged; if (fromQueue.m_visibleChanged) m_visible = fromQueue.m_visible; @@ -226,6 +228,8 @@ void CommandQueue::copyCommands(CommandQueue &fromQueue) m_globalAnimationTime = fromQueue.m_globalAnimationTime; if (fromQueue.m_delayedLoadingChanged) m_delayedLoading = fromQueue.m_delayedLoading; + if (fromQueue.m_matteEnabledChanged) + m_matteEnabled = fromQueue.m_matteEnabled; // Pending queue may be synchronized multiple times between queue processing, so let's append // to the existing queue rather than clearing it. @@ -304,6 +308,7 @@ void CommandQueue::clear(bool deleteCommandData) m_variantListChanged = false; m_globalAnimationTimeChanged = false; m_delayedLoadingChanged = false; + m_matteEnabledChanged = false; if (deleteCommandData) { for (int i = 0; i < m_size; ++i) { diff --git a/src/api/studio3d/q3dscommandqueue_p.h b/src/api/studio3d/q3dscommandqueue_p.h index 12d1b7e..effb72e 100644 --- a/src/api/studio3d/q3dscommandqueue_p.h +++ b/src/api/studio3d/q3dscommandqueue_p.h @@ -142,6 +142,7 @@ public: bool m_variantListChanged; bool m_globalAnimationTimeChanged; bool m_delayedLoadingChanged; + bool m_matteEnabledChanged; bool m_visible; Q3DSViewerSettings::ScaleMode m_scaleMode; @@ -152,6 +153,7 @@ public: QStringList m_variantList; qint64 m_globalAnimationTime; bool m_delayedLoading; + bool m_matteEnabled; void clear(bool deleteCommandData); int size() const { return m_size; } diff --git a/src/api/studio3d/q3dsviewersettings.cpp b/src/api/studio3d/q3dsviewersettings.cpp index 01f82df..9403a32 100644 --- a/src/api/studio3d/q3dsviewersettings.cpp +++ b/src/api/studio3d/q3dsviewersettings.cpp @@ -228,6 +228,40 @@ void Q3DSViewerSettings::setScaleMode(Q3DSViewerSettings::ScaleMode mode) } } +/*! + \qmlproperty bool ViewerSettings::matteEnabled + + Specifies if the empty area around the presentation (applicable when + scaleMode is set to ScaleModeCenter or ScaleModeFit) should be filled with + a custom color. + + The default value is \c false. + */ +/*! + \property Q3DSViewerSettings::matteEnabled + + Specifies if the empty area around the presentation (applicable when + scaleMode is set to ScaleModeCenter or ScaleModeFit) should be filled with + a custom color. + + The default value is \c false. + + \sa matteColor + */ +bool Q3DSViewerSettings::matteEnabled() const +{ + return d_ptr->m_matteEnabled; +} + +void Q3DSViewerSettings::setMatteEnabled(bool enabled) +{ + if (d_ptr->m_matteEnabled != enabled) { + d_ptr->setMatteEnabled(enabled); + Q_EMIT matteEnabledChanged(enabled); + } +} + + /*! \qmlmethod ViewerSettings::save(string group, string organization, string application) @@ -268,6 +302,7 @@ Q3DSViewerSettingsPrivate::Q3DSViewerSettingsPrivate(Q3DSViewerSettings *q) , m_commandQueue(nullptr) , m_matteColor(Qt::black) , m_showRenderStats(false) + , m_matteEnabled(false) , m_shadeMode(Q3DSViewerSettings::ShadeModeShaded) , m_scaleMode(Q3DSViewerSettings::ScaleModeCenter) , m_savedSettings(nullptr) @@ -282,6 +317,7 @@ void Q3DSViewerSettingsPrivate::setViewerApp(Q3DSViewer::Q3DSViewerApp *app) { m_viewerApp = app; if (m_viewerApp) { + setMatteEnabled(m_matteEnabled); setMatteColor(m_matteColor); setShowRenderStats(m_showRenderStats); setShadeMode(m_shadeMode); @@ -293,6 +329,7 @@ void Q3DSViewerSettingsPrivate::setCommandQueue(CommandQueue *queue) { m_commandQueue = queue; if (m_commandQueue) { + setMatteEnabled(m_matteEnabled); setMatteColor(m_matteColor); setShowRenderStats(m_showRenderStats); setShadeMode(m_shadeMode); @@ -309,6 +346,7 @@ void Q3DSViewerSettingsPrivate::save(const QString &group, const QString &organi m_savedSettings->setValue(QStringLiteral("showRenderStats"), m_showRenderStats); m_savedSettings->setValue(QStringLiteral("shadeMode"), m_shadeMode); m_savedSettings->setValue(QStringLiteral("scaleMode"), m_scaleMode); + m_savedSettings->setValue(QStringLiteral("matteEnabled"), m_matteEnabled); } void Q3DSViewerSettingsPrivate::load(const QString &group, const QString &organization, @@ -322,6 +360,7 @@ void Q3DSViewerSettingsPrivate::load(const QString &group, const QString &organi m_savedSettings->value(QStringLiteral("shadeMode")).toInt())); q_ptr->setScaleMode(Q3DSViewerSettings::ScaleMode( m_savedSettings->value(QStringLiteral("scaleMode")).toInt())); + q_ptr->setMatteEnabled(m_savedSettings->value(QStringLiteral("matteEnabled")).toBool()); } void Q3DSViewerSettingsPrivate::setMatteColor(const QColor &color) @@ -335,6 +374,17 @@ void Q3DSViewerSettingsPrivate::setMatteColor(const QColor &color) } } +void Q3DSViewerSettingsPrivate::setMatteEnabled(bool enabled) +{ + m_matteEnabled = enabled; + if (m_viewerApp) { + m_viewerApp->setMatteColor(enabled); + } else if (m_commandQueue) { + m_commandQueue->m_matteEnabled = enabled; + m_commandQueue->m_matteEnabledChanged = true; + } +} + void Q3DSViewerSettingsPrivate::setShowRenderStats(bool show) { m_showRenderStats = show; diff --git a/src/api/studio3d/q3dsviewersettings.h b/src/api/studio3d/q3dsviewersettings.h index 5d7abf6..7199e1c 100644 --- a/src/api/studio3d/q3dsviewersettings.h +++ b/src/api/studio3d/q3dsviewersettings.h @@ -45,9 +45,7 @@ class Q_STUDIO3D_EXPORT Q3DSViewerSettings : public QObject Q_ENUMS(ShadeMode) Q_ENUMS(ScaleMode) -// #TODO: QT3DS-3542 Q3DSViewerSettings API is missing property matteEnabled compared to 2.3 -// Q_PROPERTY(bool matteEnabled READ matteEnabled WRITE setMatteEnabled NOTIFY matteEnabledChanged) - + Q_PROPERTY(bool matteEnabled READ matteEnabled WRITE setMatteEnabled NOTIFY matteEnabledChanged) Q_PROPERTY(QColor matteColor READ matteColor WRITE setMatteColor NOTIFY matteColorChanged) Q_PROPERTY(bool showRenderStats READ isShowRenderStats WRITE setShowRenderStats NOTIFY showRenderStatsChanged) Q_PROPERTY(ScaleMode scaleMode READ scaleMode WRITE setScaleMode NOTIFY scaleModeChanged) @@ -67,6 +65,7 @@ public: explicit Q3DSViewerSettings(QObject *parent = nullptr); ~Q3DSViewerSettings(); + bool matteEnabled() const; QColor matteColor() const; bool isShowRenderStats() const; ScaleMode scaleMode() const; @@ -77,11 +76,13 @@ public: const QString &application = QString()); public Q_SLOTS: + void setMatteEnabled(bool enabled); void setMatteColor(const QColor &color); void setShowRenderStats(bool show); void setScaleMode(ScaleMode mode); Q_SIGNALS: + void matteEnabledChanged(bool enabled); void matteColorChanged(const QColor &color); void showRenderStatsChanged(bool show); void shadeModeChanged(ShadeMode mode); diff --git a/src/api/studio3d/q3dsviewersettings_p.h b/src/api/studio3d/q3dsviewersettings_p.h index 48fbae3..4628241 100644 --- a/src/api/studio3d/q3dsviewersettings_p.h +++ b/src/api/studio3d/q3dsviewersettings_p.h @@ -62,6 +62,7 @@ public: void save(const QString &group, const QString &organization, const QString &application); void load(const QString &group, const QString &organization, const QString &application); + void setMatteEnabled(bool enabled); void setMatteColor(const QColor &color); void setShowRenderStats(bool show); void setShadeMode(Q3DSViewerSettings::ShadeMode mode); @@ -78,6 +79,7 @@ private: CommandQueue *m_commandQueue; // Not owned QColor m_matteColor; bool m_showRenderStats; + bool m_matteEnabled; Q3DSViewerSettings::ShadeMode m_shadeMode; Q3DSViewerSettings::ScaleMode m_scaleMode; QSettings *m_savedSettings; diff --git a/src/api/studio3dqml/q3dsrenderer.cpp b/src/api/studio3dqml/q3dsrenderer.cpp index 7366d6a..33c7b98 100644 --- a/src/api/studio3dqml/q3dsrenderer.cpp +++ b/src/api/studio3dqml/q3dsrenderer.cpp @@ -286,6 +286,8 @@ void Q3DSRenderer::processCommands() m_settings->setShowRenderStats(m_commands.m_showRenderStats); if (m_commands.m_delayedLoadingChanged) this->m_runtime->setDelayedLoading(m_commands.m_delayedLoading); + if (m_commands.m_matteEnabledChanged) + this->m_runtime->setMatteEnabled(m_commands.m_matteEnabled); if (m_commands.m_globalAnimationTimeChanged) m_presentation->setGlobalAnimationTime(m_commands.m_globalAnimationTime); diff --git a/src/engine/Qt3DSRenderRuntimeBindingImplRenderer.cpp b/src/engine/Qt3DSRenderRuntimeBindingImplRenderer.cpp index b41c83b..0451570 100644 --- a/src/engine/Qt3DSRenderRuntimeBindingImplRenderer.cpp +++ b/src/engine/Qt3DSRenderRuntimeBindingImplRenderer.cpp @@ -167,6 +167,7 @@ struct SRenderer : public Q3DStudio::ITegraApplicationRenderEngine } void SetMatteColor(Option inColor) override { m_Context->SetMatteColor(inColor); } + void setMatteEnabled(bool enabled) override { m_Context->setMatteEnabled(enabled); }; virtual void PushState() { m_StateStack.push_back(m_Viewport); } virtual void PopState() { diff --git a/src/engine/Qt3DSRuntimeView.h b/src/engine/Qt3DSRuntimeView.h index 22d8cba..7d86022 100644 --- a/src/engine/Qt3DSRuntimeView.h +++ b/src/engine/Qt3DSRuntimeView.h @@ -143,6 +143,7 @@ public: virtual ITegraRenderStateManager &GetTegraRenderStateManager() = 0; virtual qt3ds::render::NVRenderContext &GetRenderContext() = 0; virtual void SetMatteColor(qt3ds::foundation::Option inColor) = 0; + virtual void setMatteEnabled(bool enable) = 0; virtual void EnableRenderRotation(bool inEnable) = 0; virtual void SetWriteOutShaderCache(bool inWriteOutShaderCache) = 0; virtual void Release() = 0; diff --git a/src/runtimerender/Qt3DSRenderContextCore.cpp b/src/runtimerender/Qt3DSRenderContextCore.cpp index 33e1bf6..7c84a5a 100644 --- a/src/runtimerender/Qt3DSRenderContextCore.cpp +++ b/src/runtimerender/Qt3DSRenderContextCore.cpp @@ -249,6 +249,7 @@ struct SRenderContext : public IQt3DSRenderContext bool m_IsInSubPresentation; Option m_SceneColor; Option m_MatteColor; + bool m_matteEnabled; RenderRotationValues::Enum m_Rotation; NVScopedRefCounted m_RotationFBO; NVScopedRefCounted m_RotationTexture; @@ -276,14 +277,15 @@ struct SRenderContext : public IQt3DSRenderContext , m_ResourceManager(IResourceManager::CreateResourceManager(ctx)) , m_ShaderCache(IShaderCache::CreateShaderCache(ctx, *m_InputStreamFactory, *m_PerfTimer)) , m_ThreadPool(inCore.GetThreadPool()) - , m_RenderList(IRenderList::CreateRenderList(ctx.GetFoundation())) , m_PerFrameAllocator(ctx.GetAllocator()) + , m_RenderList(IRenderList::CreateRenderList(ctx.GetFoundation())) , m_FrameCount(0) , mRefCount(0) , m_WindowDimensions(800, 480) , m_ScaleMode(ScaleModes::ExactSize) , m_WireframeMode(false) , m_IsInSubPresentation(false) + , m_matteEnabled(false) , m_Rotation(RenderRotationValues::NoRotation) , m_ContextRenderTarget(NULL) , m_PresentationScale(0, 0) @@ -420,6 +422,10 @@ struct SRenderContext : public IQt3DSRenderContext void SetSceneColor(Option inSceneColor) override { m_SceneColor = inSceneColor; } void SetMatteColor(Option inMatteColor) override { m_MatteColor = inMatteColor; } + void setMatteEnabled(bool enable) override + { + m_matteEnabled = enable; + } void SetWindowDimensions(const QSize &inWindowDimensions) override { @@ -697,10 +703,10 @@ struct SRenderContext : public IQt3DSRenderContext m_RenderContext->SetScissorTestEnabled(false); } { - QT3DSVec4 theClearColor; - if (m_MatteColor.hasValue()) + QT3DSVec4 theClearColor(0.0f, 0.0f, 0.0f, 0.0f); + if (m_MatteColor.hasValue() && m_matteEnabled) theClearColor = m_MatteColor; - else + else if (m_SceneColor.hasValue()) theClearColor = m_SceneColor; m_RenderContext->SetClearColor(theClearColor); m_RenderContext->Clear(qt3ds::render::NVRenderClearValues::Color); diff --git a/src/runtimerender/Qt3DSRenderContextCore.h b/src/runtimerender/Qt3DSRenderContextCore.h index 302571d..027d1f9 100644 --- a/src/runtimerender/Qt3DSRenderContextCore.h +++ b/src/runtimerender/Qt3DSRenderContextCore.h @@ -145,6 +145,7 @@ namespace render { virtual void SetInSubPresentation(bool inValue) = 0; virtual void SetSceneColor(Option inSceneColor) = 0; virtual void SetMatteColor(Option inMatteColor) = 0; + virtual void setMatteEnabled(bool enable) = 0; // Render screen aligned 2D text at x,y virtual void RenderText2D(QT3DSF32 x, QT3DSF32 y, qt3ds::foundation::Option inColor, diff --git a/src/viewer/Qt3DSViewerApp.cpp b/src/viewer/Qt3DSViewerApp.cpp index 2180caf..1402ef0 100644 --- a/src/viewer/Qt3DSViewerApp.cpp +++ b/src/viewer/Qt3DSViewerApp.cpp @@ -825,6 +825,12 @@ void Q3DSViewerApp::setMatteColor(const QColor &color) } } +void Q3DSViewerApp::setMatteEnabled(bool enable) +{ + if (m_Impl.m_view && m_Impl.m_view->GetTegraRenderEngine()) + m_Impl.m_view->GetTegraRenderEngine()->setMatteEnabled(enable); +} + void Q3DSViewerApp::setShowOnScreenStats(bool inShow) { if (m_Impl.m_view && m_Impl.m_view->GetTegraRenderEngine()) diff --git a/src/viewer/Qt3DSViewerApp.h b/src/viewer/Qt3DSViewerApp.h index 06fdeef..3086d55 100644 --- a/src/viewer/Qt3DSViewerApp.h +++ b/src/viewer/Qt3DSViewerApp.h @@ -477,6 +477,7 @@ public: void preloadSlide(const QString &slide); void unloadSlide(const QString &slide); void setDelayedLoading(bool enable); + void setMatteEnabled(bool enabled); private: /* -- cgit v1.2.3