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

constants.h « multi_functions « intern « functions « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 257e0012b3c9cb53733d897655a9e5d91bef6c2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include "FN_multi_function.h"

#include <sstream>

#include "BLI_float3.h"
#include "BLI_hash.h"
#include "BLI_rand_cxx.h"

namespace FN {

/**
 * The value buffer passed into the constructor should have a longer lifetime than the
 * function itself.
 */
class MF_GenericConstantValue : public MultiFunction {
 private:
  const void *m_value;

 public:
  MF_GenericConstantValue(const CPPType &type, const void *value);
  void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override;

  static void value_to_string(std::stringstream &ss, const CPPType &type, const void *value);
};

/**
 * The passed in buffer has to have a longer lifetime than the function itself.
 */
class MF_GenericConstantVector : public MultiFunction {
 private:
  GenericArrayRef m_array;

 public:
  MF_GenericConstantVector(GenericArrayRef array);
  void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override;
};

template<typename T> class MF_ConstantValue : public MultiFunction {
 private:
  T m_value;

 public:
  MF_ConstantValue(T value) : m_value(std::move(value))
  {
    MFSignatureBuilder signature = this->get_builder("Constant " + CPP_TYPE<T>().name());
    std::stringstream ss;
    MF_GenericConstantValue::value_to_string(ss, CPP_TYPE<T>(), (const void *)&m_value);
    signature.single_output<T>(ss.str());
  }

  void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
  {
    MutableArrayRef<T> output = params.uninitialized_single_output<T>(0);

    mask.foreach_index([&](uint i) { new (output.begin() + i) T(m_value); });
  }
};

}  // namespace FN