#pragma once

#include <vulkan/vulkan.hpp>

class VulkanBuffers;
class VulkanSwapChain;

class VulkanTexture
{
public:
	VulkanTexture(
		VkDevice		 Device,
		VkPhysicalDevice PhysicalDevice,
		VkQueue			 GraphicsQueue,
		VulkanBuffers&	 Buffers,
		VulkanSwapChain& SwapChain
	);

	~VulkanTexture();

	void Cleanup();
	void CleanupTextures();
	void CleanupDepth();

	void LoadFromFile(const char* Filename);
	void CreateImageView();
	void CreateSampler();

	void	 CreateDepthResources();
	VkFormat FindSupportedFormat(
		const std::vector<VkFormat>& Candidates,
		VkImageTiling				 Tiling,
		VkFormatFeatureFlags		 Features
	);
	VkFormat FindDepthFormat();
	bool	 HasStencilComponent(VkFormat Format);

	VkImageView GetImageView() const { return ImageView; }
	VkSampler	GetSampler() const { return Sampler; }
	VkImageView GetDepthImageView() const { return DepthImageView; }

private:
	VkDevice		 Device;
	VkPhysicalDevice PhysicalDevice;
	VkQueue			 GraphicsQueue;
	VulkanBuffers&	 Buffers;
	VulkanSwapChain& SwapChain;

	VkImage		   Image;
	VkDeviceMemory ImageMemory;
	VkImageView	   ImageView;
	VkSampler	   Sampler;

	VkImage		   DepthImage;
	VkDeviceMemory DepthImageMemory;
	VkImageView	   DepthImageView;

	void CreateImage(
		uint32_t			  Width,
		uint32_t			  Height,
		VkFormat			  Format,
		VkImageTiling		  Tiling,
		VkImageUsageFlags	  Usage,
		VkMemoryPropertyFlags Properties,
		VkImage&			  Image,
		VkDeviceMemory&		  ImageMemory
	);
};
