Geometry Nodes: add custom data type getter for attribute accessor

This is just an utility method, that avoids that the caller has to do
the conversion every time it is necessary.
This commit is contained in:
Jacques Lucke 2020-12-03 16:20:09 +01:00
parent 675d84826e
commit 2c181521ec
1 changed files with 23 additions and 2 deletions

View File

@ -31,6 +31,9 @@ namespace blender::bke {
using fn::CPPType;
const CPPType *custom_data_type_to_cpp_type(const CustomDataType type);
CustomDataType cpp_type_to_custom_data_type(const CPPType &type);
/**
* This class offers an indirection for reading an attribute.
* This is useful for the following reasons:
@ -47,6 +50,7 @@ class ReadAttribute {
protected:
const AttributeDomain domain_;
const CPPType &cpp_type_;
const CustomDataType custom_data_type_;
const int64_t size_;
/* Protects the span below, so that no two threads initialize it at the same time. */
@ -59,7 +63,10 @@ class ReadAttribute {
public:
ReadAttribute(AttributeDomain domain, const CPPType &cpp_type, const int64_t size)
: domain_(domain), cpp_type_(cpp_type), size_(size)
: domain_(domain),
cpp_type_(cpp_type),
custom_data_type_(cpp_type_to_custom_data_type(cpp_type)),
size_(size)
{
}
@ -75,6 +82,11 @@ class ReadAttribute {
return cpp_type_;
}
CustomDataType custom_data_type() const
{
return custom_data_type_;
}
int64_t size() const
{
return size_;
@ -104,6 +116,7 @@ class WriteAttribute {
protected:
const AttributeDomain domain_;
const CPPType &cpp_type_;
const CustomDataType custom_data_type_;
const int64_t size_;
/* When not null, this points either to the attribute array or to a temporary array. */
@ -115,7 +128,10 @@ class WriteAttribute {
public:
WriteAttribute(AttributeDomain domain, const CPPType &cpp_type, const int64_t size)
: domain_(domain), cpp_type_(cpp_type), size_(size)
: domain_(domain),
cpp_type_(cpp_type),
custom_data_type_(cpp_type_to_custom_data_type(cpp_type)),
size_(size)
{
}
@ -131,6 +147,11 @@ class WriteAttribute {
return cpp_type_;
}
CustomDataType custom_data_type() const
{
return custom_data_type_;
}
int64_t size() const
{
return size_;