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

namespace OpenVulkano::Vulkan
{
	class VulkanUniformBuffer : public IRenderResource<Scene::UniformBuffer>, public IRecordable
	{
	public:
		Unique<UniformBuffer> buffer = nullptr;

		~VulkanUniformBuffer() override = default;

		VulkanUniformBuffer(Scene::UniformBuffer* sceneBuffer, UniformBuffer* uniformBuffer)
			: IRenderResource<Scene::UniformBuffer>(sceneBuffer), buffer(uniformBuffer)
		{}

		void Record(VulkanDrawContext* context) override
		{
			buffer->Record(context);
		}

		void Release() override
		{
			//TODO
		}
	};

	struct VulkanUniformBufferDynamic : VulkanUniformBuffer
	{
		uint32_t lastUpdate = 0;

		VulkanUniformBufferDynamic(Scene::UniformBuffer* sceneBuffer, UniformBuffer* uniformBuffer)
			: VulkanUniformBuffer(sceneBuffer, uniformBuffer)
		{}

		void Record(VulkanDrawContext* context) override
		{
			if(GetOwner()->updated) //TODO fix
			{
				GetOwner()->updated = false;
				buffer->Update(GetOwner()->data, GetOwner()->size, context->currentImageId);
			}
			buffer->Record(context);
		}
	};
}
