FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_descriptorSetLayout.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_VULKAN_C_DESCRIPTORSETLAYOUT_HPP_INCLUDED
18#define _FGE_VULKAN_C_DESCRIPTORSETLAYOUT_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "volk.h"
22#include "FastEngine/vulkan/C_contextAware.hpp"
23#include <initializer_list>
24#include <vector>
25
26namespace fge::vulkan
27{
28
37class FGE_API DescriptorSetLayout : public ContextAware
38{
39public:
40 class Binding
41 {
42 public:
43 constexpr Binding(uint32_t binding,
44 VkDescriptorType type,
45 VkShaderStageFlags stageFlags,
46 uint32_t descriptorCount = 1,
47 VkDescriptorBindingFlagsEXT bindingFlags = 0) :
48 g_binding(binding),
49 g_descriptorType(type),
50 g_descriptorCount(descriptorCount),
51 g_stageFlags(stageFlags),
52 g_bindingFlags(bindingFlags)
53 {}
54
55 constexpr void setBinding(uint32_t binding) { this->g_binding = binding; }
56 [[nodiscard]] constexpr uint32_t getBinding() const { return this->g_binding; }
57
58 constexpr void setDescriptorType(VkDescriptorType type) { this->g_descriptorType = type; }
59 [[nodiscard]] constexpr VkDescriptorType getDescriptorType() const { return this->g_descriptorType; }
60
61 constexpr void setDescriptorCount(uint32_t descriptorCount) { this->g_descriptorCount = descriptorCount; }
62 [[nodiscard]] constexpr uint32_t getDescriptorCount() const { return this->g_descriptorCount; }
63
64 constexpr void setStageFlags(VkShaderStageFlags stageFlags) { this->g_stageFlags = stageFlags; }
65 [[nodiscard]] constexpr VkShaderStageFlags getStageFlags() const { return this->g_stageFlags; }
66
67 constexpr void setBindingFlags(VkDescriptorBindingFlagsEXT bindingFlags)
68 {
69 this->g_bindingFlags = bindingFlags;
70 }
71 constexpr void clearBindingFlags() { this->g_bindingFlags = 0; }
72 [[nodiscard]] constexpr VkDescriptorBindingFlagsEXT getBindingFlags() const { return this->g_bindingFlags; }
73
74 constexpr explicit operator VkDescriptorSetLayoutBinding() const
75 {
76 return {.binding = this->g_binding,
77 .descriptorType = this->g_descriptorType,
78 .descriptorCount = this->g_descriptorCount,
79 .stageFlags = this->g_stageFlags,
80 .pImmutableSamplers = nullptr};
81 }
82
83 private:
84 uint32_t g_binding;
85 VkDescriptorType g_descriptorType;
86 uint32_t g_descriptorCount;
87 VkShaderStageFlags g_stageFlags;
88 VkDescriptorBindingFlagsEXT g_bindingFlags;
89 };
90
91 explicit DescriptorSetLayout(Context const& context);
94 ~DescriptorSetLayout() override;
95
96 DescriptorSetLayout& operator=(DescriptorSetLayout const& r);
97 DescriptorSetLayout& operator=(DescriptorSetLayout&& r) noexcept;
98
99 void create(Binding const* bindings, uint32_t bindingCount);
100 inline void create(std::initializer_list<Binding> bindings)
101 {
102 this->create(bindings.begin(), static_cast<uint32_t>(bindings.size()));
103 }
104 void destroy() final;
105
106 [[nodiscard]] VkDescriptorSetLayout getLayout() const;
107 [[nodiscard]] std::vector<Binding> const& getBindings() const;
108 [[nodiscard]] uint32_t getBindingsCount() const;
109
110private:
111 VkDescriptorSetLayout g_descriptorSetLayout;
112 std::vector<Binding> g_bindings;
113};
114
115} // namespace fge::vulkan
116
117#endif //_FGE_VULKAN_C_DESCRIPTORSETLAYOUT_HPP_INCLUDED
Definition C_contextAware.hpp:28
Vulkan context.
Definition C_context.hpp:70
Definition C_descriptorSetLayout.hpp:41
This class abstract the vulkan descriptor set layout for easier use.
Definition C_descriptorSetLayout.hpp:38