Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
Texture.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Resource.h"
4 #include "stb_image.h"
5 
6 namespace Fling
7 {
11  class Texture : public Resource
12  {
13  public:
14 
15  static std::shared_ptr<Fling::Texture> Create(Guid t_ID);
16 
17  explicit Texture(Guid t_ID);
18  virtual ~Texture();
19 
20  FORCEINLINE UINT32 GetWidth() const { return m_Width; }
21  FORCEINLINE UINT32 GetHeight() const { return m_Height; }
22  FORCEINLINE INT32 GetChannels() const { return m_Channels; }
23  FORCEINLINE UINT32 GetMipLevels() const { return m_MipLevels; }
24 
25  FORCEINLINE const VkImage& GetVkImage() const { return m_vVkImage; }
26  FORCEINLINE const VkImageView& GetVkImageView() const { return m_ImageView; }
27  FORCEINLINE const VkSampler& GetSampler() const { return m_TextureSampler; }
28  FORCEINLINE VkDescriptorImageInfo* GetDescriptorInfo() { return &m_ImageInfo; }
29  FORCEINLINE const VkFormat& GetVkImageFormat() const { return m_Format; }
35  UINT64 GetImageSize() const { return m_Width * m_Height * 4; }
36 
42  stbi_uc* GetPixelData() const { return m_PixelData; }
43 
47  void Release();
48 
49  private:
50 
54  void LoadVulkanImage();
55 
59  void CreateImageView();
60 
61  void CreateTextureSampler();
62 
63  void CopyBufferToImage(VkBuffer t_Buffer);
64 
65  void GenerateMipMaps(VkFormat imageFormat);
66 
69 
72 
74 
77 
79  VkImage m_vVkImage;
80 
82  VkImageView m_ImageView;
83 
84  VkSampler m_TextureSampler;
85 
87  VkDeviceMemory m_VkMemory;
88 
89  VkDescriptorImageInfo m_ImageInfo{};
90 
92  stbi_uc* m_PixelData;
93 
94  VkFormat m_Format = VK_FORMAT_R8G8B8A8_UNORM;
95  };
96 } // namespace Fling
FORCEINLINE INT32 GetChannels() const
Definition: Texture.h:22
UINT32 m_Width
Width of this image.
Definition: Texture.h:68
VkSampler m_TextureSampler
Definition: Texture.h:84
stbi_uc * GetPixelData() const
Get the Pixel Data object.
Definition: Texture.h:42
FORCEINLINE UINT32 GetMipLevels() const
Definition: Texture.h:23
UINT32 m_Height
Height of this image.
Definition: Texture.h:71
VkFormat m_Format
Definition: Texture.h:94
void Release()
Release the Vulkan resources of this image.
Definition: Texture.cpp:272
UINT64 GetImageSize() const
Get the Image Size object (width * height * 4) Multiply by 4 because the pixel is laid out row by row...
Definition: Texture.h:35
void CreateTextureSampler()
Definition: Texture.cpp:239
uint64_t UINT64
Definition: FlingTypes.h:14
virtual ~Texture()
Definition: Texture.cpp:312
FORCEINLINE VkDescriptorImageInfo * GetDescriptorInfo()
Definition: Texture.h:28
VkDeviceMemory m_VkMemory
The Vulkan memory resource for this image.
Definition: Texture.h:87
FORCEINLINE const VkSampler & GetSampler() const
Definition: Texture.h:27
Base class that represents a loaded resource in the engine.
Definition: Resource.h:11
FORCEINLINE const VkImageView & GetVkImageView() const
Definition: Texture.h:26
An image represents a 2D file that has data about each pixel in the image.
Definition: Texture.h:11
FORCEINLINE const VkFormat & GetVkImageFormat() const
Definition: Texture.h:29
VkImageView m_ImageView
The view of this image for the swap chain.
Definition: Texture.h:82
void CopyBufferToImage(VkBuffer t_Buffer)
Definition: Texture.cpp:195
void CreateImageView()
Create a Image View object that is needed to sample this image from the swap chain.
Definition: Texture.cpp:228
int32_t INT32
Definition: FlingTypes.h:18
VkDescriptorImageInfo m_ImageInfo
Definition: Texture.h:89
INT32 m_Channels
The color channels of this image.
Definition: Texture.h:76
FORCEINLINE UINT32 GetHeight() const
Definition: Texture.h:21
UINT32 m_MipLevels
Definition: Texture.h:73
void GenerateMipMaps(VkFormat imageFormat)
Definition: Texture.cpp:97
entt::hashed_string Guid
Definition: FlingTypes.h:26
VkImage m_vVkImage
The Vulkan image data.
Definition: Texture.h:79
FORCEINLINE UINT32 GetWidth() const
Definition: Texture.h:20
static std::shared_ptr< Fling::Texture > Create(Guid t_ID)
Definition: Texture.cpp:19
Texture(Guid t_ID)
Definition: Texture.cpp:24
void LoadVulkanImage()
Loads the Vulkan resources needed for this image.
Definition: Texture.cpp:39
FORCEINLINE const VkImage & GetVkImage() const
Definition: Texture.h:25
stbi_uc * m_PixelData
Pixel data of image.
Definition: Texture.h:92
uint32_t UINT32
Definition: FlingTypes.h:13
Definition: Engine.h:29