Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/vsg/core/Inherit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ namespace vsg

/// Inherit<> uses the Curiously Recurring Template Pattern
/// to provide the classes versions of create, accept(..), RTTI and sizeofObject()
/// There's a layer of indirection to allow subclass-specific specialisation without copying and pasting everything
template<class ParentClass, class Subclass>
class Inherit : public ParentClass
class InheritBase : public ParentClass
{
public:
template<typename... Args>
Inherit(Args&&... args) :
ParentClass(std::forward<Args>(args)...) {}
using ParentClass::ParentClass;

template<typename... Args>
static ref_ptr<Subclass> create(Args&&... args)
Expand Down Expand Up @@ -72,4 +71,10 @@ namespace vsg
void accept(RecordTraversal& visitor) const override { visitor.apply(static_cast<const Subclass&>(*this)); }
};

template<class ParentClass, class Subclass, class Enable = void>
class Inherit : public InheritBase<ParentClass, Subclass>
{
using InheritBase<ParentClass, Subclass>::InheritBase;
};

} // namespace vsg
41 changes: 22 additions & 19 deletions include/vsg/state/ArrayState.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ namespace vsg
};
VSG_type_name(vsg::ArrayState);

template<class ParentClass, class Subclass>
class Inherit<ParentClass, Subclass, typename std::enable_if_t<std::is_base_of_v<ArrayState, ParentClass>>> : public InheritBase<ParentClass, Subclass>
{
public:
using InheritBase<ParentClass, Subclass>::InheritBase;

explicit Inherit(const ArrayState& rhs, const CopyOp& copyop = {}) :
InheritBase<ParentClass, Subclass>(rhs, copyop)
{}

ref_ptr<ArrayState> cloneArrayState() override
{
return Subclass::create(static_cast<Subclass&>(*this));
}

ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override
{
return Subclass::create(static_cast<Subclass&>(*arrayState));
}
};

/// NullArrayState provides a mechanism for geometry in a subgraph to be ignored by traversals that use ArrayState such as ComputeBounds/Intersector/LineSegmentIntersector
/// this is useful for subgraphs that have custom shaders that move the final rendered geometry to a different place that would be naively interpreted by a straight forward vec3Array vertex array in local coordinates.
/// To disable the handling of geometry in a subgraph simply assign a NullArrayState to the StateGroup::prototypeArrayState, i.e.
Expand All @@ -106,9 +127,6 @@ namespace vsg
NullArrayState();
explicit NullArrayState(const ArrayState& as);

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;

using ArrayState::apply;

void apply(const vec3Array&) override;
Expand All @@ -124,9 +142,6 @@ namespace vsg
TranslationArrayState(const TranslationArrayState& rhs);
explicit TranslationArrayState(const ArrayState& rhs);

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;

uint32_t translation_attribute_location = 7;
AttributeDetails translationAttribute;

Expand All @@ -145,9 +160,6 @@ namespace vsg
TranslationRotationScaleArrayState(const TranslationRotationScaleArrayState& rhs);
explicit TranslationRotationScaleArrayState(const ArrayState& rhs);

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;

uint32_t translation_attribute_location = 7;
uint32_t rotation_attribute_location = 8;
uint32_t scale_attribute_location = 9;
Expand All @@ -168,10 +180,7 @@ namespace vsg
public:
DisplacementMapArrayState();
DisplacementMapArrayState(const DisplacementMapArrayState& rhs);
explicit DisplacementMapArrayState(const ArrayState& rhs);

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;
explicit DisplacementMapArrayState(const ArrayState& rhs, const CopyOp& copyop = {});

// binding of displacement map
uint32_t normal_attribute_location = 1;
Expand Down Expand Up @@ -207,9 +216,6 @@ namespace vsg
uint32_t translation_attribute_location = 7;
AttributeDetails translationAttribute;

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;

void apply(const VertexInputState& vas) override;
ref_ptr<const vec3Array> vertexArray(uint32_t instanceIndex) override;
};
Expand All @@ -223,9 +229,6 @@ namespace vsg
BillboardArrayState(const BillboardArrayState& rhs);
explicit BillboardArrayState(const ArrayState& rhs);

ref_ptr<ArrayState> cloneArrayState() override;
ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override;

uint32_t translation_attribute_location = 7;
AttributeDetails translationAttribute;

Expand Down
65 changes: 2 additions & 63 deletions src/vsg/state/ArrayState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,6 @@ NullArrayState::NullArrayState(const ArrayState& as) :
vertices = {};
}

ref_ptr<ArrayState> NullArrayState::cloneArrayState()
{
return NullArrayState::create(*this);
}

// clone the specified ArrayState
ref_ptr<ArrayState> NullArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return NullArrayState::create(*arrayState);
}

void NullArrayState::apply(const vsg::vec3Array&)
{
vertices = {};
Expand Down Expand Up @@ -260,16 +249,6 @@ TranslationArrayState::TranslationArrayState(const ArrayState& rhs) :
{
}

ref_ptr<ArrayState> TranslationArrayState::cloneArrayState()
{
return TranslationArrayState::create(*this);
}

ref_ptr<ArrayState> TranslationArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return TranslationArrayState::create(*arrayState);
}

void TranslationArrayState::apply(const VertexInputState& vas)
{
getAttributeDetails(vas, vertex_attribute_location, vertexAttribute);
Expand Down Expand Up @@ -315,16 +294,6 @@ TranslationRotationScaleArrayState::TranslationRotationScaleArrayState(const Arr
{
}

ref_ptr<ArrayState> TranslationRotationScaleArrayState::cloneArrayState()
{
return TranslationRotationScaleArrayState::create(*this);
}

ref_ptr<ArrayState> TranslationRotationScaleArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return TranslationRotationScaleArrayState::create(*arrayState);
}

void TranslationRotationScaleArrayState::apply(const VertexInputState& vas)
{
getAttributeDetails(vas, vertex_attribute_location, vertexAttribute);
Expand Down Expand Up @@ -373,21 +342,11 @@ DisplacementMapArrayState::DisplacementMapArrayState(const DisplacementMapArrayS
{
}

DisplacementMapArrayState::DisplacementMapArrayState(const ArrayState& rhs) :
Inherit(rhs)
DisplacementMapArrayState::DisplacementMapArrayState(const ArrayState& rhs, const CopyOp& copyop ) :
Inherit(rhs, copyop)
{
}

ref_ptr<ArrayState> DisplacementMapArrayState::cloneArrayState()
{
return DisplacementMapArrayState::create(*this);
}

ref_ptr<ArrayState> DisplacementMapArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return DisplacementMapArrayState::create(*arrayState);
}

void DisplacementMapArrayState::apply(const DescriptorImage& di)
{
if (!di.imageInfoList.empty())
Expand Down Expand Up @@ -485,16 +444,6 @@ TranslationAndDisplacementMapArrayState::TranslationAndDisplacementMapArrayState
{
}

ref_ptr<ArrayState> TranslationAndDisplacementMapArrayState::cloneArrayState()
{
return TranslationAndDisplacementMapArrayState::create(*this);
}

ref_ptr<ArrayState> TranslationAndDisplacementMapArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return TranslationAndDisplacementMapArrayState::create(*arrayState);
}

void TranslationAndDisplacementMapArrayState::apply(const VertexInputState& vas)
{
getAttributeDetails(vas, vertex_attribute_location, vertexAttribute);
Expand Down Expand Up @@ -562,16 +511,6 @@ BillboardArrayState::BillboardArrayState(const ArrayState& rhs) :
{
}

ref_ptr<ArrayState> BillboardArrayState::cloneArrayState()
{
return BillboardArrayState::create(*this);
}

ref_ptr<ArrayState> BillboardArrayState::cloneArrayState(ref_ptr<ArrayState> arrayState)
{
return BillboardArrayState::create(*arrayState);
}

void BillboardArrayState::apply(const VertexInputState& vas)
{
getAttributeDetails(vas, vertex_attribute_location, vertexAttribute);
Expand Down
5 changes: 1 addition & 4 deletions src/vsg/text/CpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class VSG_DECLSPEC CpuLayoutTechniqueArrayState : public Inherit<ArrayState, Cpu
{
}

ref_ptr<ArrayState> cloneArrayState() override
{
return CpuLayoutTechniqueArrayState::create(*this);
}
using Inherit::cloneArrayState;

ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override
{
Expand Down
5 changes: 1 addition & 4 deletions src/vsg/text/GpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ class VSG_DECLSPEC GpuLayoutTechniqueArrayState : public Inherit<ArrayState, Gpu
{
}

ref_ptr<ArrayState> cloneArrayState() override
{
return GpuLayoutTechniqueArrayState::create(*this);
}
using Inherit::cloneArrayState;

ref_ptr<ArrayState> cloneArrayState(ref_ptr<ArrayState> arrayState) override
{
Expand Down
Loading