Skip to content

Commit 8ac6aca

Browse files
committed
[gpu-texture] Test VkSampler wrapper (squash me)
1 parent e0f5438 commit 8ac6aca

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

include/inexor/vulkan-renderer/wrapper/gpu_texture.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "inexor/vulkan-renderer/wrapper/device.hpp"
55
#include "inexor/vulkan-renderer/wrapper/gpu_memory_buffer.hpp"
66
#include "inexor/vulkan-renderer/wrapper/image.hpp"
7+
#include "inexor/vulkan-renderer/wrapper/sampler.hpp"
78

89
#include <volk.h>
910

@@ -20,7 +21,7 @@ class GPUMemoryBuffer;
2021
/// @todo Support 3D textures and cube maps (implement new and separate wrappers though).
2122
class GpuTexture {
2223
std::unique_ptr<wrapper::Image> m_texture_image;
23-
VkSampler m_sampler{VK_NULL_HANDLE};
24+
std::unique_ptr<Sampler> m_sampler;
2425

2526
int m_texture_width{0};
2627
int m_texture_height{0};
@@ -42,9 +43,6 @@ class GpuTexture {
4243
/// @param new_layout The new image layout.
4344
void transition_image_layout(VkImage image, VkImageLayout old_layout, VkImageLayout new_layout);
4445

45-
/// @brief Create the texture sampler.
46-
void create_texture_sampler();
47-
4846
public:
4947
/// @brief Construct a texture from a file.
5048
/// @param device The const reference to a device RAII wrapper instance.
@@ -66,7 +64,7 @@ class GpuTexture {
6664
GpuTexture(const GpuTexture &) = delete;
6765
GpuTexture(GpuTexture &&) noexcept;
6866

69-
~GpuTexture();
67+
~GpuTexture() = default;
7068

7169
GpuTexture &operator=(const GpuTexture &) = delete;
7270
GpuTexture &operator=(GpuTexture &&) = delete;
@@ -84,7 +82,7 @@ class GpuTexture {
8482
}
8583

8684
[[nodiscard]] VkSampler sampler() const {
87-
return m_sampler;
85+
return m_sampler->sampler();
8886
}
8987
};
9088

src/vulkan-renderer/wrapper/gpu_texture.cpp

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ GpuTexture::GpuTexture(GpuTexture &&other) noexcept
3535
m_sampler = std::exchange(other.m_sampler, nullptr);
3636
}
3737

38-
GpuTexture::~GpuTexture() {
39-
vkDestroySampler(m_device.device(), m_sampler, nullptr);
40-
}
41-
4238
void GpuTexture::create_texture(void *texture_data, const std::size_t texture_size) {
4339
const VkExtent2D extent{
4440
// Because stb_image stored the texture's width and height as a normal int, we need a cast here
@@ -70,35 +66,25 @@ void GpuTexture::create_texture(void *texture_data, const std::size_t texture_si
7066
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
7167
});
7268

73-
create_texture_sampler();
74-
}
75-
76-
void GpuTexture::create_texture_sampler() {
77-
VkPhysicalDeviceFeatures device_features;
78-
vkGetPhysicalDeviceFeatures(m_device.physical_device(), &device_features);
79-
80-
VkPhysicalDeviceProperties graphics_card_properties;
81-
vkGetPhysicalDeviceProperties(m_device.physical_device(), &graphics_card_properties);
82-
83-
const auto sampler_ci = make_info<VkSamplerCreateInfo>({
84-
.magFilter = VK_FILTER_LINEAR,
85-
.minFilter = VK_FILTER_LINEAR,
86-
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
87-
.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
88-
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
89-
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
90-
.mipLodBias = 0.0f,
91-
.anisotropyEnable = VK_FALSE,
92-
.maxAnisotropy = 1.0f,
93-
.compareEnable = VK_FALSE,
94-
.compareOp = VK_COMPARE_OP_ALWAYS,
95-
.minLod = 0.0f,
96-
.maxLod = 0.0f,
97-
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
98-
.unnormalizedCoordinates = VK_FALSE,
99-
});
100-
101-
m_device.create_sampler(sampler_ci, &m_sampler, m_name);
69+
m_sampler = std::make_unique<Sampler>(m_device,
70+
make_info<VkSamplerCreateInfo>({
71+
.magFilter = VK_FILTER_LINEAR,
72+
.minFilter = VK_FILTER_LINEAR,
73+
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
74+
.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
75+
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
76+
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
77+
.mipLodBias = 0.0f,
78+
.anisotropyEnable = VK_FALSE,
79+
.maxAnisotropy = 1.0f,
80+
.compareEnable = VK_FALSE,
81+
.compareOp = VK_COMPARE_OP_ALWAYS,
82+
.minLod = 0.0f,
83+
.maxLod = 0.0f,
84+
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
85+
.unnormalizedCoordinates = VK_FALSE,
86+
}),
87+
"default sampler");
10288
}
10389

10490
} // namespace inexor::vulkan_renderer::wrapper

0 commit comments

Comments
 (0)