Skip to content

Commit 1ecb45f

Browse files
author
devsh
committed
Generalize fixed-N Ngon List indexings
1 parent 193e82e commit 1ecb45f

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

include/nbl/asset/IPolygonGeometry.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ class IPolygonGeometryBase : public virtual core::IReferenceCounted
8888
virtual uint8_t rate_impl() const = 0;
8989
};
9090
//
91-
NBL_API2 static IIndexingCallback* PointList();
92-
NBL_API2 static IIndexingCallback* LineList();
93-
NBL_API2 static IIndexingCallback* TriangleList();
94-
NBL_API2 static IIndexingCallback* QuadList();
91+
static inline IIndexingCallback* PointList() {return NGonList(1);}
92+
static inline IIndexingCallback* LineList() {return NGonList(2);}
93+
static inline IIndexingCallback* TriangleList() {return NGonList(3);}
94+
static inline IIndexingCallback* QuadList() {return NGonList(4);}
95+
//
96+
NBL_API2 static IIndexingCallback* NGonList(const uint8_t n);
9597
// TODO: Adjacency, Patch, etc.
9698
NBL_API2 static IIndexingCallback* TriangleStrip();
9799
NBL_API2 static IIndexingCallback* TriangleFan();
98100

101+
99102
// This should be a pointer to a stateless singleton (think of it more like a dynamic enum/template than anything else)
100103
inline const IIndexingCallback* getIndexingCallback() const {return m_indexing;}
101104

src/nbl/asset/ICPUPolygonGeometry.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,20 @@ class CListIndexingCB final : public IPolygonGeometryBase::IIndexingCallback
3939
}
4040
}
4141
};
42-
auto IPolygonGeometryBase::PointList() -> IIndexingCallback*
42+
#include <boost/preprocessor/arithmetic/add.hpp>
43+
auto IPolygonGeometryBase::NGonList(const uint8_t n)-> IIndexingCallback*
4344
{
44-
static CListIndexingCB<1> singleton;
45-
return &singleton;
46-
}
47-
auto IPolygonGeometryBase::LineList() -> IIndexingCallback*
48-
{
49-
static CListIndexingCB<2> singleton;
50-
return &singleton;
51-
}
52-
auto IPolygonGeometryBase::TriangleList() -> IIndexingCallback*
53-
{
54-
static CListIndexingCB<3> singleton;
55-
return &singleton;
56-
}
57-
auto IPolygonGeometryBase::QuadList() -> IIndexingCallback*
58-
{
59-
static CListIndexingCB<4> singleton;
60-
return &singleton;
45+
#define DECL(z, n, text) text<n+1> singleton_ ## n;
46+
BOOST_PP_REPEAT(255,DECL,static CListIndexingCB)
47+
#undef DECL
48+
switch (n)
49+
{
50+
#define CASE(z, n, text) text BOOST_PP_ADD(n,1): return &singleton_ ## n;
51+
BOOST_PP_REPEAT(255,CASE,case)
52+
#undef CASE
53+
default:
54+
return nullptr;
55+
}
6156
}
6257

6358
class CTriangleStripIndexingCB final : public IPolygonGeometryBase::IIndexingCallback

0 commit comments

Comments
 (0)