vsg  1.0.4
VulkanSceneGraph library
ViewDependentState.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/nodes/Light.h>
16 #include <vsg/state/BindDescriptorSet.h>
17 #include <vsg/state/DescriptorBuffer.h>
18 
19 namespace vsg
20 {
21 
25  class VSG_DECLSPEC ViewDescriptorSetLayout : public Inherit<DescriptorSetLayout, ViewDescriptorSetLayout>
26  {
27  public:
29 
30  VkDescriptorSetLayout vk(uint32_t deviceID) const override { return _viewDescriptorSetLayout ? _viewDescriptorSetLayout->vk(deviceID) : 0; }
31 
32  int compare(const Object& rhs_object) const override;
33 
34  void read(Input& input) override;
35  void write(Output& output) const override;
36 
37  void compile(Context& context) override;
38 
39  protected:
40  ref_ptr<DescriptorSetLayout> _viewDescriptorSetLayout;
41  };
42  VSG_type_name(vsg::ViewDescriptorSetLayout);
43 
47  class VSG_DECLSPEC BindViewDescriptorSets : public Inherit<StateCommand, BindViewDescriptorSets>
48  {
49  public:
51 
52  BindViewDescriptorSets(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, uint32_t in_firstSet) :
53  Inherit(1 + in_firstSet),
54  pipelineBindPoint(in_bindPoint),
55  layout(in_pipelineLayout),
56  firstSet(in_firstSet)
57  {
58  }
59 
60  // vkCmdBindDescriptorSets settings
61  VkPipelineBindPoint pipelineBindPoint;
63  uint32_t firstSet;
64 
65  int compare(const Object& rhs_object) const override;
66 
67  template<class N, class V>
68  static void t_traverse(N& bds, V& visitor)
69  {
70  if (bds.layout) bds.layout->accept(visitor);
71  }
72 
73  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
74  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
75 
76  void read(Input& input) override;
77  void write(Output& output) const override;
78 
79  // compile the Vulkan object, context parameter used for Device
80  void compile(Context& context) override;
81 
82  void record(CommandBuffer& commandBuffer) const override;
83 
84  protected:
85  virtual ~BindViewDescriptorSets() {}
86  };
87  VSG_type_name(vsg::BindViewDescriptorSets);
88 
96  class VSG_DECLSPEC ViewDependentState : public Inherit<Object, ViewDependentState>
97  {
98  public:
99  ViewDependentState(uint32_t maxNumberLights = 64, uint32_t maxViewports = 1);
100 
101  template<class N, class V>
102  static void t_traverse(N& node, V& visitor)
103  {
104  node.descriptorSet->accept(visitor);
105  }
106 
107  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
108  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
109 
110  // containers filled in by RecordTraversal
111  std::vector<std::pair<dmat4, const AmbientLight*>> ambientLights;
112  std::vector<std::pair<dmat4, const DirectionalLight*>> directionalLights;
113  std::vector<std::pair<dmat4, const PointLight*>> pointLights;
114  std::vector<std::pair<dmat4, const SpotLight*>> spotLights;
115 
116  virtual void compile(Context& context);
117  virtual void clear();
118  virtual void pack();
119  virtual void bindDescriptorSets(CommandBuffer& commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet);
120 
121  ref_ptr<vec4Array> lightData;
122  ref_ptr<BufferInfo> lightDataBufferInfo;
123 
124  ref_ptr<vec4Array> viewportData;
125  ref_ptr<BufferInfo> viewportDataBufferInfo;
126 
127  ref_ptr<DescriptorSetLayout> descriptorSetLayout;
128  ref_ptr<DescriptorBuffer> descriptor;
129  ref_ptr<DescriptorSet> descriptorSet;
130 
131  protected:
133  };
134  VSG_type_name(vsg::ViewDependentState);
135 
136 } // namespace vsg
Definition: ViewDependentState.h:48
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
CommandBuffer encapsulates VkCommandBuffer.
Definition: CommandBuffer.h:27
Definition: ConstVisitor.h:140
Definition: Context.h:67
Definition: Inherit.h:28
Definition: Input.h:43
Definition: Object.h:42
Definition: Output.h:40
PipelineLayout encapsulates VkPipelineLayout and the VkPipelineLayoutCreateInfo settings used to set ...
Definition: PipelineLayout.h:27
Definition: ViewDependentState.h:97
Definition: ViewDependentState.h:26
VkDescriptorSetLayout vk(uint32_t deviceID) const override
Vulkan VkDescriptorSetLayout handle.
Definition: ViewDependentState.h:30
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Visitor.h:140
Definition: ref_ptr.h:22