Lugdunum  0.1.0
Sampler.cpp
Go to the documentation of this file.
2 
4 
5 namespace lug {
6 namespace Graphics {
7 namespace Vulkan {
8 namespace API {
9 namespace Builder {
10 
11 Sampler::Sampler(const API::Device& device) : _device{device} {}
12 
13 bool Sampler::build(API::Sampler& sampler, VkResult* returnResult) {
14  // Create the sampler creation information for vkCreateSampler
15  const VkSamplerCreateInfo createInfo{
16  /* createInfo.sType */ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
17  /* createInfo.pNext */ nullptr,
18  /* createInfo.flags */ 0,
19  /* createInfo.magFilter */ _magFilter,
20  /* createInfo.minFilter */ _minFilter,
21  /* createInfo.mipmapMode */ _mipmapMode,
22  /* createInfo.addressModeU */ _addressModeU,
23  /* createInfo.addressModeV */ _addressModeV,
24  /* createInfo.addressModeW */ _addressModeW,
25  /* createInfo.mipLodBias */ _mipLodBias,
26  /* createInfo.anisotropyEnable */ _anisotropyEnable,
27  /* createInfo.maxAnisotropy */ _maxAnisotropy,
28  /* createInfo.compareEnable */ _compareEnable,
29  /* createInfo.compareOp */ _compareOp,
30  /* createInfo.minLod */ _minLod,
31  /* createInfo.maxLod */ _maxLod,
32  /* createInfo.borderColor */ _borderColor,
33  /* createInfo.unnormalizedCoordinates */ _unnormalizedCoordinates
34  };
35 
36  // Create the sampler
37  VkSampler vkSampler{VK_NULL_HANDLE};
38  VkResult result = vkCreateSampler(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkSampler);
39 
40  if (returnResult) {
41  *returnResult = result;
42  }
43 
44  if (result != VK_SUCCESS) {
45  return false;
46  }
47 
48  sampler = API::Sampler(vkSampler, &_device);
49 
50  return true;
51 }
52 
53 std::unique_ptr<API::Sampler> Sampler::build(VkResult* returnResult) {
54  std::unique_ptr<API::Sampler> sampler = std::make_unique<API::Sampler>();
55  return build(*sampler, returnResult) ? std::move(sampler) : nullptr;
56 }
57 
58 } // Builder
59 } // API
60 } // Vulkan
61 } // Graphics
62 } // lug
bool build(API::Sampler &instance, VkResult *returnResult=nullptr)
Definition: Sampler.cpp:13
Sampler(const API::Device &device)
Definition: Sampler.cpp:11