vsg  1.0.4
VulkanSceneGraph library
GraphicsPipelineConfigurator.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2022 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/state/BindDescriptorSet.h>
16 #include <vsg/state/ColorBlendState.h>
17 #include <vsg/state/DepthStencilState.h>
18 #include <vsg/state/DescriptorBuffer.h>
19 #include <vsg/state/DescriptorImage.h>
20 #include <vsg/state/DescriptorSetLayout.h>
21 #include <vsg/state/DynamicState.h>
22 #include <vsg/state/GraphicsPipeline.h>
23 #include <vsg/state/InputAssemblyState.h>
24 #include <vsg/state/MultisampleState.h>
25 #include <vsg/state/RasterizationState.h>
26 #include <vsg/state/TessellationState.h>
27 #include <vsg/state/VertexInputState.h>
28 #include <vsg/state/ViewportState.h>
29 #include <vsg/utils/ShaderSet.h>
30 
31 namespace vsg
32 {
33 
35  class VSG_DECLSPEC GraphicsPipelineConfigurator : public vsg::Inherit<Object, GraphicsPipelineConfigurator>
36  {
37  public:
39 
40  // inputs to setup of GraphicsPipeline, the default sets are taken from any provided by ShaderSet::defaultGraphicsPipelineStates
41  ref_ptr<ColorBlendState> colorBlendState;
42  ref_ptr<DepthStencilState> depthStencilState;
43  ref_ptr<DynamicState> dynamicState;
44  ref_ptr<InputAssemblyState> inputAssemblyState;
45  ref_ptr<MultisampleState> multisampleState; // typically leave unset as compile traversal with provide MultisampleState
46  ref_ptr<RasterizationState> rasterizationState;
47  ref_ptr<TessellationState> tessellationState;
48  ref_ptr<VertexInputState> vertexInputState; // set by assignArray(..) methods.
49  ref_ptr<ViewportState> viewportState; // typically leave unset as compile traversal with provide ViewportState
50 
51  uint32_t subpass = 0;
52  uint32_t baseAttributeBinding = 0;
53  ref_ptr<ShaderSet> shaderSet;
54  ref_ptr<DescriptorSetLayout> additionalDescriptorSetLayout;
55 
56  void reset();
57 
58  bool enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format = VK_FORMAT_UNDEFINED);
59  bool enableTexture(const std::string& name);
60  bool enableUniform(const std::string& name);
61 
62  bool assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr<Data> array);
63  bool assignTexture(Descriptors& descriptors, const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {});
64  bool assignUniform(Descriptors& descriptors, const std::string& name, ref_ptr<Data> data = {});
65 
66  // setup by assign calls
68  vsg::DescriptorSetLayoutBindings descriptorBindings;
69 
70  int compare(const Object& rhs) const override;
71 
72  void init();
73 
74  // setup by init()
75  ref_ptr<DescriptorSetLayout> descriptorSetLayout;
77  ref_ptr<GraphicsPipeline> graphicsPipeline;
78  ref_ptr<BindGraphicsPipeline> bindGraphicsPipeline;
79  };
80  VSG_type_name(vsg::GraphicsPipelineConfigurator);
81 
83  class VSG_DECLSPEC DescriptorConfigurator : public vsg::Inherit<Object, DescriptorConfigurator>
84  {
85  public:
86  DescriptorConfigurator(ref_ptr<ShaderSet> in_shaderSet = {});
87 
88  ref_ptr<ShaderSet> shaderSet;
89  bool blending = false;
90  bool two_sided = false;
91 
92  bool assignTexture(const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {});
93  bool assignUniform(const std::string& name, ref_ptr<Data> data = {});
94 
95  // assign Descriptors to a DescriptorSet
96  void init();
97 
98  // filled in by assignTexture(..) and assignUniform(..)
99  Descriptors descriptors;
100  std::set<std::string> defines;
101  DescriptorSetLayoutBindings descriptorBindings;
102 
103  // filled in by init()
104  ref_ptr<DescriptorSet> descriptorSet;
105  };
106  VSG_type_name(vsg::DescriptorConfigurator);
107 
111 
112 } // namespace vsg
DescriptorConfigurator utility provides a means of setting up descriptors using ShaderSet as a guide ...
Definition: GraphicsPipelineConfigurator.h:84
GraphicsPipelineConfigurator utility provides a means of setting up state and geometry using ShaderSe...
Definition: GraphicsPipelineConfigurator.h:36
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Inherit.h:28
Definition: Object.h:42
Definition: ref_ptr.h:22