diff options
Diffstat (limited to 'src/render/framegraph/qrendercapture.cpp')
-rw-r--r-- | src/render/framegraph/qrendercapture.cpp | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/src/render/framegraph/qrendercapture.cpp b/src/render/framegraph/qrendercapture.cpp index a4a5dabcb..f3e5d53ee 100644 --- a/src/render/framegraph/qrendercapture.cpp +++ b/src/render/framegraph/qrendercapture.cpp @@ -40,6 +40,8 @@ #include <Qt3DCore/QPropertyUpdatedChange> #include <Qt3DRender/qframegraphnodecreatedchange.h> +#include <QPointer> + QT_BEGIN_NAMESPACE namespace Qt3DRender { @@ -108,19 +110,41 @@ namespace Qt3DRender { */ /*! + * \qmlmethod bool Qt3D.Render::RenderCaptureReply::saveImage(fileName) + * + * Saves the render capture result as an image to \a fileName. + * Returns true if the image was successfully saved; otherwise returns false. + * + * \since 5.9 + */ + +/*! * \qmlmethod void Qt3D.Render::RenderCaptureReply::saveToFile(fileName) + * \deprecated * * Saves the render capture result as an image to \a fileName. + * + * Deprecated in 5.9. Use saveImage(). */ /*! * \qmlmethod RenderCaptureReply Qt3D.Render::RenderCapture::requestCapture(int captureId) + * \deprecated * * Used to request render capture. User can specify a \a captureId to identify * the request. The requestId does not have to be unique. Only one render capture result * is produced per requestCapture call even if the frame graph has multiple leaf nodes. * The function returns a QRenderCaptureReply object, which receives the captured image - * when it is done. The user is reponsible for deallocating the returned object. + * when it is done. The user is responsible for deallocating the returned object. + */ + +/*! + * \qmlmethod RenderCaptureReply Qt3D.Render::RenderCapture::requestCapture() + * + * Used to request render capture. Only one render capture result is produced per + * requestCapture call even if the frame graph has multiple leaf nodes. + * The function returns a QRenderCaptureReply object, which receives the captured image + * when it is done. The user is responsible for deallocating the returned object. */ /*! @@ -178,6 +202,25 @@ bool QRenderCaptureReply::isComplete() const /*! * Saves the render capture result as an image to \a fileName. + * + * Returns true if the image was successfully saved; otherwise returns false. + * \since 5.9 + */ +bool QRenderCaptureReply::saveImage(const QString &fileName) const +{ + Q_D(const QRenderCaptureReply); + if (d->m_complete) + { + return d->m_image.save(fileName); + } + return false; +} + +/*! + * \deprecated + * Saves the render capture result as an image to \a fileName. + * + * Deprecated in 5.9. Use saveImage(). */ void QRenderCaptureReply::saveToFile(const QString &fileName) const { @@ -212,7 +255,7 @@ QRenderCaptureReply *QRenderCapturePrivate::takeReply(int captureId) { QRenderCaptureReply *reply = nullptr; for (int i = 0; i < m_waitingReplies.size(); ++i) { - if (m_waitingReplies[i]->captureId() == captureId) { + if (m_waitingReplies[i]->d_func()->m_captureId == captureId) { reply = m_waitingReplies[i]; m_waitingReplies.remove(i); break; @@ -239,11 +282,12 @@ QRenderCapture::QRenderCapture(Qt3DCore::QNode *parent) } /*! + * \deprecated * Used to request render capture. User can specify a \a captureId to identify * the request. The requestId does not have to be unique. Only one render capture result * is produced per requestCapture call even if the frame graph has multiple leaf nodes. * The function returns a QRenderCaptureReply object, which receives the captured image - * when it is done. The user is reponsible for deallocating the returned object. + * when it is done. The user is responsible for deallocating the returned object. */ QRenderCaptureReply *QRenderCapture::requestCapture(int captureId) { @@ -259,6 +303,28 @@ QRenderCaptureReply *QRenderCapture::requestCapture(int captureId) } /*! + * Used to request render capture. Only one render capture result is produced per + * requestCapture call even if the frame graph has multiple leaf nodes. + * The function returns a QRenderCaptureReply object, which receives the captured image + * when it is done. The user is responsible for deallocating the returned object. + */ +QRenderCaptureReply *QRenderCapture::requestCapture() +{ + Q_D(QRenderCapture); + static int captureId = 1; + QRenderCaptureReply *reply = d->createReply(captureId); + + Qt3DCore::QPropertyUpdatedChangePtr change(new Qt3DCore::QPropertyUpdatedChange(id())); + change->setPropertyName(QByteArrayLiteral("renderCaptureRequest")); + change->setValue(QVariant::fromValue(captureId)); + d->notifyObservers(change); + + captureId++; + + return reply; +} + +/*! * \internal */ void QRenderCapture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) @@ -268,10 +334,15 @@ void QRenderCapture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) if (propertyChange->type() == Qt3DCore::PropertyUpdated) { if (propertyChange->propertyName() == QByteArrayLiteral("renderCaptureData")) { RenderCaptureDataPtr data = propertyChange->value().value<RenderCaptureDataPtr>(); - QRenderCaptureReply *reply = d->takeReply(data.data()->captureId); + QPointer<QRenderCaptureReply> reply = d->takeReply(data.data()->captureId); if (reply) { d->setImage(reply, data.data()->image); - emit reply->completeChanged(true); + emit reply->completed(); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + if (reply) + emit reply->completeChanged(true); +QT_WARNING_POP } } } |