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
21 changes: 17 additions & 4 deletions include/vsg/core/Inherit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,29 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

namespace vsg
{
template<class ParentClass, class Subclass, class Enable = void>
struct InheritHelper
{
using Type = ParentClass;
};

template<class ParentClass, class Subclass>
struct InheritHelper<ParentClass, Subclass, typename ParentClass::template InheritExtras<ParentClass, Subclass>>
{
using Type = typename ParentClass::template InheritExtras<ParentClass, Subclass>;
};

/// Inherit<> uses the Curiously Recurring Template Pattern
/// to provide the classes versions of create, accept(..), RTTI and sizeofObject()
template<class ParentClass, class Subclass>
class Inherit : public ParentClass
class Inherit : public InheritHelper<ParentClass, Subclass>::Type
{
public:
using BaseClass = typename InheritHelper<ParentClass, Subclass>::Type;

template<typename... Args>
Inherit(Args&&... args) :
ParentClass(std::forward<Args>(args)...) {}
BaseClass(std::forward<Args>(args)...) {}

template<typename... Args>
static ref_ptr<Subclass> create(Args&&... args)
Expand All @@ -47,11 +60,11 @@ namespace vsg
std::size_t sizeofObject() const noexcept override { return sizeof(Subclass); }
const char* className() const noexcept override { return type_name<Subclass>(); }
const std::type_info& type_info() const noexcept override { return typeid(Subclass); }
bool is_compatible(const std::type_info& type) const noexcept override { return typeid(Subclass) == type || ParentClass::is_compatible(type); }
bool is_compatible(const std::type_info& type) const noexcept override { return typeid(Subclass) == type || BaseClass::is_compatible(type); }

int compare(const Object& rhs) const override
{
int result = ParentClass::compare(rhs);
int result = BaseClass::compare(rhs);
if (result != 0) return result;

size_t startOfSubclass = sizeof(ParentClass);
Expand Down
42 changes: 23 additions & 19 deletions include/vsg/state/ArrayState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ namespace vsg
class VSG_DECLSPEC ArrayState : public Inherit<ConstVisitor, ArrayState>
{
public:
template<class ParentClass, class Subclass>
class InheritExtras : public ParentClass
{
public:
using ParentClass::ParentClass;

explicit InheritExtras(const ArrayState& rhs, const CopyOp& copyop = {}) :
ParentClass(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));
}
};

ArrayState() = default;
ArrayState(const ArrayState& rhs, const CopyOp& copyop = {});

Expand Down Expand Up @@ -106,9 +128,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 +143,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 +161,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 +181,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 +217,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 +230,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