vsg  1.0.4
VulkanSceneGraph library
ArrayState.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2020 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/core/ConstVisitor.h>
16 #include <vsg/core/Data.h>
17 #include <vsg/core/Inherit.h>
18 #include <vsg/state/BufferInfo.h>
19 #include <vsg/state/Sampler.h>
20 
21 namespace vsg
22 {
23 
27  class VSG_DECLSPEC ArrayState : public Inherit<ConstVisitor, ArrayState>
28  {
29  public:
30  ArrayState() = default;
31  ArrayState(const ArrayState&) = default;
32 
35  {
36  return ArrayState::create(*this);
37  }
38 
39  // clone the specified ArrayState
40  virtual ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState)
41  {
42  return ArrayState::create(*arrayState);
43  }
44 
46  {
47  uint32_t binding = 0;
48  VkFormat format = {};
49  uint32_t stride = 0;
50  uint32_t offset = 0;
51  VkVertexInputRate inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
52  };
53 
54  std::vector<dmat4> localToWorldStack;
55  std::vector<dmat4> worldToLocalStack;
56 
57  VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
58  uint32_t vertex_attribute_location = 0;
59  AttributeDetails vertexAttribute;
60 
61  ref_ptr<const vec3Array> vertices;
62  ref_ptr<vec3Array> proxy_vertices;
63 
64  DataList arrays;
65 
66  bool getAttributeDetails(const VertexInputState& vas, uint32_t location, AttributeDetails& attributeDetails);
67 
68  using ConstVisitor::apply;
69 
70  void apply(const BindGraphicsPipeline& bpg) override;
71  void apply(const VertexInputState& vas) override;
72  void apply(const InputAssemblyState& ias) override;
73 
74  void apply(const Geometry& geometry) override;
75  void apply(const VertexIndexDraw& vid) override;
76  void apply(const BindVertexBuffers& bvb) override;
77  void apply(const BufferInfo& bufferInfo) override;
78 
79  void apply(const vec3Array& array) override;
80  void apply(const Data& array) override;
81 
82  virtual void applyArrays(uint32_t firstBinding, const BufferInfoList& in_arrays);
83  virtual void applyArrays(uint32_t firstBinding, const DataList& in_arrays);
84  virtual ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex);
85 
86  protected:
87  virtual ~ArrayState() {}
88  };
89  VSG_type_name(vsg::ArrayState);
90 
95  class VSG_DECLSPEC NullArrayState : public Inherit<ArrayState, NullArrayState>
96  {
97  public:
99  explicit NullArrayState(const ArrayState& as);
100 
102  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
103 
104  using ArrayState::apply;
105 
106  void apply(const vec3Array&) override;
107  void apply(const Data&) override;
108  };
109  VSG_type_name(vsg::NullArrayState);
110 
112  class VSG_DECLSPEC PositionArrayState : public Inherit<ArrayState, PositionArrayState>
113  {
114  public:
117  explicit PositionArrayState(const ArrayState& rhs);
118 
120  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
121 
122  uint32_t position_attribute_location = 4;
123  AttributeDetails positionAttribute;
124 
125  using ArrayState::apply;
126 
127  void apply(const VertexInputState& vas) override;
128  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
129  };
130  VSG_type_name(vsg::PositionArrayState);
131 
133  class VSG_DECLSPEC DisplacementMapArrayState : public Inherit<ArrayState, DisplacementMapArrayState>
134  {
135  public:
138  explicit DisplacementMapArrayState(const ArrayState& rhs);
139 
141  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
142 
143  // binding of displacement map
144  uint32_t normal_attribute_location = 1;
145  uint32_t texcoord_attribute_location = 2;
146  uint32_t dm_set = 0;
147  uint32_t dm_binding = 6;
148 
149  // displacement map found during traversal
150  ref_ptr<floatArray2D> displacementMap;
151  ref_ptr<Sampler> sampler;
152  AttributeDetails normalAttribute;
153  AttributeDetails texcoordAttribute;
154 
155  using ArrayState::apply;
156 
157  void apply(const DescriptorImage& di) override;
158  void apply(const DescriptorSet& ds) override;
159  void apply(const BindDescriptorSet& bds) override;
160  void apply(const BindDescriptorSets& bds) override;
161  void apply(const VertexInputState& vas) override;
162  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
163  };
164  VSG_type_name(vsg::DisplacementMapArrayState);
165 
167  class VSG_DECLSPEC PositionAndDisplacementMapArrayState : public Inherit<DisplacementMapArrayState, PositionAndDisplacementMapArrayState>
168  {
169  public:
173 
174  uint32_t position_attribute_location = 4;
175  AttributeDetails positionAttribute;
176 
178  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
179 
180  void apply(const VertexInputState& vas) override;
181  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
182  };
184 
186  class VSG_DECLSPEC BillboardArrayState : public Inherit<ArrayState, BillboardArrayState>
187  {
188  public:
191  explicit BillboardArrayState(const ArrayState& rhs);
192 
194  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
195 
196  uint32_t position_attribute_location = 4;
197  AttributeDetails positionAttribute;
198 
199  using ArrayState::apply;
200 
201  void apply(const VertexInputState& vas) override;
202  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
203  };
204  VSG_type_name(vsg::BillboardArrayState);
205 
206 } // namespace vsg
Definition: ArrayState.h:28
virtual ref_ptr< ArrayState > clone()
clone self
Definition: ArrayState.h:34
BillboardArrayState is ArrayState subclass for mapping vertex array data for billboard instanced geom...
Definition: ArrayState.h:187
ref_ptr< ArrayState > clone() override
clone self
Definition: BindDescriptorSet.h:90
BindDescriptorSets state command encapsulates vkCmdBindDescriptorSets call and associated settings fo...
Definition: BindDescriptorSet.h:25
BindGraphicsPipeline state command encapsulates the vkCmdBindPipeline call for a GraphicsPipeline.
Definition: GraphicsPipeline.h:93
BindVertexBuffers command encapsulates vkBindVertexBuffers call and associated settings.
Definition: BindVertexBuffers.h:25
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition: BufferInfo.h:27
Definition: Data.h:104
Definition: DescriptorImage.h:24
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition: DescriptorSet.h:26
DisplacementMapArrayState is ArrayState subclass for mapping vertex array data for displacement mappe...
Definition: ArrayState.h:134
ref_ptr< ArrayState > clone() override
clone self
Definition: Geometry.h:30
Definition: Inherit.h:28
InputAssemblyState encapsulates to VkPipelineInputAssemblyStateCreateInfo settings passed when settin...
Definition: InputAssemblyState.h:22
Definition: ArrayState.h:96
ref_ptr< ArrayState > clone() override
clone self
PositionAndDisplacementMapArrayState is ArrayState subclass for mapping vertex array data for instanc...
Definition: ArrayState.h:168
ref_ptr< ArrayState > clone() override
clone self
PositionArrayState is ArrayState subclass for mapping vertex array data for instanced geometries.
Definition: ArrayState.h:113
ref_ptr< ArrayState > clone() override
clone self
Definition: VertexIndexDraw.h:25
VertexInputState encapsulates to VkPipelineVertexInputStateCreateInfo settings passed when setting up...
Definition: VertexInputState.h:22
Definition: ref_ptr.h:22
Definition: ArrayState.h:46