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

type_callbacks.cc « intern « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5160432aea54dd2f0c658b7a46dd5a730a133998 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "NOD_node_tree_multi_function.hh"
#include "NOD_type_callbacks.hh"

namespace blender::nodes {

const CPPType *socket_cpp_type_get(const bNodeSocketType &stype)
{
  if (stype.get_cpp_type != nullptr) {
    return stype.get_cpp_type();
  }
  return nullptr;
}

std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype)
{
  const CPPType *cpp_type = socket_cpp_type_get(stype);
  if (cpp_type != nullptr) {
    return MFDataType::ForSingle(*cpp_type);
  }
  return {};
}

bool socket_is_mf_data_socket(const bNodeSocketType &stype)
{
  if (!socket_mf_type_get(stype).has_value()) {
    return false;
  }
  if (stype.expand_in_mf_network == nullptr && stype.get_cpp_value == nullptr) {
    return false;
  }
  return true;
}

bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value)
{
  if (socket.typeinfo->get_cpp_value != nullptr) {
    socket.typeinfo->get_cpp_value(socket, r_value);
    return true;
  }
  return false;
}

void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder)
{
  bNodeSocket &socket = builder.bsocket();
  if (socket.typeinfo->expand_in_mf_network != nullptr) {
    socket.typeinfo->expand_in_mf_network(builder);
  }
  else if (socket.typeinfo->get_cpp_value != nullptr) {
    const CPPType &type = *socket_cpp_type_get(*socket.typeinfo);
    void *buffer = builder.resource_scope().linear_allocator().allocate(type.size(),
                                                                        type.alignment());
    socket.typeinfo->get_cpp_value(socket, buffer);
    builder.set_constant_value(type, buffer);
  }
  else {
    BLI_assert_unreachable();
  }
}

}  // namespace blender::nodes