1+ // Copyright (C) 2025-2025 - DevSH Graphics Programming Sp. z O.O.
2+ // This file is part of the "Nabla Engine".
3+ // For conditions of distribution and use, see copyright notice in nabla.h
4+ #ifndef _NBL_ASSET_I_CPU_POLYGON_GEOMETRY_H_INCLUDED_
5+ #define _NBL_ASSET_I_CPU_POLYGON_GEOMETRY_H_INCLUDED_
6+
7+
8+ #include " nbl/asset/IPolygonGeometry.h"
9+
10+
11+ namespace nbl ::asset
12+ {
13+ //
14+ class NBL_API2 ICPUPolygonGeometry : public IAsset, public IPolygonGeometry<ICPUBuffer>
15+ {
16+ using base_t = IPolygonGeometry<ICPUBuffer>;
17+
18+ public:
19+ inline ICPUPolygonGeometry () = default;
20+
21+ constexpr static inline auto AssetType = ET_GEOMETRY;
22+ inline E_TYPE getAssetType () const override {return AssetType;}
23+
24+ inline core::smart_refctd_ptr<IAsset> clone (uint32_t _depth=~0u ) const
25+ {
26+ const auto nextDepth = _depth ? (_depth-1 ):0 ;
27+ auto retval = core::smart_refctd_ptr<ICPUPolygonGeometry>();
28+ retval->m_positionView = m_positionView.clone (nextDepth);
29+ retval->m_jointOBBView = m_jointOBBView.clone (nextDepth);
30+ retval->m_indexView = m_indexView.clone (nextDepth);
31+ retval->m_jointWeightViews .reserve (m_jointWeightViews.size ());
32+ for (const auto & pair : m_jointWeightViews)
33+ retval->m_jointWeightViews .push_back ({
34+ .indices = pair.indices .clone (nextDepth),
35+ .weights = pair.weights .clone (nextDepth)
36+ });
37+ retval->m_auxAttributeViews .reserve (m_auxAttributeViews.size ());
38+ for (const auto & view : m_auxAttributeViews)
39+ retval->m_auxAttributeViews .push_back (view.clone (nextDepth));
40+ retval->m_normalView = m_normalView.clone (nextDepth);
41+ retval->m_jointCount = m_jointCount;
42+ retval->m_verticesForFirst = m_verticesForFirst;
43+ retval->m_verticesPerSupplementary = m_verticesPerSupplementary;
44+ return retval;
45+ }
46+
47+ // TODO: remove after https://github.com/Devsh-Graphics-Programming/Nabla/pull/871 merge
48+ inline size_t getDependantCount () const override
49+ {
50+ size_t count = 0 ;
51+ visitDependents ([¤t](const IAsset* dep)->bool
52+ {
53+ count++;
54+ return true ;
55+ }
56+ );
57+ return count;
58+ }
59+
60+ // needs to be hidden because of mutability checking
61+ inline bool setPositionView (SDataView&& view)
62+ {
63+ if (isMutable () && view.composed .isFormatted ())
64+ return base_t::setPositionView (std::move (view));
65+ return false ;
66+ }
67+
68+ //
69+ inline bool setJointOBBView (SDataView&& view)
70+ {
71+ if (isMutable ())
72+ return base_t::setJointOBBView (std::move (view));
73+ return false ;
74+ }
75+
76+ // Needs to be hidden because ICPU base class shall check mutability
77+ inline bool setIndexView (SDataView&& view)
78+ {
79+ if (isMutable ())
80+ return base_t::setIndexView (std::move (view));
81+ return false ;
82+ }
83+
84+ //
85+ inline bool setVerticesForFirst (const uint16_t count)
86+ {
87+ if (isMutable ())
88+ {
89+ m_verticesForFirst = count;
90+ return true ;
91+ }
92+ return false ;
93+ }
94+
95+ //
96+ inline bool setVerticesPerSupplementary (const uint16_t count)
97+ {
98+ if (isMutable ())
99+ {
100+ m_verticesPerSupplementary = count;
101+ return true ;
102+ }
103+ return false ;
104+ }
105+
106+ //
107+ inline void setNormalView (SDataView&& view)
108+ {
109+ if (isMutable ())
110+ {
111+ m_normalView = std::move (view);
112+ return true ;
113+ }
114+ return false ;
115+ }
116+
117+ //
118+ inline bool setJointCount (const uint32_t count)
119+ {
120+ if (isMutable ())
121+ {
122+ m_jointCount = count;
123+ return true ;
124+ }
125+ return false ;
126+ }
127+
128+ //
129+ inline const core::vector<SJointWeight>* getJointWeightViews ()
130+ {
131+ if (isMutable ())
132+ return m_jointWeightViews;
133+ return nullptr ;
134+ }
135+
136+ //
137+ inline const core::vector<SJointWeight>* getAuxAttributeViews ()
138+ {
139+ if (isMutable ())
140+ return m_auxAttributeViews;
141+ return nullptr ;
142+ }
143+
144+ protected:
145+ //
146+ inline void visitDependents (std::function<bool (const IAsset*)>& visit) const // override
147+ {
148+ visit (m_positionView.src .buffer .get ());
149+ visit (m_jointOBBView.src .buffer .get ());
150+ visit (m_indexView.src .buffer .get ());
151+ for (const auto & pair : m_jointWeightViews)
152+ {
153+ visit (pair.indices .src .buffer .get ());
154+ visit (pair.weights .src .buffer .get ());
155+ }
156+ for (const auto & view : m_auxAttributeViews)
157+ visit (view.src .buffer .get ());
158+ visit (m_normalView.src .buffer .get ());
159+ }
160+ // TODO: remove after https://github.com/Devsh-Graphics-Programming/Nabla/pull/871 merge
161+ inline IAsset* getDependant_impl (const size_t ix) override
162+ {
163+ const IAsset* retval = nullptr ;
164+ size_t current = 0 ;
165+ visitDependents ([¤t](const IAsset* dep)->bool
166+ {
167+ retval = dep;
168+ return ix<current++;
169+ }
170+ );
171+ return const_cast <IAsset*>(retval);
172+ }
173+ };
174+
175+ }
176+ #endif
0 commit comments