-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVKSamplers.cpp
99 lines (94 loc) · 4.21 KB
/
VKSamplers.cpp
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
#include "VKPCH.h"
size_t SamplerCounter = 0;
VKSamplerState::VKSamplerState(const BearSamplerDescription& description)
{
VkSamplerCreateInfo SamplerCreateInfo = {};
SamplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
SamplerCreateInfo.addressModeU = VKFactory::Translation(description.AddressU);
SamplerCreateInfo.addressModeV = VKFactory::Translation(description.AddressV);
SamplerCreateInfo.addressModeW = VKFactory::Translation(description.AddressW);
switch (description.Filter)
{
case BearSamplerFilter::MinMagMipPoint:
SamplerCreateInfo.magFilter = VK_FILTER_NEAREST;
SamplerCreateInfo.minFilter = VK_FILTER_NEAREST;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_FALSE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
break;
case BearSamplerFilter::MinMagLinearMipPoint:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_FALSE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
break;
case BearSamplerFilter::MinMagMipLinear:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_FALSE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
break;
case BearSamplerFilter::Anisotropic:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_TRUE;
SamplerCreateInfo.compareEnable = VK_FALSE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
break;
case BearSamplerFilter::ComparisonMinMagMipPoint:
SamplerCreateInfo.magFilter = VK_FILTER_NEAREST;
SamplerCreateInfo.minFilter = VK_FILTER_NEAREST;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_TRUE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_LESS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
break;
case BearSamplerFilter::ComparisonMinMagLinearMipPoint:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_TRUE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_LESS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
break;
case BearSamplerFilter::ComparisonMinMagMipLinear:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_FALSE;
SamplerCreateInfo.compareEnable = VK_TRUE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_LESS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
break;
case BearSamplerFilter::ComparisonAnisotropic:
SamplerCreateInfo.magFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.minFilter = VK_FILTER_LINEAR;
SamplerCreateInfo.anisotropyEnable = VK_TRUE;
SamplerCreateInfo.compareEnable = VK_TRUE;
SamplerCreateInfo.compareOp = VK_COMPARE_OP_LESS;
SamplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
break;
default:
BEAR_CHECK(0);
}
SamplerCreateInfo.mipLodBias = static_cast<float>(description.MipBias);
SamplerCreateInfo.maxLod = 3.402823466e+38f;
SamplerCreateInfo.addressModeU = VKFactory::Translation(description.AddressU);
SamplerCreateInfo.addressModeV = VKFactory::Translation(description.AddressV);
SamplerCreateInfo.addressModeW = VKFactory::Translation(description.AddressW);
SamplerCreateInfo.maxAnisotropy =static_cast<float>( description.MaxAnisotropy);
SamplerCreateInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
SamplerCreateInfo.unnormalizedCoordinates = VK_FALSE;
SamplerCounter++;
V_CHK(vkCreateSampler(Factory->Device, &SamplerCreateInfo, nullptr, &ImageInfo.sampler));
}
VKSamplerState::~VKSamplerState()
{
SamplerCounter--;
vkDestroySampler(Factory->Device, ImageInfo.sampler, nullptr);
}