Mandrill 2025.6.0
Loading...
Searching...
No Matches
Texture.h
1#pragma once
2
3#include "Common.h"
4
5#include "Device.h"
6#include "Image.h"
7#include "Sampler.h"
8
9namespace Mandrill
10{
14 class Texture
15 {
16 public:
17 enum class MANDRILL_API Type {
18 Texture1D,
19 Texture2D,
20 Texture3D,
21 CubeMap,
22 };
23
24 MANDRILL_NON_COPYABLE(Texture)
25
26
34 MANDRILL_API Texture(ptr<Device> pDevice, Type type, VkFormat format, const std::filesystem::path& path,
35 bool mipmaps = false);
36
49 MANDRILL_API Texture(ptr<Device> pDevice, Type type, VkFormat format, const void* pData, uint32_t width,
50 uint32_t height, uint32_t depth, uint32_t channels, bool mipmaps = false);
51
55 MANDRILL_API ~Texture();
56
61 MANDRILL_API void setSampler(const ptr<Sampler> pSampler)
62 {
63 mImageInfo.sampler = pSampler->getSampler();
64 }
65
70 MANDRILL_API VkSampler getSampler() const
71 {
72 return mImageInfo.sampler;
73 }
74
79 MANDRILL_API ptr<Image> getImage() const
80 {
81 return mpImage;
82 }
83
88 MANDRILL_API VkImageView getImageView() const
89 {
90 return mImageInfo.imageView;
91 }
92
98 MANDRILL_API VkWriteDescriptorSet getWriteDescriptor(uint32_t binding) const
99 {
100 VkWriteDescriptorSet descriptor = {
101 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
102 .dstBinding = binding,
103 .dstArrayElement = 0,
104 .descriptorCount = 1,
105 .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
106 .pImageInfo = &mImageInfo,
107 };
108
109 return descriptor;
110 }
111
112 private:
113 void create(VkFormat format, const void* pData, uint32_t width, uint32_t height, uint32_t depth,
114 uint32_t bytesPerPixel, bool mipmaps);
115 void generateMipmaps(VkCommandBuffer cmd);
116
117 ptr<Device> mpDevice;
118
119 ptr<Image> mpImage;
120 VkDescriptorImageInfo mImageInfo;
121 };
122} // namespace Mandrill
Texture class for managing textures in Vulkan.
Definition Texture.h:15
MANDRILL_API ~Texture()
Destructor for texture.
Definition Texture.cpp:106
MANDRILL_API ptr< Image > getImage() const
Get the image of the texture.
Definition Texture.h:79
MANDRILL_API VkSampler getSampler() const
Get the sampler handle currently in use by the texture.
Definition Texture.h:70
MANDRILL_API VkImageView getImageView() const
Get the image view handle.
Definition Texture.h:88
MANDRILL_API VkWriteDescriptorSet getWriteDescriptor(uint32_t binding) const
Get the write descriptor set. Useful when using push descriptors.
Definition Texture.h:98
MANDRILL_API void setSampler(const ptr< Sampler > pSampler)
Set the sampler for the texture.
Definition Texture.h:61