vsg  1.1.0
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 VertexDraw& vid) override;
76  void apply(const VertexIndexDraw& vid) override;
77  void apply(const BindVertexBuffers& bvb) override;
78  void apply(const BufferInfo& bufferInfo) override;
79 
80  void apply(const vec3Array& array) override;
81  void apply(const Data& array) override;
82 
83  virtual void applyArrays(uint32_t firstBinding, const BufferInfoList& in_arrays);
84  virtual void applyArrays(uint32_t firstBinding, const DataList& in_arrays);
85  virtual ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex);
86 
87  protected:
88  virtual ~ArrayState() {}
89  };
90  VSG_type_name(vsg::ArrayState);
91 
96  class VSG_DECLSPEC NullArrayState : public Inherit<ArrayState, NullArrayState>
97  {
98  public:
100  explicit NullArrayState(const ArrayState& as);
101 
103  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
104 
105  using ArrayState::apply;
106 
107  void apply(const vec3Array&) override;
108  void apply(const Data&) override;
109  };
110  VSG_type_name(vsg::NullArrayState);
111 
113  class VSG_DECLSPEC PositionArrayState : public Inherit<ArrayState, PositionArrayState>
114  {
115  public:
118  explicit PositionArrayState(const ArrayState& rhs);
119 
121  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
122 
123  uint32_t position_attribute_location = 4;
124  AttributeDetails positionAttribute;
125 
126  using ArrayState::apply;
127 
128  void apply(const VertexInputState& vas) override;
129  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
130  };
131  VSG_type_name(vsg::PositionArrayState);
132 
134  class VSG_DECLSPEC DisplacementMapArrayState : public Inherit<ArrayState, DisplacementMapArrayState>
135  {
136  public:
139  explicit DisplacementMapArrayState(const ArrayState& rhs);
140 
142  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
143 
144  // binding of displacement map
145  uint32_t normal_attribute_location = 1;
146  uint32_t texcoord_attribute_location = 2;
147  uint32_t dm_set = 0;
148  uint32_t dm_binding = 6;
149 
150  // displacement map found during traversal
151  ref_ptr<floatArray2D> displacementMap;
152  ref_ptr<Sampler> sampler;
153  AttributeDetails normalAttribute;
154  AttributeDetails texcoordAttribute;
155 
156  using ArrayState::apply;
157 
158  void apply(const DescriptorImage& di) override;
159  void apply(const DescriptorSet& ds) override;
160  void apply(const BindDescriptorSet& bds) override;
161  void apply(const BindDescriptorSets& bds) override;
162  void apply(const VertexInputState& vas) override;
163  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
164  };
165  VSG_type_name(vsg::DisplacementMapArrayState);
166 
168  class VSG_DECLSPEC PositionAndDisplacementMapArrayState : public Inherit<DisplacementMapArrayState, PositionAndDisplacementMapArrayState>
169  {
170  public:
174 
175  uint32_t position_attribute_location = 4;
176  AttributeDetails positionAttribute;
177 
179  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
180 
181  void apply(const VertexInputState& vas) override;
182  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
183  };
185 
187  class VSG_DECLSPEC BillboardArrayState : public Inherit<ArrayState, BillboardArrayState>
188  {
189  public:
192  explicit BillboardArrayState(const ArrayState& rhs);
193 
195  ref_ptr<ArrayState> clone(ref_ptr<ArrayState> arrayState) override;
196 
197  uint32_t position_attribute_location = 4;
198  AttributeDetails positionAttribute;
199 
200  using ArrayState::apply;
201 
202  void apply(const VertexInputState& vas) override;
203  ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
204  };
205  VSG_type_name(vsg::BillboardArrayState);
206 
207 } // namespace vsg
Definition: ArrayState.h:28
virtual ref_ptr< ArrayState > clone()
clone self
Definition: ArrayState.h:34
BillboardArrayState is an ArrayState subclass for mapping vertex array data for billboard instanced g...
Definition: ArrayState.h:188
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:105
BindVertexBuffers command encapsulates vkCmdBindVertexBuffers call and associated settings.
Definition: BindVertexBuffers.h:25
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition: BufferInfo.h:27
Definition: Data.h:110
Definition: DescriptorImage.h:24
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition: DescriptorSet.h:26
DisplacementMapArrayState is an ArrayState subclass for mapping vertex array data for displacement ma...
Definition: ArrayState.h:135
ref_ptr< ArrayState > clone() override
clone self
Definition: Geometry.h:30
Definition: Inherit.h:28
InputAssemblyState encapsulates VkPipelineInputAssemblyStateCreateInfo settings passed when setting u...
Definition: InputAssemblyState.h:22
Definition: ArrayState.h:97
ref_ptr< ArrayState > clone() override
clone self
PositionAndDisplacementMapArrayState is an ArrayState subclass for mapping vertex array data for inst...
Definition: ArrayState.h:169
ref_ptr< ArrayState > clone() override
clone self
PositionArrayState is an ArrayState subclass for mapping vertex array data for instanced geometries.
Definition: ArrayState.h:114
ref_ptr< ArrayState > clone() override
clone self
Definition: VertexDraw.h:25
Definition: VertexIndexDraw.h:25
VertexInputState encapsulates VkPipelineVertexInputStateCreateInfo settings passed when setting up Gr...
Definition: VertexInputState.h:22
Definition: ref_ptr.h:22
Definition: ArrayState.h:46