From 7e9c568779282123f878d2f73c720b15e1976a82 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Fri, 5 Jul 2024 14:08:04 +0200 Subject: [PATCH] Add interfaces for getting textures from ar frames --- openVulkanoCpp/AR/ArFrame.cpp | 16 ++++++++++++++++ openVulkanoCpp/AR/ArFrame.hpp | 15 +++++++++++++-- openVulkanoCpp/AR/ArSession.hpp | 11 +++++++++++ .../AR/Provider/ArKit/ArSessionArKitInternal.h | 5 +++++ .../AR/Provider/Network/ArSessionStream.h | 5 +++++ .../AR/Provider/Playback/ArSessionPlayback.cpp | 10 ++++++++++ .../AR/Provider/Playback/ArSessionPlayback.hpp | 5 +++++ 7 files changed, 65 insertions(+), 2 deletions(-) diff --git a/openVulkanoCpp/AR/ArFrame.cpp b/openVulkanoCpp/AR/ArFrame.cpp index 2f2aeb6..989b713 100644 --- a/openVulkanoCpp/AR/ArFrame.cpp +++ b/openVulkanoCpp/AR/ArFrame.cpp @@ -22,4 +22,20 @@ namespace OpenVulkano::AR else m_session->GetRecorder().Save(shared_from_this()); } + + void ArFrame::SaveToFile(const std::filesystem::path& path, bool downsample) + { + m_session->GetRecorder().SaveToFile(shared_from_this(), path, downsample); + } + + const Scene::Texture* ArFrame::GetImageTexture() + { + if (!m_texture) m_texture = m_session->MakeTexture(this); + return m_texture; + } + + ArFrame::~ArFrame() + { + if (m_texture) m_session->ReturnTexture(m_texture); + } } \ No newline at end of file diff --git a/openVulkanoCpp/AR/ArFrame.hpp b/openVulkanoCpp/AR/ArFrame.hpp index ef68870..ae769a3 100644 --- a/openVulkanoCpp/AR/ArFrame.hpp +++ b/openVulkanoCpp/AR/ArFrame.hpp @@ -13,8 +13,14 @@ #include "ArDepthFormat.hpp" #include "ArTrackingState.hpp" #include "ArFrameMetadata.hpp" -#include #include +#include +#include + +namespace OpenVulkano::Scene +{ + class Texture; +} namespace OpenVulkano::AR { @@ -89,6 +95,7 @@ namespace OpenVulkano::AR { std::shared_ptr m_session; size_t m_frameId; + Scene::Texture* m_texture = nullptr; bool m_saved = false; bool m_highRes = false; @@ -99,7 +106,7 @@ namespace OpenVulkano::AR {} public: - virtual ~ArFrame() = default; + virtual ~ArFrame(); [[nodiscard]] size_t GetFrameId() const { return m_frameId; } @@ -139,8 +146,12 @@ namespace OpenVulkano::AR [[nodiscard]] bool IsSaved() const { return m_saved; }; + [[nodiscard]] const Scene::Texture* GetImageTexture(); + void Save(); + void SaveToFile(const std::filesystem::path& path, bool downsample = false); + void SetSaved() { m_saved = true; } void MarkHighRes() { m_highRes = true; } diff --git a/openVulkanoCpp/AR/ArSession.hpp b/openVulkanoCpp/AR/ArSession.hpp index f493840..058853f 100644 --- a/openVulkanoCpp/AR/ArSession.hpp +++ b/openVulkanoCpp/AR/ArSession.hpp @@ -19,6 +19,11 @@ #include #include +namespace OpenVulkano::Scene +{ + class Texture; +} + namespace OpenVulkano::AR { class ArSession; @@ -75,9 +80,15 @@ namespace OpenVulkano::AR class ArSession { + friend ArFrame; + protected: ArSession(const ArSessionMetadata& metadata) : metadata(metadata), recorder(metadata.playback ? nullptr : this) {} + virtual Scene::Texture* MakeTexture(ArFrame* frame) = 0; + + virtual void ReturnTexture(Scene::Texture* texture) = 0; + public: /** * Creates a platform native AR session. nullptr if failed to create session. diff --git a/openVulkanoCpp/AR/Provider/ArKit/ArSessionArKitInternal.h b/openVulkanoCpp/AR/Provider/ArKit/ArSessionArKitInternal.h index 5aeb960..bf60aaa 100644 --- a/openVulkanoCpp/AR/Provider/ArKit/ArSessionArKitInternal.h +++ b/openVulkanoCpp/AR/Provider/ArKit/ArSessionArKitInternal.h @@ -47,6 +47,11 @@ namespace OpenVulkano::AR::ArKit void OnArAnchorsUpdate(NSArray<__kindof ARAnchor*>* anchors); bool ArShouldAttemptRelocalization(); + protected: + Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override; + + void ReturnTexture(Scene::Texture *texture) override; + private: ArKitDelegate* m_arKitDelegate; ARWorldTrackingConfiguration* m_arConfig; diff --git a/openVulkanoCpp/AR/Provider/Network/ArSessionStream.h b/openVulkanoCpp/AR/Provider/Network/ArSessionStream.h index 045374f..d75d19c 100644 --- a/openVulkanoCpp/AR/Provider/Network/ArSessionStream.h +++ b/openVulkanoCpp/AR/Provider/Network/ArSessionStream.h @@ -12,6 +12,11 @@ namespace OpenVulkano::AR::Network { class ArSessionStream final : public ArSession { + protected: + Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override { return nullptr; } //TODO + + void ReturnTexture(Scene::Texture *texture) override {} // TODO + public: ArSessionStream(const std::string& serverAddress, std::optional requestConfig = std::nullopt); diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp index 2e11eb2..7ce3844 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp @@ -88,4 +88,14 @@ namespace OpenVulkano::AR::Playback Stop(); OnSessionInterruptionChange(true); } + + Scene::Texture* ArSessionPlayback::MakeTexture(OpenVulkano::AR::ArFrame* frame) + { + return nullptr; //TODO + } + + void ArSessionPlayback::ReturnTexture(Scene::Texture* texture) + { + //TODO + } } diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp index b506082..e3f77eb 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp @@ -31,6 +31,11 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from [[nodiscard]] ArType GetArType() override; + protected: + Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override; + + void ReturnTexture(Scene::Texture *texture) override; + private: void ReadWorker();