|
1 | | -/* Copyright (c) 2018-2019, Arm Limited and Contributors |
| 1 | +/* Copyright (c) 2018-2025, Arm Limited and Contributors |
| 2 | + * Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
2 | 3 | * |
3 | 4 | * SPDX-License-Identifier: Apache-2.0 |
4 | 5 | * |
|
17 | 18 |
|
18 | 19 | #pragma once |
19 | 20 |
|
20 | | -#include <memory> |
21 | | -#include <string> |
22 | | -#include <typeinfo> |
23 | | -#include <vector> |
24 | | - |
| 21 | +#include "core/hpp_sampler.h" |
25 | 22 | #include "core/sampler.h" |
26 | 23 | #include "scene_graph/component.h" |
27 | 24 |
|
28 | 25 | namespace vkb |
29 | 26 | { |
30 | | -namespace sg |
| 27 | +namespace scene_graph |
| 28 | +{ |
| 29 | +namespace components |
31 | 30 | { |
32 | | -class Sampler : public Component |
| 31 | +template <vkb::BindingType bindingType> |
| 32 | +class Sampler : public vkb::sg::Component |
33 | 33 | { |
34 | 34 | public: |
35 | | - Sampler(const std::string &name, core::Sampler &&vk_sampler); |
| 35 | + using CoreSamplerType = typename std::conditional<bindingType == BindingType::Cpp, vkb::core::HPPSampler, vkb::core::Sampler>::type; |
| 36 | + |
| 37 | + public: |
| 38 | + Sampler(std::string const &name, CoreSamplerType &&core_sampler); |
36 | 39 |
|
37 | 40 | Sampler(Sampler &&other) = default; |
| 41 | + virtual ~Sampler() = default; |
38 | 42 |
|
39 | | - virtual ~Sampler() = default; |
| 43 | + CoreSamplerType const &get_core_sampler() const; |
40 | 44 |
|
41 | 45 | virtual std::type_index get_type() override; |
42 | 46 |
|
43 | | - core::Sampler vk_sampler; |
| 47 | + private: |
| 48 | + vkb::core::HPPSampler core_sampler; |
44 | 49 | }; |
45 | | -} // namespace sg |
| 50 | + |
| 51 | +using SamplerC = Sampler<vkb::BindingType::C>; |
| 52 | +using SamplerCpp = Sampler<vkb::BindingType::Cpp>; |
| 53 | + |
| 54 | +// Member function definitions |
| 55 | + |
| 56 | +template <> |
| 57 | +inline Sampler<vkb::BindingType::Cpp>::Sampler(std::string const &name, vkb::core::HPPSampler &&core_sampler_) : |
| 58 | + Component{name}, |
| 59 | + core_sampler{std::move(core_sampler_)} |
| 60 | +{ |
| 61 | +} |
| 62 | + |
| 63 | +template <> |
| 64 | +inline Sampler<vkb::BindingType::C>::Sampler(std::string const &name, vkb::core::Sampler &&core_sampler_) : |
| 65 | + Component{name}, |
| 66 | + core_sampler{std::move(reinterpret_cast<vkb::core::HPPSampler &&>(core_sampler_))} |
| 67 | +{ |
| 68 | +} |
| 69 | + |
| 70 | +template <vkb::BindingType bindingType> |
| 71 | +inline typename Sampler<bindingType>::CoreSamplerType const &Sampler<bindingType>::get_core_sampler() const |
| 72 | +{ |
| 73 | + if constexpr (bindingType == BindingType::Cpp) |
| 74 | + { |
| 75 | + return core_sampler; |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + return reinterpret_cast<vkb::core::Sampler const &>(core_sampler); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +template <vkb::BindingType bindingType> |
| 84 | +inline std::type_index Sampler<bindingType>::get_type() |
| 85 | +{ |
| 86 | + return typeid(Sampler<bindingType>); |
| 87 | +} |
| 88 | +} // namespace components |
| 89 | +} // namespace scene_graph |
46 | 90 | } // namespace vkb |
0 commit comments