-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsampler.cc
115 lines (89 loc) · 3.19 KB
/
sampler.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <vkpp/sampler.hh>
#include <vkpp/device.hh>
#include <vkpp/exception.hh>
#include <utility>
namespace vkpp {
Sampler::~Sampler() noexcept {
if (handle != VK_NULL_HANDLE) {
vkDestroySampler(device, handle, nullptr);
}
}
Sampler::Sampler(Device& logical_device,
VkFilter min_filter,
VkFilter mag_filter,
VkSamplerAddressMode wrap_u,
VkSamplerAddressMode wrap_v,
VkSamplerAddressMode wrap_w,
bool anisotropy,
bool enable_compare_less_op)
: min_filter { min_filter },
mag_filter { mag_filter },
wrap_u { wrap_u },
wrap_v { wrap_v },
anisotropy { anisotropy },
device { logical_device.get_handle() } {
VkSamplerCreateInfo create_info;
create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
create_info.pNext = nullptr;
create_info.flags = 0;
create_info.magFilter = mag_filter;
create_info.minFilter = min_filter;
create_info.addressModeU = wrap_u;
create_info.addressModeV = wrap_v;
create_info.addressModeW = wrap_w;
create_info.anisotropyEnable = anisotropy;
if (anisotropy)
create_info.maxAnisotropy = 16;
create_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
create_info.mipLodBias = 0.0;
create_info.minLod = 0.0;
create_info.maxLod = 0.0;
create_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
create_info.unnormalizedCoordinates = VK_FALSE;
if (enable_compare_less_op) {
create_info.compareEnable = VK_TRUE;
create_info.compareOp = VK_COMPARE_OP_LESS;
} else {
create_info.compareEnable = VK_FALSE;
create_info.compareOp = VK_COMPARE_OP_ALWAYS;
}
if (VkResult error = vkCreateSampler(device, &create_info, nullptr, &handle)) {
throw Exception { error, "couldn't create texture sampler!" };
}
}
Sampler::Sampler(Sampler&& sampler) noexcept {
swap(*this, sampler);
}
Sampler& Sampler::operator=(Sampler&& sampler) noexcept {
swap(*this, sampler);
return *this;
}
void swap(Sampler& lhs, Sampler& rhs) {
using std::swap;
swap(lhs.handle, rhs.handle);
swap(lhs.device, rhs.device);
swap(lhs.min_filter, rhs.min_filter);
swap(lhs.mag_filter, rhs.mag_filter);
swap(lhs.wrap_u, rhs.wrap_u);
swap(lhs.wrap_v, rhs.wrap_v);
swap(lhs.anisotropy, rhs.anisotropy);
}
VkSampler& Sampler::get_handle() {
return handle;
}
VkFilter Sampler::get_min_filter() const {
return min_filter;
}
VkFilter Sampler::get_mag_filter() const {
return mag_filter;
}
VkSamplerAddressMode Sampler::get_wrap_u() const {
return wrap_u;
}
VkSamplerAddressMode Sampler::get_wrap_v() const {
return wrap_v;
}
bool Sampler::anisotropy_enabled() const {
return anisotropy;
}
}