| 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
68 UINT32 m_Width = 0;
69
71 UINT32 m_Height = 0;
72
73 UINT32 m_MipLevels = 0;
74
76 INT32 m_Channels = 0;
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
Fling::Texture::GetChannels
FORCEINLINE INT32 GetChannels() const
Definition: Texture.h:22
Fling::Texture::m_Width
UINT32 m_Width
Width of this image.
Definition: Texture.h:68
Fling::Texture::m_TextureSampler
VkSampler m_TextureSampler
Definition: Texture.h:84
Fling::Texture::GetPixelData
stbi_uc * GetPixelData() const
Get the Pixel Data object.
Definition: Texture.h:42
Fling::Texture::GetMipLevels
FORCEINLINE UINT32 GetMipLevels() const
Definition: Texture.h:23
Fling::Texture::m_Height
UINT32 m_Height
Height of this image.
Definition: Texture.h:71
Fling::Texture::m_Format
VkFormat m_Format
Definition: Texture.h:94
Fling::Texture::Release
void Release()
Release the Vulkan resources of this image.
Definition: Texture.cpp:272
Fling::Texture::GetImageSize
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
Fling::Texture::CreateTextureSampler
void CreateTextureSampler()
Definition: Texture.cpp:239
UINT64
uint64_t UINT64
Definition: FlingTypes.h:14
Fling::Texture::~Texture
virtual ~Texture()
Definition: Texture.cpp:312
Fling::Texture::GetDescriptorInfo
FORCEINLINE VkDescriptorImageInfo * GetDescriptorInfo()
Definition: Texture.h:28
Fling::Texture::m_VkMemory
VkDeviceMemory m_VkMemory
The Vulkan memory resource for this image.
Definition: Texture.h:87
Fling::Texture::GetSampler
FORCEINLINE const VkSampler & GetSampler() const
Definition: Texture.h:27
Fling::Resource
Base class that represents a loaded resource in the engine.
Definition: Resource.h:11
Fling::Texture::GetVkImageView
FORCEINLINE const VkImageView & GetVkImageView() const
Definition: Texture.h:26
Fling::Texture
An image represents a 2D file that has data about each pixel in the image.
Definition: Texture.h:11
Fling::Texture::GetVkImageFormat
FORCEINLINE const VkFormat & GetVkImageFormat() const
Definition: Texture.h:29
Fling::Texture::m_ImageView
VkImageView m_ImageView
The view of this image for the swap chain.
Definition: Texture.h:82
Fling::Texture::CopyBufferToImage
void CopyBufferToImage(VkBuffer t_Buffer)
Definition: Texture.cpp:195
Resource.h
Fling::Texture::CreateImageView
void CreateImageView()
Create a Image View object that is needed to sample this image from the swap chain.
Definition: Texture.cpp:228
INT32
int32_t INT32
Definition: FlingTypes.h:18
Fling::Texture::m_ImageInfo
VkDescriptorImageInfo m_ImageInfo
Definition: Texture.h:89
Fling::Texture::m_Channels
INT32 m_Channels
The color channels of this image.
Definition: Texture.h:76
Fling::Texture::GetHeight
FORCEINLINE UINT32 GetHeight() const
Definition: Texture.h:21
Fling::Texture::m_MipLevels
UINT32 m_MipLevels
Definition: Texture.h:73
Fling::Texture::GenerateMipMaps
void GenerateMipMaps(VkFormat imageFormat)
Definition: Texture.cpp:97
Fling::Guid
entt::hashed_string Guid
Definition: FlingTypes.h:26
Fling::Texture::m_vVkImage
VkImage m_vVkImage
The Vulkan image data.
Definition: Texture.h:79
Fling::Texture::GetWidth
FORCEINLINE UINT32 GetWidth() const
Definition: Texture.h:20
Fling::Texture::Create
static std::shared_ptr< Fling::Texture > Create(Guid t_ID)
Definition: Texture.cpp:19
Fling::Texture::Texture
Texture(Guid t_ID)
Definition: Texture.cpp:24
Fling::Texture::LoadVulkanImage
void LoadVulkanImage()
Loads the Vulkan resources needed for this image.
Definition: Texture.cpp:39
Fling::Texture::GetVkImage
FORCEINLINE const VkImage & GetVkImage() const
Definition: Texture.h:25
Fling::Texture::m_PixelData
stbi_uc * m_PixelData
Pixel data of image.
Definition: Texture.h:92
UINT32
uint32_t UINT32
Definition: FlingTypes.h:13
Fling
Definition: Engine.h:29