/*
 * 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 "Base/ICloseable.hpp"
#include <vulkan/vulkan.hpp>
#include <vector>

namespace OpenVulkano
{
	namespace Scene
	{
		class Shader;
	}

	namespace Vulkan
	{
		class Context;
		class IShaderOwner;

		class VulkanShader final : public ICloseable, public IRecordable
		{
		public:
			Scene::Shader* shader = nullptr;
			vk::Device device;
			std::vector<vk::ShaderModule> shaderModules; // TODO manage live time somewhere else to allow sharing of shader programs
			std::vector<vk::PipelineShaderStageCreateInfo> shaderStageCreateInfo;
			vk::Pipeline pipeline; // TODO pipeline and shader config should be split
			std::vector<vk::DescriptorSetLayout> descriptorSetLayouts;
			vk::PipelineLayout pipelineLayout;
			IShaderOwner* owner = nullptr;
			Context* context = nullptr;

			VulkanShader() = default;

			~VulkanShader() override;

			void Init(Context* context, Scene::Shader* shader, IShaderOwner* owner);

			void Resize();

			void Record(VulkanDrawContext* context) override;

			void Close() override;

		private:
			void BuildPipeline();

			void CreatePipelineLayout();
		};
	}
}