-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathICPUGeometryCollection.h
More file actions
120 lines (106 loc) · 4.35 KB
/
ICPUGeometryCollection.h
File metadata and controls
120 lines (106 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 2025-2025 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_ASSET_I_CPU_GEOMETRY_COLLECTION_H_INCLUDED_
#define _NBL_ASSET_I_CPU_GEOMETRY_COLLECTION_H_INCLUDED_
#include "nbl/asset/IAsset.h"
#include "nbl/asset/ICPUBuffer.h"
#include "nbl/asset/IGeometryCollection.h"
namespace nbl::asset
{
//
class NBL_API2 ICPUGeometryCollection : public IAsset, public IGeometryCollection<ICPUBuffer>
{
using base_t = IGeometryCollection<ICPUBuffer>;
public:
inline ICPUGeometryCollection() = default;
constexpr static inline auto AssetType = ET_GEOMETRY_COLLECTION;
inline E_TYPE getAssetType() const override {return AssetType;}
//
inline bool valid() const override
{
for (const auto& ref : m_geometries)
{
if (!ref.operator bool() || !ref.geometry->valid())
return false;
if (ref.jointRedirectView.src && ref.jointRedirectView.composed.getRange<hlsl::shapes::AABB<1,uint32_t>>().maxVx[0]>=getJointCount())
return false;
}
return true;
}
inline core::smart_refctd_ptr<IAsset> clone(uint32_t _depth=~0u) const override
{
const auto nextDepth = _depth ? (_depth-1):0;
auto retval = core::smart_refctd_ptr<ICPUGeometryCollection>();
retval->m_aabb = m_aabb;
retval->m_inverseBindPoseView = m_inverseBindPoseView.clone(nextDepth);
retval->m_jointAABBView = m_jointAABBView.clone(nextDepth);
retval->m_geometries.reserve(m_geometries.size());
for (const auto& in : m_geometries)
{
auto& out = retval->m_geometries.emplace_back();
out.transform = in.transform;
out.geometry = core::smart_refctd_ptr_static_cast<IGeometry<ICPUBuffer>>(in.geometry->clone(nextDepth));
out.jointRedirectView = in.jointRedirectView.clone(nextDepth);
}
return retval;
}
//
inline bool setAABB(const hlsl::shapes::AABB<3,hlsl::float64_t>& aabb)
{
if (isMutable())
{
m_aabb = aabb;
return true;
}
return false;
}
//
inline const core::vector<SGeometryReference>& getGeometries() const {return base_t::getGeometries();}
//
inline core::vector<SGeometryReference>* getGeometries()
{
if (isMutable())
return &m_geometries;
return nullptr;
}
//
inline bool setSkin(SDataView&& inverseBindPoseView, SDataView&& jointAABBView)
{
if (isMutable())
return setSkin(std::move(inverseBindPoseView),std::move(jointAABBView));
return false;
}
//
template<typename Iterator>// requires std::is_same_v<decltype(*declval<Iterator>()),decltype(ICPUBottomLevelAccelerationStructure::Triangles&)>
inline Iterator exportForBLAS(Iterator out, uint32_t* pWrittenOrdinals=nullptr) const
{
return exportForBLAS(std::forward<Iterator>(out),[this, &pWrittenOrdinals](hlsl::float32_t3x4& lhs, const hlsl::float32_t3x4& rhs)->void
{
lhs = rhs;
if (pWrittenOrdinals)
*(pWrittenOrdinals++) = (ptrdiff_t(&rhs)-offsetof(SGeometryReference,transform)-ptrdiff_t(base_t::m_geometries.data()))/sizeof(SGeometryReference);
}
);
}
protected:
//
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
{
auto nonNullOnly = [&visit](const IAsset* dep)->bool
{
if (dep)
return visit(dep);
return true;
};
if (!nonNullOnly(m_inverseBindPoseView.src.buffer.get())) return;
if (!nonNullOnly(m_jointAABBView.src.buffer.get())) return;
for (const auto& ref : m_geometries)
{
const auto* geometry = static_cast<const IAsset*>(ref.geometry.get());
if (!nonNullOnly(geometry)) return;
}
}
};
}
#endif