diff --git a/openVulkanoCpp/AR/ArSession.cpp b/openVulkanoCpp/AR/ArSession.cpp index b234af6..a87cc34 100644 --- a/openVulkanoCpp/AR/ArSession.cpp +++ b/openVulkanoCpp/AR/ArSession.cpp @@ -57,11 +57,11 @@ namespace OpenVulkano::AR return { nullptr, ArCreateResult::FAILED_UNKNOWN, "Unknown exception while initializing AR system." }; } - ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance) + ArCreateResult ArSession::CreatePlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth) { try { - const auto session = std::make_shared(recordingPath, autoAdvance); + const auto session = std::make_shared(recordingPath, autoAdvance, loadImages, loadDepth); sessions.push_back(session); return { session, ArCreateResult::SUCCESS, "" }; } diff --git a/openVulkanoCpp/AR/ArSession.hpp b/openVulkanoCpp/AR/ArSession.hpp index 1cf1101..74f4a23 100644 --- a/openVulkanoCpp/AR/ArSession.hpp +++ b/openVulkanoCpp/AR/ArSession.hpp @@ -113,7 +113,7 @@ namespace OpenVulkano::AR * @param autoAdvance If set to true the playback will advance based on the stored timestamps. If set to false it will only advance if a new frame is requested. * @return ArCreateResult about the status of the AR session creation. The session pointer will always be nullptr unless the status is SUCCESS. */ - [[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true); + [[nodiscard]] static ArCreateResult CreatePlayback(const std::string& recordingPath, bool autoAdvance = true, bool loadImages = true, bool loadDepth = true); /** * Creates a network streamed AR session. nullptr if failed to create session for given address. This will block till the connection with the remote host has been established. diff --git a/openVulkanoCpp/AR/Provider/Playback/ArFramePlayback.cpp b/openVulkanoCpp/AR/Provider/Playback/ArFramePlayback.cpp index c7f4807..59f2cd3 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArFramePlayback.cpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArFramePlayback.cpp @@ -16,21 +16,26 @@ namespace OpenVulkano::AR::Playback //BlockProfiler profile("Read_AR_Frame"); const auto data = frameReader.ReadMetadata(); frameMetadata = ArFrameMetadata::FromXML(data.Data(), data.Size()); - colorImgData = frameReader.ReadColorImage(); - auto depth = frameReader.ReadDepthImage(); - confImgData = std::move(depth.confidence.image); - depthImgData = std::move(depth.depth.image); - depthImage.format = session->GetSessionMetadata().depthFormat; - depthImage.intrinsic = frameMetadata.intrinsic.GetForResolution({depth.depth.header.width, depth.depth.header.height}); - depthImage.depth.data = depthImgData.get(); - depthImage.depth.resolution = { depth.depth.header.width, depth.depth.header.height }; - depthImage.confidence.data = confImgData.get(); - depthImage.depth.resolution = { depth.confidence.header.width, depth.confidence.header.height }; - - colorImage.intrinsic = frameMetadata.intrinsic.GetForResolution({ colorImgData.cols, colorImgData.rows }); - colorImage.format = ArImagePlanar::Format::RGB; - colorImage.luminescenceOrColor = { colorImgData.data, { colorImgData.cols, colorImgData.rows }}; - colorImage.luminescenceOrColor.numChannels = colorImgData.channels; + if (session->GetCapabilities().IsDepthSupported()) + { + auto depth = frameReader.ReadDepthImage(); + confImgData = std::move(depth.confidence.image); + depthImgData = std::move(depth.depth.image); + depthImage.format = session->GetSessionMetadata().depthFormat; + depthImage.intrinsic = frameMetadata.intrinsic.GetForResolution({depth.depth.header.width, depth.depth.header.height}); + depthImage.depth.data = depthImgData.get(); + depthImage.depth.resolution = {depth.depth.header.width, depth.depth.header.height}; + depthImage.confidence.data = confImgData.get(); + depthImage.depth.resolution = {depth.confidence.header.width, depth.confidence.header.height}; + } + if (session->IsLoadColorEnabled()) + { + colorImgData = frameReader.ReadColorImage(); + colorImage.intrinsic = frameMetadata.intrinsic.GetForResolution({colorImgData.cols, colorImgData.rows}); + colorImage.format = ArImagePlanar::Format::RGB; + colorImage.luminescenceOrColor = {colorImgData.data, {colorImgData.cols, colorImgData.rows}}; + colorImage.luminescenceOrColor.numChannels = colorImgData.channels; + } SetSaved(); } diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp index 1ea63d8..0603463 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp @@ -14,10 +14,11 @@ using namespace std::chrono_literals; namespace OpenVulkano::AR::Playback { - ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance) - : ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance), playbackReader(recordingPath) + ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth) + : ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance) + , loadImages(loadImages), loadDepth(loadDepth), playbackReader(recordingPath) { - capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE, false, false, false); + capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE && loadDepth, false, false, false); constants = { Math::Matrix4f(1), metadata.confidenceRange }; m_playbackReaderThread = std::thread([this](){ReadWorker();}); diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp index aa3c75e..971489c 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp @@ -15,7 +15,7 @@ namespace OpenVulkano::AR::Playback class ArSessionPlayback final : public ArSession, public std::enable_shared_from_this { public: - ArSessionPlayback(const std::string& recordingPath, bool autoAdvance); + ArSessionPlayback(const std::string& recordingPath, bool autoAdvance, bool loadImages, bool loadDepth); ~ArSessionPlayback() override; @@ -33,12 +33,15 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from [[nodiscard]] const std::string& GetPlaybackPath() const { return recordingPath; } + [[nodiscard]] bool IsLoadColorEnabled() const { return loadImages; } + [[nodiscard]] bool IsLoadDepthEnabled() const { return loadDepth; } + void SetRenderer(IRenderer* renderer) override; Event OnPlaybackProgress; protected: - Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override; + Scene::Texture* MakeTexture(OpenVulkano::AR::ArFrame* frame) override; void ReturnTexture(Scene::Texture *texture) override; @@ -48,7 +51,7 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from Math::Timestamp lastTimestamp; const std::string recordingPath; - const bool autoAdvance; + const bool autoAdvance, loadImages, loadDepth; ArPlaybackReader playbackReader; ArTrackingState m_lastTrackingState = ArTrackingState::UNKNOWN; diff --git a/openVulkanoCpp/Math/DenseVector3i.hpp b/openVulkanoCpp/Math/DenseVector3i.hpp index 35d06bd..3673596 100644 --- a/openVulkanoCpp/Math/DenseVector3i.hpp +++ b/openVulkanoCpp/Math/DenseVector3i.hpp @@ -78,7 +78,7 @@ namespace OpenVulkano::Math public: constexpr explicit DenseVector3i(const Math::Vector3i& vec3) : DenseVector3i(vec3.x, vec3.y, vec3.z) {} constexpr explicit DenseVector3i(const Math::Vector3i_SIMD& vec3) : DenseVector3i(vec3.x, vec3.y, vec3.z) {} - constexpr DenseVector3i(int x, int y, int z) + constexpr DenseVector3i(T x, T y, T z) : data((x & BITMASK) | ((y & BITMASK) << (2 * BITS)) | ((z & BITMASK) << BITS)) { AssertValue(x); @@ -88,9 +88,9 @@ namespace OpenVulkano::Math constexpr T Data() const { return data; } - [[nodiscard]] constexpr int X() const { int v = data & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } - [[nodiscard]] constexpr int Y() const { int v = (data >> (2 * BITS)) & BITMASK; if (v > MAX_VALUE_Y) v |= ~BITMASK; return reinterpret_cast(v); } - [[nodiscard]] constexpr int Z() const { int v = (data >> BITS) & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } + [[nodiscard]] constexpr int X() const { T v = data & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } + [[nodiscard]] constexpr int Y() const { T v = (data >> (2 * BITS)) & BITMASK; if (v > MAX_VALUE_Y) v |= ~BITMASK; return reinterpret_cast(v); } + [[nodiscard]] constexpr int Z() const { T v = (data >> BITS) & BITMASK; if (v > MAX_VALUE) v |= ~BITMASK; return reinterpret_cast(v); } void SetX(int x) { @@ -120,7 +120,7 @@ namespace OpenVulkano::Math return fmt::format("{},{},{}", X(), Y(), Z()); } - [[nodiscard]] constexpr operator T() const { return data; } + //[[nodiscard]] constexpr operator T() const { return data; } [[nodiscard]] constexpr bool operator <(DenseVec3 rhs) const { diff --git a/openVulkanoCpp/Math/RGBA5551.hpp b/openVulkanoCpp/Math/RGBA5551.hpp new file mode 100644 index 0000000..d3f698f --- /dev/null +++ b/openVulkanoCpp/Math/RGBA5551.hpp @@ -0,0 +1,40 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Math/Math.hpp" + +namespace OpenVulkano::Math +{ + class RGBA5551 + { + uint16_t Make5(uint8_t val) + { + return val * 31.0f / 255.0f; + } + + public: + union + { + uint16_t value; + struct + { + uint16_t b : 5; + uint16_t g : 5; + uint16_t r : 5; + uint16_t a : 1; + }; + }; + + RGBA5551(Math::Vector4uc color = {0, 0, 0, 1}) + : b(Make5(color.b)) + , g(Make5(color.g)) + , r(Make5(color.r)) + , a(color.a > 128) + {} + }; +} \ No newline at end of file diff --git a/openVulkanoCpp/Vulkan/Resources/ManagedBuffer.hpp b/openVulkanoCpp/Vulkan/Resources/ManagedBuffer.hpp index 4dedc18..a7c78c7 100644 --- a/openVulkanoCpp/Vulkan/Resources/ManagedBuffer.hpp +++ b/openVulkanoCpp/Vulkan/Resources/ManagedBuffer.hpp @@ -46,6 +46,8 @@ namespace OpenVulkano::Vulkan return mapped || allocation->mapped; } + [[nodiscard]] void* GetMappedMemory() const { return mapped; } + /** * \brief Maps the buffer into the memory of the host. * \tparam T The type of the buffers data. diff --git a/openVulkanoCpp/Vulkan/Resources/MemoryPool.cpp b/openVulkanoCpp/Vulkan/Resources/MemoryPool.cpp index 2b9ac70..15e9921 100644 --- a/openVulkanoCpp/Vulkan/Resources/MemoryPool.cpp +++ b/openVulkanoCpp/Vulkan/Resources/MemoryPool.cpp @@ -110,7 +110,7 @@ namespace OpenVulkano::Vulkan break; } } - if(!alloc && createIfAllFull) alloc = CreateMemoryAllocation(64_MiB, type, true); + if(!alloc && createIfAllFull) alloc = CreateMemoryAllocation(128_MiB, type, true); return alloc; }