summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2020-01-15 19:09:24 +0200
committerKari Oikarinen <kari.oikarinen@qt.io>2020-01-15 19:09:24 +0200
commit5aedae5aa9251e1216d7bc1652cb1f451dd047c1 (patch)
tree1e3c00ccac6cb4082d8bd3e52f047f8cbc058b61
parent532e108a3abf56aa0ef709af5049ce3b2161ed84 (diff)
parentdf5a63b059956e8a717db9110327cc86612cc934 (diff)
Merge 5.14 into 5.14.1v5.14.1
-rw-r--r--src/core/aspects/qaspectmanager.cpp48
-rw-r--r--src/core/aspects/qaspectmanager_p.h9
-rw-r--r--src/render/frontend/qcamera.cpp32
-rw-r--r--src/render/frontend/qcameralens.cpp4
-rw-r--r--src/render/geometry/qgeometryrenderer.cpp4
-rw-r--r--src/render/materialsystem/shaderbuilder.cpp4
-rw-r--r--src/render/renderers/opengl/renderer/renderviewbuilder.cpp4
-rw-r--r--src/render/services/vsyncframeadvanceservice.cpp5
-rw-r--r--tests/auto/core/nodes/tst_nodes.cpp6
-rw-r--r--tests/auto/global/aspects_startup_shutdown/tst_aspects_startup_shutdown.cpp4
10 files changed, 95 insertions, 25 deletions
diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp
index f24248399..74803349c 100644
--- a/src/core/aspects/qaspectmanager.cpp
+++ b/src/core/aspects/qaspectmanager.cpp
@@ -65,6 +65,7 @@
#include <Qt3DCore/private/qscene_p.h>
#include <QtCore/QCoreApplication>
+#include <QtCore/QAbstractAnimation>
#if defined(QT3D_CORE_JOB_TIMING)
#include <QElapsedTimer>
@@ -74,6 +75,23 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
+#if QT_CONFIG(animation)
+class RequestFrameAnimation final : public QAbstractAnimation
+{
+public:
+ RequestFrameAnimation(QObject *parent)
+ : QAbstractAnimation(parent)
+ {
+ }
+
+ ~RequestFrameAnimation() override;
+
+ int duration() const override { return 1; }
+ void updateCurrentTime(int currentTime) override { Q_UNUSED(currentTime) }
+};
+
+RequestFrameAnimation::~RequestFrameAnimation() = default;
+#else
namespace {
class RequestFrameEvent : public QEvent
@@ -92,7 +110,7 @@ private:
int RequestFrameEvent::requestEventType = QEvent::registerEventType();
} // anonymous
-
+#endif
/*!
\class Qt3DCore::QAspectManager
@@ -108,6 +126,9 @@ QAspectManager::QAspectManager(QObject *parent)
, m_simulationLoopRunning(false)
, m_driveMode(QAspectEngine::Automatic)
, m_postConstructorInit(nullptr)
+#if QT_CONFIG(animation)
+ , m_simulationAnimation(nullptr)
+#endif
{
qRegisterMetaType<QSurface *>("QSurface*");
qCDebug(Aspects) << Q_FUNC_INFO;
@@ -149,8 +170,19 @@ void QAspectManager::enterSimulationLoop()
qCDebug(Aspects) << "Done calling onEngineStartup() for each aspect";
// Start running loop if Qt3D is in charge of driving it
- if (m_driveMode == QAspectEngine::Automatic)
+ if (m_driveMode == QAspectEngine::Automatic) {
+#if QT_CONFIG(animation)
+ if (!m_simulationAnimation) {
+ m_simulationAnimation = new RequestFrameAnimation(this);
+ connect(m_simulationAnimation, &QAbstractAnimation::finished, this, [this]() {
+ processFrame();
+ if (m_simulationLoopRunning && m_driveMode == QAspectEngine::Automatic)
+ requestNextFrame();
+ });
+ }
+#endif
requestNextFrame();
+ }
}
// Main thread (called by QAspectEngine)
@@ -164,6 +196,11 @@ void QAspectManager::exitSimulationLoop()
return;
}
+#if QT_CONFIG(animation)
+ if (m_simulationAnimation)
+ m_simulationAnimation->stop();
+#endif
+
QAbstractFrameAdvanceService *frameAdvanceService =
m_serviceLocator->service<QAbstractFrameAdvanceService>(QServiceLocator::FrameAdvanceService);
if (frameAdvanceService)
@@ -193,7 +230,6 @@ void QAspectManager::exitSimulationLoop()
}
qCDebug(Aspects) << "Done calling onEngineShutdown() for each aspect";
-
m_simulationLoopRunning = false;
qCDebug(Aspects) << "exitSimulationLoop completed";
}
@@ -399,6 +435,7 @@ QVector<QNode *> QAspectManager::lookupNodes(const QVector<QNodeId> &ids) const
return d->m_scene ? d->m_scene->lookupNodes(ids) : QVector<QNode *>{};
}
+#if !QT_CONFIG(animation)
/*!
\internal
\brief Drives the Qt3D simulation loop in the main thread
@@ -420,13 +457,18 @@ bool QAspectManager::event(QEvent *e)
return QObject::event(e);
}
+#endif
void QAspectManager::requestNextFrame()
{
qCDebug(Aspects) << "Requesting new Frame";
// Post event in the event loop to force
// next frame to be processed
+#if QT_CONFIG(animation)
+ m_simulationAnimation->start();
+#else
QCoreApplication::postEvent(this, new RequestFrameEvent());
+#endif
}
void QAspectManager::processFrame()
diff --git a/src/core/aspects/qaspectmanager_p.h b/src/core/aspects/qaspectmanager_p.h
index ebc148324..12bf5d72a 100644
--- a/src/core/aspects/qaspectmanager_p.h
+++ b/src/core/aspects/qaspectmanager_p.h
@@ -76,6 +76,9 @@ class QAbstractAspectJobManager;
class QServiceLocator;
class NodePostConstructorInit;
struct NodeTreeChange;
+#if QT_CONFIG(animation)
+class RequestFrameAnimation;
+#endif
class Q_3DCORE_PRIVATE_EXPORT QAspectManager : public QObject
{
@@ -112,7 +115,9 @@ public:
QVector<QNode *> lookupNodes(const QVector<QNodeId> &ids) const;
private:
+#if !QT_CONFIG(animation)
bool event(QEvent *event) override;
+#endif
void requestNextFrame();
QVector<QAbstractAspect *> m_aspects;
@@ -126,7 +131,9 @@ private:
QAspectEngine::RunMode m_driveMode;
QVector<NodeTreeChange> m_nodeTreeChanges;
NodePostConstructorInit* m_postConstructorInit;
-
+#if QT_CONFIG(animation)
+ RequestFrameAnimation *m_simulationAnimation;
+#endif
};
} // namespace Qt3DCore
diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp
index b0fd16182..4d4e5bf4d 100644
--- a/src/render/frontend/qcamera.cpp
+++ b/src/render/frontend/qcamera.cpp
@@ -227,7 +227,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is the center of the scene's bounding volume
* and the entire scene fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -237,7 +237,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is the center of the entity's bounding volume
* and the entire \a entity fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -247,7 +247,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is \a center
* and a sphere of \a radius fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -823,7 +823,7 @@ void QCamera::rotateAboutViewCenter(const QQuaternion& q)
* Rotates and moves the camera so that it's viewCenter is the center of the scene's bounding volume
* and the entire scene fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
void QCamera::viewAll()
@@ -836,15 +836,31 @@ void QCamera::viewAll()
* Rotates and moves the camera so that it's viewCenter is \a center
* and a sphere of \a radius fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
void QCamera::viewSphere(const QVector3D &center, float radius)
{
Q_D(QCamera);
- if (d->m_lens->projectionType() != QCameraLens::PerspectiveProjection || radius <= 0.f)
+ if ((d->m_lens->projectionType() != QCameraLens::PerspectiveProjection &&
+ d->m_lens->projectionType() != QCameraLens::OrthographicProjection) ||
+ radius <= 0.f)
return;
- double dist = radius / std::tan(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+
+ // Ensure the sphere fits in the view port even if aspect ratio < 1 (i.e. width < height)
+ float height = (1.05f * radius) / (d->m_lens->aspectRatio() < 1.0f ? d->m_lens->aspectRatio() : 1.0f);
+ float dist = 1.0f;
+ if (d->m_lens->projectionType() == QCameraLens::PerspectiveProjection) {
+ dist = height / std::sin(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+ }
+ else if (d->m_lens->projectionType() == QCameraLens::OrthographicProjection) {
+ d->m_lens->setOrthographicProjection(-height * d->m_lens->aspectRatio(), height * d->m_lens->aspectRatio(), -height, height,
+ nearPlane(), farPlane());
+ dist = height / std::sin(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+ }
+ else {
+ dist = (d->m_viewCenter - d->m_position).length();
+ }
QVector3D dir = (d->m_viewCenter - d->m_position).normalized();
QVector3D newPos = center - (dir * dist);
setViewCenter(center);
@@ -855,7 +871,7 @@ void QCamera::viewSphere(const QVector3D &center, float radius)
* Rotates and moves the camera so that it's viewCenter is the center of the
* \a {entity}'s bounding volume and the entire entity fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa {Qt3D.Render::Camera::projectionType}{Camera.projectionType}
*/
void QCamera::viewEntity(Qt3DCore::QEntity *entity)
diff --git a/src/render/frontend/qcameralens.cpp b/src/render/frontend/qcameralens.cpp
index cf30b714a..868ee9abf 100644
--- a/src/render/frontend/qcameralens.cpp
+++ b/src/render/frontend/qcameralens.cpp
@@ -232,7 +232,7 @@ QCameraLensPrivate::QCameraLensPrivate()
void QCameraLens::viewAll(Qt3DCore::QNodeId cameraId)
{
Q_D(QCameraLens);
- if (d->m_projectionType == PerspectiveProjection) {
+ if (d->m_projectionType == PerspectiveProjection || d->m_projectionType == OrthographicProjection) {
QVariant v;
v.setValue(cameraId);
d->m_pendingViewAllCommand = {QLatin1String("QueryRootBoundingVolume"),
@@ -245,7 +245,7 @@ void QCameraLens::viewAll(Qt3DCore::QNodeId cameraId)
void QCameraLens::viewEntity(Qt3DCore::QNodeId entityId, Qt3DCore::QNodeId cameraId)
{
Q_D(QCameraLens);
- if (d->m_projectionType == PerspectiveProjection) {
+ if (d->m_projectionType == PerspectiveProjection || d->m_projectionType == OrthographicProjection) {
QVector<Qt3DCore::QNodeId> ids = {entityId, cameraId};
QVariant v;
v.setValue(ids);
diff --git a/src/render/geometry/qgeometryrenderer.cpp b/src/render/geometry/qgeometryrenderer.cpp
index 64f3e058e..8720a5c00 100644
--- a/src/render/geometry/qgeometryrenderer.cpp
+++ b/src/render/geometry/qgeometryrenderer.cpp
@@ -149,7 +149,7 @@ QGeometryRendererPrivate::~QGeometryRendererPrivate()
*/
/*!
- \qmlproperty int GeometryRenderer::restartIndex
+ \qmlproperty int GeometryRenderer::restartIndexValue
Holds the restart index.
*/
@@ -161,7 +161,7 @@ QGeometryRendererPrivate::~QGeometryRendererPrivate()
*/
/*!
- \qmlproperty bool GeometryRenderer::primitiveRestart
+ \qmlproperty bool GeometryRenderer::primitiveRestartEnabled
Holds the primitive restart flag.
*/
diff --git a/src/render/materialsystem/shaderbuilder.cpp b/src/render/materialsystem/shaderbuilder.cpp
index 23f1400c9..7434cd901 100644
--- a/src/render/materialsystem/shaderbuilder.cpp
+++ b/src/render/materialsystem/shaderbuilder.cpp
@@ -278,7 +278,7 @@ void ShaderBuilder::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
markDirty(AbstractRenderer::ShadersDirty);
}
- static const std::pair<QShaderProgram::ShaderType, QUrl (QShaderProgramBuilder::*)() const> shaderTypesToGetters[] = {
+ static const QVector<std::pair<QShaderProgram::ShaderType, QUrl (QShaderProgramBuilder::*)() const>> shaderTypesToGetters = {
{QShaderProgram::Vertex, &QShaderProgramBuilder::vertexShaderGraph},
{QShaderProgram::TessellationControl, &QShaderProgramBuilder::tessellationControlShaderGraph},
{QShaderProgram::TessellationEvaluation, &QShaderProgramBuilder::tessellationEvaluationShaderGraph},
@@ -287,7 +287,7 @@ void ShaderBuilder::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
{QShaderProgram::Compute, &QShaderProgramBuilder::computeShaderGraph},
};
- for (auto it = std::cbegin(shaderTypesToGetters), end = std::cend(shaderTypesToGetters); it != end; ++it) {
+ for (auto it = shaderTypesToGetters.cbegin(), end = shaderTypesToGetters.cend(); it != end; ++it) {
const QUrl url = (node->*(it->second))();
if (url != m_graphs.value(it->first)) {
setShaderGraph(it->first, url);
diff --git a/src/render/renderers/opengl/renderer/renderviewbuilder.cpp b/src/render/renderers/opengl/renderer/renderviewbuilder.cpp
index 8f1b17119..4034af146 100644
--- a/src/render/renderers/opengl/renderer/renderviewbuilder.cpp
+++ b/src/render/renderers/opengl/renderer/renderviewbuilder.cpp
@@ -326,8 +326,8 @@ public:
filteredCommandData->reserve(renderableEntities.size());
// Because dataCacheForLeaf.renderableEntities or computeEntities are sorted
// What we get out of EntityRenderCommandData is also sorted by Entity
- auto eIt = std::cbegin(renderableEntities);
- const auto eEnd = std::cend(renderableEntities);
+ auto eIt = renderableEntities.cbegin();
+ const auto eEnd = renderableEntities.cend();
int cIt = 0;
const int cEnd = commandData.size();
diff --git a/src/render/services/vsyncframeadvanceservice.cpp b/src/render/services/vsyncframeadvanceservice.cpp
index d7398e2ce..662c12e4e 100644
--- a/src/render/services/vsyncframeadvanceservice.cpp
+++ b/src/render/services/vsyncframeadvanceservice.cpp
@@ -80,12 +80,7 @@ qint64 VSyncFrameAdvanceService::waitForNextFrame()
{
Q_D(VSyncFrameAdvanceService);
-#ifdef Q_OS_MACOS
- if (!d->m_semaphore.tryAcquire(std::max(d->m_semaphore.available(), 1), 4))
- return -1;
-#else
d->m_semaphore.acquire(std::max(d->m_semaphore.available(), 1));
-#endif
const qint64 currentTime = d->m_elapsed.nsecsElapsed();
qCDebug(VSyncAdvanceService) << "Elapsed nsecs since last call " << currentTime - d->m_elapsedTimeSincePreviousFrame;
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp
index b5291cab7..43d9f7778 100644
--- a/tests/auto/core/nodes/tst_nodes.cpp
+++ b/tests/auto/core/nodes/tst_nodes.cpp
@@ -944,6 +944,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent()
// GIVEN
ObserverSpy spy;
Qt3DCore::QAspectEngine engine;
+ engine.setRunMode(Qt3DCore::QAspectEngine::Manual);
QScopedPointer<MyQEntity> root(new MyQEntity());
root->setArbiterAndEngine(&spy, &engine);
auto aspect = new TestAspect;
@@ -953,6 +954,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent()
MyQNode *child2(new MyQNode(root.data()));
QCoreApplication::processEvents();
+ engine.processFrame();
// Due to the way we create root, it has a backend
QVERIFY(Qt3DCore::QNodePrivate::get(root.data())->m_hasBackendNode == true);
@@ -983,6 +985,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent()
// WHEN
QCoreApplication::processEvents();
+ engine.processFrame();
// THEN
QCOMPARE(spy.events.size(), 2);
@@ -1059,6 +1062,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent()
// WHEN
QCoreApplication::processEvents();
+ engine.processFrame();
// THEN
QCOMPARE(spy.events.size(), 2);
@@ -1237,6 +1241,7 @@ void tst_Nodes::checkAllBackendCreationDoneInSingleFrame()
// GIVEN
ObserverSpy spy;
Qt3DCore::QAspectEngine engine;
+ engine.setRunMode(Qt3DCore::QAspectEngine::Manual);
auto aspect = new TestAspect;
engine.registerAspect(aspect);
@@ -1269,6 +1274,7 @@ void tst_Nodes::checkAllBackendCreationDoneInSingleFrame()
// WHEN
QCoreApplication::processEvents();
+ engine.processFrame();
// THEN - both children have their backend nodes actually created.
QCOMPARE(aspect->events.count(), 2);
diff --git a/tests/auto/global/aspects_startup_shutdown/tst_aspects_startup_shutdown.cpp b/tests/auto/global/aspects_startup_shutdown/tst_aspects_startup_shutdown.cpp
index 9eec010be..00e4890c8 100644
--- a/tests/auto/global/aspects_startup_shutdown/tst_aspects_startup_shutdown.cpp
+++ b/tests/auto/global/aspects_startup_shutdown/tst_aspects_startup_shutdown.cpp
@@ -143,6 +143,8 @@ private slots:
void checkStartupAndShutdownImmediately()
{
+ QSKIP("Fails on CI for some unexplained reason");
+
// GIVEN
QWindow *win = new QWindow();
win->setSurfaceType(QSurface::OpenGLSurface);
@@ -170,6 +172,8 @@ private slots:
void checkStartupAndShutdownAfterAFewFrames()
{
+ QSKIP("Fails on CI for some unexplained reason");
+
// GIVEN
QWindow *win = new QWindow();
win->setSurfaceType(QSurface::OpenGLSurface);