1 /* Copyright (c) 2017-2018 Hans-Kristian Arntzen 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be 12 * included in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #pragma once 24 25 #include "cookie.hpp" 26 #include "vulkan_common.hpp" 27 #include "vulkan.hpp" 28 #include "object_pool.hpp" 29 30 namespace Vulkan 31 { 32 enum class StockSampler 33 { 34 NearestClamp, 35 LinearClamp, 36 TrilinearClamp, 37 NearestWrap, 38 LinearWrap, 39 TrilinearWrap, 40 NearestShadow, 41 LinearShadow, 42 Count 43 }; 44 45 struct SamplerCreateInfo 46 { 47 VkFilter mag_filter; 48 VkFilter min_filter; 49 VkSamplerMipmapMode mipmap_mode; 50 VkSamplerAddressMode address_mode_u; 51 VkSamplerAddressMode address_mode_v; 52 VkSamplerAddressMode address_mode_w; 53 float mip_lod_bias; 54 VkBool32 anisotropy_enable; 55 float max_anisotropy; 56 VkBool32 compare_enable; 57 VkCompareOp compare_op; 58 float min_lod; 59 float max_lod; 60 VkBorderColor border_color; 61 VkBool32 unnormalized_coordinates; 62 }; 63 64 class Sampler; 65 struct SamplerDeleter 66 { 67 void operator()(Sampler *sampler); 68 }; 69 70 class Sampler : public Util::IntrusivePtrEnabled<Sampler, SamplerDeleter, HandleCounter>, 71 public Cookie, public InternalSyncEnabled 72 { 73 public: 74 friend struct SamplerDeleter; 75 ~Sampler(); 76 get_sampler() const77 VkSampler get_sampler() const 78 { 79 return sampler; 80 } 81 get_create_info() const82 const SamplerCreateInfo &get_create_info() const 83 { 84 return create_info; 85 } 86 87 private: 88 friend class Util::ObjectPool<Sampler>; 89 Sampler(Device *device, VkSampler sampler, const SamplerCreateInfo &info); 90 91 Device *device; 92 VkSampler sampler; 93 SamplerCreateInfo create_info; 94 }; 95 using SamplerHandle = Util::IntrusivePtr<Sampler>; 96 } 97