From baf012f6bce78aa1ef5896fd28a1c87a6ff2d147 Mon Sep 17 00:00:00 2001 From: Lubosz Sarnecki Date: Sat, 16 Mar 2024 15:55:42 +0100 Subject: [PATCH] OpenGlDisplayPlugin: Add possibility to present frames only once. Don't present frame more than once in OpenXrDisplayPlugin. --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 7 +++++++ .../src/display-plugins/OpenGLDisplayPlugin.h | 2 ++ plugins/openxr/src/OpenXrDisplayPlugin.cpp | 1 + 3 files changed, 10 insertions(+) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 00771927fb..9d45e91bf3 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -746,6 +746,13 @@ void OpenGLDisplayPlugin::present(const std::shared_ptr& } gpu::Backend::freeGPUMemSize.set(gpu::gl::getFreeDedicatedMemory()); + + // Drop current frame after presenting it once. + // This is required for the OpenXR frame cycle, since we call xrEndFrame after presenting. + // xrEndFrame must not be called multiple times. + if (_presentOnlyOnce) { + _currentFrame.reset(); + } } else if (alwaysPresent()) { refreshRateController->clockEndTime(); internalPresent(); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 0df0d9ac3e..a7ce2180f2 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -206,6 +206,8 @@ protected: QImage getScreenshot(float aspectRatio); QImage getSecondaryCameraScreenshot(); + bool _presentOnlyOnce = false; + private: static Setting::Handle _extraLinearToSRGBConversionSetting; }; diff --git a/plugins/openxr/src/OpenXrDisplayPlugin.cpp b/plugins/openxr/src/OpenXrDisplayPlugin.cpp index e952fe671c..e15de872dd 100644 --- a/plugins/openxr/src/OpenXrDisplayPlugin.cpp +++ b/plugins/openxr/src/OpenXrDisplayPlugin.cpp @@ -23,6 +23,7 @@ constexpr GLint XR_PREFERRED_COLOR_FORMAT = GL_SRGB8_ALPHA8; OpenXrDisplayPlugin::OpenXrDisplayPlugin(std::shared_ptr c) { _context = c; + _presentOnlyOnce = true; } bool OpenXrDisplayPlugin::isSupported() const {