Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_attribute_access.hh2
-rw-r--r--source/blender/blenkernel/BKE_attribute_math.hh71
-rw-r--r--source/blender/blenkernel/BKE_customdata.h9
-rw-r--r--source/blender/blenkernel/intern/attribute_access.cc49
-rw-r--r--source/blender/blenkernel/intern/customdata.cc55
5 files changed, 81 insertions, 105 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 36f29c7fbb7..8d449a124ec 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -164,8 +164,6 @@ using AttributeForeachCallback = blender::FunctionRef<bool(
namespace blender::bke {
-const CPPType *custom_data_type_to_cpp_type(const CustomDataType type);
-CustomDataType cpp_type_to_custom_data_type(const CPPType &type);
CustomDataType attribute_data_type_highest_complexity(Span<CustomDataType> data_types);
/**
* Domains with a higher "information density" have a higher priority,
diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh
index 9e97979fde9..3075c0689e9 100644
--- a/source/blender/blenkernel/BKE_attribute_math.hh
+++ b/source/blender/blenkernel/BKE_attribute_math.hh
@@ -8,71 +8,34 @@
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
-#include "DNA_customdata_types.h"
+#include "BKE_customdata.h"
namespace blender::attribute_math {
/**
- * Utility function that simplifies calling a templated function based on a custom data type.
+ * Utility function that simplifies calling a templated function based on a run-time data type.
*/
template<typename Func>
-inline void convert_to_static_type(const CustomDataType data_type, const Func &func)
+inline void convert_to_static_type(const CPPType &cpp_type, const Func &func)
{
- switch (data_type) {
- case CD_PROP_FLOAT:
- func(float());
- break;
- case CD_PROP_FLOAT2:
- func(float2());
- break;
- case CD_PROP_FLOAT3:
- func(float3());
- break;
- case CD_PROP_INT32:
- func(int());
- break;
- case CD_PROP_BOOL:
- func(bool());
- break;
- case CD_PROP_INT8:
- func(int8_t());
- break;
- case CD_PROP_COLOR:
- func(ColorGeometry4f());
- break;
- default:
- BLI_assert_unreachable();
- break;
- }
+ cpp_type.to_static_type_tag<float, float2, float3, int, bool, int8_t, ColorGeometry4f>(
+ [&](auto type_tag) {
+ using T = typename decltype(type_tag)::type;
+ if constexpr (std::is_same_v<T, void>) {
+ /* It's expected that the given cpp type is one of the supported once. */
+ BLI_assert_unreachable();
+ }
+ else {
+ func(T());
+ }
+ });
}
template<typename Func>
-inline void convert_to_static_type(const CPPType &cpp_type, const Func &func)
+inline void convert_to_static_type(const CustomDataType data_type, const Func &func)
{
- if (cpp_type.is<float>()) {
- func(float());
- }
- else if (cpp_type.is<float2>()) {
- func(float2());
- }
- else if (cpp_type.is<float3>()) {
- func(float3());
- }
- else if (cpp_type.is<int>()) {
- func(int());
- }
- else if (cpp_type.is<bool>()) {
- func(bool());
- }
- else if (cpp_type.is<int8_t>()) {
- func(int8_t());
- }
- else if (cpp_type.is<ColorGeometry4f>()) {
- func(ColorGeometry4f());
- }
- else {
- BLI_assert_unreachable();
- }
+ const CPPType &cpp_type = *bke::custom_data_type_to_cpp_type(data_type);
+ convert_to_static_type(cpp_type, func);
}
/* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 940dc3c4f6c..911f4aab394 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -751,3 +751,12 @@ void CustomData_debug_info_from_layers(const struct CustomData *data,
#ifdef __cplusplus
}
#endif
+
+#ifdef __cplusplus
+# include "BLI_cpp_type.hh"
+
+namespace blender::bke {
+const CPPType *custom_data_type_to_cpp_type(const CustomDataType type);
+CustomDataType cpp_type_to_custom_data_type(const CPPType &type);
+} // namespace blender::bke
+#endif
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 50e35c3c7c2..8fbab8dde25 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -54,55 +54,6 @@ std::ostream &operator<<(std::ostream &stream, const AttributeIDRef &attribute_i
return stream;
}
-const blender::CPPType *custom_data_type_to_cpp_type(const CustomDataType type)
-{
- switch (type) {
- case CD_PROP_FLOAT:
- return &CPPType::get<float>();
- case CD_PROP_FLOAT2:
- return &CPPType::get<float2>();
- case CD_PROP_FLOAT3:
- return &CPPType::get<float3>();
- case CD_PROP_INT32:
- return &CPPType::get<int>();
- case CD_PROP_COLOR:
- return &CPPType::get<ColorGeometry4f>();
- case CD_PROP_BOOL:
- return &CPPType::get<bool>();
- case CD_PROP_INT8:
- return &CPPType::get<int8_t>();
- default:
- return nullptr;
- }
- return nullptr;
-}
-
-CustomDataType cpp_type_to_custom_data_type(const blender::CPPType &type)
-{
- if (type.is<float>()) {
- return CD_PROP_FLOAT;
- }
- if (type.is<float2>()) {
- return CD_PROP_FLOAT2;
- }
- if (type.is<float3>()) {
- return CD_PROP_FLOAT3;
- }
- if (type.is<int>()) {
- return CD_PROP_INT32;
- }
- if (type.is<ColorGeometry4f>()) {
- return CD_PROP_COLOR;
- }
- if (type.is<bool>()) {
- return CD_PROP_BOOL;
- }
- if (type.is<int8_t>()) {
- return CD_PROP_INT8;
- }
- return static_cast<CustomDataType>(-1);
-}
-
static int attribute_data_type_complexity(const CustomDataType data_type)
{
switch (data_type) {
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index b348e18a6a8..251d73dc315 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -18,9 +18,11 @@
#include "DNA_meshdata_types.h"
#include "BLI_bitmap.h"
+#include "BLI_color.hh"
#include "BLI_endian_switch.h"
#include "BLI_math.h"
#include "BLI_math_color_blend.h"
+#include "BLI_math_vector.hh"
#include "BLI_mempool.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
@@ -5234,3 +5236,56 @@ void CustomData_debug_info_from_layers(const CustomData *data, const char *inden
}
#endif /* NDEBUG */
+
+namespace blender::bke {
+
+const blender::CPPType *custom_data_type_to_cpp_type(const CustomDataType type)
+{
+ switch (type) {
+ case CD_PROP_FLOAT:
+ return &CPPType::get<float>();
+ case CD_PROP_FLOAT2:
+ return &CPPType::get<float2>();
+ case CD_PROP_FLOAT3:
+ return &CPPType::get<float3>();
+ case CD_PROP_INT32:
+ return &CPPType::get<int>();
+ case CD_PROP_COLOR:
+ return &CPPType::get<ColorGeometry4f>();
+ case CD_PROP_BOOL:
+ return &CPPType::get<bool>();
+ case CD_PROP_INT8:
+ return &CPPType::get<int8_t>();
+ default:
+ return nullptr;
+ }
+ return nullptr;
+}
+
+CustomDataType cpp_type_to_custom_data_type(const blender::CPPType &type)
+{
+ if (type.is<float>()) {
+ return CD_PROP_FLOAT;
+ }
+ if (type.is<float2>()) {
+ return CD_PROP_FLOAT2;
+ }
+ if (type.is<float3>()) {
+ return CD_PROP_FLOAT3;
+ }
+ if (type.is<int>()) {
+ return CD_PROP_INT32;
+ }
+ if (type.is<ColorGeometry4f>()) {
+ return CD_PROP_COLOR;
+ }
+ if (type.is<bool>()) {
+ return CD_PROP_BOOL;
+ }
+ if (type.is<int8_t>()) {
+ return CD_PROP_INT8;
+ }
+ return static_cast<CustomDataType>(-1);
+}
+
+} // namespace blender::bke