#pragma once

/*
	VulkanFramework
	by John Ryland
	Copyright (c) 2023
*/

////////////////////////////////////////////////////////////////////////////////////
//	Vulkan Texture

#include "VulkanImageBuffer.h"

namespace Vulkan {

// A struct to manage data related to one image in vulkan
class Texture : public ImageBuffer
{
public:
    Texture();
    virtual ~Texture();

    virtual void Initialize(Device*               device,
                            const char*           fileName,
                            uint32_t              mipLevels   = UINT32_MAX,
                            VkImageUsageFlags     usage       = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
                            VkFormat              imageFormat = VK_FORMAT_R8G8B8A8_SRGB,
                            VkSampleCountFlagBits samples     = VK_SAMPLE_COUNT_1_BIT);

    virtual void Initialize(Device*               device,
                            uint8_t*              pixels,
                            uint32_t              width,
                            uint32_t              height,
                            uint32_t              mipLevels   = UINT32_MAX,
                            VkImageUsageFlags     usage       = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
                            VkFormat              imageFormat = VK_FORMAT_R8G8B8A8_SRGB,
                            VkSampleCountFlagBits samples     = VK_SAMPLE_COUNT_1_BIT);
    virtual void Destroy();

    VkSampler             m_sampler;
    VkDescriptorSet       m_descriptorSet;         // Descriptor set: this is what you'll pass to ImGui::Image() ?  (ImTextureID)my_texture.DS
    VkDescriptorSetLayout m_descriptorSetLayout;

protected:
    virtual void CreateSampler();
    virtual void CreateDescriptorSet();
    virtual void TransitionImageLayout(VkImageLayout oldLayout, VkImageLayout newLayout);
    virtual void CopyBufferToImage(VkBuffer buffer);

};

} // Vulkan namespace
