[spline/bezier]Improve template parameter dispatch method.

# Conflicts:
#	GPU/Common/SplineCommon.h
This commit is contained in:
xebra 2018-02-01 20:33:17 +09:00
parent f7ac70858d
commit da1176f2b3
2 changed files with 54 additions and 39 deletions

View file

@ -69,3 +69,40 @@ enum SplineQuality {
bool CanUseHardwareTessellation(GEPatchPrimType prim);
void TessellateSplinePatch(u8 *&dest, u16 *indices, int &count, const SplinePatchLocal &spatch, u32 origVertType, int maxVertices);
void TessellateBezierPatch(u8 *&dest, u16 *&indices, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType, int maxVertices);
#define TEMPLATE_PARAMETER_DISPATCHER(NAME, FUNCNAME) \
template<typename Func, int NumParams> \
class TemplateParameterDispatcher##NAME { \
/* Store all combinations of template functions into an array */ \
template<int LoopCount, int Index = 0, bool ...Params> \
struct Initializer { \
Initializer(Func funcs[]) { \
Initializer<LoopCount - 1, (Index << 1) + 1, true, Params...> _true(funcs); \
Initializer<LoopCount - 1, (Index << 1) + 0, false, Params...> _false(funcs); \
} \
}; \
/* Specialized for terminates the recursive loop */ \
template<int Index, bool ...Params> \
struct Initializer<0, Index, Params...> { \
Initializer(Func funcs[]) { \
funcs[Index] = &FUNCNAME<Params...>; \
} \
}; \
\
private: \
Func funcs[1 << NumParams]; /* Function pointers array */ \
public: \
TemplateParameterDispatcher##NAME() { \
Initializer<NumParams>::Initializer(funcs); \
} \
\
Func GetFunc(const bool params[]) const { \
/* Convert bool parameters to index of the array */ \
int param = 0; \
for (int i = 0; i < NumParams; ++i) \
param |= params[i] << i; \
\
return funcs[param]; \
} \
};