vOOlkan
An object oriented approach to Vulkan
TextureSampler.h
Go to the documentation of this file.
1#ifndef VULKAN_TEXTURESAMPLER
2#define VULKAN_TEXTURESAMPLER
3
4#include <vulkan/vulkan.h>
5
6#include "LogicalDevice.h"
7#include "PhysicalDevice.h"
8#include "VulkanException.h"
9
10
11namespace Vulkan { class TextureSampler; }
12
17public:
18
19 TextureSampler(const LogicalDevice& virtualGpu, const PhysicalDevice& realGpu) : virtualGpu{ &virtualGpu } {
20 VkSamplerCreateInfo samplerInfo{};
21 samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
22 samplerInfo.magFilter = VK_FILTER_LINEAR;
23 samplerInfo.minFilter = VK_FILTER_LINEAR;
24 samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
25 samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
26 samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
27 samplerInfo.anisotropyEnable = VK_TRUE;
28 samplerInfo.maxAnisotropy = realGpu.getProperties().limits.maxSamplerAnisotropy;
29 samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
30 samplerInfo.unnormalizedCoordinates = VK_FALSE;
31 samplerInfo.compareEnable = VK_FALSE;
32 samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
33 samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
34 samplerInfo.mipLodBias = 0.0f;
35 samplerInfo.minLod = 0.0f;
36 samplerInfo.maxLod = 0.0f;
37
38 if (VkResult result = vkCreateSampler(+virtualGpu, &samplerInfo, nullptr, &textureSampler); result != VK_SUCCESS) {
39 throw VulkanException{ "Failed to create texture sampler!", result };
40 }
41 }
42
43
48
49
51 vkDestroySampler(+*virtualGpu, textureSampler, nullptr);
52 }
53
54
55 const VkSampler& operator+() const {
56 return textureSampler;
57 }
58
59private:
60
61 VkSampler textureSampler;
62 LogicalDevice const* virtualGpu;
63
64};
65
66
67
68#endif
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Represents the GPU (or any other device) that will be used with Vulkan to perform computer graphics.
Definition: PhysicalDevice.h:17
VkPhysicalDeviceProperties getProperties() const
Definition: PhysicalDevice.h:43
A TextureSampler is an object which is used to apply filters (anisotropic, interpolation,...
Definition: TextureSampler.h:16
TextureSampler(TextureSampler &&)=delete
TextureSampler(const TextureSampler &)=delete
TextureSampler(const LogicalDevice &virtualGpu, const PhysicalDevice &realGpu)
Definition: TextureSampler.h:19
const VkSampler & operator+() const
Definition: TextureSampler.h:55
~TextureSampler()
Definition: TextureSampler.h:50
TextureSampler & operator=(TextureSampler &&)=delete
TextureSampler & operator=(const TextureSampler &)=delete
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Types of queue families.
Definition: Animations.h:17