vsg: include/vsg/state/ArrayState.h Source File

vsg 1.1.13 VulkanSceneGraph library

Loading...
Searching...
No Matches
ArrayState.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2020 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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
21namespace vsg
22{
23
27 class VSG_DECLSPEC ArrayState : public Inherit<ConstVisitor, ArrayState>
28 {
29 public:
30 ArrayState() = default;
31 ArrayState(const ArrayState& rhs, const CopyOp& copyop = {});
32
34 virtual ref_ptr<ArrayState> cloneArrayState()
35 {
36 return ArrayState::create(*this);
37 }
38
39 // clone the specified ArrayState
40 virtual ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState)
41 {
42 return ArrayState::create(*arrayState);
43 }
44
45 struct AttributeDetails
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 InstanceNode& in) override;
78 void apply(const InstanceDraw& id) override;
79 void apply(const InstanceDrawIndexed& id) override;
80 void apply(const BindVertexBuffers& bvb) override;
81 void apply(const BufferInfo& bufferInfo) override;
82
83 void apply(const vec3Array& array) override;
84 void apply(const Data& array) override;
85
86 virtual void applyArrays(uint32_t firstBinding, const BufferInfoList& in_arrays);
87 virtual void applyArrays(uint32_t firstBinding, const DataList& in_arrays);
88
89 virtual void applyArray(uint32_t binding, const ref_ptr<BufferInfo>& in_array);
90 virtual void applyArray(uint32_t binding, const ref_ptr<Data>& in_array);
91
92 virtual ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex);
93
94 protected:
95 virtual ~ArrayState() {}
96 };
97 VSG_type_name(vsg::ArrayState);
98
103 class VSG_DECLSPEC NullArrayState : public Inherit<ArrayState, NullArrayState>
104 {
105 public:
106 NullArrayState();
107 explicit NullArrayState(const ArrayState& as);
108
109 ref_ptr<ArrayState> cloneArrayState() override;
110 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
111
112 using ArrayState::apply;
113
114 void apply(const vec3Array&) override;
115 void apply(const Data&) override;
116 };
117 VSG_type_name(vsg::NullArrayState);
118
120 class VSG_DECLSPEC TranslationArrayState : public Inherit<ArrayState, TranslationArrayState>
121 {
122 public:
123 TranslationArrayState();
124 TranslationArrayState(const TranslationArrayState& rhs);
125 explicit TranslationArrayState(const ArrayState& rhs);
126
127 ref_ptr<ArrayState> cloneArrayState() override;
128 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
129
130 uint32_t translation_attribute_location = 7;
131 AttributeDetails translationAttribute;
132
133 using ArrayState::apply;
134
135 void apply(const VertexInputState& vas) override;
136 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
137 };
138 VSG_type_name(vsg::TranslationArrayState);
139
141 class VSG_DECLSPEC TranslationRotationScaleArrayState : public Inherit<ArrayState, TranslationRotationScaleArrayState>
142 {
143 public:
144 TranslationRotationScaleArrayState();
145 TranslationRotationScaleArrayState(const TranslationRotationScaleArrayState& rhs);
146 explicit TranslationRotationScaleArrayState(const ArrayState& rhs);
147
148 ref_ptr<ArrayState> cloneArrayState() override;
149 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
150
151 uint32_t translation_attribute_location = 7;
152 uint32_t rotation_attribute_location = 8;
153 uint32_t scale_attribute_location = 9;
154 AttributeDetails translationAttribute;
155 AttributeDetails rotationAttribute;
156 AttributeDetails scaleAttribute;
157
158 using ArrayState::apply;
159
160 void apply(const VertexInputState& vas) override;
161 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
162 };
163 VSG_type_name(vsg::TranslationRotationScaleArrayState);
164
166 class VSG_DECLSPEC DisplacementMapArrayState : public Inherit<ArrayState, DisplacementMapArrayState>
167 {
168 public:
169 DisplacementMapArrayState();
170 DisplacementMapArrayState(const DisplacementMapArrayState& rhs);
171 explicit DisplacementMapArrayState(const ArrayState& rhs);
172
173 ref_ptr<ArrayState> cloneArrayState() override;
174 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
175
176 // binding of displacement map
177 uint32_t normal_attribute_location = 1;
178 uint32_t texcoord_attribute_location = 2;
179 uint32_t dm_set = 0;
180 uint32_t dm_binding = 7;
181
182 // displacement map found during traversal
183 ref_ptr<floatArray2D> displacementMap;
184 ref_ptr<Sampler> sampler;
185 AttributeDetails normalAttribute;
186 AttributeDetails texcoordAttribute;
187
188 using ArrayState::apply;
189
190 void apply(const DescriptorImage& di) override;
191 void apply(const DescriptorSet& ds) override;
192 void apply(const BindDescriptorSet& bds) override;
193 void apply(const BindDescriptorSets& bds) override;
194 void apply(const VertexInputState& vas) override;
195 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
196 };
197 VSG_type_name(vsg::DisplacementMapArrayState);
198
200 class VSG_DECLSPEC TranslationAndDisplacementMapArrayState : public Inherit<DisplacementMapArrayState, TranslationAndDisplacementMapArrayState>
201 {
202 public:
203 TranslationAndDisplacementMapArrayState();
204 TranslationAndDisplacementMapArrayState(const TranslationAndDisplacementMapArrayState& rhs);
205 explicit TranslationAndDisplacementMapArrayState(const ArrayState& rhs);
206
207 uint32_t translation_attribute_location = 7;
208 AttributeDetails translationAttribute;
209
210 ref_ptr<ArrayState> cloneArrayState() override;
211 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
212
213 void apply(const VertexInputState& vas) override;
214 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
215 };
216 VSG_type_name(vsg::TranslationAndDisplacementMapArrayState);
217
219 class VSG_DECLSPEC BillboardArrayState : public Inherit<ArrayState, BillboardArrayState>
220 {
221 public:
222 BillboardArrayState();
223 BillboardArrayState(const BillboardArrayState& rhs);
224 explicit BillboardArrayState(const ArrayState& rhs);
225
226 ref_ptr<ArrayState> cloneArrayState() override;
227 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
228
229 uint32_t translation_attribute_location = 7;
230 AttributeDetails translationAttribute;
231
232 using ArrayState::apply;
233
234 void apply(const VertexInputState& vas) override;
235 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
236 };
237 VSG_type_name(vsg::BillboardArrayState);
238
239} // namespace vsg
vsg::ArrayState
Definition ArrayState.h:28
vsg::ArrayState::cloneArrayState
virtual ref_ptr< ArrayState > cloneArrayState()
clone self
Definition ArrayState.h:34
vsg::BillboardArrayState
BillboardArrayState is an ArrayState subclass for mapping vertex array data for billboard instanced g...
Definition ArrayState.h:220
vsg::BillboardArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::BindDescriptorSet
Definition BindDescriptorSet.h:92
vsg::BindDescriptorSets
BindDescriptorSets state command encapsulates vkCmdBindDescriptorSets call and associated settings fo...
Definition BindDescriptorSet.h:25
vsg::BindGraphicsPipeline
BindGraphicsPipeline state command encapsulates the vkCmdBindPipeline call for a GraphicsPipeline.
Definition GraphicsPipeline.h:111
vsg::BindVertexBuffers
BindVertexBuffers command encapsulates vkCmdBindVertexBuffers call and associated settings.
Definition BindVertexBuffers.h:25
vsg::BufferInfo
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition BufferInfo.h:27
vsg::CopyOp
Definition Object.h:42
vsg::Data
Definition Data.h:115
vsg::DescriptorImage
Definition DescriptorImage.h:24
vsg::DescriptorSet
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition DescriptorSet.h:26
vsg::DisplacementMapArrayState
DisplacementMapArrayState is an ArrayState subclass for mapping vertex array data for displacement ma...
Definition ArrayState.h:167
vsg::DisplacementMapArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::Geometry
Definition Geometry.h:30
vsg::InputAssemblyState
InputAssemblyState encapsulates VkPipelineInputAssemblyStateCreateInfo settings passed when setting u...
Definition InputAssemblyState.h:22
vsg::InstanceDraw
Definition InstanceDraw.h:25
vsg::InstanceDrawIndexed
Definition InstanceDrawIndexed.h:25
vsg::InstanceNode
Definition InstanceNode.h:34
vsg::NullArrayState
Definition ArrayState.h:104
vsg::NullArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::TranslationAndDisplacementMapArrayState
TranslationAndDisplacementMapArrayState is an ArrayState subclass for mapping vertex array data for i...
Definition ArrayState.h:201
vsg::TranslationAndDisplacementMapArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::TranslationArrayState
TranslationArrayState is an ArrayState subclass for mapping vertex array data for instanced geometrie...
Definition ArrayState.h:121
vsg::TranslationArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::TranslationRotationScaleArrayState
TranslationRotationScaleArrayState is an ArrayState subclass for mapping vertex array data for instan...
Definition ArrayState.h:142
vsg::TranslationRotationScaleArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::VertexDraw
Definition VertexDraw.h:25
vsg::VertexIndexDraw
Definition VertexIndexDraw.h:25
vsg::VertexInputState
VertexInputState encapsulates VkPipelineVertexInputStateCreateInfo settings passed when setting up Gr...
Definition VertexInputState.h:22
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::ArrayState::AttributeDetails
Definition ArrayState.h:46