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:
authorJacques Lucke <jacques@blender.org>2022-01-02 16:27:16 +0300
committerJacques Lucke <jacques@blender.org>2022-01-02 16:27:16 +0300
commit8be217ada5754b065723dc85c250cf2b60f14e2e (patch)
tree02e1c18407d37f05b11181c99df5a3830503ffad /source/blender/functions/FN_field.hh
parent4c46203cb52ed37694709cc42aa6ca76ed24fe7a (diff)
Geometry Nodes: add field node type for constants
It is common to have fields that contain a constant value. Before this commit, such constants were represented by operation nodes which don't have inputs. Having a special node type for constants makes working with them a bit cheaper. It also allows skipping some unnecessary processing when evaluating fields, because constant fields can be detected more easily. This commit also generalizes the concept of field node types a bit.
Diffstat (limited to 'source/blender/functions/FN_field.hh')
-rw-r--r--source/blender/functions/FN_field.hh46
1 files changed, 31 insertions, 15 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index a591aaed34a..b8cb05fecab 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -60,11 +60,21 @@ class FieldInput;
struct FieldInputs;
/**
+ * Have a fixed set of base node types, because all code that works with field nodes has to
+ * understand those.
+ */
+enum class FieldNodeType {
+ Input,
+ Operation,
+ Constant,
+};
+
+/**
* A node in a field-tree. It has at least one output that can be referenced by fields.
*/
class FieldNode {
private:
- bool is_input_;
+ FieldNodeType node_type_;
protected:
/**
@@ -76,14 +86,13 @@ class FieldNode {
std::shared_ptr<const FieldInputs> field_inputs_;
public:
- FieldNode(bool is_input);
+ FieldNode(FieldNodeType node_type);
virtual ~FieldNode() = default;
virtual const CPPType &output_cpp_type(int output_index) const = 0;
- bool is_input() const;
- bool is_operation() const;
+ FieldNodeType node_type() const;
bool depends_on_input() const;
const std::shared_ptr<const FieldInputs> &field_inputs() const;
@@ -267,6 +276,20 @@ class FieldInput : public FieldNode {
const CPPType &output_cpp_type(int output_index) const override;
};
+class FieldConstant : public FieldNode {
+ private:
+ const CPPType &type_;
+ void *value_;
+
+ public:
+ FieldConstant(const CPPType &type, const void *value);
+ ~FieldConstant();
+
+ const CPPType &output_cpp_type(int output_index) const override;
+ const CPPType &type() const;
+ const GPointer value() const;
+};
+
/**
* Keeps track of the inputs of a field.
*/
@@ -468,9 +491,7 @@ template<typename T> T evaluate_constant_field(const Field<T> &field)
template<typename T> Field<T> make_constant_field(T value)
{
- auto constant_fn = std::make_unique<fn::CustomMF_Constant<T>>(std::forward<T>(value));
- auto operation = std::make_shared<FieldOperation>(std::move(constant_fn));
- return Field<T>{GField{std::move(operation), 0}};
+ return make_constant_field(CPPType::get<T>(), &value);
}
GField make_constant_field(const CPPType &type, const void *value);
@@ -552,18 +573,13 @@ template<typename T> struct ValueOrField {
/** \name #FieldNode Inline Methods
* \{ */
-inline FieldNode::FieldNode(bool is_input) : is_input_(is_input)
-{
-}
-
-inline bool FieldNode::is_input() const
+inline FieldNode::FieldNode(const FieldNodeType node_type) : node_type_(node_type)
{
- return is_input_;
}
-inline bool FieldNode::is_operation() const
+inline FieldNodeType FieldNode::node_type() const
{
- return !is_input_;
+ return node_type_;
}
inline bool FieldNode::depends_on_input() const