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

vsg 1.1.8 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 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:
99 NullArrayState();
100 explicit NullArrayState(const ArrayState& as);
101
102 ref_ptr<ArrayState> cloneArrayState() override;
103 ref_ptr<ArrayState> cloneArrayState(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:
116 PositionArrayState();
117 PositionArrayState(const PositionArrayState& rhs);
118 explicit PositionArrayState(const ArrayState& rhs);
119
120 ref_ptr<ArrayState> cloneArrayState() override;
121 ref_ptr<ArrayState> cloneArrayState(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:
137 DisplacementMapArrayState();
138 DisplacementMapArrayState(const DisplacementMapArrayState& rhs);
139 explicit DisplacementMapArrayState(const ArrayState& rhs);
140
141 ref_ptr<ArrayState> cloneArrayState() override;
142 ref_ptr<ArrayState> cloneArrayState(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:
171 PositionAndDisplacementMapArrayState();
172 PositionAndDisplacementMapArrayState(const PositionAndDisplacementMapArrayState& rhs);
173 explicit PositionAndDisplacementMapArrayState(const ArrayState& rhs);
174
175 uint32_t position_attribute_location = 4;
176 AttributeDetails positionAttribute;
177
178 ref_ptr<ArrayState> cloneArrayState() override;
179 ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
180
181 void apply(const VertexInputState& vas) override;
182 ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
183 };
184 VSG_type_name(vsg::PositionAndDisplacementMapArrayState);
185
187 class VSG_DECLSPEC BillboardArrayState : public Inherit<ArrayState, BillboardArrayState>
188 {
189 public:
190 BillboardArrayState();
191 BillboardArrayState(const BillboardArrayState& rhs);
192 explicit BillboardArrayState(const ArrayState& rhs);
193
194 ref_ptr<ArrayState> cloneArrayState() override;
195 ref_ptr<ArrayState> cloneArrayState(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
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:188
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:109
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:110
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:135
vsg::DisplacementMapArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::Geometry
Definition Geometry.h:30
vsg::Inherit
Definition Inherit.h:28
vsg::InputAssemblyState
InputAssemblyState encapsulates VkPipelineInputAssemblyStateCreateInfo settings passed when setting u...
Definition InputAssemblyState.h:22
vsg::NullArrayState
Definition ArrayState.h:97
vsg::NullArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::PositionAndDisplacementMapArrayState
PositionAndDisplacementMapArrayState is an ArrayState subclass for mapping vertex array data for inst...
Definition ArrayState.h:169
vsg::PositionAndDisplacementMapArrayState::cloneArrayState
ref_ptr< ArrayState > cloneArrayState() override
clone self
vsg::PositionArrayState
PositionArrayState is an ArrayState subclass for mapping vertex array data for instanced geometries.
Definition ArrayState.h:114
vsg::PositionArrayState::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