vsg  1.1.0
VulkanSceneGraph library
Sampler.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/vk/Device.h>
16 #include <vsg/vk/vk_buffer.h>
17 
18 namespace vsg
19 {
20  // forward declare
21  class Context;
22 
24  class VSG_DECLSPEC Sampler : public Inherit<Object, Sampler>
25  {
26  public:
27  Sampler();
28 
30  VkSamplerCreateFlags flags = 0;
31  VkFilter magFilter = VK_FILTER_LINEAR;
32  VkFilter minFilter = VK_FILTER_LINEAR;
33  VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
34  VkSamplerAddressMode addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
35  VkSamplerAddressMode addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
36  VkSamplerAddressMode addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
37  float mipLodBias = 0.0f;
38  VkBool32 anisotropyEnable = VK_FALSE;
39  float maxAnisotropy = 0.0f;
40  VkBool32 compareEnable = VK_FALSE;
41  VkCompareOp compareOp = VK_COMPARE_OP_NEVER;
42  float minLod = 0.0f;
43  float maxLod = 0.0f;
44  VkBorderColor borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
45  VkBool32 unnormalizedCoordinates = VK_FALSE;
46 
47  // Vulkan VkSampler handle
48  VkSampler vk(uint32_t deviceID) const { return _implementation[deviceID]->_sampler; }
49 
50  int compare(const Object& rhs_object) const override;
51 
52  void read(Input& input) override;
53  void write(Output& output) const override;
54 
55  void compile(Context& context);
56 
57  void release(uint32_t deviceID) { _implementation[deviceID] = {}; }
58  void release() { _implementation.clear(); }
59 
60  protected:
61  virtual ~Sampler();
62 
63  struct Implementation : public Inherit<Object, Implementation>
64  {
65  Implementation(Device* device, const VkSamplerCreateInfo& createSamplerInfo);
66 
67  virtual ~Implementation();
68 
69  VkSampler _sampler;
70  ref_ptr<Device> _device;
71  };
72 
73  vk_buffer<ref_ptr<Implementation>> _implementation;
74  };
75  VSG_type_name(vsg::Sampler)
76 
77 } // namespace vsg
Definition: Context.h:67
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Definition: Output.h:41
Sampler encapsulates the VkSampler and the VkSamplerCreateInfo settings used to set it up.
Definition: Sampler.h:25
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: ref_ptr.h:22
Definition: Sampler.h:64
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28