vsg: include/vsg/vk/DeviceFeatures.h Source File

vsg 1.1.10 VulkanSceneGraph library |

Loading...
Searching...
No Matches
DeviceFeatures.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2021 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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 <map>
16#include <vsg/io/Logger.h>
17#include <vsg/vk/PhysicalDevice.h>
18
19namespace vsg
20{
21
24 class VSG_DECLSPEC DeviceFeatures : public Inherit<Object, DeviceFeatures>
25 {
26 public:
27 DeviceFeatures();
28
29 DeviceFeatures(const DeviceFeatures&) = delete;
30 DeviceFeatures& operator=(const DeviceFeatures&) = delete;
31
37 template<typename FeatureStruct, VkStructureType type>
38 FeatureStruct& get()
39 {
40 if (auto itr = _features.find(type); itr != _features.end()) return *reinterpret_cast<FeatureStruct*>(itr->second.first);
41
42 FeatureStruct* feature = new FeatureStruct{};
43
44 feature->sType = type;
45 feature->pNext = nullptr;
46
47 _features[type].first = reinterpret_cast<FeatureHeader*>(feature);
48 _features[type].second = [](FeatureHeader* ptr) { delete reinterpret_cast<FeatureStruct*>(ptr); };
49
50 return *feature;
51 }
52
56 VkPhysicalDeviceFeatures& get();
57
59 void clear();
60
64 void* data() const;
65
66 protected:
67 ~DeviceFeatures();
68
69 struct FeatureHeader
70 {
71 VkStructureType sType;
72 void* pNext;
73 };
74
75 using DeleteHandler = void (*)(FeatureHeader* ptr);
76
77 std::map<VkStructureType, std::pair<FeatureHeader*, DeleteHandler>> _features;
78 };
79 VSG_type_name(vsg::DeviceFeatures);
80
81} // namespace vsg
vsg::DeviceFeatures
Definition DeviceFeatures.h:25
vsg::DeviceFeatures::get
VkPhysicalDeviceFeatures & get()
vsg::DeviceFeatures::clear
void clear()
clear all the feature structures
vsg::DeviceFeatures::data
void * data() const
vsg::DeviceFeatures::get
FeatureStruct & get()
Definition DeviceFeatures.h:38
vsg::DeviceFeatures::FeatureHeader
Definition DeviceFeatures.h:70