/*
 * 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"
#include "Scene/Camera.hpp"
#include "IRecordable.hpp"
#include "Vulkan/Resources/UniformBuffer.hpp"

namespace OpenVulkano::Vulkan
{
	class VulkanCamera : public ICloseable, public IRecordable
	{
		Scene::Camera* m_camera = nullptr;
		UniformBuffer* m_buffer = nullptr;

	public:
		~VulkanCamera() override { if (m_camera) VulkanCamera::Close(); }

		void Init(Scene::Camera* camera, UniformBuffer* uniformBuffer)
		{
			m_camera = camera;
			m_buffer = uniformBuffer;
		}

		void Record(VulkanDrawContext* context) override
		{
			m_buffer->Update(m_camera->GetData(), Scene::Camera::SIZE, context->currentImageId);
			m_buffer->Record(context);
		}

		void Close() override
		{
			m_camera->renderCamera = nullptr;
			m_buffer->Close();
			m_camera = nullptr;
			delete m_buffer;
		}
		
		[[nodiscard]] Scene::Camera* GetCamera() const { return m_camera; }
	};
}
