Skip to content

Commit 1b4f2ae

Browse files
committed
Created dedicated InstanceDraw and InstanceDrawIndexed.
1 parent 60e7e55 commit 1b4f2ae

File tree

15 files changed

+331
-89
lines changed

15 files changed

+331
-89
lines changed

include/vsg/all.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
6868
#include <vsg/nodes/Geometry.h>
6969
#include <vsg/nodes/Group.h>
7070
#include <vsg/nodes/InstanceDraw.h>
71+
#include <vsg/nodes/InstanceDrawIndexed.h>
7172
#include <vsg/nodes/InstanceNode.h>
7273
#include <vsg/nodes/InstrumentationNode.h>
7374
#include <vsg/nodes/LOD.h>

include/vsg/core/ConstVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace vsg
5353
class RegionOfInterest;
5454
class InstanceNode;
5555
class InstanceDraw;
56+
class InstanceDrawIndexed;
5657

5758
// forward declare text classes
5859
class Text;
@@ -358,6 +359,7 @@ namespace vsg
358359
virtual void apply(const RegionOfInterest&);
359360
virtual void apply(const InstanceNode&);
360361
virtual void apply(const InstanceDraw&);
362+
virtual void apply(const InstanceDrawIndexed&);
361363

362364
// text
363365
virtual void apply(const Text&);

include/vsg/core/Visitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace vsg
5353
class RegionOfInterest;
5454
class InstanceNode;
5555
class InstanceDraw;
56+
class InstanceDrawIndexed;
5657

5758
// forward declare text classes
5859
class Text;
@@ -358,6 +359,7 @@ namespace vsg
358359
virtual void apply(RegionOfInterest&);
359360
virtual void apply(InstanceNode&);
360361
virtual void apply(InstanceDraw&);
362+
virtual void apply(InstanceDrawIndexed&);
361363

362364
// text
363365
virtual void apply(Text&);

include/vsg/nodes/InstanceDraw.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1919
namespace vsg
2020
{
2121

22-
/** InstanceDraw provides a lightweight way of binding vertex arrays, indices and then issuing a vkCmdDrawIndexed command.
23-
* Higher performance equivalent to use of individual vsg::BindVertexBuffers, vsg::BindIndexBuffer and vsg::DrawIndexed commands.*/
22+
/** InstanceDraw provides a lightweight way of binding vertex arrays, indices and then issuing a vkCmdDraw command.
23+
* Higher performance equivalent to use of individual vsg::BindVertexBuffers, vsg::BindIndexBuffer and vsg::Draw commands.*/
2424
class VSG_DECLSPEC InstanceDraw : public Inherit<Command, InstanceDraw>
2525
{
2626
public:
2727
InstanceDraw();
2828
InstanceDraw(const InstanceDraw& rhs, const CopyOp& copyop = {});
2929

30-
// vkCmdDrawIndexed settings
31-
// vkCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
32-
uint32_t indexCount = 0;
33-
uint32_t firstIndex = 0;
34-
uint32_t vertexOffset = 0;
30+
// vkCmdDraw settings
31+
// vkCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
32+
uint32_t vertexCount = 0;
33+
uint32_t firstVertex = 0;
3534

3635
uint32_t firstBinding = 0;
3736
BufferInfoList arrays;
38-
ref_ptr<BufferInfo> indices;
3937

4038
void assignArrays(const DataList& in_arrays);
41-
void assignIndices(ref_ptr<Data> in_indices);
4239

4340
public:
4441
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return InstanceDraw::create(*this, copyop); }
@@ -52,9 +49,6 @@ namespace vsg
5249

5350
protected:
5451
virtual ~InstanceDraw();
55-
56-
vk_buffer<VulkanArrayData> _vulkanData;
57-
VkIndexType indexType = VK_INDEX_TYPE_UINT16;
5852
};
5953
VSG_type_name(vsg::InstanceDraw)
6054

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
/* <editor-fold desc="MIT License">
4+
5+
Copyright(c) 2018 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/commands/Command.h>
16+
#include <vsg/nodes/Node.h>
17+
#include <vsg/state/BufferInfo.h>
18+
19+
namespace vsg
20+
{
21+
22+
/** InstanceDrawIndexed provides a lightweight way of binding vertex arrays, indices and then issuing a vkCmdDrawIndexed command.
23+
* Higher performance equivalent to use of individual vsg::BindVertexBuffers, vsg::BindIndexBuffer and vsg::DrawIndexed commands.*/
24+
class VSG_DECLSPEC InstanceDrawIndexed : public Inherit<Command, InstanceDrawIndexed>
25+
{
26+
public:
27+
InstanceDrawIndexed();
28+
InstanceDrawIndexed(const InstanceDrawIndexed& rhs, const CopyOp& copyop = {});
29+
30+
// vkCmdDrawIndexed settings
31+
// vkCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
32+
uint32_t indexCount = 0;
33+
uint32_t firstIndex = 0;
34+
uint32_t vertexOffset = 0;
35+
36+
uint32_t firstBinding = 0;
37+
BufferInfoList arrays;
38+
ref_ptr<BufferInfo> indices;
39+
40+
void assignArrays(const DataList& in_arrays);
41+
void assignIndices(ref_ptr<Data> in_indices);
42+
43+
public:
44+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return InstanceDrawIndexed::create(*this, copyop); }
45+
int compare(const Object& rhs) const override;
46+
47+
void read(Input& input) override;
48+
void write(Output& output) const override;
49+
50+
void compile(Context& context) override;
51+
void record(CommandBuffer& commandBuffer) const override;
52+
53+
protected:
54+
virtual ~InstanceDrawIndexed();
55+
56+
VkIndexType indexType = VK_INDEX_TYPE_UINT16;
57+
};
58+
VSG_type_name(vsg::InstanceDrawIndexed)
59+
60+
} // namespace vsg

include/vsg/state/ArrayState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace vsg
7676
void apply(const VertexIndexDraw& vid) override;
7777
void apply(const InstanceNode& in) override;
7878
void apply(const InstanceDraw& id) override;
79+
void apply(const InstanceDrawIndexed& id) override;
7980
void apply(const BindVertexBuffers& bvb) override;
8081
void apply(const BufferInfo& bufferInfo) override;
8182

include/vsg/utils/ComputeBounds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace vsg
5656
void apply(const VertexIndexDraw& vid) override;
5757
void apply(const InstanceNode& in) override;
5858
void apply(const InstanceDraw& id) override;
59+
void apply(const InstanceDrawIndexed& id) override;
5960
void apply(const BindVertexBuffers& bvb) override;
6061
void apply(const BindIndexBuffer& bib) override;
6162
void apply(const StateCommand& statecommand) override;

src/vsg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(SOURCES
4949
nodes/RegionOfInterest.cpp
5050
nodes/InstanceNode.cpp
5151
nodes/InstanceDraw.cpp
52+
nodes/InstanceDrawIndexed.cpp
5253

5354
lighting/Light.cpp
5455
lighting/AmbientLight.cpp

src/vsg/core/ConstVisitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ void ConstVisitor::apply(const InstanceDraw& value)
685685
{
686686
apply(static_cast<const Command&>(value));
687687
}
688+
void ConstVisitor::apply(const InstanceDrawIndexed& value)
689+
{
690+
apply(static_cast<const Command&>(value));
691+
}
688692

689693
////////////////////////////////////////////////////////////////////////////////
690694
//

src/vsg/core/Visitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ void Visitor::apply(InstanceDraw& value)
685685
{
686686
apply(static_cast<Command&>(value));
687687
}
688+
void Visitor::apply(InstanceDrawIndexed& value)
689+
{
690+
apply(static_cast<Command&>(value));
691+
}
688692

689693
////////////////////////////////////////////////////////////////////////////////
690694
//

0 commit comments

Comments
 (0)