Add handling for camera intrinsics

This commit is contained in:
Georg Hagen
2024-07-07 16:53:48 +02:00
parent 5b2a2bbf72
commit aabc24616d
18 changed files with 447 additions and 213 deletions

View File

@@ -11,6 +11,11 @@
namespace OpenVulkano::Scene
{
namespace
{
const Math::CameraIntrinsicWithResolution FALLBACK_INTRINSICS;
}
ArBackgroundDrawable::ArBackgroundDrawable(const Ptr<AR::ArSession>& arSession)
: Drawable(DrawEncoder::GetDrawEncoder<ArBackgroundDrawable>(), DrawPhase::BACKGROUND)
, m_arSession(arSession)
@@ -18,9 +23,11 @@ namespace OpenVulkano::Scene
m_shader.topology = Topology::TRIANGLE_STRIP;
m_shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/background");
m_shader.AddShaderProgram(ShaderProgramType::FRAGMENT, "Shader/background");
//m_shader.AddDescriptorSetLayoutBinding(DESCRIPTOR_SET_LAYOUT_BINDING);
m_shader.AddDescriptorSetLayoutBinding(UniformBuffer::DESCRIPTOR_SET_LAYOUT_BINDING);
m_shader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
SetShader(&m_shader);
m_intrinsicsBuffer.Init(sizeof(Math::CameraIntrinsicWithResolution), &FALLBACK_INTRINSICS);
m_intrinsicsBuffer.updateFrequency = UpdateFrequency::Always;
if (m_arSession)
m_arSession->OnNewFrame += EventHandler(this, &ArBackgroundDrawable::OnNewArFrame);
}
@@ -57,8 +64,10 @@ namespace OpenVulkano::Scene
m_lastFrame = std::move(m_currentFrame);
m_currentFrame = std::move(m_nextFrame);
m_nextFrame = nullptr;
m_texture = m_currentFrame->GetImageTexture();
m_intrinsicsBuffer.data = &m_currentFrame->GetFrameMetadata().intrinsic;
m_intrinsicsBuffer.updated = true;
}
if (m_currentFrame) m_texture = m_currentFrame->GetImageTexture();
if (!m_texture) m_texture = &Texture::PLACEHOLDER;
}
}

View File

@@ -10,6 +10,7 @@
#include "Scene/Drawable.hpp"
#include "Scene/Shader/Shader.hpp"
#include "Scene/Texture.hpp"
#include "Scene/UniformBuffer.hpp"
namespace OpenVulkano
{
@@ -23,9 +24,8 @@ namespace OpenVulkano
{
class ArBackgroundDrawable final : public Drawable
{
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER, 1, ShaderProgramType::ALL_GRAPHICS };
Shader m_shader;
UniformBuffer m_intrinsicsBuffer;
Ptr<AR::ArSession> m_arSession;
Ptr<AR::ArFrame> m_nextFrame, m_currentFrame, m_lastFrame;
const Texture* m_texture;
@@ -44,6 +44,8 @@ namespace OpenVulkano
void Close() override;
const Texture* GetTexture() const { return m_texture; }
UniformBuffer& GetBuffer() { return m_intrinsicsBuffer; }
};
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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 "Base/ICloseable.hpp"
namespace OpenVulkano::Scene
{
class UniformBuffer
{
public:
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER, 1, ShaderProgramType::ALL_GRAPHICS };
DescriptorSetLayoutBinding binding;
uint32_t setId = 2;
ICloseable* renderBuffer = nullptr;
size_t size = 0;
const void* data = nullptr;
UpdateFrequency updateFrequency = UpdateFrequency::Never;
bool updated = true;
void Init(size_t size, const void* data, const DescriptorSetLayoutBinding& binding = DESCRIPTOR_SET_LAYOUT_BINDING)
{
this->size = size;
this->data = data;
this->binding = binding;
}
UpdateFrequency GetUpdateFrequency() const { return updateFrequency; }
};
}