evan 2026.1.4
Evan
Loading...
Searching...
No Matches
GPUTexture.hpp
1/*
2** ETIB PROJECT, 2026
3** xider
4** File description:
5** GPUTexture
6*/
7
8#pragma once
9
10#include <utility/graphic/texture.hpp>
11
12#include "utility/logging/logger.hpp"
13#include "utility/logging/default_logger.hpp"
14
15#include "EvanPlatform.hpp"
16
17#include "DeviceContext.hpp"
18
19#include <cmath>
20#include <math.h>
21#include <algorithm>
22
23namespace evan
24{
45 protected utility::logging::Loggable<GPUTexture,
46 utility::logging::DefaultLogger>
47 {
48 public:
60 enum class TextureType {
61 Albedo,
63 Normal,
65 Roughness,
69 };
70
90 : minLod(0.0f)
91 , maxLod(-1.0f)
92 , anisotropyEnable(VK_TRUE)
93 , maxAnisotropy(0.0f)
94 , addressModeU(VK_SAMPLER_ADDRESS_MODE_REPEAT)
95 , addressModeV(VK_SAMPLER_ADDRESS_MODE_REPEAT)
96 , addressModeW(VK_SAMPLER_ADDRESS_MODE_REPEAT)
97 {
98 }
99
103 float minLod;
104
111 float maxLod;
112
117
125
129 VkSamplerAddressMode addressModeU;
130
134 VkSamplerAddressMode addressModeV;
135
139 VkSamplerAddressMode addressModeW;
140 };
141
163 VkCommandPool
166
170
171 VkImage _image;
173
174 VkFormat _imageFormat;
176
177 uint32_t _texWidth;
178
179 uint32_t
181
182 uint32_t _mipLevels;
184 };
185
221 GPUTexture(std::shared_ptr<DeviceContext> deviceContext,
222 const utility::graphic::Texture &texture,
224 const SamplerSettings &settings = SamplerSettings {});
225
231
250 void destroy(VkDevice device);
251
261 static uint32_t computeMipLevels(uint32_t width, uint32_t height);
262
274 static float computeMaxLod(uint32_t mipLevels);
275
282 [[nodiscard]] uint32_t getMipLevels() const
283 {
284 return _mipLevel;
285 }
286
290 VkImageView view = VK_NULL_HANDLE;
291
296 VkSampler sampler = VK_NULL_HANDLE;
297
306
307 protected:
316 void cleanup();
317
342 void createImage(const ADeviceBackend &deviceBackend,
343 const utility::graphic::Texture &texture,
344 VkCommandPool commandPool, VkQueue graphicsQueue);
345
361 void createImageView(const ADeviceBackend &deviceBackend);
362
383 void
384 createSampler(const ADeviceBackend &deviceBackend,
385 VkSamplerCreateInfo samplerInfo,
386 const SamplerSettings &settings = SamplerSettings {});
387
392 VkImage _image = VK_NULL_HANDLE;
393
399 VkDeviceMemory _memory = VK_NULL_HANDLE;
400
409 uint32_t _mipLevel = 1;
410
416 std::shared_ptr<DeviceContext> _deviceContext;
417
418 private:
450 void generateMipmaps(const GenerateMipmapsProperties &properties,
451 const ADeviceBackend &deviceBackend);
452
487 void applySamplerSettings(VkSamplerCreateInfo &samplerInfo,
488 const SamplerSettings &settings);
489
490 VkSamplerCreateInfo
491 getDefaultSamplerInfo(const VkPhysicalDeviceProperties &properties);
492 };
493} // namespace evan
Abstract base class for Vulkan device backends.
GPUTexture class.
static uint32_t computeMipLevels(uint32_t width, uint32_t height)
Computes the number of mipmap levels for a texture of the given dimensions.
void destroy(VkDevice device)
Destroys the Vulkan resources associated with this GPUTexture, including the image,...
~GPUTexture()
Destructs the GPUTexture object by cleaning up Vulkan resources such as the image,...
TextureType type
The type of texture represented by this GPUTexture instance, such as albedo, normal,...
void createSampler(const ADeviceBackend &deviceBackend, VkSamplerCreateInfo samplerInfo, const SamplerSettings &settings=SamplerSettings {})
Creates a Vulkan sampler for the Vulkan image associated with this GPUTexture, defining how the textu...
void createImage(const ADeviceBackend &deviceBackend, const utility::graphic::Texture &texture, VkCommandPool commandPool, VkQueue graphicsQueue)
Creates a Vulkan image based on the provided texture data and type, and allocates memory for it.
VkSampler sampler
The Vulkan sampler associated with this GPUTexture, which defines how the texture is sampled in shade...
uint32_t _mipLevel
The number of mipmap levels generated for the Vulkan image associated with this GPUTexture,...
void cleanup()
Releases every Vulkan resource owned by this texture.
VkImage _image
The Vulkan image associated with this GPUTexture, which holds the texture data in GPU memory for use ...
TextureType
Enum class representing different types of textures that can be associated with a material,...
uint32_t getMipLevels() const
Retrieves the number of mipmap levels generated for this texture.
std::shared_ptr< DeviceContext > _deviceContext
The device context used to create this texture, kept alive for the lifetime of the texture so that cl...
GPUTexture(std::shared_ptr< DeviceContext > deviceContext, const utility::graphic::Texture &texture, TextureType type=TextureType::Albedo, const SamplerSettings &settings=SamplerSettings {})
Constructs a GPUTexture object by creating a Vulkan image, image view, and sampler based on the provi...
VkImageView view
The Vulkan image view associated with this GPUTexture.
VkDeviceMemory _memory
The Vulkan device memory allocated for the image associated with this GPUTexture, which is used to st...
void createImageView(const ADeviceBackend &deviceBackend)
Creates a Vulkan image view for the Vulkan image associated with this GPUTexture, allowing shader acc...
static float computeMaxLod(uint32_t mipLevels)
Computes the maximum sampleable LOD for a texture with the given number of mipmap levels.
Holds properties required for generating mipmaps for a Vulkan image.
uint32_t _texHeight
The height of the Vulkan image in pixels.
uint32_t _texWidth
The width of the Vulkan image in pixels.
Consumer-overridable sampler parameters.
VkSamplerAddressMode addressModeW
Addressing mode for the W (depth) axis.
float maxLod
Maximum LOD that can be sampled.
VkSamplerAddressMode addressModeU
Addressing mode for the U (width) axis.
float maxAnisotropy
Maximum anisotropy value.
VkSamplerAddressMode addressModeV
Addressing mode for the V (height) axis.
SamplerSettings()
Constructs sampler settings with the default values.
VkBool32 anisotropyEnable
Whether anisotropic filtering is enabled.
float minLod
Minimum LOD that can be sampled.